c++, versioning, endianness, deb, rpm stuff
[btb/d2x.git] / configure.ac
1 # -*- mode: shell-script -*-
2 AC_INIT(main/inferno.c)
3 AC_PREREQ(2.52)
4
5 AC_CANONICAL_BUILD
6 AC_CANONICAL_HOST
7 AC_CANONICAL_TARGET
8
9 AM_CONFIG_HEADER(conf.h)
10
11 D2XMAJOR=0
12 D2XMINOR=1
13 D2XMICRO=3
14
15 AC_DEFINE_UNQUOTED(D2XMAJOR)
16 AC_DEFINE_UNQUOTED(D2XMINOR)
17 AC_DEFINE_UNQUOTED(D2XMICRO)
18
19 VERSION=$D2XMAJOR.$D2XMINOR.$D2XMICRO
20
21 AM_INIT_AUTOMAKE(d2x, $VERSION)
22
23 AM_MAINTAINER_MODE
24
25 #kludge to keep autoconf from adding -g -O2
26 CFLAGS=" $CFLAGS"
27
28 AC_PROG_INSTALL
29 AC_PROG_MAKE_SET
30 AC_ISC_POSIX
31 AC_CHECK_TOOL(CC, gcc, :)
32 AC_CHECK_TOOL(RANLIB, ranlib, :)
33 AC_CHECK_TOOL(STRIP, strip, :)
34 AC_CHECK_TOOL(AR, ar, :)
35 AC_PROG_CC
36 AC_PROG_CXX
37 AC_STDC_HEADERS
38 AC_PATH_PROGS(NASM, nasmw nasm, no)
39 AC_C_BIGENDIAN
40
41 AC_CYGWIN
42 AC_MINGW32
43 if test x$CYGWIN = xyes; then
44     AC_MSG_WARN([Cygwin found, setting -mno-cygwin])
45     CFLAGS="-mno-cygwin $CFLAGS"
46     MINGW32=yes
47 fi
48
49 AM_CONDITIONAL(MINGW32, test x$MINGW32 = xyes)
50 if test x$MINGW32 = xyes; then
51     GL_LIBS="opengl32 glu32"
52 else
53     GL_LIBS="GL GLU"
54 fi
55
56 dnl Set $prefix and $exec_prefix to $ac_default_prefix if they are not set
57 test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
58 test "x$exec_prefix" = "xNONE" && exec_prefix="${prefix}"
59
60 dnl Set default locations to find data files.
61 eval foo="$datadir"
62 default_sharepath="$foo/games/$PACKAGE"
63
64 CFLAGS="-Wall $CFLAGS"
65
66 dnl Enable editor build?
67 AC_ARG_ENABLE(editor,
68   [  --enable-editor         Build editor? (not functional)],,)
69 if test x$enable_editor = xyes; then
70     AC_DEFINE(EDITOR)
71     D2X_MAIN_SUBDIRS=editor
72 fi
73 AM_CONDITIONAL(EDITOR, test x$enable_editor = xyes)
74
75 dnl Enable shareware build?
76 AC_ARG_ENABLE(shareware,
77   [  --enable-shareware      Build for demo datafiles (not functional)],,)
78 if test x$enable_shareware = xyes; then
79     AC_DEFINE(SHAREWARE)
80     D2X_FEATURES="shareware ${D2X_FEATURES}"
81 fi
82 AM_CONDITIONAL(SHAREWARE, test x$enable_shareware = xyes)
83
84 dnl Enable movie trick?
85 AC_ARG_ENABLE(movies,
86   [  --enable-movie-trick    Enable trick to show movies],,)
87 if test x$enable_movie_trick = xyes; then
88     AC_DEFINE(MOVIE_TRICK)
89     D2X_FEATURES="movie_trick ${D2X_FEATURES}"
90 fi
91 AM_CONDITIONAL(MOVIE_TRICK, test x$enable_movie_trick = xyes)
92
93 dnl Enable NMOVIES?
94 AC_ARG_ENABLE(nmovies,
95   [  --enable-nmovies        Turn off movies (render endlevel flythrough)],,)
96 if test x$enable_nmovies = xyes; then
97     AC_DEFINE(NMOVIES)
98     D2X_FEATURES="nmovies ${D2X_FEATURES}"
99 fi
100 AM_CONDITIONAL(NMOVIES, test x$enable_nmovies = xyes)
101
102 dnl Count warnings as errors?
103 AC_ARG_ENABLE(werror,
104   [  --enable-werror         Count compiler warning as errors ],,)
105 if test x$enable_werror = xyes; then
106     CFLAGS="-Werror $CFLAGS"
107     D2X_FEATURES="werror ${D2X_FEATURES}"
108 fi
109
110 dnl Build with NDEBUG?
111 AC_ARG_ENABLE(debug,
112   [  --disable-debug         Take out debug symbols, Asserts, Int3, etc ],,)
113 if test x$enable_debug = xno; then
114     AC_DEFINE(NDEBUG)
115     CFLAGS="-O2 $CFLAGS"
116 else
117     CFLAGS="-g $CFLAGS"
118     D2X_FEATURES="debug ${D2X_FEATURES}"
119 fi
120
121 dnl Build with RELEASE?
122 AC_ARG_ENABLE(release,
123   [  --enable-release        Release build.  Removes debug/editor things ],,)
124 if test x$enable_release = xyes; then
125     AC_DEFINE(RELEASE)
126     D2X_FEATURES="release ${D2X_FEATURES}"
127 fi
128
129 AC_ARG_WITH(sharepath,
130   [[  --with-sharepath=DIR    Use DIR for shared game data [DATADIR/games/d2x]]],
131   sharepath=$withval, sharepath="auto")
132 if test "x$sharepath" = "xauto" -o "x$sharepath" = "xyes" -o "x$sharepath" = "x"; then
133     sharepath="$default_sharepath"
134 fi
135 AC_DEFINE_UNQUOTED(SHAREPATH, "$sharepath")
136
137 # Test for DJGPP
138 AM_CONDITIONAL(DJGPP, test "$host_os" = "msdosdjgpp")
139 if test "$host_os" = "msdosdjgpp"; then
140
141   CFLAGS="-I \$(top_srcdir)/arch/dos/include $CFLAGS"
142   TARGETS=d2x
143   D2X_ARCH_SUBDIRS=dos
144 else
145
146   CFLAGS="-pipe $CFLAGS"
147
148   dnl Check for SDL
149   AM_PATH_SDL(1.1.7,
150     :,
151     AC_MSG_ERROR(SDL not found. Make sure sdl-config is in your PATH, or specify with --with-sdl-prefix)
152   )
153   CFLAGS="$SDL_CFLAGS $CFLAGS"
154   LIBS="$SDL_LIBS $LIBS"
155
156   TARGETS=d2x-sdl
157   D2X_ARCH_SUBDIRS=sdl
158
159   AC_CHECK_HEADERS(netipx/ipx.h)
160
161   # Check for OpenGL
162   AC_ARG_WITH(opengl,
163     [  --with-opengl           Build OpenGL support ],,)
164   if test x$with_opengl = xyes; then
165     for lib in $GL_LIBS; do
166         AC_CHECK_LIB($lib, main,
167             OGL_LIBS="${OGL_LIBS} -l$lib",
168             [AC_MSG_ERROR([$lib not found, --with-opengl cannot be used])
169             opengl=false],
170             ${OGL_LIBS}
171         )
172     done
173     AC_DEFINE(OGL)
174     TARGETS=d2x-ogl
175     D2X_ARCH_SUBDIRS="ogl ${D2X_ARCH_SUBDIRS}"
176   fi
177   AC_SUBST(OGL_LIBS)
178   AM_CONDITIONAL(USE_OPENGL, test x$with_opengl = xyes)
179
180   # Check for GGI
181   AC_ARG_WITH(ggi,
182     [  --with-ggi              Build GGI support ],,)
183   if test x$with_ggi = xyes; then
184     AC_CHECK_LIB(ggi, ggiInit,
185       GGI_LIBS="-lggi",
186       [AC_MSG_ERROR([GGI not found, GGI version cannot be built]); ggi=false])
187     AC_CHECK_LIB(gii, giiInit,
188       GGI_LIBS="${GGI_LIBS} -lgii",
189       [AC_MSG_ERROR([GII not found, GGI version cannot be built]); ggi=false])
190     AC_DEFINE(GGI)
191     TARGETS=d2x-ggi
192     D2X_ARCH_SUBDIRS="ggi ${D2X_ARCH_SUBDIRS}"
193   fi
194   AC_SUBST(GGI_LIBS)
195   AM_CONDITIONAL(USE_GGI, test x$with_ggi = xyes)
196
197   # Check for SVGALib
198   AC_ARG_WITH(svga,
199     [  --with-svga             Build SVGALib support ],,)
200   if test x$with_svga = xyes; then
201     AC_CHECK_LIB(vga,vga_getmousetype,
202       SVGA_LIBS="-lvga",
203       [AC_MSG_ERROR([vga not found, SVGALib cannot be built])
204        svga=false],
205        )
206     AC_CHECK_LIB(vgagl,gl_getcontext,
207       SVGA_LIBS="${SVGA_LIBS} -lvgagl",
208       [AC_MSG_ERROR([vgagl not found, SVGALib cannot be built])
209        svga=false],
210        -lvga)
211     AC_DEFINE(SVGA)
212     TARGETS=d2x-svga
213     D2X_ARCH_SUBDIRS="svgalib ${D2X_ARCH_SUBDIRS}"
214   fi
215   AC_SUBST(SVGA_LIBS)
216   AM_CONDITIONAL(USE_SVGALIB, test x$with_svga = xyes)
217
218   if test x$MINGW32 = xyes; then
219     D2X_ARCH_SUBDIRS="win32 ${D2X_ARCH_SUBDIRS}"
220     AC_DEFINE(SDL_JOYSTICK)
221   else
222     CFLAGS="-I \$(top_srcdir)/arch/linux/include $CFLAGS"
223     D2X_ARCH_SUBDIRS="linux ${D2X_ARCH_SUBDIRS}"
224
225     dnl Check for SDL joystick
226     AC_ARG_ENABLE(sdl-joystick,
227       [  --enable-sdl-joystick   Use SDL joystick (required for mingw) ],,)
228     if test x$enable_sdl_joystick = xyes; then
229         AC_DEFINE(SDL_JOYSTICK)
230         D2X_FEATURES="sdl_joystick ${D2X_FEATURES}"
231     fi
232     AM_CONDITIONAL(SDL_JOYSTICK, test x$enable_sdl_joystick = xyes)
233   fi
234 fi
235
236 dnl Check for network
237 AC_ARG_ENABLE(network,
238   [  --disable-network       Do not build network/serial support ],,)
239 if test x$enable_network != xno; then
240     AC_DEFINE(NETWORK)
241     D2X_FEATURES="network ${D2X_FEATURES}"
242 fi
243 AM_CONDITIONAL(USE_NETWORK, test x$enable_network != xno)
244
245 dnl Check for assembler
246 AC_ARG_ENABLE(assembler,
247   [  --disable-assembler     Do not use assembler optimization ],,)
248 if test x$enable_assembler = xno; then
249     AC_DEFINE(NO_ASM)
250     D2X_FEATURES="no_asm ${D2X_FEATURES}"
251 else
252     if test x$NASM = xno; then
253         AC_MSG_ERROR([nasm not found. Install it or use --disable-assembler])
254     else
255         NASMFLAGS="-i\$(srcdir)/ $NASMFLAGS"
256         case $host_os in
257           cygwin)
258               NASMFLAGS="-f win32 $NASMFLAGS"
259               ;;
260           msdosdjgpp)
261               NASMFLAGS="-f coff $NASMFLAGS"
262               ;;
263           linux*)
264               NASMFLAGS="-f elf -d__linux__ $NASMFLAGS"
265               ;;
266           *)
267               AC_MSG_ERROR([Assembler not supported for this OS])
268         esac
269     fi
270 fi
271 AM_CONDITIONAL(USE_ASM, test x$enable_assembler != xno)
272
273 AM_PROG_AS
274
275 AC_SUBST(D2X_ARCH_SUBDIRS)
276
277 AC_SUBST(D2X_MAIN_SUBDIRS)
278
279 AC_SUBST(TARGETS)
280
281 AC_SUBST(NASMFLAGS)
282
283 AC_SUBST(CFLAGS)
284
285 AC_OUTPUT(
286 Makefile
287 2d/Makefile
288 3d/Makefile
289 arch/Makefile
290 arch/dos/Makefile
291 arch/ggi/Makefile
292 arch/linux/Makefile
293 arch/ogl/Makefile
294 arch/sdl/Makefile
295 arch/svgalib/Makefile
296 arch/win32/Makefile
297 cfile/Makefile
298 iff/Makefile
299 main/Makefile
300 main/editor/Makefile
301 maths/Makefile
302 mem/Makefile
303 misc/Makefile
304 texmap/Makefile
305 debian/changelog
306 rpm/d2x.spec
307 )
308
309 AC_MSG_RESULT([
310     d2x has been configured successfully.
311
312     Platform(s): $D2X_ARCH_SUBDIRS
313     Features   : $D2X_FEATURES $D2X_MAIN_SUBDIRS
314
315     Shared game data directory: $sharepath
316 ])