Merge commit '9da7f66fee' into no-examples

This commit is contained in:
Michael Schwarz 2014-12-04 10:19:29 +01:00
commit bf0c5f26a9
4 changed files with 37 additions and 11 deletions

3
.gitignore vendored
View file

@ -2,3 +2,6 @@
*.pyc
*.dxf
*.stl
# Generated files
/src/generated/

View file

@ -21,12 +21,12 @@ COMPILED_SCAD_FILES := $(filter-out $(LIBRARY_SCAD_FILES),$(SCAD_FILES))
STL_FILES := $(patsubst %.scad,%.stl,$(COMPILED_SCAD_FILES))
DXF_FILES := $(patsubst %.svg,%.dxf,$(SVG_FILES))
# Everything.
all: $(STL_FILES)
# Everything. Also generates files which aren't compiled to anything else.
all: $(STL_FILES) $(GENERATED_FILES)
# Everything^-1.
clean:
rm -rf $(DXF_FILES) $(STL_FILES) $(GENERATED_SCAD_FILES)
rm -rf $(DXF_FILES) $(STL_FILES) $(GENERATED_FILES)
# Needs to be included after target all has been defined.
-include config.mk
@ -44,4 +44,4 @@ $(foreach i,$(COMPILED_SCAD_FILES),$(eval $(i): $(filter $(dir $(i))%,$(LIBRARY_
# Rule for automaticlaly generated OpenSCAD files.
$(GENERATED_FILES): generate_sources.sh
./generate_sources.sh $@ > $@
./generate_sources.sh $@

View file

@ -1,9 +1,25 @@
#! /usr/bin/env bash
if [ "$1" ]; then
# Print the content of the generated source named $1 here.
true
else
# Print a list of names of the files that should be generated using this script here.
true
fi
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

View file

@ -41,6 +41,13 @@ use <filename>
Please see the [http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Print_version|manual] for details.
== Generating Source files
This template allows files to be generated automatically. Currently supported for inclusion in the build proess are OpenSCAD and SVG files. This works by editing the `generate_sources.sh` script, which is run by the Makefile was changed.
The script should call the function `generate_file()` once for each file which should be generated. The first argument to the function should be the name of the file to be generated, the remaining arguments a command, which when run should output the file's content to standard output. How this function is called is up to the scrtip and may e.g. be done from a `for` loop or while iterating over a set of other source files.
== Compiling
To compile the whole project, run `make` from the directory in which this readme is. This will process all necessary SVG files and produce an STL file for each OpenSCAD source file. Individual files may be created or updated by passing their names to the make command, as ussual.