mkdep

Ian Lance Taylor ian@zembu.com
Mon Apr 3 23:47:00 GMT 2000


   Date: Tue, 4 Apr 2000 12:03:43 +1000 (EST)
   From: Alan Modra <alan@linuxcare.com.au>

   Yes, I found it there when I started patching gas/Makefile :-)
   Not using that shell script simplifies the Makefiles, especially
   gas/Makefile.

   I've attached the complete Makefile.am diff, which also has some parallel
   make fixes from H.J. Lu.

   OK to install?

The general approach is OK with me.

Some of the rules should change, though.  For example:

 DEP1: $(CFILES)
-	rm -f DEP2 DEP2a
-	echo '# DO NOT DELETE THIS LINE -- mkdep uses it.' > DEP2
-	echo > DEP2a
-	$(MKDEP) -f DEP2a $(INCLUDES) $(CFLAGS) $?
-	sed -e '/DO NOT DELETE/d' -e '/^$$/d' < DEP2a >> DEP2
-	rm -f DEP2a
-	$(SHELL) $(srcdir)/../move-if-change DEP2 DEP1
+	echo '# DO NOT DELETE THIS LINE -- mkdep uses it.' > $@
+	echo '# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.' >> $@
+	$(MKDEP) $(INCLUDES) $(CFLAGS) $? >> $@

There is a reason that the original rule uses DEP2: it is because
make, or the entire system, might somehow crash in the middle of
executing the commands.  If that happens, the original rule will run
correctly.  Your modified rule will not.  DEP1 will exist and will be
newer than its dependencies, so the rule will not be rerun.  But DEP1
will not have the correct contents.

In general, make rules should create the target using a single
command.  Otherwise, they are vulnerable to a system crash.
(Admittedly, the compiler does not follow this rule, and it would be
too much to expect make rules to rename compiler targets.)

I'm not sure why the original rule uses move-if-change.  That is
generally only useful in conjunction with a stamp file of some sort.
That is, I think it could just end in mv -f.

Ian


More information about the Binutils mailing list