Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the OS with automake

Tags:

linux

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?

like image 214
melchor629 Avatar asked Aug 11 '16 14:08

melchor629


People also ask

What version of Automake can be specified in the Makefile?

A version number (e.g., ‘ 0.30 ’) can be specified. If Automake is not the same version or newer than the version specified, creation of the Makefile.in will be suppressed.

What is the No-exeext option in Automake?

However, by default automake will generate an error for this use. The no-exeext option will disable this error. This is intended for use only where it is known in advance that the package will not be ported to Windows, or any other operating system using extensions on executables.

Is there a way to initialize the source tree in Automake?

However, automake and autoconf need a bunch of other shit to actually work. There are several command used to "initialize" your source tree so automake knows everything about it and what to do. So, I usually execute a file like this to initialize. Call it autogen.sh or something similar. This isn't really something that's distributed.

Is it possible to use dist-Tarz in Automake 2?

Support for it will be removed altogether in Automake 2.0. Hook dist-tarZ to dist. Use of this option is deprecated, as the ‘ compress ’ program is obsolete. Support for it will be removed altogether in Automake 2.0. Abort if file names longer than 99 characters are found during ‘ make dist ’.


1 Answers

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:

# AC_CANONICAL_HOST is needed to access the 'host_os' variable    
AC_CANONICAL_HOST

build_linux=no
build_windows=no
build_mac=no

# Detect the target system
case "${host_os}" in
    linux*)
        build_linux=yes
        ;;
    cygwin*|mingw*)
        build_windows=yes
        ;;
    darwin*)
        build_mac=yes
        ;;
    *)
        AC_MSG_ERROR(["OS $host_os is not supported"])
        ;;
esac

# Pass the conditionals to automake
AM_CONDITIONAL([LINUX], [test "$build_linux" = "yes"])
AM_CONDITIONAL([WINDOWS], [test "$build_windows" = "yes"])
AM_CONDITIONAL([OSX], [test "$build_mac" = "yes"])

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.

like image 189
tversteeg Avatar answered Oct 28 '22 02:10

tversteeg