[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: setting a variable to be the result of severla shell commands...
From: |
Paul D. Smith |
Subject: |
Re: setting a variable to be the result of severla shell commands... |
Date: |
Tue, 25 Jun 2002 00:41:20 -0400 |
%% richard offer <address@hidden> writes:
ro> I'm trying to set a variable (build number) to be the result of
ro> several commands, so far I have :-
You cannot use multi-line commands inside make syntax in this version of
GNU make. The only place that multi-lines operations are permitted is
within a command script.
ro> define build-ver
ro> BUILD_NUM=$(shell [ -f .build_num ] && cat .build_num )
ro> NUM=$(if $(BUILD_NUM),$(shell expr $(BUILD_NUM) + 1),1)
ro> $(strip $(1)build$(NUM))
ro> endef
ro> REL=$(call build-ver,4)
ro> The intention being that if the file .build_num exists that the
ro> contents are incremented by 1 and used to set REL, ie the first
ro> build would set REL = 4build1, then, 4build2 etc (the code to
ro> write the result back to .build_num is not shown).
Why not just write it in a longer $(shell ...) function? One of the
nicest things about Bourne shell, unlike the horrible C shell, is that
you can write just about any script without needing newlines at all.
Why not something like (note, entirely untested...):
build-ver := $(strip $(1)build${shell n=`cat .build_num 2>/dev/null`; case
$$n in '') echo 1 ;; *) echo `expr $$n + 1` ;; esac})
REL := $(call build-ver,4)
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://www.paulandlesley.org/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist