Article 5S63C Little help with gnu make and .deps and rebuilding source in sub directories

Little help with gnu make and .deps and rebuilding source in sub directories

by
enine
from LinuxQuestions.org on (#5S63C)
Hoping someone with more make knowledge can help me out, I am using the make file example here https://en.wikibooks.org/wiki/OpenSC...omatic_targets

For those that don't know OpenSCAD, their module() is the same as a function in other languages. The make example here sets TARGETS to each module name with a make me comment inside it and then creates individual .scad files which display only that module. make then calls openscad with each new file and exports as a .stl file. So if my source like like this:
Code:module foo(){ //make me
module bar(){ //make me
module foobar(){make will provide a foo.scad, bar.scad, foo.stl.deps, bar.stl.deps, foo.stl and bar.stl.
Basically a pretty simple loop here to create the individual files and make them

Now I have several modules in my file and it gets messy having all these extra .scad, .stl.deps and .stl files so I should I'd just stick them all in a folder.
It was easy enough to add some variables and prefix the targets.

The problem I'm having is now make is rebuilding everything every time where before if they were all in one directory make would see the existing and up to date .scad files and skip them. The additional .scad files are there in the directory I put them so I'm guessing I'm missing something telling make where to find them. I've done a little building from source and / or editing other makes files if/when I run into an issue but haven't made one from scratch myself.

So question 1, is this the right approach to putting files in a directory
and question 2 where do I specify to make to find those files so it will see them and not rebuild.

Here is my file, though its slightly more complicated by duplicating a lot of it to make two loops, one for the original .stl and another to make any svg's I've called out in the comments, that part could probably be cleaned up too.

I first set the ROOT_DIR for that little bit I found on stackoverflow
Then set the STL_DIR and create it
Then set the DEPS_DIR and create it under STL_DIR
Then set STL_TARGETS and SVG_TARGETS like the original example
Then the .scad and .deps are created in DEPS_DIR
Finally call openscad to make the .stl in STL_DIR from the files in DEPS_DIR

Am I missing something in the .SECONDARY variable that should be pointing to the DEPS_DIR? I can't quite understand from the make documentation how .SECONDARY is working.

Thanks

Code:ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
#https://stackoverflow.com/questions/18136918/how-to-get-current-relative-directory-of-your-makefile

STL_DIR:=Case_stl
$(shell mkdir -p $(STL_DIR))

DEPS_DIR:=$(STL_DIR)/deps
$(shell mkdir -p $(DEPS_DIR))

# match "module foobar() { // `make` stl"
STL_TARGETS=$(shell sed '/^module [a-zA-Z0-9_-]*().*make..\?stl.*$$/!d;s/module //;s/().*/.stl/' Case.scad)
# match "module foobar() { // `make` svg"
SVG_TARGETS=$(shell sed '/^module [a-zA-Z0-9_-]*().*make..\?svg.*$$/!d;s/module //;s/().*/.svg/' Case.scad)

all: stl svg

stl: ${STL_TARGETS}

# auto-generated .scad files with .deps make make re-build always. keeping the
# scad files solves this problem. (explanations are welcome.)
.SECONDARY: $(shell echo "${STL_TARGETS}" | sed 's/\.stl/.scad/g')

# explicit wildcard expansion suppresses errors when no files are found
include $(wildcard $(DEPS_DIR)/*.deps)

%.scad:
echo -ne 'use <$(ROOT_DIR)/Case.scad>\n$*();' > $(DEPS_DIR)/$@

%.stl: %.scad
openscad -m make -o $(STL_DIR)/$@ -d $(DEPS_DIR)/$@.deps -D 'makestl=true' $(DEPS_DIR)/$<

svg: ${SVG_TARGETS}

# auto-generated .scad files with .deps make make re-build always. keeping the
# scad files solves this problem. (explanations are welcome.)
.SECONDARY: $(shell echo "${SVG_TARGETS}" | sed 's/\.svg/.scad/g')

# explicit wildcard expansion suppresses errors when no files are found
include $(wildcard *.deps)

%.scad:
echo -ne 'use <$(ROOT_DIR)/Case.scad>\n$*();' > $(DEPS_DIR)/$@

%.svg: %.scad
openscad -m make -o $(ROOT_DIR)/$@ -d $(DEPS_DIR)/$@.deps -D $(DEPS_DIR)/$<latest?d=yIl2AUoC8zA latest?i=dUGjU78OSno:QMXSxSAJqIo:F7zBnMy latest?i=dUGjU78OSno:QMXSxSAJqIo:V_sGLiP latest?d=qj6IDK7rITs latest?i=dUGjU78OSno:QMXSxSAJqIo:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments