1AC_PREREQ(2.67)
2AC_INIT([TilEm], [2.0], [tilem-devel@lists.sourceforge.net],
3  [tilem], [http://tilem.sourceforge.net/])
4AC_CONFIG_SRCDIR([emu/tilem.h])
5
6# Checks for programs
7
8AC_PROG_CC
9AC_PROG_CPP
10AC_ARG_VAR(OPT_CFLAGS,
11  [Additional C compiler flags used for optimizing critical areas of
12  the code (default: -O3 if using GCC)])
13if test "x$GCC" = "xyes" ; then
14  CFLAGS="$CFLAGS -W -Wall -Wwrite-strings"
15  if test "x$OPT_CFLAGS" = "x" ; then
16    OPT_CFLAGS="-O3"
17  fi
18fi
19
20AC_CHECK_TOOL(AR, [ar], [false])
21AC_ARG_VAR(AR, [Static library archiver])
22AC_ARG_VAR(AR_FLAGS, [Flags to pass to ar to build a static library])
23if test "x$AR_FLAGS" = "x" ; then
24  AR_FLAGS=cru
25fi
26
27AC_PROG_RANLIB
28AC_ARG_VAR(RANLIB, [Program to make a static library linkable])
29
30AC_PROG_INSTALL
31AC_PROG_MAKE_SET
32
33AC_CHECK_PROG([UPDATE_DESKTOP_DATABASE],
34              [update-desktop-database], [update-desktop-database], [:])
35AC_CHECK_PROG([UPDATE_MIME_DATABASE],
36              [update-mime-database], [update-mime-database], [:])
37
38# Checks for libraries
39
40m4_define(with_flags, [
41  save_cflags="$CFLAGS"
42  save_libs="$LIBS"
43  CFLAGS="$CFLAGS $$1_CFLAGS"
44  LIBS="$LIBS $$1_LIBS"
45  $2
46  CFLAGS="$save_cflags"
47  LIBS="$save_libs"
48])
49
50# GLib and GTK+
51
52PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6.0
53                       glib-2.0 >= 2.12.0
54                       gthread-2.0)
55
56AC_ARG_ENABLE([gtk-deprecated],
57  AS_HELP_STRING([--disable-gtk-deprecated], [Disable deprecated GTK+ API]),
58  [ enable_gtk_deprecated=$enableval ], [ enable_gtk_deprecated=yes ])
59if test "x$enable_gtk_deprecated" = "xno" ; then
60  GTK_CFLAGS="$GTK_CFLAGS -DG_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGSEAL_ENABLE"
61fi
62
63# If using the native Windows version of GTK+, be sure to use
64# -mms-bitfields for all compilation.  Also, use -mwindows for linking
65# GUI programs.
66
67# (If not using pkg-config, you're on your own)
68
69if test "x$PKG_CONFIG" != "x" ; then
70  gtk_target=`$PKG_CONFIG --variable=target gtk+-2.0`
71fi
72
73if test "x$gtk_target" = "xwin32" && test "x$GCC" = "xyes" ; then
74  CFLAGS="$CFLAGS -mms-bitfields"
75  GUI_LDFLAGS="-mwindows"
76  LIBS="-lcomdlg32 -lshell32 -lole32 $LIBS"
77  gui_extra_objects="tilem2rc.o"
78else
79  GUI_LDFLAGS=""
80  gui_extra_objects=""
81fi
82
83AC_SUBST(GUI_LDFLAGS)
84AC_SUBST(gui_extra_objects)
85
86with_flags(GTK,
87  [ AC_CHECK_FUNC(gtk_init, [ have_gtk=yes ], [ have_gtk=no ]) ])
88if test "x$have_gtk" != "xyes" ; then
89  AC_MSG_ERROR([GTK+ 2.x libraries not found or not usable.
90You must install a recent version of GTK+ 2.x, including the
91-dev/-devel packages if appropriate.])
92fi
93
94# Libticalcs2 and related libraries
95
96PKG_CHECK_MODULES(TICALCS, ticalcs2 ticables2 tifiles2 ticonv,
97                  [ have_ticalcs=maybe ], [ have_ticalcs=no ])
98
99if test "x$have_ticalcs" = "xmaybe" ; then
100  with_flags(TICALCS,
101    [ AC_CHECK_FUNC(ticalcs_library_init, [ have_ticalcs=yes ], [ have_ticalcs=no ]) ])
102fi
103
104if test "x$have_ticalcs" != "xyes" ; then
105  AC_MSG_ERROR([libticalcs2 not found or not usable.
106
107$TICALCS_PKG_ERRORS
108
109You must install libticalcs2, libticables2, libtifiles2, and libticonv
110(including the -dev/-devel packages if appropriate.)  These libraries
111are available from <http://lpg.ticalc.org/prj_tilp/>.
112
113If you have installed the libraries in a non-standard location (or if
114you're cross-compiling), you will need to add the location of
115ticalcs2.pc to your PKG_CONFIG_PATH environment variable, or set the
116TICALCS_CFLAGS and TICALCS_LIBS environment variables by hand.])
117fi
118
119# Tools used for building the Windows installer
120
121if test "x$gtk_target" = "xwin32" ; then
122  AC_CHECK_TOOL([STRIP], [strip], [:])
123  AC_CHECK_TOOL([OBJDUMP], [objdump], [objdump])
124  AC_CHECK_TOOL([WINDRES], [windres], [windres])
125  AC_CHECK_PROG([MAKENSIS], [makensis], [makensis])
126  AC_PROG_LN_S
127
128  AC_MSG_CHECKING([where to find GTK+ runtime libraries])
129  if test "x$GTK_BINDIR" = "x" ; then
130    prefix=`$PKG_CONFIG --variable=exec_prefix gtk+-2.0`
131    test "x$prefix" != "x" && GTK_BINDIR="$prefix/bin"
132  fi
133  AC_MSG_RESULT([$GTK_BINDIR])
134
135  AC_MSG_CHECKING([where to find ticalcs2 runtime libraries])
136  if test "x$TICALCS_BINDIR" = "x" ; then
137    prefix=`$PKG_CONFIG --variable=exec_prefix ticalcs2`
138    test "x$prefix" != "x" && TICALCS_BINDIR="$prefix/bin"
139  fi
140  AC_MSG_RESULT([$TICALCS_BINDIR])
141
142  if test "x$DLLPATH" = "x" ; then
143    DLLPATH='${GTK_BINDIR}'$PATH_SEPARATOR'${TICALCS_BINDIR}'
144  fi
145  AC_SUBST(GTK_BINDIR)
146  AC_SUBST(TICALCS_BINDIR)
147  AC_SUBST(DLLPATH)
148fi
149
150# Checks for header files
151
152AC_HEADER_STDC
153
154# Checks for system and compiler characteristics
155
156AC_C_BIGENDIAN
157AC_C_INLINE
158AC_C_RESTRICT
159AC_TYPE_UINTPTR_T
160
161# Output
162
163AC_CONFIG_HEADERS([config.h])
164AC_CONFIG_FILES([Makefile
165                 emu/Makefile
166                 db/Makefile
167                 data/Makefile
168                 gui/Makefile
169                 gui/tilem2.rc
170                 installer/win32/Makefile
171                 installer/win32/installer.nsi])
172AC_OUTPUT
173