LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 08-17-2005, 04:35 AM   #1
pycoucou
Member
 
Registered: Apr 2004
Location: Edinburgh
Posts: 78

Rep: Reputation: 15
Makefile and subdirectories


Hi there,

I would like to write down a simple Makefile at the root of my source directory in order to go in each directory to do a make all there.

I'm developping some javacode and a my own library called py. In py, I've got different subfoler in order to keep my source more or less organised:
./py/util (general purpose class, like extra math functions)
./py/images (class which open images, process them)
./py/gui (class of the gui to my program)
./py/io

etc...

In each folder, I've got some .java files and a Makefile. Usually, I go in each directory and perform a make all there and it works. Now, I would like to be smart. I stay in ./ and I type make all. I would like it goes in each subdirectory and perform a make all.

I tried so far and unsuccessfully:

-------------------------------------------------
SHELL = /bin/sh
CC = javac
SUBDIRS = images gui io util
#---------------------------------------------------------------------
# Rules
#---------------------------------------------------------------------

all:
for dir in ${SUBDIRS} ; do ( cd py/$dir ; ${MAKE} all ) ; done

-------------------------------------------------------

It says everything is up to date

How can I do?

Thanks for your help,
PY
 
Old 08-17-2005, 07:39 AM   #2
cdhgee
Member
 
Registered: Oct 2003
Location: St Paul, MN
Distribution: Fedora 8, Fedora 9
Posts: 513

Rep: Reputation: 30
Try this in your Makefile:

Code:
DIRS = src doc man etc

all:
	set -e; for d in $(DIRS); do $(MAKE) -C $$d ; done
 
Old 08-17-2005, 08:22 AM   #3
pycoucou
Member
 
Registered: Apr 2004
Location: Edinburgh
Posts: 78

Original Poster
Rep: Reputation: 15
Great! It works very well !

The only point is to give the rule to follow otherwise it takes the first by default !
Code:
all:
	set -e; for dir in ${SUBDIRS} ; do  ${MAKE} -C py/$$dir all; done
And a quick question: What the purpose of `set -e'?
 
Old 08-17-2005, 08:40 AM   #4
cdhgee
Member
 
Registered: Oct 2003
Location: St Paul, MN
Distribution: Fedora 8, Fedora 9
Posts: 513

Rep: Reputation: 30
It tells it not to exit if the result code is non-zero. This means in practice that it will continue trying to make all the subdirectories even if it encounters errors doing so.

So if you've got

Code:
SUBDIRS = images gui io util
and if make in the images directory fails, it will continue trying to make gui, io, and util.
 
Old 08-18-2005, 04:43 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
don't forget to read this:

http://www.canb.auug.org.au/~millerp...cons-harm.html

recursive make considered harmful
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to modify makefile.in or makefile.am QiangWan Linux - Newbie 1 05-17-2005 11:07 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
list all contains and subdirectories' contains babis Linux - Newbie 2 10-22-2004 09:40 PM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM
email and subdirectories hiertjou123 Linux - Newbie 5 07-16-2003 01:08 PM


All times are GMT -5. The time now is 09:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration