Makefile: set macro once (Solaris make, GNU make)

Makefile: set macro once (Solaris make, GNU make)

Post by Heiner Steve » Thu, 03 Jul 2003 05:57:21



Hello,

I have a question on a problem that is disturbing me for some
time now.

I want to set a variable in a Makefile by calling a shell
command. This usually is done like this:

    SRC = `pwd`

But in this case, `pwd` will be evaluated for each usage
of the macro SRC. I only want the shell command to be evaluated
*once*.

With GNU "make" I can use the following syntax:

    SRC := $(shell pwd | sed 's:\(.*/src\)/.*:\1:')

In a directory "/home/heiner/src/misc" this will set
SRC to "/home/heiner/src".

Solaris "make" has the following syntax for the same purpose:

    SRC:sh = pwd | sed 's:\(.*/src\)/.*:\1:'

Does anybody know of a way to write a makefile in a way
both "make"s will accept it? Is there some common syntax
both will accept? Or an if-then-else construct I could use?

Heiner
--
 ___ _

\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/

 
 
 

Makefile: set macro once (Solaris make, GNU make)

Post by Paul D. Smit » Thu, 03 Jul 2003 07:46:35



  hs> I want to set a variable in a Makefile by calling a shell
  hs> command. This usually is done like this:

  hs>     SRC = `pwd`

  hs> But in this case, `pwd` will be evaluated for each usage
  hs> of the macro SRC. I only want the shell command to be evaluated
  hs> *once*.

  hs> Does anybody know of a way to write a makefile in a way both
  hs> "make"s will accept it?  Is there some common syntax both will
  hs> accept?  Or an if-then-else construct I could use?

If your question is what you _implied_, which is there any way to get
the `pwd` evaluated only once in a way that's portable between different
variants of make, then the answer to all your questions above is "no".

Personally I recommend that you write your makefiles in GNU make.  That
way you can use powerful features and still know your build environment
is portable: GNU make is portable to every UNIX-like system, plus VMS,
Windows, DOS, and Amiga.  And a native OS/2 port will be in the next
version.

If you can't impose the requirement that users of your build system
compile GNU make first, and you must use the native system make, then
you will have to forego all special capabilities of all of them and
write to the lowest common denominator, which is basically POSIX
make... which is pretty low :).

--
-------------------------------------------------------------------------------

 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

 
 
 

1. GNU C 2.4.5 for x 86 Solaris--made it, but we cheated

We did get get the gcc package to compile thru the third stage
and compare OK, but we had to cheat by copying insn-recog.o from
another x86 V4, which satisfied the make and didn't break anything.

Configure seems to like i486-solaris2.

Another poster pointed out that insn--recog,c produces a lot of
aline ... error messages and fails in the first stage. No problem
with that using gcc itself to bootstrap a new build, so, I suppose
we could offer either insn-recog.o or gcc to a site for ftp. We
have only uucp.

--

2. NE2000 lockup

3. Making changes to env variables and making them stick

4. NFS Help

5. Making a new kernel - CVSuped, not made world yet.

6. NIS+, keylogin, keylogout, keyserv

7. Making macros

8. Will rack kit for 450 fit in APC type racks

9. sed/awk - generating Makefiles (Re: awk processing of Makefile macros)

10. Imake making bad Makefiles

11. Makefile not making

12. making Makefiles

13. Making BackSpace work in GNU Emacs with CAPS LOCK in effect