A Makefile for OpenSCAD projects
When working with OpenSCAD to generate models for 3D printing, I find it convenient to be able to build .stl and .gcode files from the command line, expecially in batch, so I've started writing a Makefile, improving it and making it more generic in subsequent iterations; this page hosts my current version.
Most of my projects use the following directory structure.
- my_project/conf/basic.ini…
- slic3r configuration files
- my_project/src/object1.scad, my_project/src/object2.scad…
- models that will be exported
- my_projects/src/lib/library1.scad, my_projects/src/lib/library2.scad…
- OpenSCAD files that don't correnspond to a single object, included / used in the files above.
- my_project/Makefile
- the Makefile shown below.
Running make will generate stl files for all of the models; make gcode adds .gcode files using slic3r; make build/object1.stl and make build/object1.gcode also work, when just one model is needed.
# Copyright 2015 Elena Grandi # This work is free. You can redistribute it and/or modify it under the # terms of the Do What The Fuck You Want To Public License, Version 2, # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. BUILDDIR = build CONFDIR = conf SRCDIR = src SLIC3R = slic3r VPATH = $(SRCDIR):$(BUILDDIR) STL_TARGETS = $(patsubst $(SRCDIR)/%.scad,$(BUILDDIR)/%.stl,$(wildcard $(SRCDIR)/*.scad)) GCODE_TARGETS = $(patsubst $(SRCDIR)/%.scad,$(BUILDDIR)/%.gcode,$(wildcard $(SRCDIR)/*.scad)) .PHONY: all gcode clean all: $(STL_TARGETS) gcode: $(GCODE_TARGETS) $(BUILDDIR)/%.stl: %.scad $(SRCDIR)/lib/* mkdir -p ${BUILDDIR} openscad -o $@ $< $(BUILDDIR)/%.gcode: %.stl ${CONFDIR}/basic.ini ${SLIC3R} --load ${CONFDIR}/basic.ini $< clean: rm -f ${BUILDDIR}/*.stl ${BUILDDIR}/*.gcode
This Makefile is released under the WTFPL:
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO.