summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile30
1 files changed, 15 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 5a77c48..c91ea47 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,10 @@ INKSCAPE ?= inkscape
OPENSCAD ?= openscad
PYTHON ?= python2
+PYTHON_CMD := PYTHONPATH="support:$$PYTHONPATH" $(PYTHON)
+
# Used by dxf_export/main.sh
-export INKSCAPE
+export INKSCAPE OPENSCAD
# 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)))
@@ -14,34 +16,32 @@ GENERATED_SCAD_FILES := $(filter %.scad, $(GENERATED_FILES))
SVG_FILES := $(shell find src -name '*.svg') $(GENERATED_SVG_FILES)
# Only OpenSCAD files whose names do not start with `_' are compiled to STL.
-SCAD_FILES := $(shell find src -name '*.scad') $(GENERATED_SCAD_FILES)
-LIBRARY_SCAD_FILES := $(foreach i,$(SCAD_FILES),$(if $(filter _%,$(notdir $(i))),$(i)))
-COMPILED_SCAD_FILES := $(filter-out $(LIBRARY_SCAD_FILES),$(SCAD_FILES))
+COMPILED_SCAD_FILES := $(foreach i,$(shell find src -name '*.scad') $(GENERATED_SCAD_FILES),$(if $(filter-out _%,$(notdir $(i))),$(i)))
+
+# 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))
# Everything. Also generates files which aren't compiled to anything else.
-all: $(STL_FILES) $(GENERATED_FILES)
+all: $(GENERATED_FILES) $(DXF_FILES) $(STL_FILES)
# Everything^-1.
clean:
- rm -rf $(DXF_FILES) $(STL_FILES) $(GENERATED_FILES)
-
-# Needs to be included after target all has been defined.
--include config.mk
+ rm -rf $(GENERATED_FILES) $(DXF_FILES) $(STL_FILES) $(DEPENDENCY_FILES)
-# Assume that any compiled OpenSCAD file may depend on any non-compiled OpenSCAD file in the same directory.
-$(foreach i,$(COMPILED_SCAD_FILES),$(eval $(i): $(filter $(dir $(i))%,$(LIBRARY_SCAD_FILES) $(DXF_FILES))))
+# Include the local configuration file and the dependency files. Needs to be included after the `all' target has been defined.
+-include config.mk $(DEPENDENCY_FILES)
# Rule to convert an SVG file to a DXF file.
%.dxf: %.svg
- PYTHONPATH="support:$$PYTHONPATH" $(PYTHON) -m dxf_export $< $@
+ $(PYTHON_CMD) -m dxf_export $< $@
-# Rule to compile an OpenSCAD file to an STL file.
-%.stl: %.scad
- $(OPENSCAD) -o $@ $<
+# 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 | $(DXF_FILES)
+ $(PYTHON_CMD) -m openscad $< $@ $*.d
# Rule for automaticlaly generated OpenSCAD files.
$(GENERATED_FILES): generate_sources.sh