Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I code a Makefile that can tell the difference between Intel OS X and Linux?

How do I write a conditional into a GNU make Makefile, which discerns the architecture (Intel OS X vs Linux, in this case) so that I can set flags appropriately, without requiring the end user to specify the Makefile when running make -f?

EDIT

I should specify that I get a makefile error from an ifeq statement that contains a shell command, if this conditional is placed outside a target:

'commands commence before first target. Stop.'

like image 586
Alex Reynolds Avatar asked Jul 01 '11 03:07

Alex Reynolds


2 Answers

You should be able to check the output of one of the uname variants, and then choose different actions withing the makefile depending on that.

Run man uname for details.

In terms of how you use it from GNU make, you can get the information into a variable from the shell function and then use ifeq on that variable:

platform=$(shell uname -o)

ifeq ($(platform),Cygwin)

defrule:
    echo I am running in Cygwin.

else

defrule:
    echo I am running elsewhere.

endif
like image 158
paxdiablo Avatar answered Sep 22 '22 01:09

paxdiablo


uname is your friend.

$ uname -o
GNU/Linux
like image 44
Ignacio Vazquez-Abrams Avatar answered Sep 21 '22 01:09

Ignacio Vazquez-Abrams