amd64 fixes
[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 AC_CHECK_SIZEOF(void *)
43
44 case $host_cpu in
45         sparc)
46                 AC_DEFINE(WORDS_NEED_ALIGNMENT,,[Define if your processor needs data to be word-aligned])
47         ;;
48 esac
49
50 case $host_os in
51     cygwin)
52         AC_MSG_WARN([Cygwin found, setting -mno-cygwin])
53         CFLAGS="-mno-cygwin $CFLAGS"
54         MINGW32=yes
55         ;;
56     mingw*)
57         MINGW32=yes
58         ;;
59     darwin*)
60         MACOSX=yes
61         CFLAGS="-no-cpp-precomp $CFLAGS"
62         ;;
63     msdos*)
64         MSDOS=yes
65         ;;
66 esac
67
68 AC_CHECK_DECLS(nanosleep,,,[#include <time.h>])
69 AC_CHECK_TYPES([struct timespec, struct timeval],,,[#include <sys/time.h>])
70
71 AM_CONDITIONAL(MINGW32, test x$MINGW32 = xyes)
72 if test x$MINGW32 = xyes; then
73     GL_LIBS="opengl32 glu32"
74 elif test x$MACOSX = xyes; then
75     GL_LIBS=""
76 else
77     GL_LIBS="GL GLU"
78 fi
79
80 AM_CONDITIONAL(MACOSX, test x$MACOSX = xyes)
81
82 dnl Set $prefix and $exec_prefix to $ac_default_prefix if they are not set
83 test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
84 test "x$exec_prefix" = "xNONE" && exec_prefix="${prefix}"
85
86 dnl Set default locations to find data files.
87 default_sharepath="$datadir/games/$PACKAGE"
88
89 CFLAGS="-Wall -Wno-char-subscripts $CFLAGS"
90
91 D2X_SUBDIRS=""
92 D2X_MAIN_SUBDIRS=""
93
94 dnl Enable editor build?
95 AC_ARG_ENABLE(editor,
96     [  --enable-editor         Build editor? (not functional)],,)
97 if test x$enable_editor = xyes; then
98     AC_DEFINE(EDITOR,,[Define if you want to build the editor])
99     D2X_SUBDIRS="ui ${D2X_SUBDIRS}"
100     D2X_MAIN_SUBDIRS="editor ${D2X_MAIN_SUBDIRS}"
101 fi
102 AM_CONDITIONAL(EDITOR, test x$enable_editor = xyes)
103
104 dnl Enable macdata build?
105 AC_ARG_ENABLE(macdata,
106     [  --enable-macdata        Build for mac datafiles],,)
107 if test x$enable_macdata = xyes; then
108     AC_DEFINE(MACDATA,,[Define if you want to build for mac datafiles])
109     D2X_FEATURES="macdata ${D2X_FEATURES}"
110 fi
111 AM_CONDITIONAL(MACDATA, test x$enable_macdata = xyes)
112
113 dnl Build with NDEBUG?
114 AC_ARG_ENABLE(debug,
115     [  --disable-debug         Take out debug symbols, Asserts, Int3, etc ],,)
116 if test x$enable_debug = xno; then
117     AC_DEFINE(NDEBUG,,[Define to disable asserts, int3, etc.])
118     CFLAGS="-O2 $CFLAGS"
119 else
120     CFLAGS="-g $CFLAGS"
121     D2X_FEATURES="debug ${D2X_FEATURES}"
122 fi
123
124 dnl Build with RELEASE?
125 AC_ARG_ENABLE(release,
126     [  --enable-release        Release build.  Removes debug/editor things ],,)
127 if test x$enable_release = xyes; then
128     AC_DEFINE(RELEASE,,[Define for a "release" build])
129     D2X_FEATURES="release ${D2X_FEATURES}"
130 fi
131
132 dnl Build without using sdl-joystick ?
133 AC_ARG_ENABLE(linuxjoy,
134     [  --enable-linuxjoy       do not use the SDL Joystick. (eg for MS Sidewinder)],,)
135 if test x$enable_linuxjoy = xyes; then
136     AC_DEFINE(USE_LINUX_JOY,,[define to not use the SDL_Joystick routines.])
137     D2X_FEATURES="linuxjoy ${D2X_FEATURES}"
138 fi
139 AM_CONDITIONAL(USE_LINUX_JOY, test x$enable_linuxjoy = xyes)
140
141 dnl Build with FAST_FILE_IO?
142 AC_ARG_ENABLE(fastfileio,
143     [  --disable-fastfileio    Disable fast file i/o. ],,)
144 if test x$enable_fastfileio != xno; then
145         if test x$ac_cv_c_bigendian = xyes; then
146                 AC_MSG_WARN([big-endian cpu detected.  disabling fastfileio])
147                 enable_fastfileio="no";
148         fi
149         if test $ac_cv_sizeof_void_p != 4; then
150                 AC_MSG_WARN([pointers not 32 bits.  disabling fastfileio])
151                 enable_fastfileio="no";
152         fi
153 fi
154 if test x$enable_fastfileio != xno; then
155     AC_DEFINE(FAST_FILE_IO,,[Define for faster i/o on little-endian cpus])
156     D2X_FEATURES="fastfileio ${D2X_FEATURES}"
157 fi
158
159 dnl Build with CONSOLE?
160 AC_ARG_ENABLE(console,
161     [  --enable-console        Enable console (experimental) ],,)
162 if test x$enable_console = xyes; then
163     AC_DEFINE(CONSOLE,,[Define to enable console])
164     D2X_SUBDIRS="console ${D2X_SUBDIRS}"
165 fi
166 AM_CONDITIONAL(CONSOLE, test x$enable_console = xyes)
167
168 AC_ARG_WITH(sharepath,
169     [[  --with-sharepath=DIR    Use DIR for shared game data (unix only) [DATADIR/games/d2x]]],
170     sharepath=$withval, sharepath="auto")
171 if test "x$sharepath" = "xauto" -o "x$sharepath" = "xyes" -o "x$sharepath" = "x"; then
172     sharepath="$default_sharepath"
173 fi
174 AC_SUBST(sharepath)
175 eval sharepath=$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 libpng
207     have_libpng=no
208     #PKG_CHECK_MODULES(LIBPNG, libpng,
209     #   AC_DEFINE(HAVE_LIBPNG,,[Define if you have libpng])
210     #   have_libpng=yes
211     #   LIBS="$LIBPNG_LIBS $LIBS",
212     #   AC_MSG_WARN([libpng not found. disabling png replacement texture support])
213 #)
214     AM_CONDITIONAL(USE_LIBPNG, test x$have_libpng = xyes)
215
216   # Check for PhysicsFS
217     AC_CHECK_HEADERS(physfs.h, , [AC_MSG_ERROR([physfs.h required])])
218     AC_CHECK_LIB(physfs, PHYSFS_init, LIBS="-lphysfs $LIBS",
219                  [AC_MSG_ERROR([physfs library required])])
220
221   # Check for OpenGL
222     AC_ARG_WITH(opengl,
223         [  --with-opengl           Build OpenGL support ],,)
224     if test x$with_opengl = xyes; then
225         for lib in $GL_LIBS; do
226             AC_CHECK_LIB($lib, main,
227                 OGL_LIBS="${OGL_LIBS} -l$lib",
228                 [AC_MSG_ERROR([$lib not found, --with-opengl cannot be used])
229                     opengl=false],
230                 ${OGL_LIBS}
231             )
232         done
233         AC_DEFINE(OGL,,[Define if you want an OpenGL build])
234         TARGETS=d2x-gl
235         D2X_ARCH_SUBDIRS="ogl ${D2X_ARCH_SUBDIRS}"
236     fi
237     AC_SUBST(OGL_LIBS)
238     AM_CONDITIONAL(USE_OPENGL, test x$with_opengl = xyes)
239
240   # Check for GGI
241     AC_ARG_WITH(ggi,
242         [  --with-ggi              Build GGI support ],,)
243     if test x$with_ggi = xyes; then
244         AC_CHECK_LIB(ggi, ggiInit,
245             GGI_LIBS="-lggi",
246             [AC_MSG_ERROR([GGI not found, GGI version cannot be built]); ggi=false])
247         AC_CHECK_LIB(gii, giiInit,
248             GGI_LIBS="${GGI_LIBS} -lgii",
249             [AC_MSG_ERROR([GII not found, GGI version cannot be built]); ggi=false])
250         AC_DEFINE(GGI,,[Define if you want a GGI build])
251         TARGETS=d2x-ggi
252         D2X_ARCH_SUBDIRS="ggi ${D2X_ARCH_SUBDIRS}"
253     fi
254     AC_SUBST(GGI_LIBS)
255     AM_CONDITIONAL(USE_GGI, test x$with_ggi = xyes)
256
257   # Check for SVGALib
258     AC_ARG_WITH(svga,
259         [  --with-svga             Build SVGALib support ],,)
260     if test x$with_svga = xyes; then
261         AC_CHECK_LIB(vga,vga_getmousetype,
262             SVGA_LIBS="-lvga",
263             [AC_MSG_ERROR([vga not found, SVGALib cannot be built])
264                 svga=false],
265         )
266         AC_CHECK_LIB(vgagl,gl_getcontext,
267             SVGA_LIBS="${SVGA_LIBS} -lvgagl",
268             [AC_MSG_ERROR([vgagl not found, SVGALib cannot be built])
269                 svga=false],
270             -lvga)
271         AC_DEFINE(SVGA,,[Define if you want an SVGALib build])
272         TARGETS=d2x-svga
273         D2X_ARCH_SUBDIRS="svgalib ${D2X_ARCH_SUBDIRS}"
274     fi
275     AC_SUBST(SVGA_LIBS)
276     AM_CONDITIONAL(USE_SVGALIB, test x$with_svga = xyes)
277
278     if test x$MINGW32 = xyes; then
279         D2X_ARCH_SUBDIRS="win32 ${D2X_ARCH_SUBDIRS}"
280     else
281         CFLAGS="-I \$(top_srcdir)/arch/linux/include $CFLAGS"
282         D2X_ARCH_SUBDIRS="linux ${D2X_ARCH_SUBDIRS}"
283     fi
284 fi
285
286 dnl Check for network
287 AC_ARG_ENABLE(network,
288     [  --disable-network       Do not build network/serial support ],,)
289 if test x$enable_network != xno; then
290     case $host_os in
291         cygwin* | mingw* | msdos* | linux*)
292             enable_native_ipx="yes";
293            ;;
294        *)
295             AC_MSG_WARN([d2x does not support native ipx on this host.  disabling native ipx])
296             enable_native_ipx="no";
297             ;;
298     esac
299         case $host_os in
300                 cygwin* | mingw* | msdos*)
301                         enable_kalinix="no";
302                         ;;
303         esac
304     case $host_os in
305         *solaris*)
306             AC_CHECK_LIB(socket, socket, LIBS="${LIBS} -lsocket",
307                 [AC_MSG_ERROR(socket lib required for net support on solaris not found)])
308             AC_CHECK_LIB(nsl, inet_addr, LIBS="${LIBS} -lnsl",
309                 [AC_MSG_ERROR(nsl lib required for net support on solaris not found)])          
310            ;;
311     esac
312 fi
313 AC_ARG_ENABLE(kalinix,
314     [  --disable-kalinix       Disable the KaliNix driver (unix-only)],,)
315 if test x$enable_network != xno; then
316     if test x$enable_native_ipx != xno; then
317         D2X_FEATURES="ipx ${D2X_FEATURES}"
318         AC_DEFINE(NATIVE_IPX,,[Define to use the IPX support of the OS])
319     fi
320     if test x$enable_kalinix != xno; then
321         D2X_FEATURES="kalinix ${D2X_FEATURES}"
322         AC_DEFINE(KALINIX,,[Define to enable use of the KaliNix driver])
323     fi
324     AC_DEFINE(NETWORK,,[Define if you want a network build])
325     D2X_FEATURES="network ${D2X_FEATURES}"
326 fi
327 AM_CONDITIONAL(USE_NETWORK, test x$enable_network != xno)
328 AM_CONDITIONAL(USE_NATIVE_IPX, test x$enable_native_ipx != xno)
329 AM_CONDITIONAL(USE_KALINIX, test x$enable_kalinix != xno)
330
331 dnl Check for assembler
332 AC_ARG_ENABLE(assembler,
333     [  --disable-assembler     Do not use assembler optimization ],,)
334 if test x$enable_assembler != xno; then
335     if test x$NASM = xno; then
336         AC_MSG_WARN([nasm not found. disabling assembler])
337         enable_assembler="no"
338     else
339         NASMFLAGS="-i\$(srcdir)/ $NASMFLAGS"
340         case $host_os in
341             cygwin* | mingw*)
342                 NASMFLAGS="-f win32 $NASMFLAGS"
343                 ;;
344             msdos*)
345                 NASMFLAGS="-f coff $NASMFLAGS"
346                 ;;
347                         linux* | freebsd*)
348                                 NASMFLAGS="-f elf -d__ELF__ $NASMFLAGS"
349                 ;;
350             *)
351                 AC_MSG_WARN([nasm not supported for this OS. disabling assembler])
352                 enable_assembler="no"
353                 ;;
354         esac
355         case $host_cpu in
356             x86_64)
357                 AC_MSG_WARN([nasm not supported for this cpu. disabling assembler])
358                 enable_assembler="no"
359                 ;;
360         esac
361     fi
362 fi
363 if test x$enable_assembler = xno; then
364     AC_DEFINE(NO_ASM,,[Define if you want an assembler free build])
365     D2X_FEATURES="no_asm ${D2X_FEATURES}"
366 fi
367 AM_CONDITIONAL(USE_ASM, test x$enable_assembler != xno)
368
369 AH_BOTTOM([
370         /* General defines */
371 #ifndef PACKAGE_STRING
372 #define PACKAGE_STRING PACKAGE " " VERSION
373 #endif
374 #define VERSION_NAME PACKAGE_STRING
375 #define NMONO 1
376 #define PIGGY_USE_PAGING 1
377 #define NEWDEMO 1
378
379 #if defined(__APPLE__) && defined(__MACH__)
380 #define __unix__ /* since we're doing a unix-style compilation... */
381 #endif
382
383 #ifdef __unix__
384 # ifdef GGI
385 #  define GII_INPUT 1
386 #  define GGI_VIDEO 1
387 # else
388 #  ifdef SVGA
389 #   define SVGALIB_INPUT 1
390 #   define SVGALIB_VIDEO 1
391 #  else
392 #   define SDL_INPUT 1
393 #   ifdef OGL
394 #    define SDL_GL_VIDEO 1
395 #   else
396 #    define SDL_VIDEO 1
397 #   endif
398 #  endif
399 # endif
400 #endif
401
402 #ifdef _WIN32
403 # define SDL_INPUT 1
404 # ifdef OGL
405 #  define SDL_GL_VIDEO 1
406 # else
407 #  define SDL_VIDEO 1
408 # endif
409 #endif
410         ])
411
412 TARGETS="$TARGETS$ac_cv_exeext"
413
414 AM_PROG_AS
415
416 AC_SUBST(D2X_SUBDIRS)
417
418 AC_SUBST(D2X_ARCH_SUBDIRS)
419
420 AC_SUBST(D2X_MAIN_SUBDIRS)
421
422 AC_SUBST(TARGETS)
423
424 AC_SUBST(NASMFLAGS)
425
426 AC_SUBST(CFLAGS)
427
428 AC_OUTPUT(
429     Makefile
430     2d/Makefile
431     3d/Makefile
432     arch/Makefile
433     arch/dos/Makefile
434     arch/ggi/Makefile
435     arch/linux/Makefile
436     arch/ogl/Makefile
437     arch/sdl/Makefile
438     arch/svgalib/Makefile
439     arch/win32/Makefile
440     console/Makefile
441     iff/Makefile
442     libmve/Makefile
443     main/Makefile
444     main/editor/Makefile
445     maths/Makefile
446     mem/Makefile
447     misc/Makefile
448     texmap/Makefile
449     ui/Makefile
450     utilities/Makefile
451     debian/changelog
452     rpm/d2x.spec
453 )
454
455 AC_MSG_RESULT([
456         d2x has been configured successfully.
457
458         Platform(s): $D2X_ARCH_SUBDIRS
459         Features   : $D2X_FEATURES $D2X_SUBDIRS $D2X_MAIN_SUBDIRS
460
461         Shared game data directory (unix only): $sharepath
462         ])