Awful
[openitg.git] / configure.ac
1 # only tested with autoconf 2.57
2 AC_PREREQ(2.53)
3 AC_INIT(src/StepMania.cpp)
4 AC_CONFIG_AUX_DIR(autoconf)
5 AC_CANONICAL_TARGET
6
7 AM_INIT_AUTOMAKE(OpenITG, 1.01)
8 AM_CONFIG_HEADER(src/config.h)
9 AM_MAINTAINER_MODE
10
11 # We don't want PROG_CC/CXX default settings, but don't ignore explicit settings.
12 test -z "$CFLAGS" && DEFAULT_CFLAGS=yes
13 test -z "$CXXFLAGS" && DEFAULT_CXXFLAGS=yes
14 test -z "$LDFLAGS" && DEFAULT_LDFLAGS=yes
15
16 AC_PROG_CC
17 AC_PROG_CXX
18 AC_PROG_RANLIB
19
20 test "$DEFAULT_CFLAGS" = "yes" && CFLAGS="-Wall -W -Wno-unused -Wno-switch"
21 test "$DEFAULT_CXXFLAGS" = "yes" && CXXFLAGS="-Wall -W -Wno-unused -Wno-switch"
22 test "$DEFAULT_LDFLAGS" = "yes" && LDFLAGS=""
23
24 compile=release
25 AC_ARG_WITH(debug, AC_HELP_STRING([--with-debug], [Enable debug mode]), with_debug=$withval, with_debug=no)
26 AC_ARG_WITH(fast-compile, AC_HELP_STRING([--with-fast-compile], [Enable fast compile]), with_fast_compile=$withval, with_fast_compile=no)
27 if test "$with_debug" = "yes"; then
28 compile=debug
29 fi
30 if test "$with_fast_compile" = "yes"; then
31 compile=fast
32 fi
33
34 case $compile in
35 release)
36 test "$DEFAULT_CFLAGS" = "yes" && CFLAGS="$CFLAGS -O3"
37 test "$DEFAULT_CXXFLAGS" = "yes" && CXXFLAGS="$CXXFLAGS -O3"
38 ;;
39 debug)
40 test "$DEFAULT_CFLAGS" = "yes" && CFLAGS="$CFLAGS -g"
41 test "$DEFAULT_CXXFLAGS" = "yes" && CXXFLAGS="$CXXFLAGS -g"
42 ;;
43 fast)
44 test "$DEFAULT_CFLAGS" = "yes" && CFLAGS="$CFLAGS -O2 -fno-inline"
45 test "$DEFAULT_CXXFLAGS" = "yes" && CXXFLAGS="$CXXFLAGS -O2 -fno-inline"
46 ;;
47 esac
48
49 # Define UNIX for all Unix-like systems. Don't define it for cross-compiling to
50 # non-Unix-like systems. (-DUNIX selects the archutils and ArchHooks to use; if
51 # your platform doesn't use the Unix ones, you probably don't want to define UNIX.)
52 case $host in
53 *-linux-*)
54 AC_DEFINE(LINUX, 1, [Linux])
55 AC_DEFINE(UNIX, 1, [Unix])
56 linux=yes
57 unix=yes
58 ;;
59
60 *)
61 AC_DEFINE(UNIX, 1, [Unix])
62 unix=yes
63 ;;
64 esac
65 AM_CONDITIONAL(UNIX, test "$unix" = "yes" )
66 AM_CONDITIONAL(LINUX, test "$linux" = "yes" )
67
68 # Define macros for individual CPU types, for a few bits of inline assembly.
69 # This is for major, compatible CPU classes--"CPU_X86" includes P2, P3, P4,
70 # AMD, etc. If you need CPU-specific assembly, check at runtime--don't create
71 # separate binaries for each CPU if the binaries themselves are otherwise
72 # compatible.
73 case $host in
74 i?86-*)
75 AC_DEFINE(CPU_X86, 1, [x86])
76 ;;
77 x86_64-*)
78 AC_DEFINE(CPU_X86_64, 1, [x86-64])
79 ;;
80 powerpc-*)
81 AC_DEFINE(CPU_PPC, 1, [PPC])
82 ;;
83 esac
84
85
86 AC_C_BIGENDIAN(
87 AC_DEFINE(ENDIAN_BIG, 1, [Big endian]),
88 AC_DEFINE(ENDIAN_LITTLE, 1, [Little endian]),
89 AC_MSG_ERROR([Can't determine endianness]) )
90
91 AC_ARG_WITH(prof, AC_HELP_STRING([--with-prof], [Enable profiling]), with_prof=$withval, with_prof=no)
92 if test "$with_prof" = "yes"; then
93 test "$DEFAULT_CFLAGS" = "yes" && CFLAGS="$CFLAGS -pg"
94 test "$DEFAULT_CXXFLAGS" = "yes" && CXXFLAGS="$CXXFLAGS -pg"
95 test "$DEFAULT_LDFLAGS" = "yes" && LDFLAGS="$LDFLAGS -pg"
96 fi
97
98 SM_X_WITH_OPENGL
99
100 AC_ARG_ENABLE(sdl, AC_HELP_STRING([--enable-sdl], [Enable SDL support]), enable_sdl=$enableval, enable_sdl=no)
101 if test "$enable_sdl" = "yes"; then
102 AM_PATH_SDL(1.2.6,have_sdl=yes,have_sdl=no)
103 fi
104 AM_CONDITIONAL(HAVE_SDL, test "$have_sdl" = "yes")
105 if test "$have_sdl" = "yes"; then
106 AC_DEFINE(HAVE_SDL, 1, [SDL is available])
107 fi
108
109 # sdl-config puts -L/usr/lib in the library search path, which reorders things
110 # in a way that breaks some configurations.
111 # Does this still need to be in?
112 # not sure
113 # SDL_LIBS="`echo $SDL_LIBS | sed 's_-L/usr/lib/\?[[ $]]__'`"
114
115 have_libpng=yes
116 AC_CHECK_LIB(png, png_create_read_struct, [x=y], have_libpng=no, [-lz -lm]) # x=y to stop autoconf from messing with LIBS
117 AC_CHECK_HEADER(png.h, , have_libpng=no)
118 if test "$have_libpng" = "no"; then
119 echo
120 echo "*** libpng is required to build StepMania; please make sure that"
121 echo "*** it is installed to continue the build process."
122 exit 1
123 fi
124 LIBS="$LIBS -lpng -lz -lm"
125
126 AC_ARG_WITH(jpeg, AC_HELP_STRING([--without-jpeg], [Disable JPEG support]), with_jpeg=$withval, with_jpeg=yes)
127
128 if test "$with_jpeg" = "yes"; then
129 have_libjpeg=yes
130 AC_CHECK_LIB(jpeg, jpeg_read_scanlines, [x=y], have_libjpeg=no) # x=y to stop autoconf from messing with LIBS
131 AC_CHECK_HEADER(jpeglib.h, , have_libjpeg=no)
132
133 if test "$have_libjpeg" = "no"; then
134 # Require JPEG by default, so people don't compile without it
135 # by accident and then come asking us why files won't load.
136 AC_MSG_ERROR(
137 [libjpeg is required to build StepMania; please make sure that it is installed
138 to continue the build process. If you really want to compile without JPEG
139 support, pass the "--without-jpeg" flag to configure.])
140 fi
141 have_libjpeg=
142
143 LIBS="$LIBS -ljpeg"
144 else
145 AC_DEFINE(NO_JPEG_SUPPORT, 1, [JPEG support not available])
146 fi
147
148 AC_ARG_WITH(network, AC_HELP_STRING([--without-network], [Disable networking]), with_network=$withval, with_network=yes)
149 if test "$with_network" = "no"; then
150 AC_DEFINE(WITHOUT_NETWORKING, 1, [Networking support not available])
151 fi
152 AM_CONDITIONAL(WITHOUT_NETWORKING, test "$with_network" = "no")
153
154
155 AC_ARG_ENABLE(itg-arcade, AC_HELP_STRING([--enable-itg-arcade], [Enable arcade-specific behavior]), itg_arcade=$enableval, itg_arcade=no)
156 if test "$itg_arcade" = "yes"; then
157 AC_DEFINE(ITG_ARCADE, 1, [Use arcade mountpoints and behavior])
158 fi
159 AM_CONDITIONAL(ITG_ARCADE, test "$itg_arcade" = "yes")
160
161 SM_LUA
162 SM_ZLIB
163 SM_AUDIO
164 SM_TLS
165 SM_LIBUSB
166
167 # for linux joystick hotplug
168 have_inotify=no
169 AC_CHECK_HEADER([sys/inotify.h],
170 have_inotify=yes
171 AC_DEFINE(HAVE_INOTIFY, 1, [inotify support in kernel])
172 ,)
173
174 have_ffmpeg=static
175 have_libresample=static
176 have_sse2=no
177
178 # search for system libs if not building for arcade
179 if test "$itg_arcade" = "no"; then
180 AC_SEARCH_LIBS(avcodec_init, [avcodec], have_libavcodec=yes, have_libavcodec=no)
181 AC_SEARCH_LIBS(guess_format, [avformat], have_libavformat=yes, have_libavformat=no)
182 AC_SEARCH_LIBS(swscale_version, [swscale], have_libswscale=yes, have_libswscale=no)
183
184 have_libresample=yes
185 AC_CHECK_LIB(resample, resample_open, [x=y], have_libresample=static, [-lm])
186 if test "$have_libresample" = "yes"; then
187 LIBS="$LIBS -lresample"
188 fi
189
190 if test "$have_libavcodec" = "yes"; then
191 AC_MSG_CHECKING([for libavcodec >= 0.5.2])
192 AC_TRY_RUN([
193 #include <libavcodec/avcodec.h>
194 int main()
195 {
196 return ( LIBAVCODEC_VERSION_INT < 0x341401 )? 1:0;
197 }
198 ],,have_libavcodec=no,)
199 AC_MSG_RESULT($have_libavcodec)
200 fi
201
202 if test "$have_libavformat" = "yes"; then
203 AC_MSG_CHECKING([for libavformat >= 0.5.2])
204 AC_TRY_RUN([
205 #include <libavformat/avformat.h>
206 int main()
207 {
208 return ( LIBAVFORMAT_VERSION_INT < 0x341F00 )? 1:0;
209 }
210 ],,have_libavformat=no,)
211 AC_MSG_RESULT($have_libavformat)
212 fi
213
214 if test "$have_libswscale" = "yes"; then
215 AC_MSG_CHECKING([for libswscale >= 0.5.2])
216 AC_TRY_RUN([
217 #include <libswscale/swscale.h>
218 int main()
219 {
220 return ( LIBSWSCALE_VERSION_INT < 0x000701 )? 1:0;
221 }
222 ],,have_libswscale=no,)
223 AC_MSG_RESULT($have_libswscale)
224 fi
225
226 if test "$have_libavformat" = "yes" -a "$have_libavcodec" = "yes" -a "$have_libswscale" = "yes"; then
227 have_ffmpeg=yes
228 AC_DEFINE(HAVE_FFMPEG, 1, [FFMPEG support available])
229 fi
230
231 # test if processor supports SSE2
232 AC_TRY_RUN([int main() { int a,d; asm ("cpuid":"=a"(a),"=d"(d):"0"(1)); return d & (1 << 26) ? 0 : 1; }], have_sse2=yes, have_sse2=no)
233 fi
234
235 AM_CONDITIONAL(HAVE_FFMPEG, test "$have_ffmpeg" = "yes")
236 AM_CONDITIONAL(HAVE_LIBRESAMPLE, test "$have_libresample" = "yes")
237
238 # Don't use SSE2 by default; some GCC versions misoptimise the code, which
239 # causes Heisenbugs, and we don't want to inflict that pain unnecessarily.
240 # Only supply it if the user specifically asks.
241
242 AC_ARG_WITH(sse2, AC_HELP_STRING([--with-sse2], [Enable SSE2 optimization]), with_sse2=$withval, with_sse2=no)
243 if test "$with_sse2" = "yes"; then
244 CFLAGS="$CFLAGS -msse2"
245 CXXFLAGS="$CXXFLAGS -msse2"
246 fi
247
248 SM_CHECK_CRASH_HANDLER
249
250 alsa=yes
251 AM_PATH_ALSA(0.9.0,AC_DEFINE([HAVE_ALSA],1,[Define presence of ALSA]),alsa=no)
252
253 AM_ICONV
254
255 AC_ARG_ENABLE(gtk2, AC_HELP_STRING([--disable-gtk2], [Disable GTK support]), enable_gtk2=$enableval, enable_gtk2=yes)
256
257 if test x$enable_gtk2 = xyes; then
258 AM_PATH_GTK_2_0(2.0.0,AC_DEFINE([HAVE_GTK],1,[Define presence of GTK]),enable_gtk2=no)
259 fi
260
261 AC_CHECK_HEADER(sys/soundcard.h, [AC_DEFINE(HAVE_OSS, 1, [OSS support available])])
262 AC_CHECK_DECL(OSS_GETVERSION, AC_DEFINE([HAVE_OSS_GETVERSION],1,[OSS_GETVERSION is defined]), , [#include <sys/soundcard.h>])
263 AC_ARG_ENABLE(force-oss, AC_HELP_STRING([--enable-force-oss], [Force OSS]), force_oss=$enableval, force_oss=no)
264 AC_CHECK_HEADER(stdint.h, , [AC_DEFINE(MISSING_STDINT_H, 1, [stdint.h is missing])])
265 AC_CHECK_HEADERS([inttypes.h endian.h])
266
267 AC_MSG_CHECKING(if cstdlib breaks llabs)
268 AC_TRY_COMPILE( [#include <stdlib.h>
269 #include <cstdlib> ],
270 [int foo() { return llabs(1); }],
271 [AC_MSG_RESULT(no)],
272 [AC_MSG_RESULT(yes)
273 AC_DEFINE([NEED_CSTDLIB_WORKAROUND], 1, [cstdlib breaks llabs])]
274 )
275
276 AC_CHECK_LIB( pthread, pthread_create, AC_DEFINE([HAVE_LIBPTHREAD],1,[libpthread is available]) )
277 AC_CHECK_LIB( pthread, pthread_mutex_timedlock, AC_DEFINE([HAVE_PTHREAD_MUTEX_TIMEDLOCK],1,[pthreads has pthread_mutex_timedlock()]) )
278 AC_CHECK_LIB( pthread, pthread_cond_timedwait, AC_DEFINE([HAVE_PTHREAD_COND_TIMEDWAIT],1,[pthreads has pthread_cond_timedwait()]) )
279
280 # Always:
281 AC_DEFINE(_GNU_SOURCE, 1, [Use GNU extensions])
282
283 AM_CONDITIONAL(HAVE_ALSA, test x$alsa != xno )
284 AM_CONDITIONAL(HAVE_GTK, test "$enable_gtk2" != "no" )
285 AM_CONDITIONAL(HAVE_OSS, test x$ac_cv_header_sys_soundcard_h = xyes )
286 AM_CONDITIONAL(USE_CRASH_HANDLER, test "$use_crash_handler" = "yes" )
287
288 if test x$force_oss = xyes && test x$ac_cv_header_sys_soundcard_h = xyes; then
289 AC_DEFINE([FORCE_OSS], 1, [Force OSS Usage])
290 fi
291
292 AC_CHECK_DECL(powf, , AC_DEFINE([NEED_POWF],1,[Need powf]), [#include <math.h>])
293 AC_CHECK_DECL(sqrtf, , AC_DEFINE([NEED_SQRTF],1,[Need sqrtf]), [#include <math.h>])
294 AC_CHECK_DECL(sinf, , AC_DEFINE([NEED_SINF],1,[Need sinf]), [#include <math.h>])
295 AC_CHECK_DECL(tanf, , AC_DEFINE([NEED_COSF],1,[Need tanf]), [#include <math.h>])
296 AC_CHECK_DECL(cosf, , AC_DEFINE([NEED_TANF],1,[Need cosf]), [#include <math.h>])
297 AC_CHECK_DECL(acosf, , AC_DEFINE([NEED_ACOSF],1,[Need acosf]), [#include <math.h>])
298 AC_CHECK_DECL(roundf, , AC_DEFINE([NEED_ROUNDF],1,[Need roundf]), [#include <math.h>])
299 AC_CHECK_DECL(truncf, , AC_DEFINE([NEED_TRUNCF],1,[Need truncf]), [#include <math.h>])
300
301 # This doesn't work on glibc math functions:
302 # AC_CHECK_FUNCS([sqrtf sinf tanf cosf acosf roundf truncf])
303
304 AC_CHECK_DECLS([SIGPWR],,,[#include <signal.h>])
305
306 AC_ARG_ENABLE(tests, AC_HELP_STRING([--enable-tests], [Build test programs]), enable_tests=$enableval, enable_tests=no)
307 AM_CONDITIONAL(BUILD_TESTS, test "$enable_tests" = "yes" )
308
309 AC_CONFIG_FILES(Makefile)
310 AC_CONFIG_FILES(src/Makefile)
311
312 if test "$have_libresample" = "no"; then
313 # use our own libresample in vain
314 cd src/libresample && autoconf && ./configure && cd ../..
315 fi
316
317 AC_CHECK_PROG([have_git], [git], yes, no)
318
319 have_git_repo=no
320 if test "$have_git" = "yes"; then
321 if test -d .git; then
322 have_git_repo=yes
323 else
324 echo "Warning: This is not a git checkout, can't determine version!"
325 fi
326 else
327 echo "Warning: git is not installed, can't determine version!"
328 fi
329
330 if test "$have_git_repo" = "yes"; then
331 build_version=`git tag`
332 build_rev_date=`git log -1 --pretty="format:%ad" --date="short"`
333 build_rev_tag=`git describe`
334
335 # If the rev_tag and the version are the same, this is
336 # an official release; otherwise, it's a dev build.
337 if test "$build_version" != "$build_rev_tag"; then
338 build_version="$build_version DEV"
339 fi
340
341 # HACK: the arcade chroot's git version is too old to understand our
342 # desired YYYY-MM-DD format. If we don't get a date in that format,
343 # fall back to today's date.
344
345 # HACK x2 COMBO!!: 'expr', in bash 2.05, doesn't seem to parse
346 # {n} for matching n repeats, hence the brain-dead regex.
347
348 if ! [ expr "$build_rev_date" : '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' > /dev/null ]; then
349 build_rev_date=`date +%Y-%m-%d`
350 fi
351 else
352 build_version="unknown version"
353 build_rev_date="unknown date"
354 build_rev_tag="unknown revision"
355 fi
356
357 AC_DEFINE_UNQUOTED(BUILD_VERSION, "$build_version", [Version tag])
358 AC_DEFINE_UNQUOTED(BUILD_DATE, "$build_rev_date", [Date of source revision])
359 AC_DEFINE_UNQUOTED(BUILD_REVISION_TAG, "$build_rev_tag", [ID of source revision])
360
361 AC_OUTPUT
362
363 echo
364 echo
365
366 echo "OpenITG $build_version (revision $build_rev_tag, $build_rev_date)"
367
368 echo
369
370 echo "Arcade build $itg_arcade"
371 echo "SSE2 optimizations $with_sse2 (supported: $have_sse2)"
372 echo "SDL $enable_sdl"
373 echo "FFMPEG $have_ffmpeg"
374 echo "libresample $have_libresample"
375 echo "GTK2 $enable_gtk2"
376 echo "ALSA $alsa"
377 echo "OSS $ac_cv_header_sys_soundcard_h (forced: $force_oss)"
378 echo "inotify hotplug $have_inotify"
379
380 echo