1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.57)
5AC_INIT([gpsim], [0.31.0], [<http://gpsim.sourceforge.net/gpsim.html>])
6AC_CONFIG_SRCDIR([config.h.in])
7AC_CONFIG_HEADER([config.h])
8AM_INIT_AUTOMAKE([subdir-objects])
9AM_MAINTAINER_MODE
10AC_CONFIG_MACRO_DIR([m4])
11
12# Determine the host and build type. The target is always a PIC.
13AC_CANONICAL_BUILD
14AC_CANONICAL_HOST
15
16dnl --enable-leak-sanitize : Turn on memory leak detection
17dnl The default is off
18dnl X86-64 Linux GCC 4.8+ CLang only
19
20AC_ARG_ENABLE(leak-sanitize,
21    [  --enable-leak-sanitize    Enable memory leak debugging],
22     [case "${enableval}" in
23      yes) use_leak_sanitize=yes ;;
24      no) use_leak_sanitize=no ;;
25      *) AC_MSG_ERROR(bad value ${enableval} for --enable-leak-sanitize) ;;
26    esac],[use_leak_sanitize=no])
27
28if test "$use_leak_sanitize" = "yes"; then
29    echo enabling memory leak debugging
30    LD_SANITIZE="-fsanitize=leak"
31else
32    LD_SANITIZE=""
33fi
34
35dnl --enable-address-sanitize : Turn on memory error detection
36dnl The default is off
37dnl X86-64 Linux GCC 4.8+ CLang only
38
39AC_ARG_ENABLE(address-sanitize,
40    [  --enable-address-sanitize    Enable memory error debugging],
41     [case "${enableval}" in
42      yes) use_address_sanitize=yes ;;
43      no) use_address_sanitize=no ;;
44      *) AC_MSG_ERROR(bad value ${enableval} for --enable-address-sanitize) ;;
45    esac],[use_address_sanitize=no])
46
47if test "$use_address_sanitize" = "yes"; then
48    echo enabling memory address debugging
49    LD_ADDRESS="-fsanitize=address"
50else
51    LD_ADDRESS=""
52fi
53
54dnl --enable-undefined-sanitize : Turn on undefined behavior detection
55dnl The default is off
56dnl X86-64 Linux GCC 4.8+ CLang only
57
58AC_ARG_ENABLE(undefined-sanitize,
59    [  --enable-undefined-sanitize    Enable undefined behavior detection],
60     [case "${enableval}" in
61      yes) use_undefined_sanitize=yes ;;
62      no) use_undefined_sanitize=no ;;
63      *) AC_MSG_ERROR(bad value ${enableval} for --enable-undefined-sanitize) ;;
64    esac],[use_undefined_sanitize=no])
65
66if test "$use_undefined_sanitize" = "yes"; then
67    echo enabling undefined behavior detection
68    LD_UNDEFINED="-fsanitize=undefined"
69else
70    LD_UNDEFINED=""
71fi
72
73dnl --disable-gui : turn off gui support (cli only)
74dnl    The default is to have the gui.
75
76AC_ARG_ENABLE(gui,
77     [  --disable-gui           Only use the cli and not the gui],
78     [case "${enableval}" in
79       yes) use_gui=yes ;;
80       no)  use_gui=no ;;
81       *) AC_MSG_ERROR(bad value ${enableval} for --disable-gui) ;;
82     esac],[use_gui=yes])
83
84if test "$use_gui" = "no"; then
85        echo disabling gui support
86else
87        echo enabling gui support
88        [
89         use_gui=yes
90        ]
91        AC_DEFINE([HAVE_GUI],[],[True if GUI is being used])
92fi
93
94
95dnl --enable-sockets : allows gpsim to be controlled from a socket interface
96dnl    The default is to not use sockets.
97
98AC_ARG_ENABLE(sockets,
99     [  --enable-sockets        Allows gpsim to be controlled via a socket interface],
100     [case "${enableval}" in
101       yes) use_sockets=yes ;;
102       no)  use_sockets=no ;;
103       *) AC_MSG_ERROR(bad value ${enableval} for --enable-sockets) ;;
104     esac],[use_sockets=no])
105
106if test "$use_sockets" = "no"; then
107        echo disabling gpsim socket interface
108else
109        echo enabling gpsim socket interface
110        [
111         use_sockets=yes
112        ]
113        AC_DEFINE([HAVE_SOCKETS],[],[True if gpsim socket interface is being used])
114fi
115
116dnl check if popt is installed
117AC_CHECK_HEADER(popt.h, , AC_MSG_ERROR(popt not installed: cannot find popt.h))
118
119GTK=
120GDK=
121GLIB=
122
123PKG_PROG_PKG_CONFIG()
124
125if test "$use_gui" = "no"; then
126  dnl glib2 checks
127
128  PKG_CHECK_MODULES(P_GLIB, [glib-2.0 >= 2.26 gthread-2.0 gmodule-2.0])
129  X_LDFLAGS=$P_GLIB_LIBS
130  X_CFLAGS=$P_GLIB_CFLAGS
131  Y_LDFLAGS=
132  Y_CFLAGS=
133else
134  dnl gtk2 checks
135
136#  PKG_CHECK_MODULES(GTKEXTRAMOD, gtkextra-2.0, ,
137#    [PKG_CHECK_MODULES(GTKEXTRAMOD, gtkextra-3.0, ,
138#      [AC_MSG_ERROR(Cannot find gtkextra-2.0 or gtkextra-3.0 package)])])
139
140  PKG_CHECK_MODULES(P_GTK, [gtk+-2.0 >= 2.24 glib-2.0 >= 2.26 gthread-2.0])
141  X_LDFLAGS=$P_GTK_LIBS
142  X_CFLAGS=$P_GTK_CFLAGS
143#  Y_LDFLAGS=$GTKEXTRAMOD_LIBS
144#  Y_CFLAGS=$GTKEXTRAMOD_CFLAGS
145  GTK_VERSION_T=`$PKG_CONFIG --modversion gtk+-2.0`
146  echo linking with gtk-$GTK_VERSION_T
147  AC_DEFINE_UNQUOTED([GTK_VERSION],"$GTK_VERSION_T",[gtk version])
148fi
149
150wi_LIB_READLINE
151  if test "$wi_cv_lib_readline" != yes; then
152	AC_MSG_ERROR(Cannot find readline library)
153  fi
154
155# Checks for programs.
156AC_PROG_CXX
157AC_PROG_CXXCPP
158AC_PROG_CC
159AC_PROG_CPP
160AC_PROG_INSTALL
161AC_PROG_LN_S
162AC_PROG_MAKE_SET
163AC_PROG_YACC
164AM_PROG_LEX
165AM_PROG_LIBTOOL
166
167# Checks for libraries.
168AC_LANG([C++])
169#AC_CHECK_LIB([gpsim], [main])
170AC_CHECK_LIB([popt], [main])
171#AC_CHECK_LIB([pthread], [main])
172
173AC_CHECK_LIB([dl], [dlopen], [LIBDL="-ldl"])
174
175# Checks for header files.
176AC_HEADER_STDC
177AC_CHECK_HEADERS([fcntl.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/file.h sys/ioctl.h sys/socket.h sys/time.h termios.h unistd.h])
178
179# Checks for typedefs, structures, and compiler characteristics.
180AC_HEADER_STDBOOL
181AC_C_CONST
182AC_C_INLINE
183AC_TYPE_SIZE_T
184AC_HEADER_TIME
185AC_TYPE_SIGNAL
186
187# Checks for library functions.
188AC_FUNC_ALLOCA
189AC_PROG_GCC_TRADITIONAL
190#AC_FUNC_MALLOC
191#AC_FUNC_REALLOC
192AC_FUNC_SELECT_ARGTYPES
193AC_FUNC_STRTOD
194AC_CHECK_FUNCS([floor gethostbyname gethostname gettimeofday memset pow select socket sqrt strcasecmp strchr strdup strerror strncasecmp strndup strpbrk strrchr strstr strtoul])
195
196# printf modifier define for long long as "ll"
197# config_win32.h.in defines this for Visual Studio stdclib as "I64"
198AC_DEFINE([PRINTF_INT64_MODIFIER],["ll"],[printf modifier define for long long])
199
200# define printf modifier for GINT64 (guint64 and gint64) as "ll" on 32 bit machines and as "l" on 64 bit machines
201# config_win32.h.in defines this for Visual Studio stdclib as "I64"
202AC_CHECK_SIZEOF(long)
203if test "$ac_cv_sizeof_long" -ge 8; then
204  gpsim_cv_printf_gint64_modifier=l
205else
206  gpsim_cv_printf_gint64_modifier=ll
207fi
208AC_DEFINE_UNQUOTED([PRINTF_GINT64_MODIFIER],"$gpsim_cv_printf_gint64_modifier",[printf modifier define for GINT64])
209
210AM_CFLAGS=
211AM_CXXFLAGS=
212AM_LDFLAGS=
213
214# Options for the system on which the package will run
215case "${host}" in
216  *linux* )
217    if test "x$GCC" = "xyes"; then
218      AM_CFLAGS="-Wall"
219      AM_CXXFLAGS="-Wall"
220      AM_LDFLAGS="-Wl,-warn-common -Wl,-warn-once"
221    fi
222    ;;
223  *mingw* )
224    ;;
225esac
226
227CFLAGS="${CFLAGS} ${AM_CFLAGS} ${LD_SANITIZE} ${LD_ADDRESS} ${LD_UNDEFINED}"
228CXXFLAGS="${CXXFLAGS} ${AM_CXXFLAGS} ${LD_SANITIZE} ${LD_ADDRESS} ${LD_UNDEFINED}"
229LDFLAGS="${LDFLAGS} ${AM_LDFLAGS} ${LD_SANITIZE} ${LD_ADDRESS} ${LD_UNDEFINED}"
230
231# Host filesystem options
232case "${host}" in
233  *mingw* | *-pc-os2_emx | *-pc-os2-emx | *djgpp* )
234    AC_DEFINE(HAVE_DOS_BASED_FILE_SYSTEM, 1,
235      [Define if your host uses a DOS based file system. ])
236    ;;
237esac
238
239AC_SUBST(Y_CFLAGS)
240AC_SUBST(Y_LDFLAGS)
241AC_SUBST(X_CFLAGS)
242AC_SUBST(X_LDFLAGS)
243AC_SUBST(GTK)
244AC_SUBST(GDK)
245AC_SUBST(GLIB)
246AC_SUBST(LIBREADLINE)
247AC_SUBST(LIBDL)
248
249AC_CONFIG_FILES([Makefile
250                 cli/Makefile
251                 doc/Makefile
252                 examples/Makefile
253                 examples/modules/Makefile
254                 examples/projects/Makefile
255                 examples/12bit/Makefile
256                 examples/14bit/Makefile
257                 examples/16bit/Makefile
258                 eXdbm/Makefile
259                 gpsim/Makefile
260                 gui/Makefile
261                 modules/Makefile
262		 extras/Makefile
263		 extras/lcd/Makefile
264		 extras/dht11/Makefile
265		 extras/ds1820/Makefile
266		 extras/ds1307/Makefile
267		 extras/solar/Makefile
268		 extras/graphic_lcd/Makefile
269                 regression/Makefile
270                 src/Makefile
271                 src/dspic/Makefile
272                 xpms/Makefile
273                 gpsim.spec])
274
275AC_OUTPUT
276
277AC_MSG_RESULT([
278
279gpsim-$PACKAGE_VERSION is now configured for $canonical_host_type
280
281  Build:                $build
282  Host:                 $host
283  Source directory:     $srcdir
284  Installation prefix:  $prefix
285  C compiler:           $CC $CPPFLAGS $CFLAGS
286  C++ compiler:         $CXX $CPPFLAGS $CXXFLAGS
287
288  gui:                  $use_gui
289  Socket interface:     $use_sockets
290
291])
292