Move version check up to beginning of configure.ac.
[rtaudio.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 AC_INIT(RtAudio, 4.1.2, gary@music.mcgill.ca, rtaudio)
3 AC_CONFIG_AUX_DIR(config)
4 AC_CONFIG_SRCDIR(RtAudio.cpp)
5 AC_CONFIG_FILES([rtaudio-config rtaudio.pc Makefile tests/Makefile doc/Makefile doc/doxygen/Doxyfile])
6 AM_INIT_AUTOMAKE([1.14 -Wall -Werror foreign subdir-objects])
7
8 # libtool version: current:revision:age
9 #
10 # If the library source code has changed at all since the last update, then
11 # increment revision (`c:r:a' becomes `c:r+1:a').
12 #
13 # If any interfaces have been added, removed, or changed since the last update,
14 # increment current, and set revision to 0.
15 #
16 # If any interfaces have been added since the last public release, then
17 # increment age.
18 #
19 # If any interfaces have been removed since the last public release, then set
20 # age to 0.
21 m4_define([lt_current], 5)
22 m4_define([lt_revision], 0)
23 m4_define([lt_age], 0)
24
25 m4_define([lt_version_info], [lt_current:lt_revision:lt_age])
26 m4_define([lt_current_minus_age], [m4_eval(lt_current - lt_age)])
27
28 SO_VERSION=lt_version_info
29 AC_SUBST(SO_VERSION)
30
31 # Check version number coherency between RtAudio.h and configure.ac
32 AC_MSG_CHECKING([that version numbers are coherent])
33 AC_RUN_IFELSE(
34    [AC_LANG_PROGRAM([#include <string.h>
35                      `grep "define RTAUDIO_VERSION" $srcdir/RtAudio.h`],
36                     [return strcmp(RTAUDIO_VERSION, PACKAGE_VERSION);])],
37    [AC_MSG_RESULT([yes])],
38    [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.])])
39
40 # Enable some nice automake features if they are available
41 m4_ifdef([AM_MAINTAINER_MODE], [AM_MAINTAINER_MODE])
42 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
43
44 # Fill GXX with something before test.
45 AC_SUBST( GXX, ["no"] )
46
47 dnl Check for pkg-config program, used for configuring some libraries.
48 m4_define_default([PKG_PROG_PKG_CONFIG],
49 [AC_MSG_CHECKING([pkg-config])
50 AC_MSG_RESULT([no])])
51
52 PKG_PROG_PKG_CONFIG
53
54 dnl If the pkg-config autoconf support isn't installed, define its
55 dnl autoconf macro to disable any packages depending on it.
56 m4_define_default([PKG_CHECK_MODULES],
57 [AC_MSG_CHECKING([$1])
58 AC_MSG_RESULT([no])
59 $4])
60
61 # Checks for programs.
62 AC_PROG_CXX(g++ CC c++ cxx)
63 AM_PROG_AR
64 AC_PATH_PROG(AR, ar, no)
65 if [[ $AR = "no" ]] ; then
66     AC_MSG_ERROR("Could not find ar - needed to create a library");
67 fi
68
69 # Initialize libtool
70 LT_INIT([win32-dll])
71 AC_CONFIG_MACRO_DIR([m4])
72
73 # Checks for header files.
74 AC_HEADER_STDC
75 AC_CHECK_HEADERS(sys/ioctl.h unistd.h)
76
77 # Check for debug
78 AC_MSG_CHECKING(whether to compile debug version)
79 AC_ARG_ENABLE(debug,
80   [  --enable-debug = enable various debug output],
81   [AC_SUBST( cppflag, [-D__RTAUDIO_DEBUG__] ) AC_SUBST( cxxflag, [-g] ) AC_SUBST( object_path, [Debug] ) AC_MSG_RESULT(yes)],
82   [AC_SUBST( cppflag, [] ) AC_SUBST( cxxflag, [-O2] ) AC_SUBST( object_path, [Release] ) AC_MSG_RESULT(no)])
83
84 # Checks for functions
85 AC_CHECK_FUNC(gettimeofday, [cppflag="$cppflag -DHAVE_GETTIMEOFDAY"], )
86
87 # Set paths if prefix is defined
88 if test "x$prefix" != "x" && test "x$prefix" != "xNONE"; then
89   LIBS="$LIBS -L$prefix/lib"
90   CPPFLAGS="$CPPFLAGS -I$prefix/include"
91 fi
92
93 # For -I and -D flags
94 CPPFLAGS="$CPPFLAGS $cppflag"
95
96 # For debugging and optimization ... overwrite default because it has both -g and -O2
97 #CXXFLAGS="$CXXFLAGS $cxxflag"
98 CXXFLAGS="$cxxflag"
99
100 # Check compiler and use -Wall if gnu.
101 if [test $GXX = "yes" ;] then
102   AC_SUBST( cxxflag, ["-Wall -Wextra"] )
103 fi
104
105 CXXFLAGS="$CXXFLAGS $cxxflag"
106
107 # Checks for doxygen
108 AC_CHECK_PROG( DOXYGEN, [doxygen], [doxygen] )
109 AM_CONDITIONAL( MAKE_DOC, [test "x${DOXYGEN}" != x] )
110
111 # Copy doc files to build dir if necessary
112 AC_CONFIG_LINKS( [doc/release.txt:doc/release.txt] )
113 AC_CONFIG_LINKS( [doc/doxygen/footer.html:doc/doxygen/footer.html] )
114 AC_CONFIG_LINKS( [doc/doxygen/error.txt:doc/doxygen/error.txt] )
115 AC_CONFIG_LINKS( [doc/doxygen/tutorial.txt:doc/doxygen/tutorial.txt] )
116 AC_CONFIG_LINKS( [doc/doxygen/compiling.txt:doc/doxygen/compiling.txt] )
117 AC_CONFIG_LINKS( [doc/doxygen/acknowledge.txt:doc/doxygen/acknowledge.txt] )
118 AC_CONFIG_LINKS( [doc/doxygen/license.txt:doc/doxygen/license.txt] )
119 AC_CONFIG_LINKS( [doc/doxygen/header.html:doc/doxygen/header.html] )
120 AC_CONFIG_LINKS( [doc/doxygen/duplex.txt:doc/doxygen/duplex.txt] )
121 AC_CONFIG_LINKS( [doc/doxygen/settings.txt:doc/doxygen/settings.txt] )
122 AC_CONFIG_LINKS( [doc/doxygen/probe.txt:doc/doxygen/probe.txt] )
123 AC_CONFIG_LINKS( [doc/doxygen/playback.txt:doc/doxygen/playback.txt] )
124 AC_CONFIG_LINKS( [doc/doxygen/multi.txt:doc/doxygen/multi.txt] )
125 AC_CONFIG_LINKS( [doc/doxygen/recording.txt:doc/doxygen/recording.txt] )
126 AC_CONFIG_LINKS( [doc/doxygen/apinotes.txt:doc/doxygen/apinotes.txt] )
127 AC_CONFIG_LINKS( [doc/images/mcgill.gif:doc/images/mcgill.gif] )
128 AC_CONFIG_LINKS( [doc/images/ccrma.gif:doc/images/ccrma.gif] )
129
130 # Checks for package options and external software
131 AC_CANONICAL_HOST
132
133 AC_SUBST( api, [""] )
134 AC_SUBST( req, [""] )
135 AC_MSG_CHECKING(for audio API)
136 case $host in
137   *-*-netbsd*)
138     AC_MSG_RESULT(using OSS)
139     api="$api -D__LINUX_OSS__"
140     LIBS="$LIBS -lossaudio"
141     AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
142   ;;
143
144   *-*-linux*)
145   AC_ARG_WITH(jack, [  --with-jack = choose JACK server support (mac and linux only)], [
146     api="$api -D__UNIX_JACK__"
147     AC_MSG_RESULT(using JACK)
148     AC_CHECK_LIB(jack, jack_client_open, , AC_MSG_ERROR(JACK support requires the jack library!))
149     AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(Jack support also requires the asound library!))], )
150
151   # Look for ALSA flag
152   AC_ARG_WITH(alsa, [  --with-alsa = choose native ALSA API support (linux only)], [
153     api="$api -D__LINUX_ALSA__"
154     req="$req alsa"
155     AC_MSG_RESULT(using ALSA)
156     AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))], )
157
158   # Look for PULSE flag
159   AC_ARG_WITH(pulse, [  --with-pulse = choose PulseAudio API support (linux only)], [
160     api="$api -D__LINUX_PULSE__"
161     req="$req libpulse-simple"
162     AC_MSG_RESULT(using PulseAudio)
163     AC_CHECK_LIB(pulse-simple, pa_simple_flush, , AC_MSG_ERROR(PulseAudio support requires the pulse-simple library!))], )
164
165   # Look for OSS flag
166   AC_ARG_WITH(oss, [  --with-oss = choose OSS API support (linux only)], [
167     api="$api -D__LINUX_OSS__"
168     AC_MSG_RESULT(using OSS)], )
169
170   # If no audio api flags specified, use ALSA
171   if [test "$api" == "";] then
172     AC_MSG_RESULT(using ALSA)
173     AC_SUBST( api, [-D__LINUX_ALSA__] )
174     req="$req alsa"
175     AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))
176   fi
177
178   AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
179   ;;
180
181   *-apple*)
182   AC_ARG_WITH(jack, [  --with-jack = choose JACK server support (unix only)], [
183     api="$api -D__UNIX_JACK__"
184     AC_MSG_RESULT(using JACK)
185     AC_CHECK_LIB(jack, jack_client_open, , AC_MSG_ERROR(JACK support requires the jack library!))], )
186
187 #    AC_CHECK_HEADER(jack/jack.h, [], [AC_MSG_ERROR(Jack header file not found!)] )
188 #    LIBS="$LIBS -framework jackmp" ], )
189
190
191   # Look for Core flag
192   AC_ARG_WITH(core, [  --with-core = choose CoreAudio API support (mac only)], [
193     api="$api -D__MACOSX_CORE__"
194     AC_MSG_RESULT(using CoreAudio)
195     AC_CHECK_HEADER(CoreAudio/CoreAudio.h, [], [AC_MSG_ERROR(CoreAudio header files not found!)] )
196     LIBS="$LIBS -framework CoreAudio -framework CoreFoundation" ], )
197
198   # If no audio api flags specified, use CoreAudio
199   if [test "$api" == ""; ] then
200     AC_SUBST( api, [-D__MACOSX_CORE__] )
201     AC_MSG_RESULT(using CoreAudio)
202     AC_CHECK_HEADER(CoreAudio/CoreAudio.h,
203       [],
204       [AC_MSG_ERROR(CoreAudio header files not found!)] )
205     AC_SUBST( LIBS, ["-framework CoreAudio -framework CoreFoundation"] )
206   fi
207
208   AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
209   ;;
210
211   *-mingw32*)
212   AC_ARG_WITH(asio, [  --with-asio = choose ASIO API support (windoze only)], [
213     api="$api -D__WINDOWS_ASIO__"
214     AC_MSG_RESULT(using ASIO)
215     AC_SUBST( objects, ["asio.o asiodrivers.o asiolist.o iasiothiscallresolver.o"] ) ], )
216
217   # Look for DirectSound flag
218   AC_ARG_WITH(ds, [  --with-ds = choose DirectSound API support (windoze only)], [
219     api="$api -D__WINDOWS_DS__"
220     AC_MSG_RESULT(using DirectSound)
221     LIBS="-ldsound -lwinmm $LIBS" ], )
222
223   # Look for WASAPI flag
224   AC_ARG_WITH(wasapi, [  --with-wasapi = choose Windows Audio Session API support (windoze only)], [
225     api="$api -D__WINDOWS_WASAPI__"
226     AC_MSG_RESULT(using WASAPI)
227     LIBS="-lwinmm -luuid -lksuser $LIBS" ], )
228
229   # If no audio api flags specified, use DS
230   if [test "$api" == "";] then
231     AC_SUBST( api, [-D__WINDOWS_DS__] )
232     AC_MSG_RESULT(using DirectSound)
233     LIBS="-ldsound -lwinmm $LIBS"
234   fi
235
236   LIBS="-lole32 $LIBS"
237   ;;
238
239   *)
240   # Default case for unknown realtime systems.
241   AC_MSG_ERROR(Unknown system type for realtime support!)
242   ;;
243 esac
244
245 CPPFLAGS="$CPPFLAGS $api"
246
247 AC_OUTPUT
248
249 chmod oug+x rtaudio-config