help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

.PHONY targets and prerequisite checking


From: Anoneironaut
Subject: .PHONY targets and prerequisite checking
Date: Thu, 27 Jul 2006 10:28:25 -0700 (PDT)

Hi, 

I want to build a program that consists of several modules: 

  toplevel/ 
    foo/ 
      Makefile 
      foo.c 
    bar/ 
      Makefile 
      bar.c 
    Makefile 
    main.c 

Each module would be compiled into a library, ie. in foo/, 
a library libfoo.a would be created, and in bar/ a libbar.a. 
The top-level Makefile would then compile main.c and link it 
with all modules' libraries into the main program. 

In order to make adding other modules very easy, I'd like 
to use a top-level Makefile like this: 

------------- Top-Level Makefile ------------------------------ 
MODULES := foo bar 

MODULE_LIBS := $(patsubst %,-l%,$(MODULES)) 
MODULE_DIRS := $(patsubst %,-L%,$(MODULES)) 

vpath %.a $(patsubst %,%:,$(MODULES)) 

toplevel: main.o $(MODULES) $(MODULE_LIBS) 
        $(CC) -o $@ main.o $(MODULE_DIRS) $(MODULE_LIBS) 

.PHONY: $(MODULES) 
$(MODULES): 
        $(MAKE) -C $@ 
--------------------------------------------------------------- 

This basically does what I want; a new module can be added just 
by appending to MODULES. The modules' Makefiles are very 
straightforward, like: 
  libfoo.a: foo.o 
        ar -rs $@ $< 


However, this re-links toplevel on each invokation of "make", 
even if no files have been changed at all. 
"make -d" gives me: 
--------->8---------->8------------ 
  [...] 
  Considering target file `toplevel'. 
    [...] 
    Considering target file `foo'. 
     File `foo' does not exist. 
     Finished prerequisites of target file `foo'. 
    Must remake target `foo'. 
  make -C foo 
  [...] 
  No need to remake target `libfoo.a'. 
  [...] 
    Successfully remade target file `foo'. 
  [[dito for 'bar']] 
    No need to remake target `-lfoo'; using VPATH name `foo/libfoo.a'. 
    No need to remake target `-lbar'; using VPATH name `bar/libbar.a'. 
   Finished prerequisites of target file `toplevel'. 
   Prerequisite `main.o' is older than target `toplevel'. 
   Prerequisite `foo' of target `toplevel' does not exist. 
   Prerequisite `bar' of target `toplevel' does not exist. 
   Prerequisite `foo/libfoo.a' is older than target `toplevel'. 
   Prerequisite `bar/libbar.a' is older than target `toplevel'. 
  Must remake target `toplevel'. 
  cc -o toplevel main.o -Lfoo -Lbar -lfoo -lbar 
--------->8---------->8------------ 
Even though it says it "Successfully remade target file `foo'", it then 
concludes with "Prerequisite `foo' of target `toplevel' does not exist." 
I suspect this is because "foo" and "bar" are phony targets, which are 
never up-to-date? If so, how can I avoid setting "foo" and "bar" to be 
phony? 

I'm using GNU make 3.80 and I am on a Windows XP system.

-- 
View this message in context: 
http://www.nabble.com/.PHONY-targets-and-prerequisite-checking-tf2010896.html#a5525550
Sent from the Gnu - Make - Help forum at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]