[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Make, Implicit Rules, and Better Output
From: |
Paul Smith |
Subject: |
Re: Make, Implicit Rules, and Better Output |
Date: |
Mon, 02 Jul 2007 21:49:24 -0400 |
On Mon, 2007-07-02 at 18:18 -0500, Michael Aaron Safyan wrote:
> The problem was that I did not define the target "% : %.o". I now have
> the following rules:
Please always send to the mailing lists, not to me directly. Sometimes
I don't have a chance to respond to email for a while; if you send
requests for help to the mailing list you'll always get the quickest
answer.
> .SUFFIXES:
>
> ifneq ($(VERBOSE),1)
> %.o : %.c
> @ $(ECHO) "Compiling: $< => $@"
> @ $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
> %.o : %.cpp
> @ $(ECHO) "Compiling: $< => $@"
> @ $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
> % : %.o
> @ $(ECHO) "Linking: $^ => $@"
> @ $(LD) $(LDFLAGS) $^ -o $@
> else
> %.o : %.c
> $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
> %.o : %.cpp
> $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $< -o $@
> % : %.o
> $(LD) $(LDFLAGS) $^ -o $@
> endif
This is too complex for my taste. You have to remember to update
multiple rules whenever you change something. Plus you're redefining
pattern rules that you don't need to redefine; there are built-in
variables you could use instead. I would use something like:
ifneq ($(VERBOSE),1)
COMPILE_COMMENT = @ $(ECHO) "Compiling: $< => $@" &&
LINK_COMMENT = @ $(ECHO) "Linking: $^ => $@" &&
else
COMPILE_COMMENT =
LINK_COMMENT =
endif
COMPILE.c = $(COMPILE_COMMENT) $(CC) $(CFLAGS) $(CPPFLAGS) -c
COMPILE.cc = $(COMPILE_COMMENT) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
LINK.o = $(LINK_COMMENT) $(CC) $(LDFLAGS) $(TARGET_ARCH)
> I could still use a little bit of help, though. The values of $< and
> $@ tend to be fairly long file names such as "path/to/file.cpp"
> and I would like it to, preferably, output only "file.cpp". Can you
> help?
There are lots of ways to do this. There are the $(@F) and $(<F)
variants of the automatic variables, or you could directly invoke one of
a number of different make functions such as $(notdir ...).
See the GNU make manual for full details.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
- Make, Implicit Rules, and Better Output, Michael Aaron Safyan, 2007/07/02
- Re: Make, Implicit Rules, and Better Output, Paul Smith, 2007/07/02
- Message not available
- Re: Make, Implicit Rules, and Better Output,
Paul Smith <=
- Re: Make, Implicit Rules, and Better Output, Stephan Beal, 2007/07/02