Defining macros conditionally in Makefiles - Unix

This is a discussion on Defining macros conditionally in Makefiles - Unix ; Hello, I have a Makfile that I am trying to ensure it platform-independent. So I have a macro, UNAME, that is the system name as returned by the uname command (e.g. SunOS for Solaris, AIX for AIX, etc). I want ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Defining macros conditionally in Makefiles

  1. Defining macros conditionally in Makefiles

    Hello,

    I have a Makfile that I am trying to ensure it platform-independent. So I
    have a macro, UNAME, that is the system name as returned by the uname
    command (e.g. SunOS for Solaris, AIX for AIX, etc). I want to define
    various other macros in my Makefile in a way that depends on the value of
    UNAME. Essentially I want to say something like:

    if UNAME equals SunOS
    SOME_VAR = SolarisSpecificValue
    elseif UNAME equals AIX
    SOME_VAR = AIXSpecificValue
    else
    SOME_VAR = SomeDefaultValue
    endif

    I realise how to do this using GNU make. It's easy because one can use the
    ifeq statement. But I need to be able to do this with the vendor-crippled
    make (don't ask). I know it can be done because I did it several years ago
    but I cannot remember how. I seem to recall it involved some kind of
    conditional macro assignment similar to the environment variable
    conditional assignment that can be done in the shell.

    Needless to say, because this is an effort to ensure
    platform-independence, the solution must NOT involve any proprietary
    non-portable differences between the vendor make and the lowest common
    denominator (as defined by POSIX or the SVID). So this rules out the
    conditional assignment that is supported by the Solaris special version of
    make.

    Any help will be greatly appreciated.

    Regards,

    Andrew Marlow


  2. Re: Defining macros conditionally in Makefiles

    A Marlow writes:

    > I realise how to do this using GNU make. It's easy because one can use the
    > ifeq statement. But I need to be able to do this with the vendor-crippled
    > make (don't ask).


    The "standard" answer is to use recursive make in that case, e.g.

    all: arch-$(UNAME)

    arch-SunOS:
    $(MAKE) $(MFLAGS) UNAME=$(UNAME) SOME_VAR=SolarisSpecificValue target

    arch-AIX:
    $(MAKE) $(MFLAGS) UNAME=$(UNAME) SOME_VAR=AIXSpecificValue target

    # Not sure how to handle the default, unless you make UNAME=unknown and add
    arch-unknown:
    $(MAKE) $(MFLAGS) UNAME=$(UNAME) SOME_VAR=SomeDefaultValue target

    target: # whatever needs to be built ...

    > I know it can be done because I did it several years ago
    > but I cannot remember how. I seem to recall it involved some kind of
    > conditional macro assignment similar to the environment variable
    > conditional assignment that can be done in the shell.


    Conditional macro assignments are supported by some, but not *all*
    vendor makes. So this was either a specific-vendor-make solution,
    or some different mechanism was actually used.

    > Any help will be greatly appreciated.


    I wonder if you'll be better off with a build.sh script, which
    could figure everything out, and exec make with the right args.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  3. Re: Defining macros conditionally in Makefiles

    On Wed, 22 Feb 2006 20:00:46 -0800, Paul Pluzhnikov wrote:

    > A Marlow writes:
    >
    >> I realise how to do this using GNU make. It's easy because one can use the
    >> ifeq statement. But I need to be able to do this with the vendor-crippled
    >> make (don't ask).

    >
    > The "standard" answer is to use recursive make in that case, e.g.
    >
    > all: arch-$(UNAME)
    >
    > arch-SunOS:
    > $(MAKE) $(MFLAGS) UNAME=$(UNAME) SOME_VAR=SolarisSpecificValue target
    >
    > arch-AIX:
    > $(MAKE) $(MFLAGS) UNAME=$(UNAME) SOME_VAR=AIXSpecificValue target
    >


    Many thanks. This is not exactly how I did it all those years ago but this
    should work and is in fact clearer, and therefore better than the solution
    I had. Much appreciated!

    -Andrew M.


+ Reply to Thread