help-make
[Top][All Lists]
Advanced

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

Re: issue on 'echo'ing names of files those


From: Paul D. Smith
Subject: Re: issue on 'echo'ing names of files those
Date: Fri, 6 Jan 2006 08:24:28 -0500

%% "Ninad Pachpute" <address@hidden> writes:

  np> I want to echo CC -c filename.c with compilation of each file.
  np> with the following code snippet, it 'echo'ed name of first file that was 
  np> compiled.
  np> Can anybody tell me the reason?
  np> And correct way to do it?

  np> $(OBJECTS):$(SOURCES)
  np>   @$(CC) -c $(CFLAGS) $< -o $@
  np>   @echo "CC -c" $<

This cannot work... echoing the wrong name is the LEAST of your
problems.  You are compiling the same file every time, but calling it a
different .o in the output.

Your problem is you believe that:

    $(OBJECTS) : $(SOURCES)

is the same as writing:

    obj1 : src1
    obj2 : src2
    obj3 : src3

etc.  But, it is definitely not (check the GNU make manual).  Really
it's the same as writing:

    obj1 : $(SOURCES)
    obj2 : $(SOURCES)
    obj3 : $(SOURCES)

which is _clearly_ not what you want, since (a) it means that every .o
depends on ALL the source files, not just one, and (b) it means that $<
will always equal the first source file in the list regardless of what
object file you're building.

You should do this:

    %.o : %.c
            @$(CC) -c $(CFLAGS) $< -o $@
            @echo "CC -c" $<

    all: $(OBJECTS)

(that's assuming that all your objects are XXX.o and can be built from
XXX.c.)  See the GNU make manual sections on implicit and pattern rules.

-- 
-------------------------------------------------------------------------------
 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




reply via email to

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