1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(Angband, 4.2.2, bugs@rephial.org)
3AC_CONFIG_SRCDIR(src)
4
5AC_CANONICAL_HOST
6AC_CANONICAL_TARGET
7
8BUILDSYS_INIT
9BUILDSYS_TOUCH_DEPS
10
11AC_SUBST(PACKAGE, angband)
12
13AC_CONFIG_HEADERS(src/autoconf.h)
14
15AC_CONFIG_MACRO_DIR([m4])
16
17AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
18AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])
19
20AC_ARG_WITH(setgid,
21	[  --with-setgid=NAME      install angband as group NAME],
22	[wsetgid=yes])
23AC_ARG_WITH(private_dirs,
24	[  --with-private-dirs     use private scorefiles/savefiles])
25AC_ARG_WITH(no_install,
26	[  --with-no-install       don't install, just run in-place])
27
28if test "x$with_setgid" = "xyes"; then
29	AC_MSG_ERROR([Please specify a group to install as.])
30fi
31
32if test "x$wsetgid" = "x" && test "x$with_no_install" = "x"; then
33	with_private_dirs="yes"
34fi
35
36if test "x$wsetgid$with_private_dirs$with_no_install" != "xyes";  then
37
38	echo "Please run ./configure with only one of:
39
40--with-setgid=<groupname>
41    This configures the game to store savefiles and scorefiles in a central
42    location on the system, writeable only by the group \"groupname\".  If you
43    want a traditional installation of Angband, where all users share a
44    scorefile, then use this option, and set the groupname to your \"games\"
45    group.  This option requires the game to have the \"setgid\" bit set on its
46    permissions, and thus this option requires root when installing.
47
48--with-private-dirs
49    This configures the game to store savefiles and scorefiles for each user
50    in that user's home directory.  The game requires no special privileges if
51    you do this, and should be used for most installations of the game. This
52    is the default, if you specify none of these three options.
53
54--with-no-install
55    This leaves the game to run from the directory into which it was extracted
56    and compiled, touching nothing else on the system - make install is not
57    run.
58"
59	AC_MSG_ERROR([Please specify an installation method.])
60fi
61
62if test "x$with_no_install" = "x"; then
63	echo "Note: You have chosen to compile for installation, with data files
64    in standard locations. For development, you may wish to consider using
65    --with-no-install which will leave the game to run from the directory
66    into which it was extracted and compiled.
67"
68fi
69
70AC_PROG_CC
71AC_PROG_MAKE_SET
72AC_PROG_LN_S
73AC_PROG_INSTALL
74AC_PROG_MKDIR_P
75AC_CHECK_TOOL(RC, windres, no)
76AC_ARG_VAR([RST2HTML], [command for converting reStructuredText to HTML])
77AC_CHECK_PROGS([RST2HTML], [rst2html.py rst2html], [NOTFOUND])
78AC_SUBST(RST2HTML)
79AC_ARG_VAR([RST2LATEX], [command for converting reStructuredText to LaTeX])
80AC_CHECK_PROGS([RST2LATEX], [rst2latex.py rst2latex], [NOTFOUND])
81AC_SUBST(RST2LATEX)
82AC_CHECK_PROGS([PDFLATEX], [pdflatex], [NOTFOUND])
83AC_SUBST(PDFLATEX)
84
85AC_PATH_PROG(RM, rm)
86AC_PATH_PROG(MV, mv)
87AC_PATH_PROG(CP, cp)
88
89AC_HEADER_DIRENT
90AC_CHECK_HEADERS([fcntl.h stdint.h])
91AC_HEADER_STDBOOL
92AC_C_CONST
93AC_TYPE_SIGNAL
94AC_CHECK_FUNCS([mkdir setresgid setegid stat])
95
96dnl needed because h-basic.h checks for this define for autoconf support.
97CFLAGS="$CFLAGS -DHAVE_CONFIG_H"
98CPPFLAGS="$CPPFLAGS -I."
99
100if test "$GCC" = "yes"; then
101	CFLAGS="$CFLAGS -W -Wall -Wextra -Wno-unused-parameter -pedantic"
102fi
103
104MY_PROG_MAKE_SYSVINC
105MY_PROG_MAKE_SINCLUDE
106
107dnl Work around an autoconf bug.
108if test "$prefix" = "NONE"; then
109	prefix="${ac_default_prefix}"
110fi
111if test "$exec_prefix" = "NONE"; then
112	exec_prefix="${prefix}"
113fi
114
115if test "x$with_private_dirs" != "x"; then
116	AC_DEFINE(USE_PRIVATE_PATHS, 1, [Define to use private save and score paths.])
117fi
118
119# Only change bindir if it's the configure-supplied default, which handily doesn't expand exec_prefix
120if test "x$bindir" = "x\${exec_prefix}/bin"; then
121  bindir=${exec_prefix}/bin
122fi
123
124if test "x$with_no_install" != "x"; then
125	configpath="${PWD}/lib/"
126else
127	configpath="${sysconfdir}/${PACKAGE}/"
128fi
129
130case "/$configpath" in
131	*/) MY_EXPAND_DIR(configdir, "$configpath")  ;;
132	*)  MY_EXPAND_DIR(configdir, "$configpath/") ;;
133esac
134
135
136if test "x$with_no_install" != "x"; then
137	libpath="${PWD}/lib/"
138	bindir=".."
139else
140	libpath="${datarootdir}/${PACKAGE}/"
141fi
142
143case "/$libpath" in
144	*/) MY_EXPAND_DIR(libdatadir, "$libpath")  ;;
145	*)  MY_EXPAND_DIR(libdatadir, "$libpath/") ;;
146esac
147
148if test "x$with_no_install" != "x"; then
149	docdir="${PWD}/doc/"
150else
151	# Only change docdir if it's the configure-supplied default, which handily doesn't expand prefix
152	if test "x$docdir" = "x\${datarootdir}/doc/\${PACKAGE_TARNAME}"; then
153		docdir=${datarootdir}/doc/${PACKAGE}
154	fi
155fi
156
157case "/$docdir" in
158 	*/) MY_EXPAND_DIR(docdatadir, "$docdir")  ;;
159	*)  MY_EXPAND_DIR(docdatadir, "$docdir/") ;;
160esac
161
162if test "x$with_no_install" != "x"; then
163	varpath="${PWD}/lib/"
164else
165	varpath="${localstatedir}/games/${PACKAGE}/"
166fi
167
168case "/$varpath" in
169	*/) MY_EXPAND_DIR(vardatadir, "$varpath")  ;;
170	*)  MY_EXPAND_DIR(vardatadir, "$varpath/") ;;
171esac
172
173
174AC_SUBST([configdir])
175AC_SUBST([libdatadir])
176AC_SUBST([vardatadir])
177AC_SUBST([docdatadir])
178
179AC_DEFINE_UNQUOTED([DEFAULT_CONFIG_PATH], "${configdir}", [Path to the game's configuration data])
180AC_DEFINE_UNQUOTED([DEFAULT_LIB_PATH], "${libdatadir}", [Path to the game's lib directory])
181AC_DEFINE_UNQUOTED([DEFAULT_DATA_PATH], "${vardatadir}", [Path to the game's variable data])
182
183NOINSTALL="$with_noinstall"; AC_SUBST(NOINSTALL)
184SETEGID="$with_setgid";      AC_SUBST(SETEGID)
185
186dnl Frontends
187AC_ARG_ENABLE(curses,
188	[AS_HELP_STRING([--enable-curses],    [Enables Curses frontend (default: enabled)])],
189	[enable_curses=$enableval],
190	[enable_curses=yes])
191AC_ARG_ENABLE(x11,
192	[AS_HELP_STRING([--enable-x11],       [Enables X11 frontend (default: enabled)])],
193	[enable_x11=$enableval],
194	[enable_x11=yes])
195AC_ARG_ENABLE(sdl2,
196	[AS_HELP_STRING([--enable-sdl2],       [Enables SDL2 frontend (default: disabled)])],
197	[enable_sdl2=$enableval],
198	[enable_sdl2=no])
199AC_ARG_ENABLE(sdl,
200	[AS_HELP_STRING([--enable-sdl],       [Enables SDL frontend (default: disabled)])],
201	[enable_sdl=$enableval],
202	[enable_sdl=no])
203AC_ARG_ENABLE(win,
204	[AS_HELP_STRING([--enable-win],       [Enables Windows frontend (default: disabled)])],
205	[enable_win=$enableval],
206	[enable_win=no])
207AC_ARG_ENABLE(test,
208	[AS_HELP_STRING([--enable-test],      [Enables test frontend (default: disabled)])],
209	[enable_test=$enableval],
210	[enable_test=no])
211AC_ARG_ENABLE(stats,
212	[AS_HELP_STRING([--enable-stats],     [Enables stats frontend (default: disabled)])],
213	[enable_stats=$enableval],
214	[enable_stats=no])
215
216dnl Sound modules
217AC_ARG_ENABLE(sdl2_mixer,
218	[AS_HELP_STRING([--enable-sdl2-mixer], [Enables SDL2 mixer sound support (default: disabled unless SDL2 enabled)])],
219	[enable_sdl2_mixer=$enable_sdl2_mixer],
220	[enable_sdl2_mixer=$enable_sdl2])
221AC_ARG_ENABLE(sdl_mixer,
222	[AS_HELP_STRING([--enable-sdl-mixer], [Enables SDL mixer sound support (default: disabled unless SDL enabled)])],
223	[enable_sdl_mixer=$enable_sdl_mixer],
224	[enable_sdl_mixer=$enable_sdl])
225
226MAINFILES="\$(BASEMAINFILES)"
227
228dnl curses checking
229if test "$enable_curses" = "yes"; then
230	AM_PATH_NCURSESW(with_curses=yes, with_curses=no)
231	if test "$with_curses" = "yes"; then
232		AC_DEFINE(USE_NCURSES, 1, [Define to 1 if NCurses is found.])
233		AC_DEFINE(USE_GCU, 1, [Define to 1 if using the Curses frontend.])
234		CFLAGS="${CFLAGS} ${NCURSES_CFLAGS}"
235		LIBS="${LIBS} ${NCURSES_LIBS}"
236		MAINFILES="${MAINFILES} \$(GCUMAINFILES)"
237	else
238		AC_CHECK_LIB([ncursesw], [initscr], [
239			AC_DEFINE(USE_NCURSES, 1, [Define to 1 if NCurses is found.])
240			AC_DEFINE(USE_GCU, 1, [Define to 1 if using the Curses frontend.])
241			AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Defined for systems that guard ncurses decls with _XOPEN_SOURCE_EXTENDED])
242			with_curses=yes
243			LIBS="${LIBS} -lncursesw"
244			MAINFILES="${MAINFILES} \$(GCUMAINFILES)"
245		])
246		AC_SEARCH_LIBS([keypad], [tinfow tinfo])
247	fi
248fi
249
250AC_CHECK_FUNCS([mvwaddnwstr use_default_colors can_change_color])
251
252dnl X11 checking
253if test "$enable_x11" = "yes"; then
254	AC_PATH_XTRA
255
256	if test "x$have_x" != "xyes"; then
257		with_x11=no
258	else
259		AC_DEFINE(USE_X11, 1, [Define to 1 if using the X11 frontend and X11 libraries are found.])
260		CFLAGS="$CFLAGS $X_CFLAGS"
261		LIBS="${LIBS} ${X_PRE_LIBS} ${X_LIBS} -lX11 ${X_EXTRA_LIBS}"
262		MAINFILES="${MAINFILES} \$(X11MAINFILES)"
263		with_x11=yes
264	fi
265fi
266
267dnl SDL2 checking
268if test "$enable_sdl2" = "yes"; then
269	AM_PATH_SDL2(2.0.0,,)
270
271	if test "$SDL2_CONFIG" = "no"; then
272		with_sdl2=no
273	else
274		AC_CHECK_LIB(SDL2_image, IMG_LoadPNG_RW, with_sdl2=yes, with_sdl2=no)
275		AC_CHECK_LIB(SDL2_ttf, TTF_Init, with_sdl2x=yes, with_sdl2=no)
276
277		if test "$with_sdl2" = "yes"; then
278			AC_DEFINE(USE_SDL2, 1, [Define to 1 if using the SDL2 interface and SDL2 is found.])
279			CFLAGS="${CFLAGS} ${SDL2_CFLAGS}"
280			LIBS="${LIBS} ${SDL2_LIBS} -lSDL2_image -lSDL2_ttf"
281			MAINFILES="${MAINFILES} \$(SDL2MAINFILES)"
282			enable_sdl=no
283			enable_sdl_mixer=no
284		fi
285	fi
286else
287	dnl SDL checking
288	if test "$enable_sdl" = "yes"; then
289	   AM_PATH_SDL(1.2.10,,)
290
291	   if test "$SDL_CONFIG" = "no"; then
292		  with_sdl=no
293	   else
294			AC_CHECK_LIB(SDL_image, IMG_LoadPNG_RW, with_sdl=yes, with_sdl=no)
295			AC_CHECK_LIB(SDL_ttf, TTF_Init, with_sdlx=yes, with_sdl=no)
296
297			if test "$with_sdl" = "yes"; then
298			   		AC_DEFINE(USE_SDL, 1, [Define to 1 if using the SDL interface and SDL is found.])
299					CFLAGS="${CFLAGS} ${SDL_CFLAGS}"
300					LIBS="${LIBS} ${SDL_LIBS} -lSDL_image -lSDL_ttf"
301					MAINFILES="${MAINFILES} \$(SDLMAINFILES)"
302		    fi
303	    fi
304	fi
305fi
306
307dnl Windows checking
308if test "$enable_win" = "yes"; then
309	AC_DEFINE(USE_WIN, 1, [Define to 1 if using the Windows interface.])
310	AC_DEFINE(SOUND, 1, [Define to 1 if including sound support.])
311	CFLAGS="${CFLAGS} -DWINDOWS -static -Iwin/include"
312	LDFLAGS="${LDFLAGS} -Lwin/lib"
313	LIBS="${LIBS} -mwindows -lwinmm -lzlib -llibpng -lmsimg32"
314dnl Note complete replacement of all main files
315	MAINFILES="\$(WINMAINFILES)"
316fi
317
318dnl SDL2 mixer checking
319if test "$enable_sdl2_mixer" = "yes"; then
320	if test "$enable_sdl_mixer" = "yes"; then
321		AC_MSG_ERROR(both --enable-sdl-mixer and --enable-sdl2-mixer set, 1)
322	fi
323	AC_CHECK_LIB(SDL2_mixer, Mix_OpenAudio, found_sdl2_mixer=yes, found_sdl2_mixer=no)
324
325	if test "$found_sdl2_mixer" = "yes"; then
326		AC_DEFINE(SOUND_SDL2, 1, [Define to 1 if using SDL2_mixer sound support and it's found.])
327		AC_DEFINE(SOUND, 1, [Define to 1 if including sound support.])
328		if test "$with_sdl2" = "yes"; then
329			LIBS="${LIBS} -lSDL2_mixer"
330		else
331			SDL2_CFLAGS=`sdl2-config --cflags`
332			CFLAGS="${CFLAGS} ${SDL2_CFLAGS}"
333			SDL2_LIBS=`sdl2-config --libs`
334			LIBS="${LIBS} ${SDL2_LIBS} -lSDL2_mixer"
335		fi
336		MAINFILES="${MAINFILES} \$(SNDSDLFILES)"
337	fi
338fi
339
340dnl SDL mixer checking
341if test "$enable_sdl_mixer" = "yes"; then
342	AC_CHECK_LIB(SDL_mixer, Mix_OpenAudio, found_sdl_mixer=yes, found_sdl_mixer=no)
343
344	if test "$found_sdl_mixer" = "yes"; then
345		AC_DEFINE(SOUND_SDL, 1, [Define to 1 if using SDL_mixer sound support and it's found.])
346		AC_DEFINE(SOUND, 1, [Define to 1 if including sound support.])
347		if test "$with_sdl" = "yes"; then
348			LIBS="${LIBS} -lSDL_mixer"
349		else
350			SDL_CFLAGS=`sdl-config --cflags`
351			CFLAGS="${CFLAGS} ${SDL_CFLAGS}"
352			SDL_LIBS=`sdl-config --libs`
353			LIBS="${LIBS} ${SDL_LIBS} -lSDL_mixer"
354		fi
355		MAINFILES="${MAINFILES} \$(SNDSDLFILES)"
356	fi
357fi
358
359
360LIBS="${LIBS} -lm"
361
362
363dnl Test checking
364if test "$enable_test" = "yes"; then
365	AC_DEFINE(USE_TEST, 1, [Define to 1 to build the test frontend])
366	MAINFILES="${MAINFILES} \$(TESTMAINFILES)"
367fi
368
369dnl Stats checking
370
371LDFLAGS_SAVE="$LDFLAGS"
372if test "$enable_stats" = "yes"; then
373	# SQLite3 detection
374	SQLITE3_OK=yes
375	AC_CHECK_HEADER(sqlite3.h, [], [
376		SQLITE3_OK=missing
377		for sqlite3_path in $SEARCH_DIR_HEADERS; do
378			if test "x$ac_cv_header_sqlite3_h" != xyes; then
379				unset ac_cv_header_sqlite3_h
380				AC_CHECK_HEADER($sqlite3_path/sqlite3.h,
381					[
382						SQLITE3_CFLAGS="-I$sqlite3_path"
383						SQLITE3_OK=yes
384					]
385				)
386			fi
387		done
388	])
389	if test "x$SQLITE3_OK" = xyes; then
390		AC_CHECK_LIB(sqlite3, sqlite3_open, [
391			SQLITE3_LIBS="-lsqlite3"
392		], [
393			SQLITE3_OK=missing
394			for sqlite3_path in $SEARCH_DIR_LIBS; do
395				if test "x$ac_cv_lib_sqlite3_sqlite3_open" != xyes; then
396					unset ac_cv_lib_sqlite3_sqlite3_open
397					LDFLAGS="${LDFLAGS_SAVE} -L$sqlite3_path"
398					AC_CHECK_LIB(sqlite3, sqlite3_open, [
399						SQLITE3_LDFLAGS="-L$sqlite3_path"
400						SQLITE3_LIBS="-lsqlite3"
401						SQLITE3_OK=yes
402					])
403				fi
404			done
405		])
406	fi
407	if test "x$SQLITE3_OK" = xyes; then
408		AC_DEFINE(USE_STATS, 1, [Define to 1 to build the stats frontend])
409		CFLAGS="${CFLAGS} ${SQLITE3_CFLAGS}"
410		LDFLAGS="${LDFLAGS_SAVE} ${SQLITE3_LDFLAGS}"
411		LIBS="${LIBS} ${SQLITE3_LIBS}"
412		MAINFILES="${MAINFILES} \$(STATSMAINFILES)"
413		AC_SUBST(USE_STATS, 1)
414	else
415		AC_MSG_ERROR(Could not find sqlite3 library; disabling stats)
416		enable_stats=no
417		AC_DEFINE(USE_STATS, 0, [Define to 0 to omit the stats frontend])
418		LDFLAGS="$LDFLAGS_SAVE"
419		AC_SUBST(USE_STATS, 0)
420	fi
421fi
422
423AC_SUBST(MAINFILES, ${MAINFILES})
424AC_CONFIG_FILES([mk/buildsys.mk mk/extra.mk mk/sinc@&t@lude.mk])
425AC_OUTPUT
426
427if test "x$with_private_dirs" = "xyes"; then
428	displayedvardatadir="(not used)"
429else
430	displayedvardatadir="$vardatadir"
431fi
432
433if test "x$with_no_install" = "xyes"; then
434	displayedprefix="(not used)"
435else
436	displayedprefix="$prefix"
437fi
438
439echo
440echo "Configuration:"
441echo
442echo "  Install path:                           ${displayedprefix}"
443echo "  binary path:                            ${bindir}"
444echo "  config path:                            ${configdir}"
445echo "  lib path:                               ${libdatadir}"
446echo "  doc path:                               ${docdatadir}"
447echo "  var path:                               ${displayedvardatadir}"
448
449if test "x$wsetgid" = "xyes"; then
450	echo "  (as group ${SETEGID})"
451elif test "x$with_private_dirs" = "xyes"; then
452	echo "  (with private save and score files in ~/.angband/Angband/)"
453fi
454
455echo
456echo "-- Frontends --"
457if test "$enable_curses" = "yes"; then
458	if test "$with_curses" = "no"; then
459		echo "- Curses                                  No; missing libraries"
460	else
461		echo "- Curses                                  Yes"
462	fi
463else
464	echo "- Curses                                  Disabled"
465fi
466if test "$enable_x11" = "yes"; then
467	if test "$with_x11" = "no"; then
468		echo "- X11                                     No; missing libraries"
469	else
470		echo "- X11                                     Yes"
471	fi
472else
473	echo "- X11                                     Disabled"
474fi
475if test "$enable_sdl2" = "yes"; then
476	if test "$with_sdl2" = "no"; then
477		echo "- SDL2                                    No; missing libraries"
478	else
479		echo "- SDL2                                    Yes"
480	fi
481else
482	echo "- SDL2                                    Disabled"
483fi
484if test "$enable_sdl" = "yes"; then
485	if test "$with_sdl" = "no"; then
486		echo "- SDL                                     No; missing libraries"
487	else
488		echo "- SDL                                     Yes"
489	fi
490else
491	echo "- SDL                                     Disabled"
492fi
493
494if test "$enable_win" = "yes"; then
495	if test "$with_sdl" = "no"; then
496		echo "- Windows                                 No; missing libraries"
497	else
498		echo "- Windows                                 Yes"
499	fi
500else
501	echo "- Windows                                 Disabled"
502fi
503
504if test "$enable_test" = "yes"; then
505	echo "- Test                                    Yes"
506else
507    echo "- Test                                    No"
508fi
509
510if test "$enable_stats" = "yes"; then
511	echo "- Stats                                   Yes"
512else
513    echo "- Stats                                   No"
514fi
515
516echo
517
518if test "$enable_sdl2_mixer" = "yes"; then
519	if test "$found_sdl2_mixer" = "no"; then
520		echo "- SDL2 sound                              No; missing libraries"
521	else
522		echo "- SDL2 sound                              Yes"
523	fi
524else
525	echo "- SDL2 sound                              Disabled"
526fi
527if test "$enable_sdl_mixer" = "yes"; then
528	if test "$found_sdl_mixer" = "no"; then
529		echo "- SDL sound                               No; missing libraries"
530	else
531		echo "- SDL sound                               Yes"
532	fi
533else
534	echo "- SDL sound                               Disabled"
535fi
536