Variables in GNU make

Tim Writer tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Sun Dec 17 21:05:47 UTC 2006


Neil Watson <tlug-neil-8agRmHhQ+n2CxnSzwYWP7Q at public.gmane.org> writes:

> Hello,
> 
> I'm delving into GNU make for the first time.  My goal is to build a
> revision labeled tar file from a working copy of source code.  Here is
> what I have started:
> 
> # makefile
> 
> # This file will build a boot strap client. SHELL=/bin/sh
> 
> 
> # Vpath works like PATH.  The inputs directory will be searched for any
> # .conf
> # files that are referenced.
> vpath %.conf inputs
> vpath %.sv init.d
> 
> PUBLICKEY=tor-heisenberg.pub
> 
> .PHONY: help
> help:
>         make --print-data-base --question | \
>         awk '/^[^.%][-A-Za-z0-9]*:/ \
>         { print substr($$1, 1, length($$1)-1) }' | \
>         sort
> 
> # Make client tarball to be copied to client.
> .PHONY: client
> client: cfengine-bs.tgz
> 
> # Tarball file that will be copied to the client.
> cfengine-bs.tgz: makefile cfagent cfkey cfexecd update.conf ${PUBLCKEY} cfexecd.sv
>         tar -cvzpf cfengine-bs.tgz $^
> 
> # server public key
> ${PUBLICKEY}:
>     cp /var/cfengine/ppkeys/${PUBLICKEY} ${PUBLICKEY}
> 
> 
> This current version works.  I'd like the tar file name (from 'make client') to
> include the revision number.  I can get it like this:
>         REV=`svn info|awk '/^Revision.*/ { print $2 }'`
> 
> How can ensure that the dependancy in 'client: cfengine-bs.tgz' changes with
> the revision (cfengine-bs-22.tgz)?  Also how could this apply to the target
> 
> cfengine-bs-22.tgz: makefile cfagent cfkey cfexecd update.conf ${PUBLCKEY} cfexecd.sv

There are a couple of approaches. The simplest is probably to put the revision
into a make variable using $(shell), like this:

    REV := $(shell svn info | awk '/^Revision.*/ { print $2 }')

Then, include the revision in the tar ball target:

    cfengine-bs-$(REV).tgz: makefile cfagent cfkey cfexecd update.conf ${PUBLCKEY} cfexecd.sv
        commands to build tarball

> This make file will also include the install target.  On the host where the
> install target will be used, the revision is not needed (svn is not even
> installed).  How can I make the revision variable conditional or a dependant of
> the client target?
> 
> 
> -- 
> Neil Watson             | Debian Linux
> System Administrator    | Uptime  13:49:14 up 16:16,  2 users,  load average: 0.14, 0.04, 0.01
> http://watson-wilson.ca
> --
> The Toronto Linux Users Group.      Meetings: http://gtalug.org/
> TLUG requests: Linux topics, No HTML, wrap text below 80 columns
> How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
> 

-- 
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org>                                  starnix inc.
647.722.5301                                      toronto, ontario, canada
http://www.starnix.com              professional linux services & products
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list