Using Make to detect an OS version?

Using Make to detect an OS version?

Post by Brian Flemin » Tue, 24 Aug 1999 04:00:00



Is there a way to have a makefile determine the OS being used and then
exit if the makefile is being executed on an incorrect OS version?

I have script code that does this:

# Define switches for path specific to the platform/OS (4.1.x or
Solaris)
SUNOS_TYPE=`/bin/uname -a | awk '{ print $3 }' | /bin/sed -e 's|\.|\ |g'
| awk '{ print $1 }'`
case $SUNOS_TYPE in
    "4")  echo "SUNOS"
          #make install
        ;;
    "5")  echo "You must be on a SunOS machine."
        ;;
    esac

But I don't know how to do this with a makefile syntax, and I'm not
using the gnu make, just standard old make utility.

thanks for any input.

 
 
 

Using Make to detect an OS version?

Post by Chris Thomps » Wed, 25 Aug 1999 04:00:00




Quote:>Is there a way to have a makefile determine the OS being used and then
>exit if the makefile is being executed on an incorrect OS version?

>I have script code that does this:

># Define switches for path specific to the platform/OS (4.1.x or
>Solaris)
>SUNOS_TYPE=`/bin/uname -a | awk '{ print $3 }' | /bin/sed -e 's|\.|\ |g'
>| awk '{ print $1 }'`
>case $SUNOS_TYPE in
>    "4")  echo "SUNOS"
>      #make install
>        ;;
>    "5")  echo "You must be on a SunOS machine."
>    ;;
>    esac

You must enter that one for the UUOAE (Useless Use of Almost Everything) award -
you would be a strong contender...

What was wrong with

  case `uname -r` in
    4.*) do the SunOS4 thing ;;
    5.*) do the SunOS5 thing ;;
    *) echo "I haven't the faintest idea where I am running" ;;
  esac

?

Quote:>But I don't know how to do this with a makefile syntax, and I'm not
>using the gnu make, just standard old make utility.

You can call any shell construct you want from a Makefile, and it will stop
on a non-zero exit code by default, so you can abort the make on any test
you like. For example:

target: dependencies

        *) echo "Go use a SunOS4 box, buster"; exit 1;; esac )

Chris Thompson
Email: cet1 [at] cam.ac.uk

 
 
 

Using Make to detect an OS version?

Post by Tom Well » Thu, 26 Aug 1999 04:00:00



> Is there a way to have a makefile determine the OS being used and then
> exit if the makefile is being executed on an incorrect OS version?

[snip]

By reading the man page for make, I was able to glean the
following example:

/tmp/Makefile:

OS:sh           =uname -s
REV:sh          =uname -r|sed -e 's/5/2/'

test:

test1:

                echo "We are using SunOS"; \
        fi

test2:

                echo "We are running $(REV)"; \
        fi

Tom