Elena ``of Valhalla''

A Makefile for OpenSCAD projects

Elena ``of Valhalla'' at

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; I've added a page on my website to 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.

Christopher Allan Webber, olm-e, Charles Stanhope likes this.

I think it's a great idea for more free culture projects to include "binary format" builds from the command line.

Christopher Allan Webber at 2015-07-23T20:53:14Z

X11R5 likes this.

Being exposed to Debian's policies on having sources for everything, including non-software, helped.


Sometimes it's not easy: e.g. when I need a 2d shape in OpenSCAD I usually prepare it in inkscape as SVG, but then the conversion from an editable shape to a DXF involves a few manual steps, so I usually include both in the repo. Luckily this particular case will be solved with support for SVG in OpenSCAD itself, but I can think a few other examples.

Elena ``of Valhalla'' at 2015-07-24T08:20:04Z