Skip to content

Instantly share code, notes, and snippets.

@speshak
Created January 20, 2021 13:23
Show Gist options
  • Save speshak/1da7fac746fc58ab5d9168f349ec5bde to your computer and use it in GitHub Desktop.
Save speshak/1da7fac746fc58ab5d9168f349ec5bde to your computer and use it in GitHub Desktop.
OScad Makefile
####################################
# Common Makefile snippets
#
# Most simple projects can just include this file and supply nothing else
# More complex projects may need to define additional targets
####################################
oscad := /Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD
sources=$(shell find . -type f -name \*.scad -not -name \*.inc.scad)
stls=$(patsubst %.scad,%.stl,$(sources))
pngs=$(patsubst %.scad,%.png,$(sources))
# All builds will get the current revision, it's up to the models to do something with it
GIT_VERSION := $(shell git describe --tags --always)
all: $(stls)
.PHONY: pngs
pngs: $(pngs)
.PHONY: clean
clean:
-rm $(stls) $(pngs) *.d
%.stl: %.scad
$(oscad) -o $@ -D 'git_rev="$(GIT_VERSION)"' $<
# Create PNG of object
%.png: %.scad
$(oscad) -o $@ -D 'git_rev="$(GIT_VERSION)"' --autocenter --viewall --colorscheme "Tomorrow Night" --imgsize 1024,1024 $<
## Search for scad includes
# This builds a .d file for each scad that lists all of the files that the scad
# includes. This does not follow second level deps.
%.d: %.scad
echo "$(patsubst %.scad,%.stl,$<) $@: $(shell perl -n -e 'print "$$1 " if /^\s*include\s+\<(.*)\>;/' $<)" > $@
include $(sources:.scad=.d)
include ../common.mk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment