help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conditionals based on compiler version?


From: Paul D. Smith
Subject: Re: Conditionals based on compiler version?
Date: Fri, 13 Sep 2002 09:19:55 -0400

%% Ian Britten <address@hidden> writes:

  ib> Is there a way to do conditionals in a makefile, based on the version of
  ib> the compiler?   (GNU make v3.79.1)

  ib> I've been trying to use 'ifeq' with combinations of "$(CC) --version",
  ib> $(__GNUC_MAJOR__), etc, but without much luck... :-(

Well, you have to keep firmly in mind the difference between running a
command and expanding a variable.

Something like this:

  FOO = cc --version

  ifeq ($(FOO),2.95)

will not do what you want, because the make variable $(FOO) is expanded
returning the string "cc --version", but the "cc --version" command is
_NOT_ executed!

If you want to run a command you want the $(shell ...) function.

So:

  FOO := $(shell $(CC) --version)

will run the command and set FOO to the results.

Then you can test it using patsubst, filter, or whatever you prefer.

If you want more flexibility you can just do the whole test in the
shell, like this:

  FOO := ${shell case `$(CC) --version` in 3.*) echo 3 ;; 2.*) echo 2 ;; esac}

etc.

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]