1 # Process this file with autoconf to produce a configure script, like so:
2 # aclocal && autoconf && autoheader && automake
5 AC_INIT(libmudflap, 1.0)
6 AC_CONFIG_SRCDIR(mf-runtime.c)
11 # For libtool versioning info, format is CURRENT:REVISION:AGE
13 AC_SUBST(libtool_VERSION)
15 AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
16 AC_ARG_ENABLE(version-specific-runtime-libs,
17 [ --enable-version-specific-runtime-libs Specify that runtime libraries should be installed in a compiler-specific directory ],
19 yes) version_specific_libs=yes ;;
20 no) version_specific_libs=no ;;
21 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
23 [version_specific_libs=no])
24 AC_MSG_RESULT($version_specific_libs)
29 AM_ENABLE_MULTILIB(, ..)
31 target_alias=${target_alias-$target}
32 AC_SUBST(target_alias)
34 AC_CONFIG_HEADERS(config.h)
37 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
38 # We must force CC to /not/ be precious variables; otherwise
39 # the wrong, non-multilib-adjusted value will be used in multilibs.
40 # As a side effect, we have to subst CFLAGS ourselves.
42 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
43 m4_define([_AC_ARG_VAR_PRECIOUS],[])
45 m4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
49 if test "x$GCC" != "xyes"; then
50 AC_MSG_ERROR([libmudflap must be built with GCC])
54 # Some hosts don't have dlsym(RTLD_NEXT, "symbol") for use in
55 # symbol interposition. We disable shared libraries for these.
56 AC_MSG_CHECKING([whether dlsym(RTLD_NEXT,...) is available])
61 [void *foo = dlsym (RTLD_NEXT, "exit");],
66 AC_CHECK_HEADERS(stdint.h execinfo.h signal.h dlfcn.h dirent.h \
67 netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h ctype.h)
68 AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal)
70 dnl Check for 64-bit stdio calls related to Large File Support
71 AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64)
73 dnl Check for nonstandard functions
74 AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname)
76 dnl Check for glibc ctype functions
77 AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc)
79 AC_TRY_COMPILE([#include <sys/types.h>
81 #include <sys/sem.h>],[union semun foo;], [mf_have_semun=1], [mf_have_semun=0])
82 if test $mf_have_semun = 1
84 AC_DEFINE(HAVE_UNION_SEMUN, 1, [union semun defined in sys/ipc.h or sys/sem.h])
88 AC_MSG_CHECKING([for socklen_t in sys/socket.h])
89 AC_TRY_COMPILE([#define _POSIX_PII_SOCKET
90 #include <sys/types.h>
91 #include <sys/socket.h>], [socklen_t x = 5;],
92 [AC_DEFINE(HAVE_SOCKLEN_T, 1, [Define it socklen_t typedef is in sys/socket.h.])
98 AC_SUBST(enable_shared)
99 AC_SUBST(enable_static)
101 AC_CHECK_HEADER(stdint.h, [MF_HAVE_STDINT_H=1], [MF_HAVE_STDINT_H=0])
102 AC_SUBST(MF_HAVE_STDINT_H)
103 if test $MF_HAVE_STDINT_H = 1
107 AC_TRY_COMPILE([#include <sys/types.h>], [uintptr_t k = 0;],
108 [MF_HAVE_UINTPTR_T=1], [MF_HAVE_UINTPTR_T=0])
110 AC_SUBST(MF_HAVE_UINTPTR_T)
114 # libmudflapth objects are built in this subdirectory
118 pthread_create_version='""'
119 AC_CHECK_HEADER(pthread.h,[
120 AC_DEFINE_UNQUOTED(HAVE_PTHREAD_H, 1, [define if you have <pthread.h>])
121 ac_have_pthread_h=yes
125 AM_CONDITIONAL(LIBMUDFLAPTH, [test "x$ac_have_pthread_h" != "x"])
126 if test "x$ac_have_pthread_h" != "x"
132 AC_SUBST(build_libmudflapth)
134 AC_CHECK_LIB(dl, dlsym)
136 # Process the option "--enable-version-specific-runtime-libs"
137 gcc_version_trigger=${srcdir}/../gcc/version.c
138 gcc_version_full=`grep version_string ${gcc_version_trigger} | sed -e 's/.*\"\([[^ \"]]*\)[[ \"]].*/\1/'`
139 gcc_version=`echo ${gcc_version_full} | sed -e 's/\([^ ]*\) .*/\1/'`
140 AC_SUBST(gcc_version)
142 # Calculate toolexeclibdir
143 # Also toolexecdir, though it's only used in toolexeclibdir
144 case ${version_specific_libs} in
146 # Need the gcc compiler version to know where to install libraries
147 # and header files if --enable-version-specific-runtime-libs option
149 toolexecdir='$(libdir)/gcc/$(target_alias)'
150 toolexeclibdir='$(toolexecdir)/'${gcc_version}'$(MULTISUBDIR)'
153 if test -n "$with_cross_host" &&
154 test x"$with_cross_host" != x"no"; then
155 # Install a library built with a cross compiler in tooldir, not libdir.
156 toolexecdir='$(exec_prefix)/$(target_alias)'
157 toolexeclibdir='$(toolexecdir)/lib'
159 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
160 toolexeclibdir='$(libdir)'
162 multi_os_directory=`$CC -print-multi-os-directory`
163 case $multi_os_directory in
164 .) ;; # Avoid trailing /.
165 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
169 AC_SUBST(toolexecdir)
170 AC_SUBST(toolexeclibdir)
172 if test "x$enable_shared" = "xyes" && test "x$ac_have_pthread_h" != "x"; then
173 # NB: don't check for -lpthread here, because then it would be
174 # added to LIBS. For the thread-unaware libmudflap.la, we don't
177 # glibc-related hacks. dlsym() may pick the wrong version of
178 # interposed functions like pthread_create on modern glibc.
179 # We need to find the proper symbol version string, and use
180 # the nonstandard dlvsym().
181 AC_CHECK_FUNCS(dlvsym)
182 AC_CHECK_TOOL(NM, nm)
183 if test "x$ac_cv_have_dlvsym" != "x"; then
184 # Try compiling a simple pthreads program. Find the shared libraries it
185 # ends up with. Then use "nm" on those libraries to extract the
186 # default symbol versioning suffix ("@@"), if any. But that's tricky.
187 # Rather, run nm on the resulting executable. Unfortunately, autoconf
188 # doesn't appear to have a macro that builds a test executable for
189 # subsequent analysis ... so we do it by hand here.
190 cat >> conftest.c << EOF
192 int main () { void *p = (void *) & pthread_create; return (int) p; }
195 LIBS="$LIBS -lpthread"
196 pthread_create_version="\"\""
197 AC_MSG_CHECKING(pthread_create symbol version)
198 if eval $ac_link 2>&5 && test -s conftest${ac_exeext}; then
199 version=`$NM conftest${ac_exeect} | grep 'pthread_create@@' | sed -e 's/^.*@@//'`
200 if test "x$version" != "x"; then
201 pthread_create_version="\"$version\""
204 AC_MSG_RESULT($pthread_create_version)
208 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_VERSION, $pthread_create_version, [pthread_create symbol version])
211 # Figure out whether the compiler supports "-ffunction-sections -fdata-sections",
212 # similarly to how libstdc++ does it
213 ac_test_CFLAGS="${CFLAGS+set}"
214 ac_save_CFLAGS="$CFLAGS"
216 # Check for -ffunction-sections -fdata-sections
217 AC_MSG_CHECKING([for gcc that supports -ffunction-sections -fdata-sections])
218 CFLAGS='-Werror -ffunction-sections -fdata-sections'
219 AC_TRY_COMPILE(, [int foo;], [ac_fdsections=yes], [ac_fdsections=no])
220 if test "$ac_test_CFLAGS" = set; then
221 CFLAGS="$ac_save_CFLAGS"
223 # this is the suspicious part
226 if test x"$ac_fdsections" = x"yes"; then
227 SECTION_FLAGS='-ffunction-sections -fdata-sections'
229 AC_MSG_RESULT($ac_fdsections)
230 AC_SUBST(SECTION_FLAGS)
233 if test ${multilib} = yes; then
234 multilib_arg="--enable-multilib"
239 AC_CONFIG_FILES([Makefile testsuite/Makefile testsuite/mfconfig.exp mf-runtime.h])