[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SUFFIXES bug
From: |
Paul D. Smith |
Subject: |
Re: SUFFIXES bug |
Date: |
Tue, 8 May 2001 18:08:32 -0400 |
%% Patrick Craig <address@hidden> writes:
pc> GNU Make version 3.79.1
pc> Built for i686-pc-cygwin
pc> My project has some autogenerated C files. I use a different
pc> suffix for these files (.agc) so that I can delete them in the
pc> clean rule (rm -f *.agc). Here is a simplified Makefile:
pc> .SUFFIXES: .agc
pc> all::boot test.o
pc> boot::
pc> cp test.pre test.agc
pc> #test.agc::
pc> .agc.o:
pc> gcc -c -xc $?
pc> clean::
pc> rm -f test.agc test.o
pc> If I have just the test.pre file and run make, it generates
pc> test.agc and then says it doesn't know how to make test.o. If I
pc> then run make again it correctly generates test.o. If I uncomment
pc> out the empty test.agc rule, make works correctly, generating both
pc> test.agc and test.o in one pass. Microsoft nmake works correctly
pc> even without the test.agc rule.
This doesn't have anything to do with suffixes; you could get the same
behavior in other ways.
The issue is GNU make's directory cache feature.
When GNU make first needs to find a file in a directory it caches the
contents internally. Then as it runs rules which create new files, it
adds them to its cache. This allows a significant performance
improvement.
The problem is that, if you create files as a side-effect of a rule and
make doesn't know about it, then make can't know to add that new file to
the cache, so it can't be found later even though it actually exists on
the disk.
That's what happens here: first the "boot" rule is run which creates
test.agc, but make doesn't know that. Then make wants to find a rule
that can create test.o; it sees the implicit rule to build the .o from
the .agc, _but_ you have no rule telling it how to build a .agc file
and, looking at the cached version of the directory, no file named
"test.agc" exists.
So it fails.
The next time you run make, it sees that the test.agc file exists, so it
knows how to use it to build test.o.
What you really want to do is include a rule that tells make how to
build a test.agc; you say that these files are autogenerated, so you
should tell make how to generate them, like this:
%.agc : %.in # or whatever you build them from
<autogenerate a $@ from a $<>
%.o : %.agc
gcc -c -xc $<
(you don't want $? here, you want $<). You can do this with suffix
rules too, of course, but pattern rules are simpler to read and
understand.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://www.paulandlesley.org/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
- SUFFIXES bug, Patrick Craig, 2001/05/08
- Re: SUFFIXES bug,
Paul D. Smith <=