Subject: Re: Makefile rules
To: Stuart Brooks <stuartb@cat.co.za>
From: Jachym Holecek <freza@psi.cz>
List: tech-userlevel
Date: 09/09/2004 15:59:01
Hello,

> Using the .PATH option looks promising but the documentation I have found
> about make is very thin. Is there anything I could read to get a bit more
> information. I've been through 'Make - a Tutorial" but it only seems to
> scratch the surface.

Both .PATH and .OBJDIR are BSD specific (I think), so the right place
to look is make(1) (available on www.netbsd.org, too) and maybe
/usr/share/doc/psd/12.make (but that is probably outdated). If you're
serious about learning (BSD) make, you might also read /usr/share/mk/*
but be prepared for slight headache :-).

> What I'm interested in is the exact role which .OBJDIR and .PATH play.

.PATH: dir1 ...

	When make looks for a file (such as when it hits foo.o: foo.c),
	it can try to find it in more places (only ${.CURDIR} is used
	by default, see below). Directories to use are stored in the
	.PATH variable and the above adds dir1 there (for some reason,
	it should not be extended using .PATH+=... but .PATH: ...).

	GNU make uses VPATH for this as already noted.

.CURDIR

	The directory make is currently working for ("the directory
	where the Makefile is" - but not exactly). This may be
	different from actual working directory. If you're reffering to
	files from the source directory, you should always use .CURDIR
	(doing just "./foo" could break).

	GNU make uses CURDIR for this.

.OBJDIR

	Make is able execute the rules in directory different then the
	source directory. The obvious advantage is that you don't
	pollute it with *.o etc. Less obvious advantage is that you
	can build the same sources for different architectures at
	the same time.

	This feature is automatically used if "obj" or "obj.${MACHINE}"
	directory (or symlink) exists in ${.CURDIR}.

	I don't know what GNU make does here.

> I had hoped that I could specify the .OBJDIR and then adjust the implicit
> rules as follows but it doesn't seem to work ...

.OBJDIR and .CURDIR are only meant for reading. You should not try
to modify them.

> DIR=some_directory
> .OBJDIR: $(DIR)
> 
> .cpp.o:
>   $(COMPILER) -c -o$(DIR)/$@ $<

Didn't just specifying .PATH/VPATH work? It should have ;-)

	Regards,
		-- Jachym Holecek