Determining OS X version in Makefile

There is a number of ways to set up compilation options depending on an environment, including sophisticated tools like Autoconf and CMake. The most basic and commonly used approach is to include environment-specific options in a makefile for GNU Make. A typical example is choosing different options for Linux, Windows and OS X. Here we extend this example by considering the OS X version.

To determine the OS X version, we use output of the uname command with the -r option that returns the operating system release, e.g., 15.3.0. The first number of the release denotes the OS X version, for example, 15 denotes El Capitan. The table of OS X versions and release numbers is available on Wikipedia.

To extract the first number from the release, we use sed with the pattern 's/\..*//' that removes all symbols after the first dot including the dot.

A dummy makefile that illustrates the tricks described above and prints the OS X version is shown below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s