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