How to check the OS with automake
NickName:melchor629 Ask DateTime:2016-08-11T22:03:48

How to check the OS with automake

I have a project that uses automake to create the configure and all related files (I'm using autoreconf command to make all this stuff). So, I'm trying to set some conditional files to compile when the project is compiling for macOS (OS X), Windows or Linux. But it fails with the following:

 $ autoreconf -i ..
src/Makefile.am:30: error: LINUX does not appear in AM_CONDITIONAL
autoreconf: automake failed with exit status: 1

And the part containing the error in that Makefile.am is the following:

if OSX
    butt_SOURCES += CurrentTrackOSX.h CurrentTrackOSX.m
endif
if LINUX
    butt_SOURCES += currentTrack.h currentTrackLinux.cpp
endif
if WINDOWS
    butt_SOURCES += currentTrack.h currentTrack.cpp
endif

My question is, how can I check if the OS is Linux? And if it's possible, is there a better way to check the OS in automake?

Copyright Notice:Content Author:「melchor629」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/38898591/how-to-check-the-os-with-automake

Answers
tversteeg 2016-08-11T14:27:00

You can detect it directly in the Makefile, or define the conditionals in the configure source file (probably configure.ac), since you are using autoreconf:\n\n# AC_CANONICAL_HOST is needed to access the 'host_os' variable \nAC_CANONICAL_HOST\n\nbuild_linux=no\nbuild_windows=no\nbuild_mac=no\n\n# Detect the target system\ncase \"${host_os}\" in\n linux*)\n build_linux=yes\n ;;\n cygwin*|mingw*)\n build_windows=yes\n ;;\n darwin*)\n build_mac=yes\n ;;\n *)\n AC_MSG_ERROR([\"OS $host_os is not supported\"])\n ;;\nesac\n\n# Pass the conditionals to automake\nAM_CONDITIONAL([LINUX], [test \"$build_linux\" = \"yes\"])\nAM_CONDITIONAL([WINDOWS], [test \"$build_windows\" = \"yes\"])\nAM_CONDITIONAL([OSX], [test \"$build_mac\" = \"yes\"])\n\n\n\n Note: host_os refers to the target system, so if you are cross-compiling it sets the OS conditional of the system you are compiling to.\n",


More about “How to check the OS with automake” related questions

How to check the OS with automake

I have a project that uses automake to create the configure and all related files (I'm using autoreconf command to make all this stuff). So, I'm trying to set some conditional files to compile whe...

Show Detail

How to check whether it's a 32/64 bit os in an automake file?

I want to check whether the operating system used is 32 bit or 64 bit inside an automake(.am) file.

Show Detail

MacOS - automake: command not found

I am trying to install automake on MacOS using brew. From terminal I write, brew install automake says Warning: automake-1.15 already installed. When I then try automake version it responds -bash:

Show Detail

check automake/autoconf version in configure script

I'm trying to edit a configure script that will execute this piece of code if it is above Automake version x.xx, and if it isn't, it executes a different piece of code. So, I need the version to b...

Show Detail

new version of automake failing

I'm trying to build iptables which requires automake as part of the build step. While I have this working on my machine, a colleague is having trouble. the configure is failing due to an automake...

Show Detail

automake install target prior to make check

How can I get automake to install one of the libraries prior to executing the check scripts? The project builds a mock testing library for one of the libraries we dynamically load (via a call to d...

Show Detail

automake error: no proper invocation of AM_INIT_AUTOMAKE was found

I am new in autotools, and following this tutorial. but I could not solve this errors, $ automake configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found. .. Makefile...

Show Detail

How to define AUTOMAKE_OPTIONS conditionally?

In an autotools-based project, I currently have the following line in my Makefile.am: AUTOMAKE_OPTIONS = serial-tests I would like to make this option apply if and only if my automake version is ...

Show Detail

Makefile.in Files Not Generated with Automake 1.12.2

I recently upgraded my OS and upgraded my autotools versions with it. Now, one branch of my project will no longer build because automake no longer is using the Makefile.am files to generate the Ma...

Show Detail

How do I get a list of symbols from an automake/libtool library?

I am the maintainer of twolame, a MPEG Audio Layer 2 encoding library. It is built using autoconf/automake/libtool. As part of the build/test process I would like to get a list of visible/exported

Show Detail