1 # Process this file with autoconf to produce a configure script, like so:
2 # aclocal -I .. -I ../config && autoconf && autoheader && automake
5 AC_INIT(libmudflap, 1.0)
6 AC_CONFIG_SRCDIR(mf-runtime.c)
8 ACX_NONCANONICAL_TARGET
10 AM_INIT_AUTOMAKE([no-dist])
12 AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
13 AC_ARG_ENABLE(version-specific-runtime-libs,
14 [ --enable-version-specific-runtime-libs Specify that runtime libraries should be installed in a compiler-specific directory ],
16 yes) version_specific_libs=yes ;;
17 no) version_specific_libs=no ;;
18 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
20 [version_specific_libs=no])
21 AC_MSG_RESULT($version_specific_libs)
26 AM_ENABLE_MULTILIB(, ..)
28 target_alias=${target_alias-$host_alias}
29 AC_SUBST(target_alias)
31 AC_CONFIG_HEADERS(config.h)
34 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
35 # We must force CC to /not/ be precious variables; otherwise
36 # the wrong, non-multilib-adjusted value will be used in multilibs.
37 # As a side effect, we have to subst CFLAGS ourselves.
39 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
40 m4_define([_AC_ARG_VAR_PRECIOUS],[])
42 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
46 if test "x$GCC" != "xyes"; then
47 AC_MSG_ERROR([libmudflap must be built with GCC])
51 # We use the C++ compiler during testing.
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 pwd.h grp.h \
67 netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h ctype.h mntent.h \
68 sys/socket.h netinet/in.h arpa/inet.h dlfcn.h sys/mman.h)
70 AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal)
71 AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64 freopen64)
72 AC_CHECK_FUNCS(setbuf setbuffer setlinebuf setvbuf)
73 AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname)
74 AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc)
75 AC_CHECK_FUNCS(getlogin cuserid getpwnam getpwuid getpwent getgrnam getgrgid getgrent)
76 AC_CHECK_FUNCS(getlogin_r getpwnam_r getpwuid_r getgrnam_r getgrgid_r)
77 AC_CHECK_FUNCS(getservent getservbyname getservbyport getaddrinfo gai_strerror)
78 AC_CHECK_FUNCS(getprotoent getprotobyname getprotobynumber)
79 AC_CHECK_FUNCS(getmntent setmntent addmntent)
80 AC_CHECK_FUNCS(inet_ntoa mmap munmap)
81 AC_CHECK_FUNCS(__libc_freeres)
83 AC_TRY_COMPILE([#include <sys/types.h>
85 #include <sys/sem.h>],[union semun foo;], [mf_have_semun=1], [mf_have_semun=0])
86 if test $mf_have_semun = 1
88 AC_DEFINE(HAVE_UNION_SEMUN, 1, [union semun defined in sys/ipc.h or sys/sem.h])
92 AC_MSG_CHECKING([for socklen_t in sys/socket.h])
93 AC_TRY_COMPILE([#define _POSIX_PII_SOCKET
94 #include <sys/types.h>
95 #include <sys/socket.h>], [socklen_t x = 5;],
96 [AC_DEFINE(HAVE_SOCKLEN_T, 1, [Define it socklen_t typedef is in sys/socket.h.])
102 AC_SUBST(enable_shared)
103 AC_SUBST(enable_static)
105 AC_CHECK_HEADER(stdint.h, [MF_HAVE_STDINT_H=1], [MF_HAVE_STDINT_H=0])
106 AC_SUBST(MF_HAVE_STDINT_H)
107 if test $MF_HAVE_STDINT_H = 1
111 AC_TRY_COMPILE([#include <sys/types.h>], [uintptr_t k = 0;],
112 [MF_HAVE_UINTPTR_T=1], [MF_HAVE_UINTPTR_T=0])
114 AC_SUBST(MF_HAVE_UINTPTR_T)
118 # libmudflapth objects are built in this subdirectory
122 AC_CHECK_HEADERS(pthread.h)
124 AC_MSG_CHECKING([for thread model used by GCC])
125 target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
126 AC_MSG_RESULT([$target_thread_file])
128 # We only support posix threads, or no threads at all.
130 case ${target_thread_file} in
137 echo "${target_thread_file} is an unsupported thread package" 1>&2
142 AM_CONDITIONAL(LIBMUDFLAPTH, [test "x$posix_threads" != "x"])
143 if test "x$posix_threads" != "x"
149 AC_SUBST(build_libmudflapth)
151 AC_CHECK_LIB(dl, dlsym)
153 # Calculate toolexeclibdir
154 # Also toolexecdir, though it's only used in toolexeclibdir
155 case ${version_specific_libs} in
157 # Need the gcc compiler version to know where to install libraries
158 # and header files if --enable-version-specific-runtime-libs option
160 toolexecdir='$(libdir)/gcc/$(target_alias)'
161 toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
164 if test -n "$with_cross_host" &&
165 test x"$with_cross_host" != x"no"; then
166 # Install a library built with a cross compiler in tooldir, not libdir.
167 toolexecdir='$(exec_prefix)/$(target_alias)'
168 toolexeclibdir='$(toolexecdir)/lib'
170 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
171 toolexeclibdir='$(libdir)'
173 multi_os_directory=`$CC -print-multi-os-directory`
174 case $multi_os_directory in
175 .) ;; # Avoid trailing /.
176 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
180 AC_SUBST(toolexecdir)
181 AC_SUBST(toolexeclibdir)
183 includedir=${toolexecdir}/include
186 pthread_create_version='""'
187 if test "x$enable_shared" = "xyes" && test "x$posix_threads" != "x"; then
188 # NB: don't check for -lpthread here, because then it would be
189 # added to LIBS. For the thread-unaware libmudflap.la, we don't
192 # glibc-related hacks. dlsym() may pick the wrong version of
193 # interposed functions like pthread_create on modern glibc.
194 # We need to find the proper symbol version string, and use
195 # the nonstandard dlvsym().
196 AC_CHECK_FUNCS(dlvsym)
197 AC_CHECK_TOOL(NM, nm)
198 if test "x$ac_cv_have_dlvsym" != "x"; then
199 # Try compiling a simple pthreads program. Find the shared libraries it
200 # ends up with. Then use "nm" on those libraries to extract the
201 # default symbol versioning suffix ("@@"), if any. But that's tricky.
202 # Rather, run nm on the resulting executable. Unfortunately, autoconf
203 # doesn't appear to have a macro that builds a test executable for
204 # subsequent analysis ... so we do it by hand here.
205 cat >> conftest.c << EOF
207 int main () { void *p = (void *) & pthread_create; return (int) p; }
210 LIBS="$LIBS -lpthread"
211 pthread_create_version="\"\""
212 AC_MSG_CHECKING(pthread_create symbol version)
213 if eval $ac_link 2>&5 && test -s conftest${ac_exeext}; then
214 version=`$NM conftest${ac_exeect} | grep 'pthread_create@@' | sed -e 's/^.*@@//'`
215 if test "x$version" != "x"; then
216 pthread_create_version="\"$version\""
219 AC_MSG_RESULT($pthread_create_version)
223 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_VERSION, $pthread_create_version, [pthread_create symbol version])
226 # Figure out whether the compiler supports "-ffunction-sections -fdata-sections",
227 # similarly to how libstdc++ does it
228 ac_test_CFLAGS="${CFLAGS+set}"
229 ac_save_CFLAGS="$CFLAGS"
231 # Check for -ffunction-sections -fdata-sections
232 AC_MSG_CHECKING([for gcc that supports -ffunction-sections -fdata-sections])
233 CFLAGS='-Werror -ffunction-sections -fdata-sections'
234 AC_TRY_COMPILE(, [int foo;], [ac_fdsections=yes], [ac_fdsections=no])
235 if test "$ac_test_CFLAGS" = set; then
236 CFLAGS="$ac_save_CFLAGS"
238 # this is the suspicious part
241 if test x"$ac_fdsections" = x"yes"; then
242 SECTION_FLAGS='-ffunction-sections -fdata-sections'
244 AC_MSG_RESULT($ac_fdsections)
245 AC_SUBST(SECTION_FLAGS)
248 # Check for the name of the symbol used for the entry point.
249 AC_CACHE_CHECK([for the name of the symbol used for the entry point],
250 [mudflap_cv_entry_point], [
251 for name in _start __start unknown; do
252 AC_LINK_IFELSE([AC_LANG_PROGRAM([extern char $name@<:@@:>@;], [$name@<:@0@:>@ = 0;])],
255 mudflap_cv_entry_point="$name"])
256 if test "$mudflap_cv_entry_point" = unknown; then
257 AC_MSG_ERROR([none of the known symbol names works])
259 AC_DEFINE_UNQUOTED([ENTRY_POINT], [$mudflap_cv_entry_point],
260 [Define to the name of the symbol used for the entry point.])
263 if test ${multilib} = yes; then
264 multilib_arg="--enable-multilib"
269 # See if we support thread-local storage.
273 AC_CONFIG_FILES([Makefile testsuite/Makefile testsuite/mfconfig.exp])