Subject: Re: Makefile rules
To: Jachym Holecek <freza@psi.cz>
From: Stuart Brooks <stuartb@cat.co.za>
List: tech-userlevel
Date: 09/09/2004 17:08:56
Thanks for all the pointers, something for me to chew on :). I've had a
brief look at the /usr/share/mk stuff and I think I'll give that a good
solid read before posting any more questions. It looks like it might answer
quite a few of them.

Thanks again,
 Stuart

> 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
>