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