a nested Makefile...

From: muko (casottobriano_at_yahoo.it)
Date: 09/29/04


Date: Wed, 29 Sep 2004 16:04:31 +0200

Hi,
I'm developing an application. I decided to split source code in 2
directories: a static library and the application that uses such library.

So sourcers are organized like this:

app/ -> application root directory
app/lib/ -> library root directory

I used 2 Makefiles: one in app/ and another one in app/lib/. The second one
can be invoked directly if you want to compile only the library. The first
one is my problem :). I can't do a Makefile that looks if the library is
updated (calling the internal Makefile) and if ok, DOESN'T start compiling
all the application code from the beginning... Here example tha show my
situation:

----------------------------------------------------------------------------
----------------------------------------------------------------------------
# library Makefile in app/lib/

# Settings
CC         = g++
CFLAGS     = -Wall -ggdb
STATIC_LIB = lib.a

# Rules
$(STATIC_LIB): tree.o iterators.o node.o
        ar rcs $(STATIC_LIB) tree.o iterators.o node.o

tree.o: tree.cpp tree.h exceptions.h iterators.o node.o
        $(CC) $(CFLAGS) -c tree.cpp
iterators.o: iterators.cpp iterators.h exceptions.h node.o
        $(CC) $(CFLAGS) -c iterators.cpp
node.o: node.cpp node.h
        $(CC) $(CFLAGS) -c node.cpp

# Utilities
clean:
        @echo -n 'cleaning up... '
        @rm -f $(STATIC_LIB) *.o *~ \#*\#
        @echo 'done.'
doc:
        doxygen Doxyfile

----------------------------------------------------------------------------
----------------------------------------------------------------------------
# application Makefile in app/

# Settings
CC      = g++
CFLAGS  = -Wall -ggdb
TARGET  = ../bin/app
OBJECTS = dkstShell.o wordChain.o dictionary.o words.o dkst/dkst.a

# Rules
$(TARGET): $(OBJECTS) main.cpp
        $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) main.cpp
dkstShell.o: wordChain.o dkstShell.cpp dkstShell.h
        $(CC) $(CFLAGS) -c dkstShell.cpp
wordChain.o: dictionary.o wordChain.cpp wordChain.h
        $(CC) $(CFLAGS) -c wordChain.cpp
dictionary.o: words.o dictionary.cpp dictionary.h
        $(CC) $(CFLAGS) -c dictionary.cpp
words.o: dkst/dkst.a words.cpp words.h
        $(CC) $(CFLAGS) -c words.cpp
dkst/dkst.a:
        $(MAKE) -eC dkst/

# Utilities
clean:
        $(MAKE) -eC dkst/ clean
        @echo -n 'cleaning up... '
        @rm -f $(TARGET) *.o *~ \#*\#
        @echo 'done.'
----------------------------------------------------------------------------
----------------------------------------------------------------------------

Sorry for the long post. Bye.