a nested Makefile...

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

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

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

# 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
        @echo -n 'cleaning up... '
        @rm -f $(STATIC_LIB) *.o *~ \#*\#
        @echo 'done.'
        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
        $(MAKE) -eC dkst/

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

Sorry for the long post. Bye.

Relevant Pages

  • Re: Cant use gprof
    ... following makefile: ... all:main clean2 ... $$(CFLAGS) -c main.cpp ... clean:; rm -f main.o main ...
  • Fix overlinking in base aka import pkgconf
    ... is BSD license pkg-config implementation 100% compatible with pkg-config. ... PCADD will invoke pkgconf to gather the libraries and the cflags for a given ... Index: Makefile ...
  • Re: 2.6.23-rc6-mm1 - Mostly working, with a kbuild oddity
    ... had to namually add a 'CFLAGS += $' or GSPCA_VERSION came up undefined. ... The actual problematic code in the Makefile: ... All the EXTRA_ variables apply only to the kbuild makefile ... variable $and uses it for compilation flags for the ...
  • [PATCH] Fix CFLAGS overwrite by Makefile
    ... Many Makefile overwrite the value of CFLAGS. ... This is an issue if you want to generate code for a specific CPU as before the ...
  • Re: setting CFLAGS in /etc/make.conf
    ... this is an abuse of the intended CFLAGS usage. ... From a ports point of view, ... Not that the ports Makefile is always run through make, ...