fix crash when specifying --source on command line
[rofl0r-gnuboy.git] / configure.ac
bloba5fc762ed2a73d4197cc52b825b5300bda1215d1
2 AC_INIT(cpu.c)
4 CFLAGS="$CFLAGS"
5 # if user sets custom CFLAGS, don't enforce our optimization flags
6 test -n "$CFLAGS" && enable_optimize=no
9 AC_PROG_CC
10 AC_PROG_CPP
11 AC_PROG_INSTALL
13 old_cflags="$CFLAGS"
14 CFLAGS="$CFLAGS -Wno-unused-function -Wno-deprecated-declarations -Wno-overlength-strings"
15 AC_TRY_COMPILE([], [typedef int foo;], [], [CFLAGS="$old_cflags"])
17 test "$cross_compiling" = "yes" || AC_C_BIGENDIAN
18 test "$ac_cv_c_bigendian" = "no" && ENDIAN="-DIS_LITTLE_ENDIAN"
19 test "$cross_compiling" = "yes" || LIBS="$LIBS -L/usr/X11R6/lib"
20 test x"$host" = x && host=`$CC -dumpmachine`
23 AC_ARG_WITH(fb,      [  --with-fb                       build framebuffer device interface], [], [with_fb=yes])
24 AC_ARG_WITH(svgalib, [  --with-svgalib                  build Linux svgalib interface], [], [with_svgalib=yes])
25 AC_ARG_WITH(sdl,     [  --with-sdl                      build SDL interface], [], [with_sdl=auto])
26 AC_ARG_WITH(sdl2,    [  --with-sdl2                     build SDL2 interface], [], [with_sdl2=yes])
27 AC_ARG_WITH(sound,   [  --with-sound=no,oss,sdl,ao      select sound interface], [], [with_sound=yes])
28 AC_ARG_WITH(x11,     [  --with-x                        build x11 interface], [], [with_x11=auto])
31 SOUND=""
32 JOY=""
34 if test "$with_sound" != "no" ; then
35 if test "$with_sound" = "yes" || test "$with_sound" = "ao" ; then
36 AC_CHECK_HEADERS(ao/ao.h, [SOUND=sys/ao/ao.o ; LIBS="$LIBS -Wl,--as-needed -lao -Wl,--no-as-needed"])
38 if test -z "$SOUND" && ( test "$with_sound" = "yes" || test "$with_sound" = "sdl" ) ; then
39 AC_CHECK_HEADERS(SDL/SDL.h, [SOUND=sys/sdl/sdl-audio.o ; LIBS="$LIBS -lSDL"])
41 if test -z "$SOUND" && ( test "$with_sound" = "yes" || test "$with_sound" = "oss" ) ; then
42 AC_CHECK_HEADERS(sys/soundcard.h, [SOUND=sys/oss/oss.o ; CPPFLAGS="$CPPFLAGS -DHAVE_SYS_SOUNDCARD_H"], [
43  AC_CHECK_HEADERS(machine/soundcard.h, [SOUND=sys/oss/oss.o ; CPPFLAGS="$CPPFLAGS -DHAVE_MACHINE_SOUNDCARD_H"], [
44   AC_CHECK_HEADERS(soundcard.h, [SOUND=sys/oss/oss.o ; CPPFLAGS="$CPPFLAGS -DHAVE_SOUNDCARD_H"], [
45    test "$with_sound" = "oss" && AC_MSG_WARN(oss selected but required headers not found)
46   ])
47  ])
52 AC_CHECK_HEADERS(linux/joystick.h, [JOY=sys/linux/joy.o])
53 test "$with_fb" = "no" || AC_CHECK_HEADERS(linux/fb.h, [with_fb=linux])
55 test "$SOUND" || SOUND=sys/dummy/nosound.o
56 test "$JOY" || JOY=sys/dummy/nojoy.o
63 case "$with_fb" in
64 linux) FB_OBJS="sys/linux/fbdev.o sys/linux/kb.o sys/pc/keymap.o" ;;
65 *) FB_OBJS="" ; with_fb=no ;;
66 esac
68 if test "$with_svgalib" != "no" ; then
69 AC_CHECK_LIB(vga, vga_init, [
70 AC_CHECK_HEADERS(vga.h vgakeyboard.h, ,[
71 AC_MSG_WARN(svgalib found but headers are missing!!)
72 with_svgalib=no
73 ])], [with_svgalib=no])
76 test -z "$PKG_CONFIG" && PKG_CONFIG=pkg-config
78 if test "$with_sdl2" != no ; then
79 SDL2_LIBS=-lSDL2
80 AC_CHECK_LIB(SDL2, SDL_Init, [
81  AC_CHECK_HEADERS(SDL2/SDL.h, [
82    with_sdl2=yes
83   ], [
84    AC_MSG_WARN(SDL2 found but headers are missing!!)
85    with_sdl2=no
86  ])
87 ], [
88   AC_MSG_WARN(testing pkg-config for SDL2)
89   if "$PKG_CONFIG" --libs sdl2 >/dev/null 2>&1 ; then
90     with_sdl2=yes
91     SDL2_LIBS=$("$PKG_CONFIG" --libs sdl2)
92   else
93     with_sdl2=no
94   fi
95 ], $SDL2_LIBS)
98 if test "$with_sdl2" = "no" && test "$with_sdl" != "no" ; then
99  SDL_LIBS=-lSDL
100  AC_CHECK_LIB(SDL, SDL_Init, [
101   AC_CHECK_HEADERS(SDL/SDL.h, [
102     with_sdl=yes
103    ], [
104     AC_MSG_WARN(SDL found but headers are missing!!)
105     with_sdl=no
106   ])
107  ], [with_sdl=no], $SDL2_LIBS)
108 else
109  with_sdl=no
112 if test "$with_sdl" != yes && test "$with_sdl2" != yes ; then
113 AC_CHECK_FUNCS(usleep, ,[
114 AC_CHECK_FUNCS(select, ,[
115 AC_MSG_ERROR(your system must support either usleep or select)
116 ])])
119 if test "$with_x" != "no" ; then
121 if test "$cross_compiling" != "yes" ; then
122 AC_PATH_X
125 AH_TEMPLATE(HAVE_LIBXEXT)
126 if test "$no_x" != "yes" ; then
127 with_x=yes
128 AC_CHECK_LIB(Xext, XShmCreateImage, [AC_DEFINE(HAVE_LIBXEXT)])
129 AC_CHECK_HEADERS(sys/ipc.h sys/shm.h X11/Xlib.h X11/Xutil.h X11/keysym.h X11/extensions/XShm.h, [], [], [[
130 #include <X11/Xlib.h>
131 #include <X11/Xutil.h>
132 #include <X11/keysym.h>
133 #define _SVID_SOURCE
134 #define _XOPEN_SOURCE
136 test "$x_includes" && XINCS="-I$x_includes"
137 test "$x_libraries" && XLIBS="-L$x_libraries"
138 else
139 with_x=no
144 test "$with_x" = "no" || TARGETS="$TARGETS xgnuboy"
145 test "$with_fb" = "no" || TARGETS="$TARGETS fbgnuboy"
146 test "$with_svgalib" = "no" || TARGETS="$TARGETS sgnuboy"
147 test "$with_sdl" = "no" || TARGETS="$TARGETS sdlgnuboy"
148 test "$with_sdl2" = "no" || TARGETS="$TARGETS sdl2gnuboy"
159 AC_ARG_ENABLE(warnings, [  --enable-warnings       enable selected compiler warnings], [], [enable_warnings=yes])
160 AC_ARG_ENABLE(debug,    [  --enable-debug          include debugging symbols], [])
161 AC_ARG_ENABLE(profile,  [  --enable-profile        enable performance profiling], [])
162 AC_ARG_ENABLE(arch,     [  --enable-arch           compile for specific host cpu architecture], [], [enable_arch=no])
163 AC_ARG_ENABLE(optimize, [  --enable-optimize=LEVEL select optimization level (full,low,none)], [], [enable_optimize=yes])
164 AC_ARG_ENABLE(asm,      [  --enable-asm            use hand-optimized asm cores], [], [enable_asm=no])
167 if test "$enable_warnings" = yes ; then
168 case "$CC" in *gcc*)
169 AC_MSG_RESULT(enabling selected compiler warnings)
170 CFLAGS="$CFLAGS -Wall" ;;
172 AC_MSG_RESULT(disabling warnings for non-gcc compiler) ;;
173 esac
176 if test "$enable_debug" = yes ; then
177 AC_MSG_RESULT(including debugging symbols)
178 CFLAGS="$CFLAGS -g"
181 if test "$enable_profile" = yes ; then
182 AC_MSG_RESULT(enabling performance profiling)
183 CFLAGS="$CFLAGS -pg"
186 if test "$enable_arch" = yes ; then
187 CFLAGS="$CFLAGS -march=native"
190 case "$enable_optimize" in
191 yes|full)
192 AC_MSG_RESULT(producing heavily optimized code)
194 CFLAGS="$CFLAGS -O3"
196 case "$host" in
197 x86_64*|i?86*) CFLAGS="$CFLAGS -DALLOW_UNALIGNED_IO" ;;
198 esac
200 case "$CC" in
201 *gcc*) CFLAGS="$CFLAGS -fstrength-reduce -fthread-jumps \
202  -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop \
203  -fexpensive-optimizations -fforce-addr" ;;
204 esac
206 if test "$enable_debug" != yes -a "$enable_profile" != yes ; then
207 CFLAGS="$CFLAGS -fomit-frame-pointer"
208 LDFLAGS="$LDFLAGS -s"
209 fi ;;
211 low)
213 AC_MSG_RESULT(using minimal optimizations)
214 CFLAGS="$CFLAGS -O3" ;;
216 esac
218 if test "$enable_asm" = yes ; then
219 case "$host" in
220 i?86*)
221 AC_MSG_RESULT(using optimized i386 cores)
222 ASM="-DUSE_ASM -I./asm/i386" ; ASM_OBJS="asm/i386/cpu.o asm/i386/lcd.o asm/i386/refresh.s" ;;
224 AC_MSG_RESULT(no optimized asm core available for $host) ;;
225 esac
228 case "$host" in
229     *-*-mingw* | *-*-cygwin* | *-*-windows* ) SYS_OBJS=sys/windows/windows.o ;;
230     *-*-dos* ) SYS_OBJS=sys/dos/dos.o ;;
231     *) SYS_OBJS=sys/nix/nix.o ;;
232 esac
235 AC_SUBST(SYS_DEFS)
236 AC_SUBST(ENDIAN)
237 AC_SUBST(SOUND)
238 AC_SUBST(JOY)
239 AC_SUBST(ASM)
240 AC_SUBST(ASM_OBJS)
241 AC_SUBST(SYS_OBJS)
242 AC_SUBST(FB_OBJS)
243 AC_SUBST(SDL_CFLAGS)
244 AC_SUBST(SDL_LIBS)
245 AC_SUBST(SDL2_LIBS)
246 AC_SUBST(TARGETS)
247 AC_SUBST(XINCS)
248 AC_SUBST(XLIBS)
250 AC_CONFIG_HEADER(sys/nix/config.h)
251 AC_OUTPUT(Makefile)