1dnl Run autogen.sh to produce a configure script.
2
3dnl Version info, see http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
4dnl
5dnl CW_INTERFACE_VERSION           : Current interface version, increment whenever the interface is changed.
6dnl CW_INTERFACE_VERSION_REVISION  : Revision, increment every public release; or set to 0 when the interface is changed.
7dnl CW_INTERFACE_AGE               : Increment if interfaces have been added; or set to 0 when interfaces have been removed.
8
9define(CW_INTERFACE_VERSION, 4)
10define(CW_INTERFACE_VERSION_REVISION, 0)
11define(CW_INTERFACE_AGE, 3)
12define(CW_PACKAGE_NAME, [libcwd])
13define(CW_BUGREPORT, [libcwd@alinoe.com])
14
15dnl CW_VERSION_MAJOR               : Increment when the whole library was rewritten; or some VERY MAJOR change was made.
16dnl CW_VERSION_MINOR               : Increment when major changes have occured, like removing interfaces.
17dnl CW_VERSION_REVISION            : Increment every public release; or set to 0 when CW_VERSION_MINOR was incremented.
18
19dnl Also change the version strings in INSTALL when changing this.
20define(CW_VERSION_MAJOR, 1)
21define(CW_VERSION_MINOR, 0)
22define(CW_VERSION_REVISION, 6)
23
24dnl Package name and version
25AC_INIT(CW_PACKAGE_NAME, CW_VERSION_MAJOR.CW_VERSION_MINOR.CW_VERSION_REVISION, CW_BUGREPORT)
26
27dnl Put resulting configuration defines in this header file.
28AC_CONFIG_HEADERS([config.h])
29
30dnl Put revision of configure.ac in configure script.
31AC_REVISION($Revision$)dnl
32
33dnl Ensure that the directory specified with --srcdir was correct
34dnl by demanding that it contains `libcwtl.pc.in'.
35AC_CONFIG_SRCDIR(CW_PACKAGE_NAME[.pc.in])
36
37dnl Automake options.
38AM_INIT_AUTOMAKE
39
40dnl Include maintainer mode targets
41AM_MAINTAINER_MODE
42
43dnl Because we use cwautomacros.
44CW_AUTOMACROS
45
46dnl We use doxygen for documentation.
47CW_DOXYGEN
48
49dnl Demand at least version 2.57 of autoconf.
50AC_PREREQ(2.57)
51
52dnl Libtool version info
53VERSIONINFO="CW_INTERFACE_VERSION:CW_INTERFACE_VERSION_REVISION:CW_INTERFACE_AGE"
54AC_SUBST(VERSIONINFO)
55
56dnl For version code used in check_configuration().
57VERSION_MAJOR=CW_VERSION_MAJOR
58VERSION_MINOR=CW_VERSION_MINOR
59VERSION_REVISION=CW_VERSION_REVISION
60AC_SUBST(VERSION_MAJOR)
61AC_SUBST(VERSION_MINOR)
62AC_SUBST(VERSION_REVISION)
63
64dnl Workaround
65true=
66AC_SUBST(true)
67
68dnl Set a decent default value in case we don't have the right libraries
69case "$host" in
70  *sparc*) CW_CONFIG_BUILTIN_RETURN_ADDRESS_OFFSET="0" ;;
71  *) CW_CONFIG_BUILTIN_RETURN_ADDRESS_OFFSET="-1" ;;
72esac
73AC_SUBST(CW_CONFIG_BUILTIN_RETURN_ADDRESS_OFFSET)
74
75dnl Manual configuration options of libcwd.
76AC_ARG_ENABLE(libcwd, [
77Options of package libcwd:])
78
79libcwd_config_glibcxx_debug=no
80AC_ARG_ENABLE(glibcxx_debug,
81    [  --enable-glibcxx_debug  compile libcwd with -D_GLIBCXX_DEBUG.
82                          See http://gcc.gnu.org/onlinedocs/libstdc++/debug.html.],
83    libcwd_config_glibcxx_debug=$enableval)
84
85libcwd_config_alloc=yes
86AC_ARG_ENABLE(alloc,
87    [  --disable-alloc         disable memory allocation debugging support.],
88    libcwd_config_alloc=$enableval)
89
90libcwd_config_magic=yes
91AC_ARG_ENABLE(magic,
92    [  --disable-magic         disable magic numbers in memory allocation debugging.],
93    libcwd_config_magic=$enableval)
94
95AC_ARG_WITH(redzone,
96    [  --with-redzone@<:@=ARG@:>@    The minimum size of a redzone in bytes @<:@default=0@:>@],
97    [libcwd_config_redzone=$withval], [libcwd_config_redzone=0])
98AC_DEFINE_UNQUOTED([LIBCWD_REDZONE], $libcwd_config_redzone, [The minimum size of a redzone in bytes.])
99
100libcwd_config_marker=yes
101AC_ARG_ENABLE(marker,
102    [  --disable-marker        disable memory allocation markers.],
103    libcwd_config_marker=$enableval)
104
105libcwd_config_location=yes
106AC_ARG_ENABLE(location,
107    [  --disable-location      disable the ability to lookup source file and line
108                          number, you might need this on a non-ELF32 system.],
109    libcwd_config_location=$enableval)
110
111libcwd_config_debug=no
112AC_ARG_ENABLE(debug,
113    [  --enable-debug          enable debugging of libcwd itself.],
114    libcwd_config_debug=$enableval)
115
116libcwd_config_debug_output=yes
117AC_ARG_ENABLE(debug-output,
118    [  --disable-debug-output  disable debug output of --enable-debug.],
119    libcwd_config_debug_output=$enableval)
120
121libcwd_config_debugm=no
122AC_ARG_ENABLE(debugm,
123    [  --enable-debugm         enable debugging of memory allocation debugging code
124                          in libcwd itself.],
125    libcwd_config_debugm=$enableval)
126
127libcwd_config_threading=yes
128AC_ARG_ENABLE(threading,
129    [  --disable-threading     don't compile libcwd_r, the thread-safe version of
130                          libcwd.],
131    libcwd_config_threading=$enableval)
132
133libcwd_config_nonthreading=yes
134AC_ARG_ENABLE(nonthreading,
135    [  --disable-nonthreading  don't compile libcwd, the thread-unsafe version of
136                          libcwd.],
137    libcwd_config_nonthreading=$enableval)
138
139libcwd_config_debugt=no
140AC_ARG_ENABLE(debugt,
141    [  --enable-debugt         enable debugging of threading debugging code
142                          in libcwd itself.],
143    libcwd_config_debugt=$enableval)
144
145dnl Process default options.
146CW_OPG_FLAGS([-W -Wall -Woverloaded-virtual -Wundef -Wpointer-arith -Wwrite-strings -Wno-inline -Wno-frame-address])
147dnl Dependencies of PHC seem broken beyond repair. Turn it off.
148PCHFLAGS=
149AC_SUBST([PCHFLAGS])
150AM_CONDITIONAL(USE_PCH, [false])
151
152AC_ARG_VAR(THREADSMAX, [The maximum number of simultaneously running threads that are supported [1024].])
153if test -z "$THREADSMAX"; then
154  THREADSMAX=1024
155fi
156AC_DEFINE_UNQUOTED([CW_THREADSMAX], $THREADSMAX, [The maximum number of simultaneously running threads that are supported.])
157
158dnl Restore the environment variables used when running `configure' when
159dnl `config.status --recheck' was invoked.
160dnl Always let CXX and CXXCPP override cached values
161CW_ENVIRONMENT
162
163dnl Remember the original environment variable.
164CXXFLAGS_env="$CXXFLAGS"
165
166dnl Check for compiler and preprocessor
167if test -n "$CC"; then
168  unset ac_cv_prog_CC
169  unset am_cv_CC_dependencies_compiler_type
170  unset am_cv_CXX_dependencies_compiler_type
171fi
172AC_PROG_CC
173AC_PROG_CXX
174AC_PROG_CXXCPP
175
176# __cxa_atexit not being used is always wrong, but not really our concern if we are configured with --disable-alloc.
177if test x"$libcwd_config_alloc" = x"yes"; then
178dnl Test if g++ was configured correctly.
179CW_ATEXITTEST
180fi
181
182dnl Check if C compiler and C++ compiler versions match.
183CW_COMPILER_VERSIONS
184
185dnl Clear the cache values of all remaining tests if important
186dnl environment variables have been changed since last run.
187CW_CLEAN_CACHE
188
189dnl Figure out linker characteristics
190CW_RPATH_OPTION
191
192dnl Checks for other programs.
193AC_PROG_INSTALL
194AC_PROG_MAKE_SET
195AC_PROG_AWK
196AC_PATH_PROG(PS, ps, /bin/ps, $PATH)
197# The PS_WIDE_PID_OPTION test is not needed when --disable-location is used.
198if test x"$libcwd_config_location" = x"yes"; then
199CW_SYS_PS_WIDE_PID_OPTION
200fi
201AC_DEFINE_UNQUOTED(CW_PATH_PROG_PS, "$PS", [Full path to the 'ps' executable.])
202
203dnl This block cannot be replaced by a macro because the DISABLE_* and the
204dnl AC_PROG_LIBTOOL macro need to be in configure.ac itself for some reason.
205dnl Generate libtool (also checks shared/static prerequisites)
206if expr "$host" : ".*openbsd.*" >/dev/null; then
207  dnl openBSD has a buggy ld, no way that a shared library will work.
208  AC_DISABLE_SHARED
209else
210  dnl Disable building static libraries by default
211  AC_DISABLE_STATIC
212fi
213test -n "$enable_shared" || enable_shared=yes
214test -n "$enable_static" || enable_static=yes
215dnl Note: due to a bug in libtool-1.3c, the language must be C at this point!
216AC_PROG_LIBTOOL
217if test -e ./libtool -a "X$enable_shared" = "X"; then
218dnl Configuration needed by the testsuite, extract this from the generated 'libtool'
219enable_shared=`./libtool --config | grep '^build_libtool_libs=' | sed -e 's/build_libtool_libs=//'`
220enable_static=`./libtool --config | grep '^build_old_libs=' | sed -e 's/build_old_libs=//'`
221fi
222if test $enable_shared = yes; then
223  if expr "$host" : ".*openbsd.*" >/dev/null; then
224    AC_MSG_ERROR([
225
226The dynamic linker (ld) on openBSD is too buggy for C++ shared libraries.
227Static libraries are supported however, please configure using
228--enable-static --disable-shared, which is the default for openBSD.
229])
230  fi
231fi
232if ! grep 'BEGIN LIBTOOL CONFIG' $srcdir/configure >/dev/null; then
233dnl libtool has a bug that it adds an -rpath for the $libdir, we don't want
234dnl that because the only programs we have are test executables that are
235dnl never installed anyway!  There is no option to turn this off other than
236dnl by directly messing with the just generated libtool.  The trick used here
237dnl is to add $libdir (or what it will become later) to `sys_lib_dlsearch_path_spec`,
238dnl causing libtool to think that a hard coded path is not needed.
239sys_lib_dlsearch_path_spec=`./libtool --config | grep '^sys_lib_dlsearch_path_spec=' | sed -e 's/sys_lib_dlsearch_path_spec="\(.*\)"$/\1/'`
240tmp=$libdir
241test "x$tmp" = 'x${exec_prefix}/lib' && tmp=$exec_prefix/lib
242test "x$tmp" = 'xNONE/lib' && tmp=$prefix/lib
243test "x$tmp" = 'xNONE/lib' && tmp=$ac_default_prefix/lib
244dq='"'
245dnl " <-- quote needed for vim.
246sq="'"
247se='|'
248eval sed -e ${sq}s${se}^sys_lib_dlsearch_path_spec=.*${se}sys_lib_dlsearch_path_spec=${dq}$sys_lib_dlsearch_path_spec $tmp${dq}${se}${sq} libtool > libtool.tmp && mv libtool.tmp libtool
249fi
250
251dnl Used in sys.h to force recompilation
252CC_FINGER_PRINT="$cw_cv_sys_CC_finger_print"
253AC_SUBST([CC_FINGER_PRINT])
254CXX_FINGER_PRINT="$cw_cv_sys_CXX_finger_print"
255AC_SUBST([CXX_FINGER_PRINT])
256CXXCPP_FINGER_PRINT="$cw_cv_sys_CXXCPP_finger_print"
257AC_SUBST([CXXCPP_FINGER_PRINT])
258
259dnl Configuration defines of config.h
260AC_SUBST(CW_CONFIG_ALLOC)
261CW_CONFIG_ALLOC=0
262AC_SUBST(CW_CONFIG_MAGIC)
263CW_CONFIG_MAGIC=0
264AC_SUBST(CW_CONFIG_GLIBCXX_DEBUG)
265CW_CONFIG_GLIBCXX_DEBUG=0
266AC_SUBST(CW_CONFIG_LOCATION)
267CW_CONFIG_LOCATION=0
268AC_SUBST(CW_CONFIG_LIBBFD)
269CW_CONFIG_LIBBFD=0
270AC_SUBST(CW_CONFIG_DEBUG)
271CW_CONFIG_DEBUG=0
272AC_SUBST(CW_CONFIG_DEBUGOUTPUT)
273CW_CONFIG_DEBUGOUTPUT=0
274AC_SUBST(CW_CONFIG_DEBUGM)
275CW_CONFIG_DEBUGM=0
276AC_SUBST(CW_CONFIG_DEBUGT)
277CW_CONFIG_DEBUGT=0
278AC_SUBST(CW_CONFIG_MARKER)
279CW_CONFIG_MARKER=0
280AC_SUBST(CW_CONFIG_HAVE___LIBC_MALLOC)
281CW_CONFIG_HAVE___LIBC_MALLOC=undef
282AC_SUBST(CW_CONFIG_HAVE__LIBC_MALLOC)
283CW_CONFIG_HAVE__LIBC_MALLOC=undef
284AC_SUBST(CW_CONFIG_HAVE_DLOPEN)
285CW_CONFIG_HAVE_DLOPEN=undef
286AC_SUBST(CW_CONFIG_HAVE_POSIX_MEMALIGN)
287CW_CONFIG_HAVE_POSIX_MEMALIGN=undef
288AC_SUBST(CW_CONFIG_HAVE_MEMALIGN)
289CW_CONFIG_HAVE_MEMALIGN=undef
290AC_SUBST(CW_CONFIG_HAVE_VALLOC)
291CW_CONFIG_HAVE_VALLOC=undef
292
293dnl Configuration needed by the testsuite
294AC_SUBST(enable_shared)
295AC_SUBST(enable_static)
296AC_SUBST(libcwd_config_threading)
297AC_SUBST(libcwd_config_nonthreading)
298
299if test "$libcwd_config_alloc" = yes; then
300  CW_CONFIG_ALLOC=1
301fi
302
303if test "$libcwd_config_magic" = yes; then
304  CW_CONFIG_MAGIC=1
305fi
306
307PCCFLAGS="-DCWDEBUG"
308AC_SUBST(PCCFLAGS)
309if test "$libcwd_config_glibcxx_debug" = yes; then
310  CW_CONFIG_GLIBCXX_DEBUG=1
311  CXXFLAGS="$CXXFLAGS -D_GLIBCXX_DEBUG"
312  PCCFLAGS="$PCCFLAGS -D_GLIBCXX_DEBUG"
313fi
314
315dnl Set language requirements for the tests below.
316AC_LANG_CPLUSPLUS
317AC_REQUIRE_CPP
318
319AC_CHECK_FUNCS(__libc_malloc _libc_malloc)
320
321if test "$libcwd_config_location" = yes -o \
322    \("$ac_cv_func___libc_malloc" != yes -a "$ac_cv_func__libc_malloc" != yes\) ; then
323
324dnl Check if we have dlopen in libc or libdl
325AC_CHECK_LIB(c, dlopen, [AC_DEFINE_UNQUOTED(HAVE_DLOPEN, 1, [Defined if dlopen is available.])],
326    [AC_CHECK_LIB(dl, dlopen, [LIBS="-ldl $LIBS"; AC_DEFINE_UNQUOTED(HAVE_DLOPEN)])])
327
328fi
329
330if test "$libcwd_config_location" = yes ; then
331  CW_CONFIG_LOCATION=1
332fi
333
334AC_SUBST(CW_CONFIG_HAVE_PTHREADS)
335CW_CONFIG_HAVE_PTHREADS=undef
336AC_SUBST(LIB_THREADS)
337AC_SUBST(LIB_THREADS_SHARED)
338if test "$libcwd_config_threading" = yes; then
339
340  dnl Check if we have POSIX threads
341  AC_LANG_SAVE
342  AC_LANG_C
343  CFLAGS="-pthread"
344  AC_SEARCH_LIBS(pthread_create, pthread,
345    [AC_CHECK_HEADER(pthread.h,
346      [CW_CONFIG_HAVE_PTHREADS=define],
347      [AC_MSG_WARN([
348
349**************************************************************************
350* Sorry but libcwd only supports POSIX Threads at the moment and I can't *
351* find the header file pthread.h.  Only the thread unsafe library libcwd *
352* will be compiled.  Use --disable-threading to suppress this warning.   *
353**************************************************************************
354])
355      libcwd_config_threading=no])],
356    [AC_MSG_WARN([
357
358**************************************************************************
359* Sorry but libcwd only supports POSIX Threads at the moment.  Your libc *
360* doesn't include posix threads by itself and I can't find -lpthread.    *
361* Use --disable-threading to suppress this warning.                      *
362**************************************************************************
363])
364     libcwd_config_threading=no])
365  if test "$libcwd_config_threading" = yes; then
366    if test "$ac_cv_search_pthread_create" = "none required"; then
367      dnl Even if nothing is required, we still need to use -lpthread explicitly
368      dnl while linking a shared library, otherwise the versioning info of
369      dnl versioned symbols will be missing!  This is needed for pthread_create
370      dnl itself even!.
371      AC_CHECK_LIB(pthread, pthread_create, [LIB_THREADS_SHARED=-lpthread])
372    fi
373  fi
374
375  AC_LANG_RESTORE
376
377  if test "$libcwd_config_threading" = yes; then
378    dnl pthread_kill_other_threads_np is a GNU extension, therefore we need to
379    dnl define _GNU_SOURCE.  The extension also needs -lpthread to be available.
380    AC_DEFINE_UNQUOTED(CW_NEED__GNU_SOURCE, 1, [This is needed when using threading, for example to get 'pthread_kill_other_threads_np'.])
381    SAVE_LIBS="$LIBS"
382    LIBS="$LIBS $LIB_THREADS $LIB_THREADS_SHARED"
383    AC_CHECK_FUNCS(pthread_kill_other_threads_np)
384    LIBS="$SAVE_LIBS"
385  fi
386
387fi
388
389dnl This test needs the full set of libraries we just determined.
390CW_SYS_BUILTIN_RETURN_ADDRESS_OFFSET
391
392if test "$libcwd_config_debug" = yes; then
393  CW_CONFIG_DEBUG=1
394fi
395
396if test "$libcwd_config_debug_output" = yes; then
397  CW_CONFIG_DEBUGOUTPUT=1
398fi
399
400if test "$libcwd_config_debugm" = yes; then
401  CW_CONFIG_DEBUGM=1
402fi
403
404if test "$libcwd_config_debugt" = yes; then
405  CW_CONFIG_DEBUGT=1
406fi
407
408if test "$libcwd_config_marker" = yes; then
409  CW_CONFIG_MARKER=1
410fi
411
412AM_CONDITIONAL(ENABLETHREADING, test x$libcwd_config_threading = xyes)
413AM_CONDITIONAL(ENABLENONTHREADING, test x$libcwd_config_nonthreading = xyes)
414AM_CONDITIONAL(ENABLESHARED, test x$enable_shared = xyes)
415AM_CONDITIONAL(ENABLESTATIC, test x$enable_static = xyes)
416
417dnl Checks for header files.
418AC_HEADER_STAT
419AC_CHECK_HEADERS(_G_config.h link.h pwd.h sys/resource.h malloc.h unistd.h)
420
421dnl Check for global variable.
422if test "$ac_cv_header_link_h" = yes; then
423  AC_CHECK_FUNCS(_dl_loaded _rtld_global)
424fi
425
426dnl Check for typedefs.
427AC_TYPE_UID_T
428CW_TYPE_GETGROUPS
429
430dnl Check for structures.
431
432dnl Check for compiler/system characteristics.
433CW_BUG_REDEFINES([sys/resource.h])
434CW_SYS_MALLOC_OVERHEAD
435CW_BUG_G_CONFIG_H
436CW_SYS_RECURSIVE_BUILTIN_RETURN_ADDRESS
437CW_SYS_FRAME_ADDRESS_OFFSET
438AC_C_BIGENDIAN
439
440dnl Check for library functions.
441AC_CHECK_FUNCS(getgid getegid getgroups wmemcpy sysconf valloc memalign)
442AC_CHECK_DECL([_SC_PAGESIZE],
443  AC_DEFINE_UNQUOTED([HAVE__SC_PAGESIZE], 1, [Defined if we have _SC_PAGESIZE.]),
444  [], [#include <unistd.h>])
445AC_CHECK_DECL([posix_memalign],
446  AC_DEFINE_UNQUOTED([HAVE_POSIX_MEMALIGN], 1, [Defined if we have posix_memalign.]), [],
447[#define _XOPEN_SOURCE 600
448#include <cstdlib>])
449
450if test "$ac_cv_func___libc_malloc" = "yes"; then
451  CW_CONFIG_HAVE___LIBC_MALLOC=define
452else if test "$ac_cv_func__libc_malloc" = "yes"; then
453  CW_CONFIG_HAVE__LIBC_MALLOC=define
454fi fi
455if test "$ac_cv_lib_c_dlopen" = "yes" -o "$ac_cv_lib_dl_dlopen" = "yes"; then
456  CW_CONFIG_HAVE_DLOPEN=define
457fi
458if test "$ac_cv_func_valloc" = "yes"; then
459  CW_CONFIG_HAVE_VALLOC=define
460fi
461if test "$ac_cv_func_memalign" = "yes"; then
462  CW_CONFIG_HAVE_MEMALIGN=define
463fi
464if test "$ac_cv_have_decl_posix_memalign" = "yes"; then
465  CW_CONFIG_HAVE_POSIX_MEMALIGN=define
466fi
467
468dnl Check for system services.
469
470dnl Set up build directory
471test ! -d include && mkdir include
472
473dnl The install prefix is hardcoded in the library in order to find the default rc file.
474libcwd_datarootdir=`eval echo "$datadir"`
475libcwd_datadir=`eval echo "$libcwd_datarootdir/$PACKAGE" | sed -e 's|NONE|'$ac_default_prefix'|'`
476AC_DEFINE_UNQUOTED([CW_DATADIR], "$libcwd_datadir", [Data directory where the default rcfile is read from.])
477
478dnl Generate include/libcwd/config.h, include/libcwd/sys.h and include/sys.h, preserving timestamp when they are not changed.
479CW_CONFIG_FILE([include/libcwd], [config.h])
480CW_CONFIG_FILE([include/libcwd], [sys.h])
481CW_CONFIG_FILE([include], [sys.h])
482
483dnl Output the other configuration files.
484AC_CONFIG_FILES([libcwd.spec] [libcwd.lsm] [maintMakefile] [Makefile] [utils/Makefile] [include/Makefile]
485		[include/libcwd/Makefile] [testsuite/Makefile] [cutee/Makefile] [tests/Makefile]
486		[documentation/doxygen.config] [documentation/Makefile] [documentation/styles/Makefile]
487		[documentation/tutorial/Makefile] [libcwd.pc] [libcwd_r.pc])
488
489AC_OUTPUT
490
491