[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: makefile issues

On Sat, 3 May 2003, franciszek holop wrote:

> 1. my first problem:
>    how can i get the `pwd` where the makefile was started?
>    GNU: ROOTDIR=$(shell pwd)
>    is there a universal solution in the Makefile?  or any other
>    ideas (./configure preferably not)

if it helps, all actions in the makefile in both BSD and GNU always start
in the Makefile's pwd. here's an example with the target "example":

$ cat Makefile
        echo `pwd`
        cd /tmp && echo `pwd`
$ make example    # BSD make
echo `pwd`
cd /tmp && echo `pwd`
$ gmake example   # explicitely GNU make
echo `pwd`
cd /tmp && echo `pwd`

if you tie lines together (ie using &&, || operators and \ to continue a
line to the next) you can keep your pwd. this meets 99% of peoples' needs
when used properly in my experience.

> 2. the GNUmakefile specifies a "%" macro which
> 	can match any part of the target name; this part is called the
> 	"stem".  The rest of the pattern must match exactly.  For
> 	example, the target `foo.o' matches the pattern `%.o', with
> 	`foo' as the stem.  The targets `foo.c' and `foo.out' do not
> 	match that pattern.
>    the makefile i am trying to make more BSD like uses this feature
>    as a kind parameter passing mechanims in the rule names:
> Makefile:
> ---------------------------------------
> rule4%.dict:
>         @echo "this is rule4$(*F).dict"
> this: rule4this.dict
> that: rule4that.dict
> ---------------------------------------
> amaaq> gmake this
> this is rule4this.dict
> amaaq> gmake that
> this is rule4that.dict
>    it is useful, because the make process runs a lot of scripts, and
>    passes the $(*F) as parameter for those scripts.
>    so the rules are written just once and make use of this parameter.
>    how can accomplish the same w/bsd make?

i think you should look at .IMPSRC (the implied source), the .TARGET
(target of the action), and the .SUFFIXES rules:

.SUFFIXES:	.c .o

	cc ${CFLAGS} -c -o ${.TARGET} ${.IMPSRC}

for BSD make documentation, look in /usr/share/doc/psd/12.make. for great
examples of uses, look in /usr/share/mk at the system makefiles.

hope this helps. it may be possible to do what you want using BSD make

i have never seen a port so complicated as to require these kinds of

jose nazario, ph.d.			jose@monkey.org