Merge pull request #47 from radarsat1/fix-version
[rtaudio-cdist.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 AC_INIT(RtAudio, 4.1.1, gary@music.mcgill.ca, rtaudio)
3 AC_CONFIG_AUX_DIR(config)
4 AC_CONFIG_SRCDIR(RtAudio.cpp)
5 AC_CONFIG_FILES([rtaudio-config librtaudio.pc Makefile tests/Makefile])
6
7 # Fill GXX with something before test.
8 AC_SUBST( GXX, ["no"] )
9
10 dnl Check for pkg-config program, used for configuring some libraries.
11 m4_define_default([PKG_PROG_PKG_CONFIG],
12 [AC_MSG_CHECKING([pkg-config])
13 AC_MSG_RESULT([no])])
14
15 PKG_PROG_PKG_CONFIG
16
17 dnl If the pkg-config autoconf support isn't installed, define its
18 dnl autoconf macro to disable any packages depending on it.
19 m4_define_default([PKG_CHECK_MODULES],
20 [AC_MSG_CHECKING([$1])
21 AC_MSG_RESULT([no])
22 $4])
23
24 # Checks for programs.
25 AC_PROG_CXX(g++ CC c++ cxx)
26 AC_PROG_RANLIB
27 AC_PATH_PROG(AR, ar, no)
28 if [[ $AR = "no" ]] ; then
29     AC_MSG_ERROR("Could not find ar - needed to create a library");
30 fi
31
32 # Checks for header files.
33 AC_HEADER_STDC
34 AC_CHECK_HEADERS(sys/ioctl.h unistd.h)
35
36 # Check version number coherency between RtAudio.h and configure.ac
37 AC_MSG_CHECKING([that version numbers are coherent])
38 AC_RUN_IFELSE(
39    [AC_LANG_PROGRAM([#include <string.h>
40                      `grep "define RTAUDIO_VERSION" $srcdir/RtAudio.h`],
41                     [return strcmp(RTAUDIO_VERSION, PACKAGE_VERSION);])],
42    [AC_MSG_RESULT([yes])],
43    [AC_MSG_FAILURE([testing RTAUDIO_VERSION==PACKAGE_VERSION failed, check that RtAudio.h defines RTAUDIO_VERSION as "$PACKAGE_VERSION" or that the first line of configure.ac has been updated.])])
44
45 # Check for debug
46 AC_MSG_CHECKING(whether to compile debug version)
47 AC_ARG_ENABLE(debug,
48   [  --enable-debug = enable various debug output],
49   [AC_SUBST( cppflag, [-D__RTAUDIO_DEBUG__] ) AC_SUBST( cxxflag, [-g] ) AC_SUBST( object_path, [Debug] ) AC_MSG_RESULT(yes)],
50   [AC_SUBST( cppflag, [] ) AC_SUBST( cxxflag, [-O2] ) AC_SUBST( object_path, [Release] ) AC_MSG_RESULT(no)])
51
52 # Checks for functions
53 AC_CHECK_FUNC(gettimeofday, [cppflag="$cppflag -DHAVE_GETTIMEOFDAY"], )
54
55 # Set paths if prefix is defined
56 if test "x$prefix" != "x" && test "x$prefix" != "xNONE"; then
57   LIBS="$LIBS -L$prefix/lib"
58   CPPFLAGS="$CPPFLAGS -I$prefix/include"
59 fi
60
61 # For -I and -D flags
62 CPPFLAGS="$CPPFLAGS $cppflag"
63
64 # For debugging and optimization ... overwrite default because it has both -g and -O2
65 #CXXFLAGS="$CXXFLAGS $cxxflag"
66 CXXFLAGS="$cxxflag"
67
68 # Check compiler and use -Wall if gnu.
69 if [test $GXX = "yes" ;] then
70   AC_SUBST( cxxflag, ["-Wall -Wextra"] )
71 fi
72
73 CXXFLAGS="$CXXFLAGS $cxxflag"
74
75 AC_CANONICAL_HOST
76
77 AC_SUBST( sharedlib, ["librtaudio.so"] )
78 AC_SUBST( sharedname, ["librtaudio.so.\$(RELEASE)"] )
79 AC_SUBST( libflags, ["-shared -Wl,-soname,\$(SHARED).\$(MAJOR) -o \$(SHARED).\$(RELEASE)"] )
80 case $host in
81   *-apple*)
82   AC_SUBST( sharedlib, ["librtaudio.dylib"] )
83   AC_SUBST( sharedname, ["librtaudio.\$(RELEASE).dylib"] )
84   AC_SUBST( libflags, ["-dynamiclib -o librtaudio.\$(RELEASE).dylib"] )
85 esac
86
87 # Checks for package options and external software
88 AC_SUBST( api, [""] )
89 AC_SUBST( req, [""] )
90 AC_MSG_CHECKING(for audio API)
91 case $host in
92   *-*-netbsd*)
93     AC_MSG_RESULT(using OSS)
94     api="$api -D__LINUX_OSS__"
95     LIBS="$LIBS -lossaudio"
96     AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
97   ;;
98
99   *-*-linux*)
100   AC_ARG_WITH(jack, [  --with-jack = choose JACK server support (mac and linux only)], [
101     api="$api -D__UNIX_JACK__"
102     AC_MSG_RESULT(using JACK)
103     AC_CHECK_LIB(jack, jack_client_open, , AC_MSG_ERROR(JACK support requires the jack library!))
104     AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(Jack support also requires the asound library!))], )
105
106   # Look for ALSA flag
107   AC_ARG_WITH(alsa, [  --with-alsa = choose native ALSA API support (linux only)], [
108     api="$api -D__LINUX_ALSA__"
109     req="$req alsa"
110     AC_MSG_RESULT(using ALSA)
111     AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))], )
112
113   # Look for PULSE flag
114   AC_ARG_WITH(pulse, [  --with-pulse = choose PulseAudio API support (linux only)], [
115     api="$api -D__LINUX_PULSE__"
116     req="$req libpulse-simple"
117     AC_MSG_RESULT(using PulseAudio)
118     AC_CHECK_LIB(pulse-simple, pa_simple_flush, , AC_MSG_ERROR(PulseAudio support requires the pulse-simple library!))], )
119
120   # Look for OSS flag
121   AC_ARG_WITH(oss, [  --with-oss = choose OSS API support (linux only)], [
122     api="$api -D__LINUX_OSS__"
123     AC_MSG_RESULT(using OSS)], )
124
125   # If no audio api flags specified, use ALSA
126   if [test "$api" == "";] then
127     AC_MSG_RESULT(using ALSA)
128     AC_SUBST( api, [-D__LINUX_ALSA__] )
129     req="$req alsa"
130     AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))
131   fi
132
133   AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
134   ;;
135
136   *-apple*)
137   AC_ARG_WITH(jack, [  --with-jack = choose JACK server support (unix only)], [
138     api="$api -D__UNIX_JACK__"
139     AC_MSG_RESULT(using JACK)
140     AC_CHECK_LIB(jack, jack_client_open, , AC_MSG_ERROR(JACK support requires the jack library!))], )
141
142 #    AC_CHECK_HEADER(jack/jack.h, [], [AC_MSG_ERROR(Jack header file not found!)] )
143 #    LIBS="$LIBS -framework jackmp" ], )
144
145
146   # Look for Core flag
147   AC_ARG_WITH(core, [  --with-core = choose CoreAudio API support (mac only)], [
148     api="$api -D__MACOSX_CORE__"
149     AC_MSG_RESULT(using CoreAudio)
150     AC_CHECK_HEADER(CoreAudio/CoreAudio.h, [], [AC_MSG_ERROR(CoreAudio header files not found!)] )
151     LIBS="$LIBS -framework CoreAudio -framework CoreFoundation" ], )
152
153   # If no audio api flags specified, use CoreAudio
154   if [test "$api" == ""; ] then
155     AC_SUBST( api, [-D__MACOSX_CORE__] )
156     AC_MSG_RESULT(using CoreAudio)
157     AC_CHECK_HEADER(CoreAudio/CoreAudio.h,
158       [],
159       [AC_MSG_ERROR(CoreAudio header files not found!)] )
160     AC_SUBST( LIBS, ["-framework CoreAudio -framework CoreFoundation"] )
161   fi
162
163   AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
164   ;;
165
166   *-mingw32*)
167   AC_ARG_WITH(asio, [  --with-asio = choose ASIO API support (windoze only)], [
168     api="$api -D__WINDOWS_ASIO__"
169     AC_MSG_RESULT(using ASIO)
170     AC_SUBST( objects, ["asio.o asiodrivers.o asiolist.o iasiothiscallresolver.o"] ) ], )
171
172   # Look for DirectSound flag
173   AC_ARG_WITH(ds, [  --with-ds = choose DirectSound API support (windoze only)], [
174     api="$api -D__WINDOWS_DS__"
175     AC_MSG_RESULT(using DirectSound)
176     LIBS="-ldsound -lwinmm $LIBS" ], )
177
178   # Look for WASAPI flag
179   AC_ARG_WITH(wasapi, [  --with-wasapi = choose Windows Audio Session API support (windoze only)], [
180     api="$api -D__WINDOWS_WASAPI__"
181     AC_MSG_RESULT(using WASAPI)
182     LIBS="-lwinmm -luuid -lksuser $LIBS" ], )
183
184   # If no audio api flags specified, use DS
185   if [test "$api" == "";] then
186     AC_SUBST( api, [-D__WINDOWS_DS__] )
187     AC_MSG_RESULT(using DirectSound)
188     LIBS="-ldsound -lwinmm $LIBS"
189   fi
190
191   LIBS="-lole32 $LIBS"
192   ;;
193
194   *)
195   # Default case for unknown realtime systems.
196   AC_MSG_ERROR(Unknown system type for realtime support!)
197   ;;
198 esac
199
200 CPPFLAGS="$CPPFLAGS $api"
201
202 AC_OUTPUT
203
204 chmod oug+x rtaudio-config