add support for MacOS X bundle
[btb/d2x.git] / configure.ac
1 # -*- mode: shell-script -*-
2
3 define([D2X_MAJOR],0)
4 define([D2X_MINOR],2)
5 define([D2X_MICRO],4)
6
7 AC_INIT(d2x,[D2X_MAJOR.D2X_MINOR.D2X_MICRO],[descent-source@warpcore.org])
8 AC_PREREQ(2.52)
9
10 AC_CANONICAL_BUILD
11 AC_CANONICAL_HOST
12 AC_CANONICAL_TARGET
13
14 AM_INIT_AUTOMAKE([1.6])
15
16 AM_CONFIG_HEADER(conf.h)
17
18 AC_DEFINE_UNQUOTED(D2XMAJOR,D2X_MAJOR,[d2x major version])
19 AC_DEFINE_UNQUOTED(D2XMINOR,D2X_MINOR,[d2x minor version])
20 AC_DEFINE_UNQUOTED(D2XMICRO,D2X_MICRO,[d2x micro version])
21
22 AM_MAINTAINER_MODE
23
24 #kludge to keep autoconf from adding -g -O2
25 CFLAGS=" $CFLAGS"
26
27 AC_PROG_INSTALL
28 AC_PROG_MAKE_SET
29 AC_ISC_POSIX
30 AC_CHECK_TOOL(CC, gcc, :)
31 AC_CHECK_TOOL(RANLIB, ranlib, :)
32 AC_CHECK_TOOL(STRIP, strip, :)
33 AC_CHECK_TOOL(AR, ar, :)
34 AC_PROG_CC
35 AC_PROG_CXX
36 AC_STDC_HEADERS
37 AC_PATH_PROGS(NASM, nasm nasmw, no)
38 AC_C_BIGENDIAN
39
40 case $host_cpu in
41         sparc)
42                 AC_DEFINE(WORDS_NEED_ALIGNMENT,,[Define if your processor needs data to be word-aligned])
43         ;;
44 esac
45
46 build_macosx_bundle=no
47 build_simple_bundle=no
48
49 case $host_os in
50     cygwin)
51         AC_MSG_WARN([Cygwin found, setting -mno-cygwin])
52         CFLAGS="-mno-cygwin $CFLAGS"
53         MINGW32=yes
54         ;;
55     mingw*)
56         MINGW32=yes
57         ;;
58     darwin*)
59         MACOSX=yes
60         AC_MSG_RESULT(Mac OS X/Darwin; Mac OS X bundle)
61         build_macosx_bundle=yes
62         DATADIR='EXE>>../Resources'
63         #SCOREDIR='/Library/Preferences/KoboDeluxe/scores'
64         #CONFIGDIR='HOME>>Library/Preferences'
65         #CONFIGFILE='KoboDeluxe Preferences'
66         MATHLIB=""
67         ;;
68     msdos*)
69         MSDOS=yes
70         ;;
71 esac
72
73 AC_CHECK_DECLS(nanosleep,,,[#include <time.h>])
74 AC_CHECK_TYPES(struct timespec)
75
76 AM_CONDITIONAL(MINGW32, test x$MINGW32 = xyes)
77 if test x$MINGW32 = xyes; then
78     GL_LIBS="opengl32 glu32"
79 elif test x$MACOSX = xyes; then
80     GL_LIBS=""
81 else
82     GL_LIBS="GL GLU"
83 fi
84
85 AM_CONDITIONAL(MACOSX, test x$MACOSX = xyes)
86 AM_CONDITIONAL(BUILD_MACOSX_BUNDLE, test x$build_macosx_bundle = xyes)
87 AM_CONDITIONAL(BUILD_SIMPLE_BUNDLE, test x$build_simple_bundle = xyes)
88
89 dnl Set $prefix and $exec_prefix to $ac_default_prefix if they are not set
90 test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
91 test "x$exec_prefix" = "xNONE" && exec_prefix="${prefix}"
92
93 dnl Set default locations to find data files.
94 default_sharepath="$datadir/games/$PACKAGE"
95
96 CFLAGS="-Wall $CFLAGS"
97
98 dnl Enable editor build?
99 AC_ARG_ENABLE(editor,
100     [  --enable-editor         Build editor? (not functional)],,)
101 if test x$enable_editor = xyes; then
102     AC_DEFINE(EDITOR,,[Define if you want to build the editor])
103     D2X_MAIN_SUBDIRS=editor
104 fi
105 AM_CONDITIONAL(EDITOR, test x$enable_editor = xyes)
106
107 dnl Enable macdata build?
108 AC_ARG_ENABLE(macdata,
109     [  --enable-macdata        Build for mac datafiles],,)
110 if test x$enable_macdata = xyes; then
111     AC_DEFINE(MACDATA,,[Define if you want to build for mac datafiles])
112     D2X_FEATURES="macdata ${D2X_FEATURES}"
113 fi
114 AM_CONDITIONAL(MACDATA, test x$enable_macdata = xyes)
115
116 dnl Build with NDEBUG?
117 AC_ARG_ENABLE(debug,
118     [  --disable-debug         Take out debug symbols, Asserts, Int3, etc ],,)
119 if test x$enable_debug = xno; then
120     AC_DEFINE(NDEBUG,,[Define to disable asserts, int3, etc.])
121     CFLAGS="-O2 $CFLAGS"
122 else
123     CFLAGS="-g $CFLAGS"
124     D2X_FEATURES="debug ${D2X_FEATURES}"
125 fi
126
127 dnl Build with RELEASE?
128 AC_ARG_ENABLE(release,
129     [  --enable-release        Release build.  Removes debug/editor things ],,)
130 if test x$enable_release = xyes; then
131     AC_DEFINE(RELEASE,,[Define for a "release" build])
132     D2X_FEATURES="release ${D2X_FEATURES}"
133 fi
134
135 dnl Build without using sdl-joystick ?
136 AC_ARG_ENABLE(linuxjoy,
137     [  --enable-linuxjoy       do not use the SDL Joystick. (eg for MS Sidewinder)],,)
138 if test x$enable_linuxjoy = xyes; then
139     AC_DEFINE(USE_LINUX_JOY,,[define to not use the SDL_Joystick routines.])
140 fi
141 AM_CONDITIONAL(USE_LINUX_JOY, test x$enable_linuxjoy = xyes)
142
143 dnl Build with FAST_FILE_IO?
144 AC_ARG_ENABLE(fastfileio,
145     [  --disable-fastfileio    Disable fast file i/o. ],,)
146 if test x$enable_fastfileio != xno; then
147         if test x$ac_cv_c_bigendian = xyes; then
148                 AC_MSG_WARN([big-endian cpu detected.  disabling fastfileio])
149                 enable_fastfileio="no";
150         fi
151 fi
152 if test x$enable_fastfileio != xno; then
153     AC_DEFINE(FAST_FILE_IO,,[Define for faster i/o on little-endian cpus])
154     D2X_FEATURES="fastfileio ${D2X_FEATURES}"
155 fi
156
157 dnl Build with CONSOLE?
158 AC_ARG_ENABLE(console,
159     [  --enable-console         Enable console (very experimental) ],,)
160 if test x$enable_console = xyes; then
161     AC_DEFINE(CONSOLE,,[Define to enable console])
162     D2X_FEATURES="console ${D2X_FEATURES}"
163 fi
164
165 AC_ARG_WITH(sharepath,
166     [[  --with-sharepath=DIR    Use DIR for shared game data (unix only) [DATADIR/games/d2x]]],
167     sharepath=$withval, sharepath="auto")
168 if test "x$sharepath" = "xauto" -o "x$sharepath" = "xyes" -o "x$sharepath" = "x"; then
169     sharepath="$default_sharepath"
170 fi
171 AC_SUBST(sharepath)
172 eval sharepath=$sharepath
173 AC_DEFINE_UNQUOTED(SHAREPATH, "$sharepath",[Define this to be the shared game directory root])
174
175 # Test for MSDOS
176 if test x$MSDOS = xyes; then
177     CFLAGS="-I \$(top_srcdir)/arch/dos/include $CFLAGS"
178     TARGETS=d2x
179     D2X_ARCH_SUBDIRS=dos
180 else
181
182     CFLAGS="-pipe $CFLAGS"
183
184     dnl Check for SDL
185     AM_PATH_SDL(1.1.0,
186         :,
187         AC_MSG_ERROR(SDL not found. Make sure sdl-config is in your PATH, or specify with --with-sdl-prefix)
188     )
189     CFLAGS="$SDL_CFLAGS $CFLAGS"
190     LIBS="$SDL_LIBS $LIBS"
191
192     TARGETS=d2x-sdl
193     D2X_ARCH_SUBDIRS=sdl
194
195     AC_CHECK_HEADERS(netipx/ipx.h)
196
197   # Check for SDL_image
198         AC_CHECK_LIB(SDL_image, IMG_ReadXPMFromArray,
199                 LIBS="-lSDL_image $LIBS"
200                 AC_DEFINE(SDL_IMAGE,,[Define if you have the SDL_image library]))
201
202   # Check for OpenGL
203     AC_ARG_WITH(opengl,
204         [  --with-opengl           Build OpenGL support ],,)
205     if test x$with_opengl = xyes; then
206         for lib in $GL_LIBS; do
207             AC_CHECK_LIB($lib, main,
208                 OGL_LIBS="${OGL_LIBS} -l$lib",
209                 [AC_MSG_ERROR([$lib not found, --with-opengl cannot be used])
210                     opengl=false],
211                 ${OGL_LIBS}
212             )
213         done
214         AC_DEFINE(OGL,,[Define if you want an OpenGL build])
215         TARGETS=d2x-gl
216         D2X_ARCH_SUBDIRS="ogl ${D2X_ARCH_SUBDIRS}"
217     fi
218     AC_SUBST(OGL_LIBS)
219     AM_CONDITIONAL(USE_OPENGL, test x$with_opengl = xyes)
220
221   # Check for GGI
222     AC_ARG_WITH(ggi,
223         [  --with-ggi              Build GGI support ],,)
224     if test x$with_ggi = xyes; then
225         AC_CHECK_LIB(ggi, ggiInit,
226             GGI_LIBS="-lggi",
227             [AC_MSG_ERROR([GGI not found, GGI version cannot be built]); ggi=false])
228         AC_CHECK_LIB(gii, giiInit,
229             GGI_LIBS="${GGI_LIBS} -lgii",
230             [AC_MSG_ERROR([GII not found, GGI version cannot be built]); ggi=false])
231         AC_DEFINE(GGI,,[Define if you want a GGI build])
232         TARGETS=d2x-ggi
233         D2X_ARCH_SUBDIRS="ggi ${D2X_ARCH_SUBDIRS}"
234     fi
235     AC_SUBST(GGI_LIBS)
236     AM_CONDITIONAL(USE_GGI, test x$with_ggi = xyes)
237
238   # Check for SVGALib
239     AC_ARG_WITH(svga,
240         [  --with-svga             Build SVGALib support ],,)
241     if test x$with_svga = xyes; then
242         AC_CHECK_LIB(vga,vga_getmousetype,
243             SVGA_LIBS="-lvga",
244             [AC_MSG_ERROR([vga not found, SVGALib cannot be built])
245                 svga=false],
246         )
247         AC_CHECK_LIB(vgagl,gl_getcontext,
248             SVGA_LIBS="${SVGA_LIBS} -lvgagl",
249             [AC_MSG_ERROR([vgagl not found, SVGALib cannot be built])
250                 svga=false],
251             -lvga)
252         AC_DEFINE(SVGA,,[Define if you want an SVGALib build])
253         TARGETS=d2x-svga
254         D2X_ARCH_SUBDIRS="svgalib ${D2X_ARCH_SUBDIRS}"
255     fi
256     AC_SUBST(SVGA_LIBS)
257     AM_CONDITIONAL(USE_SVGALIB, test x$with_svga = xyes)
258
259     if test x$MINGW32 = xyes; then
260         D2X_ARCH_SUBDIRS="win32 ${D2X_ARCH_SUBDIRS}"
261     else
262         CFLAGS="-I \$(top_srcdir)/arch/linux/include $CFLAGS"
263         D2X_ARCH_SUBDIRS="linux ${D2X_ARCH_SUBDIRS}"
264     fi
265 fi
266
267 dnl Check for network
268 AC_ARG_ENABLE(network,
269     [  --disable-network       Do not build network/serial support ],,)
270 if test x$enable_network != xno; then
271         if test x$MACOSX = xyes; then
272                 AC_MSG_WARN([OS X detected.  disabling network])
273                 enable_network="no";
274         fi
275 fi
276 if test x$enable_network != xno; then
277     AC_DEFINE(NETWORK,,[Define if you want a network build])
278     D2X_FEATURES="network ${D2X_FEATURES}"
279 fi
280 AM_CONDITIONAL(USE_NETWORK, test x$enable_network != xno)
281
282 dnl Check for assembler
283 AC_ARG_ENABLE(assembler,
284     [  --disable-assembler     Do not use assembler optimization ],,)
285 if test x$enable_assembler != xno; then
286     if test x$NASM = xno; then
287         AC_MSG_WARN([nasm not found. disabling assembler])
288         enable_assembler="no"
289     else
290         NASMFLAGS="-i\$(srcdir)/ $NASMFLAGS"
291         case $host_os in
292             cygwin* | mingw*)
293                 NASMFLAGS="-f win32 $NASMFLAGS"
294                 ;;
295             msdos*)
296                 NASMFLAGS="-f coff $NASMFLAGS"
297                 ;;
298             linux*)
299                 NASMFLAGS="-f elf -d__linux__ $NASMFLAGS"
300                 ;;
301             *)
302                 AC_MSG_WARN([nasm not supported for this OS. disabling assembler])
303                 enable_assembler="no"
304                 ;;
305         esac
306     fi
307 fi
308 if test x$enable_assembler = xno; then
309     AC_DEFINE(NO_ASM,,[Define if you want an assembler free build])
310     D2X_FEATURES="no_asm ${D2X_FEATURES}"
311 fi
312 AM_CONDITIONAL(USE_ASM, test x$enable_assembler != xno)
313
314 AH_BOTTOM([
315         /* General defines */
316 #ifndef PACKAGE_STRING
317 #define PACKAGE_STRING PACKAGE " " VERSION
318 #endif
319 #define VERSION_NAME PACKAGE_STRING
320 #define NMONO 1
321 #define PIGGY_USE_PAGING 1
322 #define NEWDEMO 1
323
324 #if defined(__APPLE__) && defined(__MACH__)
325 #define __unix__
326 #endif
327
328 #ifdef __unix__
329 # ifdef GGI
330 #  define GII_INPUT 1
331 #  define GGI_VIDEO 1
332 # else
333 #  ifdef SVGA
334 #   define SVGALIB_INPUT 1
335 #   define SVGALIB_VIDEO 1
336 #  else
337 #   define SDL_INPUT 1
338 #   ifdef OGL
339 #    define SDL_GL_VIDEO 1
340 #   else
341 #    define SDL_VIDEO 1
342 #   endif
343 #  endif
344 # endif
345 #endif
346
347 #ifdef __MINGW32__
348 # define SDL_INPUT 1
349 # ifdef OGL
350 #  define SDL_GL_VIDEO 1
351 # else
352 #  define SDL_VIDEO 1
353 # endif
354 #endif
355         ])
356
357 AM_PROG_AS
358
359 AC_SUBST(D2X_ARCH_SUBDIRS)
360
361 AC_SUBST(D2X_MAIN_SUBDIRS)
362
363 AC_SUBST(TARGETS)
364
365 AC_SUBST(NASMFLAGS)
366
367 AC_SUBST(CFLAGS)
368
369 AC_OUTPUT(
370     Makefile
371     2d/Makefile
372     3d/Makefile
373     arch/Makefile
374     arch/dos/Makefile
375     arch/ggi/Makefile
376     arch/linux/Makefile
377     arch/ogl/Makefile
378     arch/sdl/Makefile
379     arch/svgalib/Makefile
380     arch/win32/Makefile
381     cfile/Makefile
382     iff/Makefile
383     libmve/Makefile
384     main/Makefile
385     main/editor/Makefile
386     maths/Makefile
387     mem/Makefile
388     misc/Makefile
389     texmap/Makefile
390     utilities/Makefile
391     debian/changelog
392     rpm/d2x.spec
393     Info.plist
394 )
395
396 AC_MSG_RESULT([
397         d2x has been configured successfully.
398
399         Platform(s): $D2X_ARCH_SUBDIRS
400         Features   : $D2X_FEATURES $D2X_MAIN_SUBDIRS
401
402         Shared game data directory (unix only): $sharepath
403         ])