help-make
[Top][All Lists]
Advanced

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

Re: adding *.h dependency, problem


From: Kristof Provost
Subject: Re: adding *.h dependency, problem
Date: Tue, 14 Aug 2007 21:40:56 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

On 2007-08-14 19:21:33 (+0300), Yakov Lerner <address@hidden> wrote:
> I have tiny makefile that looks like this:
> 
> all: prog
> prog: a.o b.o ; $(CC) -o $@ a.o b.o
> 
> It is very short because it relies on builtin %.o: %.c rule.
> How do I add the following dependency:  that all *.c files depend on all *.h ?
> So that when any *.h changes, all *.o are recompiled ?
> I tried to add '%.o: %.c *.h' now, but it didn't do the trick.

HEADERS := $(shell ls *.h)

prog: a.o b.o 
   $(CC) -o $@ $^

%.o: %.c $(HEADERS)
   $(CC) -c $< -o $@ 

This expresses that a.o depends on a.h, b.h, ... If you just want to
express that a.o depends on a.h and b.o depends on b.h the following
rule should do:

$.o: %.c %.

Though you may want to look in to the traditional methods of solving this.
See http://www.cmcrossroads.com/option,com_smf/Itemid,180/topic,69672.0.html, 
which will scale a lot better.

Kristof

Attachment: signature.asc
Description: Digital signature


reply via email to

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