[U-Boot-Users] [PATCH] Fix/workaround broken dependency handling with make 3.81

Wolfgang Denk wd at denx.de
Mon Aug 28 23:15:32 CEST 2006


In message <1defaf580608281323n6ff6a04fh9369b68264374c1c at mail.gmail.com> you wrote:
>
> Anyway, I can make a new patch that assign the ELF, SREC and BIN
> explicitly. Would that be acceptable?

You're trying to tenderize me, aren't you? ;-) Yes, probably I'd give
in.

> be quite dangerous -- consider the following Makefile (NOTE: don't run
> it with files you care about in the same directory, including the
> Makefile itself):
> 
> all: hello_world.tgt
> 
> %.tgt: %
>         cp $< $@
> 
> %: %.src
>         cp $< $@
> 
> %.src: FORCE
>         touch $@
> 
> .PHONY: FORCE
> FORCE:
> 
> When executing make, this is what happens (same result with make 3.80 and 3.81):

Yes, and IMHO you can easily show more problems with make. To me it's
really frightening to see so many issues with a tool in so  wide  use
like GNU make.

> touch Makefile.src
> cp Makefile.src Makefile
> rm Makefile.src
> make: *** No targets.  Stop.

OK. Let's give it a try:

-> cat Makefile 
all: hello_world.tgt

%.tgt: %
        cp $< $@

%: %.src
        cp $< $@

%.src: FORCE
        touch $@

.PHONY: FORCE
FORCE:
-> make -n
touch Makefile.src
cp Makefile.src Makefile
rm Makefile.src
make: *** No targets.  Stop.
-> ls -l
total 0
-rw-r--r--  1 wd users 0 Aug 28 23:08 Makefile
-rw-r--r--  1 wd users 0 Aug 28 23:08 Makefile.src
-> make --version
GNU Make 3.80
...

So yes, your Makefile is dangerous.

But wait. I used "-n" on the command line. And the man page says:

	-n   Print the commands that would be executed, but do not
             execute them.

Do not execute them? So who did execute the "touch" and the "cp", but
skip the "rm"? I'm frightened.

Actually: where is the "rm" coming from?

> > Seriously: the make result must never depend on the  order  in  which
> > targets are given; and if there is a bug in the Makefile, I expect to
> > see a (helpful) error message instand of random behaviour.
> 
> Yeah, but the jungle of internal implicit rules, remaking of Makefiles
> and such is not easy to understand. I for one don't.

Neither do I> I don't even understand  simple  command  line  options
like "-n" :-(

> I'll send a mail to the make mailinglist tomorrow to see if anyone can
> give an explanation.

Thanks.

Best regards,

Wolfgang Denk

-- 
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"It's when they say 2 + 2 = 5 that I begin to argue."    - Eric Pepke




More information about the U-Boot mailing list