1# Tell autoconf we're compiling a C++ program using automake and libtool.
2AC_INIT(adplay,1.8.1)
3AC_CONFIG_SRCDIR(src/adplay.cc)
4AC_CONFIG_FILES(Makefile src/Makefile doc/Makefile)
5AC_CANONICAL_TARGET
6AM_INIT_AUTOMAKE
7AM_CONFIG_HEADER(src/config.h)
8AM_PROG_LIBTOOL
9AC_LANG(C++)
10
11# Check if we got a sane C/C++ compilation environment.
12AC_PROG_INSTALL
13AC_PROG_CC
14AC_PROG_CXX
15AC_PROG_CPP
16AC_PROG_CXXCPP
17
18# Nothing works without these libraries...
19AC_CHECK_LIB(stdc++,main,,AC_MSG_ERROR([libstdc++ not installed]))
20PKG_CHECK_MODULES([adplug], [adplug >= 2.0],,[
21AC_MSG_WARN([You seem to be using a version of AdPlug prior to 2.0. \
22I will try to do the old-style library search for which i cannot check \
23versions. Please bear in mind that i am requiring at least version 1.4.])
24AC_CHECK_LIB(adplug,main,,AC_MSG_ERROR([*** AdPlug not installed ***]))])
25
26# Check if getopt header is installed on this system
27AC_CHECK_HEADERS([getopt.h], ,
28	AC_SUBST(GETOPT_SOURCES, [getopt.c getopt1.c getopt.h]))
29
30# Save compiler flags and set up for compiling test programs
31oldlibs="$LIBS"
32oldcppflags="$CPPFLAGS"
33LIBS="$LDFLAGS $adplug_LIBS"
34CPPFLAGS="$CPPFLAGS $adplug_CFLAGS"
35
36# Check if AdPlug is installed and linked correctly
37AC_MSG_CHECKING([whether AdPlug is linked correctly])
38AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <adplug/player.h>
39
40class Testplayer: public CPlayer
41{
42  public:
43    Testplayer(): CPlayer(NULL) {}
44    bool load(const std::string &f, const CFileProvider &fp) { return false; }
45    bool update() { return false; }
46    float getrefresh() { return 0; }
47    std::string gettype() { return std::string(); }
48    void rewind(int s) {}
49};
50
51Testplayer p;], [p.getrefresh();])],
52  AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]); AC_MSG_ERROR([Unable to compile a program using AdPlug. Please check to ensure AdPlug is installed correctly.]) )
53
54# Check if AdPlug supports the new getsubsong() method
55AC_MSG_CHECKING([whether AdPlug supports the getsubsong() method])
56AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <adplug/player.h>
57
58class Testplayer: public CPlayer
59{
60  public:
61    Testplayer(): CPlayer(NULL) {}
62    bool load(const std::string &f, const CFileProvider &fp) { return false; }
63    bool update() { return false; }
64    float getrefresh() { return 0; }
65    std::string gettype() { return std::string(); }
66    void rewind(int s) {}
67};
68
69Testplayer p;], [p.getsubsong();])],
70   AC_DEFINE(HAVE_ADPLUG_GETSUBSONG,, [Defined if AdPlug supports the getsubsong() method])
71AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]))
72
73# Check if AdPlug supports the new surround/harmonic synth
74AC_MSG_CHECKING([whether AdPlug supports the surround/harmonic synth])
75AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <adplug/surroundopl.h>], [CSurroundopl *dummy;])],
76   AC_DEFINE(HAVE_ADPLUG_SURROUND,, [Defined if AdPlug supports the surround/harmonic synth])
77AC_MSG_RESULT([yes]), AC_MSG_RESULT([no - AdPlug >= 2.2 required]))
78
79# Check if AdPlug supports NukedOPL
80AC_MSG_CHECKING([whether AdPlug supports the NukedOPL synth])
81AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <adplug/nemuopl.h>], [CNemuopl *dummy;])],
82   AC_DEFINE(HAVE_ADPLUG_NUKEDOPL,, [Defined if AdPlug supports the NukedOPL synth])
83AC_MSG_RESULT([yes]), AC_MSG_RESULT([no - AdPlug >= 2.3 required]))
84
85# Restore flags after compiling test programs
86LIBS="$oldlibs"
87CPPFLAGS="$oldcppflags"
88
89##### Output mechanism checks #####
90# These checks enable or disable certain output mechanisms,
91# depending on system facilities and user requests.
92
93# Define user option arguments
94AC_ARG_ENABLE([output-oss],AC_HELP_STRING([--disable-output-oss],[Disable OSS output]))
95AC_ARG_ENABLE([output-null],AC_HELP_STRING([--disable-output-null],[Disable null output]))
96AC_ARG_ENABLE([output-disk],AC_HELP_STRING([--disable-output-disk],[Disable disk writer]))
97AC_ARG_ENABLE([output-esound],AC_HELP_STRING([--disable-output-esound],[Disable EsounD output]))
98AC_ARG_ENABLE([output-qsa],AC_HELP_STRING([--disable-output-qsa],[Disable QSA output]))
99AC_ARG_ENABLE([output-sdl],AC_HELP_STRING([--disable-output-sdl],[Disable SDL output]))
100AC_ARG_ENABLE([output-alsa],AC_HELP_STRING([--disable-output-alsa],[Disable ALSA output]))
101AC_ARG_ENABLE([output-ao],AC_HELP_STRING([--disable-output-ao],[Disable AO output]))
102# Check if we can compile the enabled drivers:
103# OSS driver
104if test ${enable_output_oss:=yes} = yes; then
105   AC_MSG_CHECKING([for OSS headers])
106   AC_TRY_CPP([
107                #include <fcntl.h>
108                #include <sys/ioctl.h>
109       		#include <sys/soundcard.h>
110              ],[
111               	AC_DEFINE(DRIVER_OSS,1,[Build OSS driver])
112               	drivers=$drivers' oss.$(OBJEXT)'
113               	AC_MSG_RESULT([found])
114              ],[
115               	enable_output_oss=no
116               	AC_MSG_RESULT([not found -- OSS output disabled])
117              ])
118fi
119
120# AO output
121if test ${enable_output_ao:=yes} = yes; then
122   XIPH_PATH_AO(AC_DEFINE(DRIVER_AO,1,[Build AO output])
123   drivers=$drivers' ao.${OBJEXT}',
124   enable_output_ao=no
125   AC_MSG_RESULT([*** AO (libao) not installed ***]))
126fi
127
128# Null output
129if test ${enable_output_null:=yes} = yes; then
130   AC_DEFINE(DRIVER_NULL,1,[Build null output])
131fi
132
133# Disk writer
134if test ${enable_output_disk:=yes} = yes; then
135   AC_DEFINE(DRIVER_DISK,1,[Build disk writer])
136   drivers=$drivers' disk.$(OBJEXT)'
137fi
138
139# EsounD output
140if test ${enable_output_esound:=yes} = yes; then
141   AM_PATH_ESD(0.2.8,
142      AC_DEFINE(DRIVER_ESOUND,1,[Build EsounD output])
143      drivers=$drivers' esound.$(OBJEXT)',
144      enable_output_esound=no
145      AC_MSG_RESULT([*** EsounD (libesd) >= 0.2.8 not installed ***]))
146fi
147
148# QSA driver
149if test ${enable_output_qsa:=yes} = yes; then
150   AC_MSG_CHECKING([for QSA headers])
151   AC_TRY_COMPILE([
152                  #include <sys/asoundlib.h>
153                  #include <sys/neutrino.h>
154                  ],[
155                  int arg=snd_pcm_open_preferred(NULL, NULL, NULL, 0);
156                  ],[
157                  have_qsa=yes
158                  ])
159    if test x$have_qsa = xyes; then
160	AC_DEFINE(DRIVER_QSA,1,[Build QSA driver])
161	drivers=$drivers' qsa.$(OBJEXT)'
162        QSA_LIBS=-lasound
163        AC_SUBST(QSA_LIBS)
164	AC_MSG_RESULT([found])
165    else
166	enable_output_qsa=no
167        QSA_LIBS=""
168        AC_SUBST(QSA_LIBS)
169	AC_MSG_RESULT([not found -- QSA output disabled])
170    fi
171fi
172
173# SDL output
174if test ${enable_output_sdl:=yes} = yes; then
175   AC_LANG_PUSH(C)
176   EXULT_CHECK_SDL(
177	AC_DEFINE(DRIVER_SDL,1,[Build SDL output])
178	drivers=$drivers' sdl.$(OBJEXT)',
179	enable_output_sdl=no
180	AC_MSG_RESULT([*** SDL (libsdl) >= 1.2.0 not installed ***]))
181   AC_LANG_POP(C)
182fi
183
184# ALSA output
185if test ${enable_output_alsa:=yes} = yes; then
186   AM_PATH_ALSA(0.9.1,
187	AC_DEFINE(DRIVER_ALSA,1,[Build ALSA output])
188	drivers=$drivers' alsa.${OBJEXT}',
189	enable_output_alsa=no
190	AC_MSG_RESULT([*** ALSA (libasound) >= 0.9.1 not installed ***]))
191fi
192
193
194
195AC_SUBST([drivers])
196
197AC_OUTPUT
198
199# Display user informative configuration output
200echo ""
201echo "Configuration:"
202echo "Install path:             ${prefix}"
203echo ""
204echo "Build output mechanisms:"
205echo "OSS output (oss):         ${enable_output_oss}"
206echo "Null output (null):       ${enable_output_null}"
207echo "Disk writer (disk):       ${enable_output_disk}"
208echo "EsounD output (esound):   ${enable_output_esound}"
209echo "QSA output (qsa):         ${enable_output_qsa}"
210echo "SDL output (sdl):         ${enable_output_sdl}"
211echo "ALSA output (alsa):       ${enable_output_alsa}"
212echo "Libao output (ao):        ${enable_output_ao}"
213
214if test "x$exult_sdlok" = xyes; then
215   echo ""
216   echo "SDL version:              `$SDL_CONFIG $sdl_args --version`"
217fi
218