]> icculus.org git repositories - btb/d2x.git/blob - configure.ac
move i/o defines to cppflags
[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],[https://github.com/btb/d2x/issues])
8 AC_PREREQ(2.52)
9
10 m4_include([m4/ax_check_compile_flag.m4])
11
12 AC_CANONICAL_BUILD
13 AC_CANONICAL_HOST
14 AC_CANONICAL_TARGET
15
16 AC_EXEEXT
17 AC_OBJEXT
18
19 AM_INIT_AUTOMAKE([subdir-objects])
20
21 AM_CONFIG_HEADER(conf.h)
22
23 AC_DEFINE_UNQUOTED(D2XMAJOR,D2X_MAJOR,[d2x major version])
24 AC_DEFINE_UNQUOTED(D2XMINOR,D2X_MINOR,[d2x minor version])
25 AC_DEFINE_UNQUOTED(D2XMICRO,D2X_MICRO,[d2x micro version])
26
27 AM_MAINTAINER_MODE
28
29 #kludge to keep autoconf from adding -g -O2
30 CFLAGS=" $CFLAGS"
31
32 AC_PROG_INSTALL
33 AC_PROG_MAKE_SET
34 AC_ISC_POSIX
35 AC_CHECK_TOOL(CC, gcc, :)
36 AC_CHECK_TOOL(RANLIB, ranlib, :)
37 AC_CHECK_TOOL(STRIP, strip, :)
38 AC_CHECK_TOOL(AR, ar, :)
39 AC_PROG_CC
40 AC_PROG_CXX
41 AC_STDC_HEADERS
42 AC_PATH_PROGS(NASM, nasm nasmw, no)
43 AC_C_BIGENDIAN
44 AC_CHECK_SIZEOF(void *)
45
46 case $host_cpu in
47     sparc)
48         AC_DEFINE(WORDS_NEED_ALIGNMENT,,[Define if your processor needs data to be word-aligned])
49     ;;
50 esac
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         CFLAGS="-no-cpp-precomp $CFLAGS"
64         ;;
65     msdos*)
66         MSDOS=yes
67         ;;
68 esac
69
70 AC_CHECK_DECLS(nanosleep,,,[#include <time.h>])
71 AC_CHECK_TYPES([struct timespec, struct timeval],,,[#include <sys/time.h>])
72
73 AM_CONDITIONAL(MINGW32, test x$MINGW32 = xyes)
74
75 AM_CONDITIONAL(MACOSX, test x$MACOSX = xyes)
76
77 AM_CONDITIONAL(MSDOS, test x$MSDOS = xyes)
78
79 dnl Set $prefix and $exec_prefix to $ac_default_prefix if they are not set
80 test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
81 test "x$exec_prefix" = "xNONE" && exec_prefix="${prefix}"
82
83 dnl Set default locations to find data files.
84 default_sharepath="$datadir/games/$PACKAGE"
85
86 CFLAGS="-Wall -Werror -Wno-deprecated-declarations -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-unused-value -Wno-address $CFLAGS"
87 AX_CHECK_COMPILE_FLAG([-Wno-ignored-attributes], [CFLAGS="$CFLAGS -Wno-ignored-attributes"])
88 AX_CHECK_COMPILE_FLAG([-Wno-unused-but-set-variable], [CFLAGS="$CFLAGS -Wno-unused-but-set-variable"])
89
90 dnl Enable editor build?
91 AC_ARG_ENABLE(editor,
92     [  --enable-editor         Build editor? (not functional)],,)
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     D2X_FEATURES="linuxjoy ${D2X_FEATURES}"
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     if test $ac_cv_sizeof_void_p != 4; then
140         AC_MSG_WARN([pointers not 32 bits.  disabling fastfileio])
141         enable_fastfileio="no";
142     fi
143 fi
144 if test x$enable_fastfileio != xno; then
145     AC_DEFINE(FAST_FILE_IO,,[Define for faster i/o on little-endian cpus])
146     D2X_FEATURES="fastfileio ${D2X_FEATURES}"
147 fi
148
149 AC_ARG_WITH(sharepath,
150     [[  --with-sharepath=DIR    Use DIR for shared game data (unix only) [DATADIR/games/d2x]]],
151     sharepath=$withval, sharepath="auto")
152 if test "x$sharepath" = "xauto" -o "x$sharepath" = "xyes" -o "x$sharepath" = "x"; then
153     sharepath="$default_sharepath"
154 fi
155 AC_SUBST(sharepath)
156 eval sharepath=$sharepath
157 eval sharepath=$sharepath
158 AC_DEFINE_UNQUOTED(SHAREPATH, "$sharepath",[Define this to be the shared game directory root])
159
160 TARGETS=
161
162 # Test for MSDOS
163 if test x$MSDOS = xyes; then
164     TARGETS="d2x$ac_cv_exeext $TARGETS"
165         if test x$enable_editor = xyes; then
166                 TARGETS="miner$ac_cv_exeext $TARGETS"
167         fi
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
178     TARGETS="d2x-sdl$ac_cv_exeext $TARGETS"
179         if test x$enable_editor = xyes; then
180                 TARGETS="miner-sdl$ac_cv_exeext $TARGETS"
181         fi
182
183     AC_CHECK_HEADERS(netipx/ipx.h)
184
185   # Check for SDL_image
186     AC_CHECK_LIB(SDL_image, IMG_ReadXPMFromArray,
187         SDLIMAGE_LIBS="-lSDL_image"
188         AC_DEFINE(SDL_IMAGE,,[Define if you have the SDL_image library]))
189     AC_SUBST(SDLIMAGE_LIBS)
190
191   # Check for SDL_mixer
192     PKG_CHECK_MODULES(SDLMIXER, SDL_mixer)
193     AC_SUBST(SDLMIXER_CFLAGS)
194     AC_SUBST(SDLMIXER_LIBS)
195
196   # Check for libpng
197     have_libpng=no
198     #PKG_CHECK_MODULES(LIBPNG, libpng,
199     #    AC_DEFINE(HAVE_LIBPNG,,[Define if you have libpng])
200     #    have_libpng=yes
201     #    LIBS="$LIBPNG_LIBS $LIBS",
202     #    AC_MSG_WARN([libpng not found. disabling png replacement texture support])
203     #)
204     AM_CONDITIONAL(USE_LIBPNG, test x$have_libpng = xyes)
205
206   # Check for PhysicsFS
207     AC_CHECK_HEADERS(physfs.h, , [AC_MSG_ERROR([physfs.h required])])
208     AC_CHECK_LIB(physfs, PHYSFS_init, PHYSFS_LIBS="-lphysfs",
209                  [AC_MSG_ERROR([physfs library required])])
210     AC_SUBST(PHYSFS_LIBS)
211
212   # Check for OpenGL
213     AC_ARG_WITH(opengl,
214         [  --with-opengl           Build OpenGL support ],,)
215     if test x$with_opengl = xyes; then
216         TARGETS="d2x-gl$ac_cv_exeext $TARGETS"
217                 if test x$enable_editor = xyes; then
218                         TARGETS="miner-gl$ac_cv_exeext $TARGETS"
219                 fi
220     fi
221
222   # Check for SVGALib
223     AC_ARG_WITH(svga,
224         [  --with-svga             Build SVGALib support ],,)
225     if test x$with_svga = xyes; then
226         TARGETS="d2x-svga$ac_cv_exeext $TARGETS"
227                 if test x$enable_editor = xyes; then
228                         TARGETS="miner-svga$ac_cv_exeext $TARGETS"
229                 fi
230     fi
231     AC_SUBST(SVGA_LIBS)
232     AM_CONDITIONAL(USE_SVGALIB, test x$with_svga = xyes)
233 fi
234
235 dnl Check for network
236 AC_ARG_ENABLE(network,
237     [  --disable-network       Do not build network/serial support ],,)
238 if test x$enable_network != xno; then
239     case $host_os in
240         cygwin* | mingw* | msdos* | linux*)
241             enable_native_ipx="yes";
242            ;;
243        *)
244             AC_MSG_WARN([d2x does not support native ipx on this host.  disabling native ipx])
245             enable_native_ipx="no";
246             ;;
247     esac
248     case $host_os in
249         cygwin* | mingw* | msdos*)
250             enable_kalinix="no";
251             ;;
252     esac
253     case $host_os in
254         *solaris*)
255             AC_CHECK_LIB(socket, socket, LIBS="${LIBS} -lsocket",
256                 [AC_MSG_ERROR(socket lib required for net support on solaris not found)])
257             AC_CHECK_LIB(nsl, inet_addr, LIBS="${LIBS} -lnsl",
258                 [AC_MSG_ERROR(nsl lib required for net support on solaris not found)])
259             ;;
260     esac
261 fi
262 AC_ARG_ENABLE(kalinix,
263     [  --disable-kalinix       Disable the KaliNix driver (unix-only)],,)
264 if test x$enable_network != xno; then
265     if test x$enable_native_ipx != xno; then
266         D2X_FEATURES="ipx ${D2X_FEATURES}"
267         AC_DEFINE(NATIVE_IPX,,[Define to use the IPX support of the OS])
268     fi
269     if test x$enable_kalinix != xno; then
270         D2X_FEATURES="kalinix ${D2X_FEATURES}"
271         AC_DEFINE(KALINIX,,[Define to enable use of the KaliNix driver])
272     fi
273     AC_DEFINE(NETWORK,,[Define if you want a network build])
274     D2X_FEATURES="network ${D2X_FEATURES}"
275 fi
276 AM_CONDITIONAL(USE_NETWORK, test x$enable_network != xno)
277 AM_CONDITIONAL(USE_NATIVE_IPX, test x$enable_native_ipx != xno)
278 AM_CONDITIONAL(USE_KALINIX, test x$enable_kalinix != xno)
279
280 dnl Check for assembler
281 AC_ARG_ENABLE(assembler,
282     [  --disable-assembler     Do not use assembler optimization ],,)
283 if test x$enable_assembler != xno; then
284     if test x$NASM = xno; then
285         AC_MSG_WARN([nasm not found. disabling assembler])
286         enable_assembler="no"
287     else
288         NASMFLAGS="-i\$(srcdir)/ $NASMFLAGS"
289         case $host_os in
290             cygwin* | mingw*)
291                 NASMFLAGS="-f win32 $NASMFLAGS"
292                 ;;
293             msdos*)
294                 NASMFLAGS="-f coff $NASMFLAGS"
295                 ;;
296             linux* | freebsd*)
297                 NASMFLAGS="-f elf -d__ELF__ $NASMFLAGS"
298                 ;;
299             *)
300                 AC_MSG_WARN([nasm not supported for this OS. disabling assembler])
301                 enable_assembler="no"
302                 ;;
303         esac
304         case $host_cpu in
305             x86_64)
306                 AC_MSG_WARN([nasm not supported for this cpu. disabling assembler])
307                 enable_assembler="no"
308                 ;;
309         esac
310     fi
311 fi
312 if test x$enable_assembler = xno; then
313     AC_DEFINE(NO_ASM,,[Define if you want an assembler free build])
314     D2X_FEATURES="no_asm ${D2X_FEATURES}"
315 fi
316 AM_CONDITIONAL(USE_ASM, test x$enable_assembler != xno)
317
318 AH_BOTTOM([
319         /* General defines */
320 #ifndef PACKAGE_STRING
321 #define PACKAGE_STRING PACKAGE " " VERSION
322 #endif
323 #define VERSION_NAME PACKAGE_STRING
324 #define NMONO 1
325 #define PIGGY_USE_PAGING 1
326 #define NEWDEMO 1
327
328 #if defined(__APPLE__) && defined(__MACH__)
329 #define __unix__ /* since we're doing a unix-style compilation... */
330 #endif
331         ])
332
333 AM_PROG_AS
334
335 AC_SUBST(TARGETS)
336
337 AC_SUBST(NASMFLAGS)
338
339 AC_SUBST(CFLAGS)
340
341 AC_OUTPUT(
342     Makefile
343     debian/changelog
344     rpm/d2x.spec
345 )
346
347 AC_MSG_RESULT([
348         d2x has been configured successfully.
349
350         Targets: $TARGETS
351         Features: $D2X_FEATURES
352
353         Shared game data directory (unix only): $sharepath
354         ])