Greg
Greg

Reputation: 8340

How to execute gmake/make from a bash script file?

I'd like to execute my Makefile from a bash script file using make/gmake depending on the system it is being compiled on: gmake on FreeBSD (not the standard make) and make on others. For that I would like to determine if the make command installed on the system is GNU make: - if GNU make then compile with make - if not GNU make then compile with gmake (and raise error if gmake is not installed)

Is there an easy way of doing this?

Upvotes: 0

Views: 1333

Answers (2)

uzsolt
uzsolt

Reputation: 6037

You can use uname:

if [ `uname -s` = "FreeBSD" ]; then
    makeprg=gmake
else
    makeprg=make
fi

As I see on wikipedia on FreeBSD uname -s will print FreeBSD and on Linux will the output Linux (on my machine too).

Edit: FreeBSD instead of Linux.

Upvotes: 1

Igor Chubin
Igor Chubin

Reputation: 64593

if make --version | grep "^GNU Make" >& /dev/null
then
  MAKE=make
else
  MAKE=gmake
fi

${MAKE} ...

EDIT: Changed --ver to --version

Upvotes: 3

Related Questions