summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorMichael Schwarz <michi.schwarz@gmail.com>2015-08-07 01:56:28 +0200
committerMichael Schwarz <michi.schwarz@gmail.com>2015-08-07 02:03:38 +0200
commit3971ddf2561a11d70d319177796e40662b67ce86 (patch)
tree56a4d1e220cd3b6d0fe9146b774290c63f61fc76 /Makefile
parent6c1fefff1b54c150dbdb6aeff5f4e7e5940433e8 (diff)
downloadpogojig-3971ddf2561a11d70d319177796e40662b67ce86.tar.gz
pogojig-3971ddf2561a11d70d319177796e40662b67ce86.tar.bz2
pogojig-3971ddf2561a11d70d319177796e40662b67ce86.zip
Reworked make file.
This time to remove duplicate functionality in generating list of different products.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile45
1 files changed, 25 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index d1bfa08..9aaf797 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ ASYMPTOTE := asy
# 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 :=
-ASY_SVG_FILES :=
+ASYMPTOTE_EXPORTED_SVG_FILES :=
# Non-file goals.
.PHONY: all clean generated dxf stl asy pdf
@@ -18,47 +18,52 @@ all: generated dxf stl asy pdf
# 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)
+INKSCAPE_CMD := INKSCAPE=$(INKSCAPE) DXF_FLATNESS=$(DXF_FLATNESS) $(PYTHON_CMD) -m inkscape
+OPENSCAD_CMD := OPENSCAD=$(OPENSCAD) $(PYTHON_CMD) -m openscad
+ASYMPTOTE_CMD := ASYMPTOTE=$(ASYMPTOTE) $(PYTHON_CMD) -m asymptote
+
+# Function with arguments (ext, subst_ext, names).
+# Takes a list of file names and returns all elements whose basename do not start with a `_' and which have extension ext. The returned names will have their extension replaced by subst_ext.
+filter_compiled = $(foreach i,$(patsubst %$1,%$2,$(filter %$1,$3)),$(if $(filter-out _%,$(notdir $i)),$i))
-# Run generate_scad.sh to get the names of all OpenSCAD files that should be generated using that same script.
+# Run generate_scad.sh to get the names of all files that should be generated using that same script.
GENERATED_FILES := $(addsuffix .scad,$(basename $(shell ./generate_sources.sh)))
# All visible files in the src directory that either exist or can be generated. Ignore files whose names contain spaces.
SRC_FILES := $(GENERATED_FILES) $(shell find src -type f -not \( \( -name '.*' -or -name '* *' \) -prune \))
-# Source files whose names start with `_' are not compiled directly but may be used from other source files.
-COMPILED_SRC_FILES := $(foreach i,$(SRC_FILES),$(if $(filter-out _%,$(notdir $(i))),$(i)))
-
# STL files produced from OpenSCAD files.
-SCAD_STL_FILES := $(patsubst %.scad,%.stl,$(filter-out $(FLAT_SCAD_FILES),$(filter %.scad,$(COMPILED_SRC_FILES))))
+SCAD_STL_FILES := $(call filter_compiled,.scad,.stl,$(filter-out $(FLAT_SCAD_FILES),$(SRC_FILES)))
# DXF files produced from OpenSCAD fiels. Ignore non-OpenSCAD files in FLAT_SCAD_FILES.
-SCAD_DXF_FILES := $(patsubst %.scad,%.dxf,$(filter %.scad,$(filter $(FLAT_SCAD_FILES),$(COMPILED_SRC_FILES))))
+SCAD_DXF_FILES := $(call filter_compiled,.scad,.dxf,$(filter $(FLAT_SCAD_FILES),$(SRC_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,$(filter %.svg,$(filter-out $(ASY_SVG_FILES),$(COMPILED_SRC_FILES)))))
+# DXF files produced from SVG files. This excludes SVG files that are exported to Asymptote Files. Also, ignores 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),$(call filter_compiled,.svg,.dxf,$(filter-out $(ASYMPTOTE_EXPORTED_SVG_FILES),$(SRC_FILES))))
-SVG_ASY_FILES := $(patsubst %.svg,%.asy,$(filter %.svg,$(filter $(ASY_SVG_FILES),$(COMPILED_SRC_FILES))))
+# Asymptote files produced from SVG files.
+SVG_ASY_FILES := $(call filter_compiled,.svg,.asy,$(filter $(ASYMPTOTE_EXPORTED_SVG_FILES),$(SRC_FILES)))
# PDF files which can be generated from Asymptote files. We exclude SVG_ASY_FILES because they don't contain any drawing primitives and thus won't produce a PDF.
-ASY_PDF_FILES := $(patsubst %.asy,%.pdf,$(filter %.asy,$(filter-out $(SVG_ASY_FILES), $(COMPILED_SRC_FILES))))
+ASY_PDF_FILES := $(call filter_compiled,.asy,.pdf,$(filter-out $(SVG_ASY_FILES),$(SRC_FILES)))
# Makefiles which are generated while compiling to record dependencies.
-DEPENDENCY_FILES := $(foreach i,.scad,$(patsubst %$i,%.d,$(filter %$i,$(COMPILED_SRC_FILES))))
+DEPENDENCY_FILES := $(foreach i,.scad,$(call filter_compiled,$i,.d,$(filter-out $(SVG_ASY_FILES),$(SRC_FILES))))
# Files that may be used from OpenSCAD files and thus must exist before OpenSCAD is called.
SCAD_ORDER_DEPS := $(filter %.scad %.dxf,$(GENERATED_FILES)) $(SVG_DXF_FILES)
+# Files that may be used from Asymptote files.
+ASY_DEPS := $(filter %.asy,$(GENERATED_FILES)) $(SVG_ASY_FILES)
+
# Dependencies which may affect the result of all build products.
GLOBAL_DEPS := Makefile $(wildcard config.mk settings.mk)
# Everything^-1.
clean:
- rm -rf $(GENERATED_FILES) $(SVG_DXF_FILES) $(SCAD_DXF_FILES) $(SCAD_STL_FILES) $(SVG_ASY_FILES) $(ASY_PDF_FILES) $(DEPENDENCY_FILES)
+ rm -rf $(SVG_DXF_FILES) $(SCAD_DXF_FILES) $(SCAD_STL_FILES) $(SVG_ASY_FILES) $(ASY_PDF_FILES) $(GENERATED_FILES) $(DEPENDENCY_FILES)
# Goals to build the project up to a specific step.
generated: $(GENERATED_FILES)
@@ -69,18 +74,18 @@ asy: $(SVG_ASY_FILES)
# Rule to convert an SVG file to a DXF file.
$(SVG_DXF_FILES): %.dxf: %.svg $(GLOBAL_DEPS)
- $(PYTHON_CMD) -m inkscape $< $@
+ $(INKSCAPE_CMD) $< $@
$(SVG_ASY_FILES): %.asy: %.svg $(GLOBAL_DEPS)
- $(PYTHON_CMD) -m inkscape $< $@
+ $(INKSCAPE_CMD) $< $@
# 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
+ $(OPENSCAD_CMD) $< $@ $*.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
+ $(OPENSCAD_CMD) $< $@ $*.d
# Rule to export an SVG file to an Asymptote file.
$(ASY_PDF_FILES): %.pdf: $(ASY_DEPS) $(GLOBAL_DEPS)