+# reprap-objects Makefile, reuseable parts
+#
+# Build scripts for various 3D designs
+# Copyright 2012-2016 Ian Jackson
+#
+# This work is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This work is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this work. If not, see <http://www.gnu.org/licenses/>.
+
+
+HRR=/home/reprap
+SLIC3R=$(HRR)/Slic3r/bin/slic3r
+M4=m4
+SKEINFORGE=python $(HRR)/reprappro-software.git/skeinforge/skeinforge_application/skeinforge_utilities/skeinforge_craft.py
+
+CWD := $(shell pwd)
+PLAY ?= $(CWD)
+
+CONFIG=$(PLAY)/slic3r-config.ini
+
+AUTO_TOPLEVELS := $(foreach m,$(USING_AUTOS),$(shell $(PLAY)/toplevel-find $m))
+
+AUTO_INCS += funcs.scad
+
+default: autoincs scads
+
+$(shell set -xe; $(PLAY)/commitid.scad.pl >commitid.scad.tmp; cmp commitid.scad.tmp commitid.scad || mv -f commitid.scad.tmp commitid.scad )
+
+autoincs: $(AUTO_INCS)
+scads: $(addsuffix .auto.scad, $(AUTO_TOPLEVELS))
+stls: $(addsuffix .auto.stl, $(AUTO_TOPLEVELS))
+
+%.auto.scads: %.scad
+ $(MAKE) $(addsuffix .auto.scad, $(shell $(PLAY)/toplevel-find $*))
+%.auto.stls:
+ $(MAKE) $(addsuffix .auto.stl, $(shell $(PLAY)/toplevel-find $*))
+
+-include .*.d
+
+%.stl: %.scad $(AUTO_INCS)
+ openscad -d .$@.d.tmp -o $*.tmp.stl $<
+ @rm -f $@
+ @sed -e 's/\.tmp\.stl:/.stl:/' <.$@.d.tmp >.$@.d
+ @rm .$@.d.tmp
+ mv -f $*.tmp.stl $@
+
+AUTOBASE=$(shell echo $(1) | perl -pe 's/,\w+\.auto$$//')
+
+%.gcode: %.stl $(CONFIG)
+ $(SLIC3R) --load $(CONFIG) \
+ --ignore-nonexistent-config \
+ --load $(call AUTOBASE,$*).slic3r \
+ --load $*.slic3r \
+ --output $@.tmp $<
+ @mv -f $@.tmp $@
+
+%.gcode-sd: %.gcode
+ mount /media/sd
+ rm -f /media/sd/JOB.* /media/sd/job.*
+ cp $^ /media/sd/JOB.G
+ sleep 0.5
+ umount /media/sd
+
+%: %.cpp
+ cpp -nostdinc -P <$< >$@.tmp && mv -f $@.tmp $@
+
+funcs.scad:
+
+#%.gcode: %.stl
+# $(SKEINFORGE) $<
+
+%.gcode: manual-gcode-generator %.m-g
+ $(PLAY)/$^ >$@.tmp && mv -f $@.tmp $@
+
+%.dxf: %.eps
+ pstoedit -dt -f "dxf: -polyaslines -mm" $< $@
+
+%: %.pl
+ ./$< >$@.tmp && mv -f $@.tmp $@
+
+%: %.m4
+ $(M4) -P >$@.tmp $< && mv -f $@.tmp $@
+
+.PRECIOUS: %.auto.scad
+%.auto.scad: $(PLAY)/toplevel-make Makefile $(PLAY)/toplevel-find
+ @echo ' write $@'
+ $< $@ >$@.tmp
+ @mv -f $@.tmp $@
+
+.PRECIOUS: %.stl %.gcode %.eps %.dxf
+
+clean:
+ rm -f *~ *.stl *.auto.scad *.gcode .*.d $(AUTO_INCS)
+