summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile60
-rw-r--r--support/openscad/__main__.py14
2 files changed, 49 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 51108ab..9b1f796 100644
--- a/Makefile
+++ b/Makefile
@@ -5,21 +5,27 @@ PYTHON := python2
# Settings affecting the compiled results. You can overwrite these in a file called settings.mk in the same directory as this makefile. See readme.creole.
DXF_FLATNESS := 0.1
+FLAT_SCAD_FILES :=
+# Include the configuration files.
+-include config.mk settings.mk
+
+# Export variables used by the Python scripts.
export INKSCAPE OPENSCAD DXF_FLATNESS
+# Command to run the Python scripts.
PYTHON_CMD := PYTHONPATH="support:$$PYTHONPATH" $(PYTHON)
-# All visible files in the src directory. Ignore files whose names contain spaces.
-SRC_FILES := $(shell find src -not \( \( -name '.*' -or -name '* *' \) -prune \))
-SRC_SCAD_FILES := $(filter %.scad,$(SRC_FILES))
-SRC_SVG_FILES := $(filter %.svg,$(SRC_FILES))
-
# Run generate_scad.sh to get the names of all OpenSCAD files that should be generated using that same script.
GENERATED_FILES := $(addsuffix .scad,$(basename $(shell ./generate_sources.sh)))
GENERATED_SVG_FILES := $(filter %.svg, $(GENERATED_FILES))
GENERATED_SCAD_FILES := $(filter %.scad, $(GENERATED_FILES))
+# All visible files in the src directory. Ignore files whose names contain spaces. Also ignore generated files.
+SRC_FILES := $(filter-out $(GENERATED_FILES),$(shell find src -not \( \( -name '.*' -or -name '* *' \) -prune \)))
+SRC_SCAD_FILES := $(filter %.scad,$(SRC_FILES))
+SRC_SVG_FILES := $(filter %.svg,$(SRC_FILES))
+
# Source SVG files.
SVG_FILES := $(SRC_SVG_FILES) $(GENERATED_SVG_FILES)
@@ -29,38 +35,54 @@ COMPILED_SCAD_FILES := $(foreach i, $(SRC_SCAD_FILES) $(GENERATED_SCAD_FILES),$(
# Makefiles which are generated while compiling to record dependencies.
DEPENDENCY_FILES := $(patsubst %.scad,%.d,$(COMPILED_SCAD_FILES))
-# All files that may be generated from the source files.
-STL_FILES := $(patsubst %.scad,%.stl,$(COMPILED_SCAD_FILES))
-DXF_FILES := $(patsubst %.svg,%.dxf,$(SVG_FILES))
+# STL files produced from OpenSCAD files.
+SCAD_STL_FILES := $(patsubst %.scad,%.stl,$(filter-out $(FLAT_SCAD_FILES),$(COMPILED_SCAD_FILES)))
+
+# DXF files produced from OpenSCAD fiels. Ignore non-OpenSCAD files in FLAT_SCAD_FILES.
+SCAD_DXF_FILES := $(patsubst %.scad,%.dxf,$(filter $(FLAT_SCAD_FILES),$(COMPILED_SCAD_FILES)))
+
+# DXF files produced from SVG files. Ignore an SVG file if the same DXF file can also be produced from an OpenSCAD file. This is just to get reproducable builds without aborting it.
+SVG_DXF_FILES := $(filter-out $(SCAD_DXF_FILES),$(patsubst %.svg,%.dxf,$(SVG_FILES)))
+
+# Files that may be used from OpenSCAD files and thus must exist before OpenSCAD is called.
+SCAD_ORDER_DEPS := $(SVG_DXF_FILES) $(GENERATED_FILES)
# Dependencies which may affect the result of all build products.
GLOBAL_DEPS := Makefile $(wildcard config.mk settings.mk)
+# Make the next goal (`all`) the default goal.
+.DEFAULT_GOAL :=
+
+# Non-file goals.
.PHONY: all clean generated dxf stl
-# Everything. Also generates files which aren't compiled to anything else.
+# Goal to build Everything. Also generates files which aren't compiled to anything else.
all: generated dxf stl
# Everything^-1.
clean:
- rm -rf $(GENERATED_FILES) $(DXF_FILES) $(STL_FILES) $(DEPENDENCY_FILES)
+ rm -rf $(GENERATED_FILES) $(SVG_DXF_FILES) $(SCAD_DXF_FILES) $(SCAD_STL_FILES) $(DEPENDENCY_FILES)
-# Targets to build the project up to a specific step.
+# Goals to build the project up to a specific step.
generated: $(GENERATED_FILES)
-dxf: $(DXF_FILES)
-stl: $(STL_FILES)
-
-# Include the local configuration file and the dependency files. Needs to be included after the `all' target has been defined.
--include config.mk settings.mk $(DEPENDENCY_FILES)
+dxf: $(SVG_DXF_FILES) $(SCAD_DXF_FILES)
+stl: $(SCAD_STL_FILES)
# Rule to convert an SVG file to a DXF file.
-%.dxf: %.svg $(GLOBAL_DEPS)
+$(SVG_DXF_FILES): %.dxf: %.svg $(GLOBAL_DEPS)
$(PYTHON_CMD) -m dxf_export $< $@
-# Rule to compile an OpenSCAD file to an STL file. We require all DXF files to exist before an OpenSCAD file can be used to generate an STL file. Additional dependencies are read from the included makefiles generated during compiling.
-%.stl: %.scad $(GLOBAL_DEPS) | $(DXF_FILES)
+# Rule to compile an OpenSCAD file to a DXF file.
+$(SCAD_DXF_FILES): %.dxf: %.scad $(GLOBAL_DEPS) | $(SCAD_ORDER_DEPS)
+ $(PYTHON_CMD) -m openscad $< $@ $*.d
+
+# Rule to compile an OpenSCAD file to an STL file.
+$(SCAD_STL_FILES): %.stl: %.scad $(GLOBAL_DEPS) | $(SCAD_ORDER_DEPS)
$(PYTHON_CMD) -m openscad $< $@ $*.d
# Rule for automaticaly generated OpenSCAD files.
$(GENERATED_FILES): generate_sources.sh $(GLOBAL_DEPS)
./generate_sources.sh $@
+
+# Include dependency files produced by an earlier build.
+-include $(DEPENDENCY_FILES)
diff --git a/support/openscad/__main__.py b/support/openscad/__main__.py
index 3c103e5..bc1135d 100644
--- a/support/openscad/__main__.py
+++ b/support/openscad/__main__.py
@@ -21,14 +21,16 @@ def main(in_path, out_path, deps_path):
temp_mk_path = os.path.join(temp_dir, 'mk')
temp_files_path = os.path.join(temp_dir, 'files')
- # OpenSCAD requires the output file name to end in .stl
- temp_stl_path = os.path.join(temp_dir, 'out.stl')
+ _, out_ext = os.path.splitext(out_path)
- _openscad(in_path, temp_stl_path, temp_deps_path)
+ # OpenSCAD requires the output file name to end in .stl or .dxf.
+ temp_out_path = os.path.join(temp_dir, 'out' + out_ext)
+
+ _openscad(in_path, temp_out_path, temp_deps_path)
mk_content = '%:; echo "$@" >> {}'.format(util.bash_escape_string(temp_files_path))
- # Use make to parse the dependency makefile written by OpenSCAD
+ # Use make to parse the dependency makefile written by OpenSCAD.
util.write_file(temp_mk_path, mk_content.encode())
util.command(['make', '-s', '-B', '-f', temp_mk_path, '-f', temp_deps_path])
@@ -36,11 +38,11 @@ def main(in_path, out_path, deps_path):
deps = set(map(relpath, util.read_file(temp_files_path).decode().splitlines()))
# Relative paths to all files that should not appear in the dependency makefile.
- ignored_files = set(map(relpath, [in_path, temp_deps_path, temp_mk_path, temp_stl_path]))
+ ignored_files = set(map(relpath, [in_path, temp_deps_path, temp_mk_path, temp_out_path]))
# Write output files.
_write_dependencies(deps_path, relpath(out_path), deps - ignored_files)
- os.rename(temp_stl_path, out_path)
+ os.rename(temp_out_path, out_path)
try: