LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-21-2021, 10:56 AM   #1
enine
Senior Member
 
Registered: Nov 2003
Distribution: Slackʍɐɹǝ
Posts: 1,486
Blog Entries: 4

Rep: Reputation: 282Reputation: 282Reputation: 282
Little help with gnu make and .deps and rebuilding source in sub directories


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)/$<
 
Old 11-21-2021, 03:24 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
1. Shouldn't this
Quote:
Originally Posted by enine View Post
Code:
include $(wildcard *.deps)
be
Code:
include $(wildcard $(DEPS_DIR)/*.deps)

2. Why're you creating the intermediate .scad files in DEPS_DIR?
Quote:
Originally Posted by enine View Post
Code:
%.scad:
	echo -ne 'use <$(ROOT_DIR)/Case.scad>\n$*();' > $(DEPS_DIR)/$@
Shouldn't they be created in the current directory? I mean
Code:
openscad -d $(DEPS_DIR)/$@.deps
generates dependency files for modules from the current directory and puts them to DEPS_DIR. The make rules in those .deps files will still search for modules in the current directory. See discussion of automatic prerequisites in the GNU make manual. Instead of cc -M you have openscad -d here, but the principle is the same.

Last edited by shruggy; 11-21-2021 at 03:54 PM.
 
Old 11-22-2021, 06:05 AM   #3
enine
Senior Member
 
Registered: Nov 2003
Distribution: Slackʍɐɹǝ
Posts: 1,486

Original Poster
Blog Entries: 4

Rep: Reputation: 282Reputation: 282Reputation: 282
Hey, Thanks for the help.

Quote:
Originally Posted by shruggy View Post
1. Shouldn't this

be
Code:
include $(wildcard $(DEPS_DIR)/*.deps)
Yeah, I see now I missed it in the second loop (svg


Quote:
Originally Posted by shruggy View Post
2. Why're you creating the intermediate .scad files in DEPS_DIR?

Shouldn't they be created in the current directory? I mean
Code:
openscad -d $(DEPS_DIR)/$@.deps
generates dependency files for modules from the current directory and puts them to DEPS_DIR. The make rules in those .deps files will still search for modules in the current directory. See discussion of automatic prerequisites in the GNU make manual. Instead of cc -M you have openscad -d here, but the principle is the same.

So they were in the current directory, but they are not needed after the .stl's are created, they are just there for make. I moved them down as well because there are a bunch and they are not needed for me so they are just in my way. I was trying to keep only my file, the makefile and docs in the top level.
The .deps are getting created with the correct paths into the DEPS_DIR so that part seems to be working ok.


well, digging through the docs a little more I found

Code:
VPATH = $(STL_DIR)
which works

Last edited by enine; 11-22-2021 at 11:46 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line Help: Bulk Moving from Sub-directories to directories vaneen Linux - Newbie 3 02-24-2016 04:11 AM
rebuilding a failed portion of a SlackBuilds build, instead of rebuilding everything Geremia Slackware 26 01-21-2015 05:56 PM
Shell Script to compare folders,Sub-Folders and Sub-Sub-Folders unix_72427 Programming 8 08-08-2012 02:51 PM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 12:23 PM
creating sub-sub directories dominant Linux - Newbie 13 07-23-2004 05:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration