summaryrefslogtreecommitdiff
path: root/generate_sources.sh
blob: 4a0576040c69886a247a30f2818a863433c515f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/env bash

set -e -o pipefail

current_file_name=$1

# This function should be called for each generated file with the file's name as the first argument and the command to call to produce the file's content as the remaining arguments.
function generate_file() {
	file_name=$1
	shift
	generate_command=("$@")
	
	if ! [ "$current_file_name" ]; then
		echo "$file_name"
	elif [ "$current_file_name" == "$file_name" ]; then
		mkdir -p "$(dirname "$file_name")"
		"${generate_command[@]}" > "$file_name"
	fi
}

# Call generate_file for each file to be generated.
for i in {1..5}; do
	size=$[ $i * 10 ]
	generate_file "src/generated/cube_$size.scad" echo "cube($size);"
done