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