help-make
[Top][All Lists]
Advanced

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

Re: Request for critique on a small makefile


From: Greg Chicares
Subject: Re: Request for critique on a small makefile
Date: Tue, 12 Dec 2006 22:55:55 +0000
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

On 2006-12-12 22:20 UTC, Edward Z. Yang wrote:
> Philip Guenther wrote:
[...]
>>> Ah.  Hmm.  My *guess* is that g++ will only add the .exe suffix if
>>> there isn't already such a suffix present.  If so, then following the
>>> three points I listed should work.
> 
> This seems to be the case. I'm currently working around it by cleaning
> up *.exe files with make clean. On Unix, ${programs} does the dirty
> work. I think this is a satisfactory solution (and not a hack).

Here's how automake handles it:

  http://www.gnu.org/software/automake/manual/html_node/EXEEXT.html

You can use that technique yourself, even though you're not using
automake. Just name your programs this way:

programs := fibonacci$(EXEEXT) printNumbers$(EXEEXT)

Then a rule like

.PHONY: all
all: $(programs)

will do the right thing, portably, as long as you define $(EXEEXT)
appropriately. Changing the platform only requires changing that
one definition. And this gains the benefits of following Paul's
second rule ("Every non-.PHONY rule must update a file with the
exact name of its target"):

fibonacci$(EXEEXT): fibonacci.o

# not PHONY, so use *exact* name
%$(EXEEXT):
        $(LD) -o $@ $^ $(ALL_LDFLAGS)




reply via email to

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