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.