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

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

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

    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
    --
    ___ _
    / __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
    \__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
    |___/\__\___|\_/\___|_||_| [url]http://www.shelldorado.com/[/url]

    Heiner Steven Guest

  2. Similar Questions and Discussions

    1. Crypt:DES make problem on Solaris 9
      Hi, I'm trying to install Crypt::DES module on a Solaris9 box and have the following problem when running make: gcc -c ...
    2. "make Makefile.PL" returns "...up to date"; make returns "no target to make"
      I'm attempting to install a perl module (AppConfig-1.56) on a FreeBSD 4.9 system. It has both perl 5.5.3 and 5.8.3 and several modules are already...
    3. Math::Pari - Solaris 2.8 sparcv9 - make test error
      Although I am able to make pari-2.1.5 with no problems, and Math-Pari-2.010500 seems to build just fine, make test fails. The general error is: ...
    4. To many intersect scripts make Macro a sad panda
      Hello there, I'm trying to create a 2d game. To prevent my 'player' from walking through objects I am using intersect scripts like the following...
    5. I am trying to make the swith but sun and their OS is not making it easy. (I cant even connect to the internet with solaris)
      william.quiter@sylvania.com (Hank) wrote in message news:<7e15f9e1.0306012204.2fc5dbfc@posting.google.com>... See ...
  3. #2

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

    %% Heiner Steven <heiner.steven@nexgo.de> writes:

    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 :).

    --
    -------------------------------------------------------------------------------
    Paul D. Smith <psmith@gnu.org> Find some GNU make tips at:
    [url]http://www.gnu.org[/url] [url]http://make.paulandlesley.org[/url]
    "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
    Paul D. Smith Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139