make doesn't honor -n switch plus wrong target selection
Hi, I was experimenting on the recursive invocation of make. I found something that's not expected and couldn't find out why that happens by reading the manual. Please see the attached package. Problem 1: Make is not recognizing the first available target all and is going behind another one. I have specified it as .PHONY have written all as the first target. But still make seems to skip it. Problem 2: Apart from the first bug, even if I specify -n switch, make tries to *execute* the commands for the target. There are a couple of variables set using the shell function. Interestingly, if I comment those out, make seems to work well! Please check whether this is a bug or not. Make version: 3.79.1 Machine: Linux x 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:52:56 EDT 2003 i686 i686 i386 GNU/Linux Thanks Jeenu maketest.tar Description: Unix tar archive ___ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make
Re: make doesn't honor -n switch plus wrong target selection
On Mon, 2007-09-10 at 15:37 +0530, Jeenu V wrote: Please see the attached package. It's difficult for us to unpack and debug larger packages. It's easier if you provide just a single makefile, and also show the command you invoked and show the output you received (cut and paste, please) Problem 1: Make is not recognizing the first available target all and is going behind another one. I have specified it as .PHONY have written all as the first target. But still make seems to skip it. Problem 2: Apart from the first bug, even if I specify -n switch, make tries to *execute* the commands for the target. There are a couple of variables set using the shell function. Interestingly, if I comment those out, make seems to work well! Your problem is here: DIRS = $(shell ls) The result of this is a list of all files in the current directory, which includes the subdirectories you want... BUT it also includes the Makefile itself! This is the same as writing: DIRS = Makefile dir1 dir2 dir3 So that means this target: $(DIRS): compile_common becomes this: Makefile dir1 dir2 dir3: compile_common Since you've shown make how to rebuild the Makefile, and the prerequisites are .PHONY so they always get rebuilt, make will always run these rules (see the GNU make manual section How Makefiles are Remade in the chapter Writing Makefiles). -- --- Paul D. Smith [EMAIL PROTECTED] Find some GNU make tips at: http://www.gnu.org http://make.mad-scientist.us Please remain calm...I may be mad, but I am a professional. --Mad Scientist ___ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make
Re: make doesn't honor -n switch plus wrong target selection
Please always CC the mailing list. On Mon, 2007-09-10 at 19:13 +0530, Jeenu V wrote: Your problem is here: DIRS = $(shell ls) Thanks for this too. Actually I tried to get the list of directories with this command: $(shell for i in $(ls -d */); do echo $i | sed 's#/$$##'; done) but was failing and had to resort to what was there in the Makefile. I could work it around by COMMAND := ls -d */ | sed s#/$$# $(shell $(COMMAND)) All of these are too complicated. All you have to do is something like this: DIRS = $(patsubst %/.,%,$(wildcard */.)) Not only is this significantly simpler BUT it's a LOT more efficient than forking a new shell, plus a bunch of other programs like ls, sed, etc. However, IMO you should not do this. A common thing people want to do when they first start using make is to have it intuit everything about their build environment, by using $(wildcard ...) etc. to have make find all the things it needs to build. In my opinion this is usually a mistake. It's too easy to get something wrong; someone makes a temporary file or directory that you didn't expect and all of a sudden your build is failing, maybe for reasons that aren't immediately obvious. I understand the attraction of not having to change your makefile but (again IMO) it's not worth it. Source files should be explicitly stated in the makefile, and if you create new ones you want to build you should modify the makefile to add them. In this case (subdirectories) it's a bit less clear-cut (I've created build systems where it would automatically try to build in each subdirectory without being explicitly told to do so, and it does work), but still probably a useful rule to follow. I'm wondering why it executed the commands even with make -n. As I said, check out the section of the GNU make manual How Makefiles are Remade in the chapter Writing Makefiles. That happens even if you specify -n, because otherwise how can make know if the makefile is correct? If you don't understand it, let us know. -- --- Paul D. Smith [EMAIL PROTECTED] Find some GNU make tips at: http://www.gnu.org http://make.mad-scientist.us Please remain calm...I may be mad, but I am a professional. --Mad Scientist ___ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make