Skip to content

Commit

Permalink
Integrated Asymptote compilation into makefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feuermurmel committed Aug 6, 2015
1 parent e2d4776 commit 4a103f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,4 +3,5 @@

/src/**/*.dxf
/src/**/*.stl
/src/**/*.pdf
/src/**/*.d
32 changes: 24 additions & 8 deletions Makefile
Expand Up @@ -2,16 +2,18 @@
INKSCAPE := inkscape
OPENSCAD := openscad
PYTHON := python2
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 :=

# Non-file goals.
.PHONY: all clean generated dxf stl
.PHONY: all clean generated dxf stl asy pdf

# Goal to build Everything. Also generates files which aren't compiled to anything else. Deined here to make it the default goal.
all: generated dxf stl
all: generated dxf stl asy pdf

# Include the configuration files.
-include config.mk settings.mk
Expand All @@ -26,22 +28,27 @@ PYTHON_CMD := PYTHONPATH="support:$$PYTHONPATH" $(PYTHON)
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 -not \( \( -name '.*' -or -name '* *' \) -prune \))
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)))

# Makefiles which are generated while compiling to record dependencies.
DEPENDENCY_FILES := $(foreach i,.scad,$(patsubst %$i,%.d,$(filter %$i,$(COMPILED_SRC_FILES))))

# STL files produced from OpenSCAD files.
SCAD_STL_FILES := $(patsubst %.scad,%.stl,$(filter-out $(FLAT_SCAD_FILES),$(filter %.scad,$(COMPILED_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))))

# 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,$(COMPILED_SRC_FILES))))
SVG_DXF_FILES := $(filter-out $(SCAD_DXF_FILES),$(patsubst %.svg,%.dxf,$(filter %.svg,$(filter-out $(ASY_SVG_FILES),$(COMPILED_SRC_FILES)))))

SVG_ASY_FILES := $(patsubst %.svg,%.asy,$(filter %.svg,$(filter $(ASY_SVG_FILES),$(COMPILED_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))))

# Makefiles which are generated while compiling to record dependencies.
DEPENDENCY_FILES := $(foreach i,.scad,$(patsubst %$i,%.d,$(filter %$i,$(COMPILED_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)
Expand All @@ -51,17 +58,22 @@ GLOBAL_DEPS := Makefile $(wildcard config.mk settings.mk)

# Everything^-1.
clean:
rm -rf $(GENERATED_FILES) $(SVG_DXF_FILES) $(SCAD_DXF_FILES) $(SCAD_STL_FILES) $() $(DEPENDENCY_FILES)
rm -rf $(GENERATED_FILES) $(SVG_DXF_FILES) $(SCAD_DXF_FILES) $(SCAD_STL_FILES) $(SVG_ASY_FILES) $(ASY_PDF_FILES) $(DEPENDENCY_FILES)

# Goals to build the project up to a specific step.
generated: $(GENERATED_FILES)
dxf: $(SVG_DXF_FILES) $(SCAD_DXF_FILES)
stl: $(SCAD_STL_FILES)
pdf: $(ASY_PDF_FILES)
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 $< $@

$(SVG_ASY_FILES): %.asy: %.svg $(GLOBAL_DEPS)
$(PYTHON_CMD) -m inkscape $< $@

# 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
Expand All @@ -70,6 +82,10 @@ $(SCAD_DXF_FILES): %.dxf: %.scad $(GLOBAL_DEPS) | $(SCAD_ORDER_DEPS)
$(SCAD_STL_FILES): %.stl: %.scad $(GLOBAL_DEPS) | $(SCAD_ORDER_DEPS)
$(PYTHON_CMD) -m openscad $< $@ $*.d

# Rule to export an SVG file to an Asymptote file.
$(ASY_PDF_FILES): %.pdf: %.asy $(GLOBAL_DEPS) $(COMPILED_SRC_FILES) $(SVG_ASY_FILES)
ASYMPTOTE_DIR=$$(dirname $@) $(ASYMPTOTE) -f pdf -o $@ $<

# Rule for automaticaly generated OpenSCAD files.
$(GENERATED_FILES): generate_sources.sh $(GLOBAL_DEPS)
./generate_sources.sh $@
Expand Down

0 comments on commit 4a103f6

Please sign in to comment.