LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2005, 04:14 PM   #1
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Makefile to resursively compile a folder tree


Hi!

I'm looking for a Makefile to compile a tree of source files to a destination tree. I'm only familiar with the basics of make, and a few auto-magic targets, but that's now enough to compile a folder resursively. How can I do that?

(I don't intent to use automake for this project, it concerns my website. it's written in xml, and converted to html with an xslt sheet using sablotron)
 
Old 05-26-2005, 12:17 PM   #2
niknah
Member
 
Registered: Dec 2002
Location: In front of a computer
Distribution: UPS, DHL, FedEx
Posts: 466

Rep: Reputation: 38
Code:
do:
        for i in `find . -type d`; do make e "D=$$i"; done

e:
        cd "$(D)"; echo "making: $(D)##"

...replace the "making:" part with whatever you want to do in those directorys.

But if you want actual dependancies checking in all those directories you'll have to put a Makefile inside each directory.
maybe use "include ../Makefile" so you don't have to rewrite stuff.

Last edited by niknah; 05-26-2005 at 12:18 PM.
 
Old 05-26-2005, 01:40 PM   #3
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Original Poster
Rep: Reputation: 30
niknah,
Thanks for your Makefile help. The 'find' trick was definitely a nice pointer.

I did came up with something completely different in my next version, having read some more online Make books/tutorials.
Code:
# Build list of files
DIRS  = $(shell find . -type d)
FILES = $(subst .xml,.html,$(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.xml)))

# default target, build all dependencies
all: $(FILES)

# other target, remove all files
clean:
    rm -f $(FILES)

# automatic target using pattern matching
%.html: %.xml
    @#echo "Compile $< to $@"
    sabcmd "resources/xslt/codingdomain.xsl" $< $@

# explicitly declare a target phony,
# so it still works if a file called "all" is created
.PHONY: all clean
There is one thing I'm wondering about.. is it possible to support a different "build" directory? (or know what the "source" and "destination" folders are?)

Last edited by yapp; 05-26-2005 at 02:47 PM.
 
Old 05-26-2005, 07:08 PM   #4
niknah
Member
 
Registered: Dec 2002
Location: In front of a computer
Distribution: UPS, DHL, FedEx
Posts: 466

Rep: Reputation: 38
try...

sabcmd "resources/xslt/codingdomain.xsl" $< builddir/$(notdir @)

change builddir to whatever.
 
Old 06-14-2005, 12:14 PM   #5
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by niknah
try...

sabcmd "resources/xslt/codingdomain.xsl" $< builddir/$(notdir @)

change builddir to whatever.
Er.. doesn't that give problems with subfolders in the source tree?
Sorry for asking.
 
Old 06-14-2005, 07:51 PM   #6
niknah
Member
 
Registered: Dec 2002
Location: In front of a computer
Distribution: UPS, DHL, FedEx
Posts: 466

Rep: Reputation: 38
builddir should be the full dir, like /xxx/yyy

you set get it with...
TOPDIR=$(shell pwd)
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
makefile to compile kernel? RIgimp75 Slackware 7 07-19-2006 01:42 AM
can i delete the folder i compile from? whatpot Linux - Newbie 16 04-10-2005 06:54 PM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM
the bible = the tree of the knowledge of good and evil () Jesus = the tree of life Michael111 General 2 04-14-2004 04:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:02 AM.

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