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 AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
12 AC_ARG_ENABLE(version-specific-runtime-libs,
13 [ --enable-version-specific-runtime-libs Specify that runtime libraries should be installed in a compiler-specific directory ],
15 yes) version_specific_libs=yes ;;
16 no) version_specific_libs=no ;;
17 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
19 [version_specific_libs=no])
20 AC_MSG_RESULT($version_specific_libs)
25 AM_ENABLE_MULTILIB(, ..)
27 target_alias=${target_alias-$host_alias}
28 AC_SUBST(target_alias)
30 AC_CONFIG_HEADERS(config.h)
33 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
34 # We must force CC to /not/ be precious variables; otherwise
35 # the wrong, non-multilib-adjusted value will be used in multilibs.
36 # As a side effect, we have to subst CFLAGS ourselves.
38 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
39 m4_define([_AC_ARG_VAR_PRECIOUS],[])
41 m4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
45 if test "x$GCC" != "xyes"; then
46 AC_MSG_ERROR([libmudflap must be built with GCC])
50 # Some hosts don't have dlsym(RTLD_NEXT, "symbol") for use in
51 # symbol interposition. We disable shared libraries for these.
52 AC_MSG_CHECKING([whether dlsym(RTLD_NEXT,...) is available])
57 [void *foo = dlsym (RTLD_NEXT, "exit");],
62 AC_CHECK_HEADERS(stdint.h execinfo.h signal.h dlfcn.h dirent.h pwd.h grp.h \
63 netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h ctype.h mntent.h \
64 sys/socket.h netinet/in.h arpa/inet.h dlfcn.h sys/mman.h)
66 AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal)
67 AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64 freopen64)
68 AC_CHECK_FUNCS(setbuf setbuffer setlinebuf setvbuf)
69 AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname)
70 AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc)
71 AC_CHECK_FUNCS(getlogin cuserid getpwnam getpwuid getpwent getgrnam getgrgid getgrent)
72 AC_CHECK_FUNCS(getlogin_r getpwnam_r getpwuid_r getgrnam_r getgrgid_r)
73 AC_CHECK_FUNCS(getservent getservbyname getservbyport getaddrinfo gai_strerror)
74 AC_CHECK_FUNCS(getprotoent getprotobyname getprotobynumber)
75 AC_CHECK_FUNCS(getmntent setmntent addmntent)
76 AC_CHECK_FUNCS(inet_ntoa mmap munmap)
78 AC_TRY_COMPILE([#include <sys/types.h>
80 #include <sys/sem.h>],[union semun foo;], [mf_have_semun=1], [mf_have_semun=0])
81 if test $mf_have_semun = 1
83 AC_DEFINE(HAVE_UNION_SEMUN, 1, [union semun defined in sys/ipc.h or sys/sem.h])
87 AC_MSG_CHECKING([for socklen_t in sys/socket.h])
88 AC_TRY_COMPILE([#define _POSIX_PII_SOCKET
89 #include <sys/types.h>
90 #include <sys/socket.h>], [socklen_t x = 5;],
91 [AC_DEFINE(HAVE_SOCKLEN_T, 1, [Define it socklen_t typedef is in sys/socket.h.])
97 AC_SUBST(enable_shared)
98 AC_SUBST(enable_static)
100 AC_CHECK_HEADER(stdint.h, [MF_HAVE_STDINT_H=1], [MF_HAVE_STDINT_H=0])
101 AC_SUBST(MF_HAVE_STDINT_H)
102 if test $MF_HAVE_STDINT_H = 1
106 AC_TRY_COMPILE([#include <sys/types.h>], [uintptr_t k = 0;],
107 [MF_HAVE_UINTPTR_T=1], [MF_HAVE_UINTPTR_T=0])
109 AC_SUBST(MF_HAVE_UINTPTR_T)
113 # libmudflapth objects are built in this subdirectory
117 pthread_create_version='""'
118 AC_CHECK_HEADER(pthread.h,[
119 AC_DEFINE_UNQUOTED(HAVE_PTHREAD_H, 1, [define if you have <pthread.h>])
120 ac_have_pthread_h=yes
124 AM_CONDITIONAL(LIBMUDFLAPTH, [test "x$ac_have_pthread_h" != "x"])
125 if test "x$ac_have_pthread_h" != "x"
131 AC_SUBST(build_libmudflapth)
133 AC_CHECK_LIB(dl, dlsym)
135 # Calculate toolexeclibdir
136 # Also toolexecdir, though it's only used in toolexeclibdir
137 case ${version_specific_libs} in
139 # Need the gcc compiler version to know where to install libraries
140 # and header files if --enable-version-specific-runtime-libs option
142 toolexecdir='$(libdir)/gcc/$(target_alias)'
143 toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
146 if test -n "$with_cross_host" &&
147 test x"$with_cross_host" != x"no"; then
148 # Install a library built with a cross compiler in tooldir, not libdir.
149 toolexecdir='$(exec_prefix)/$(target_alias)'
150 toolexeclibdir='$(toolexecdir)/lib'
152 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
153 toolexeclibdir='$(libdir)'
155 multi_os_directory=`$CC -print-multi-os-directory`
156 case $multi_os_directory in
157 .) ;; # Avoid trailing /.
158 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
162 AC_SUBST(toolexecdir)
163 AC_SUBST(toolexeclibdir)
165 if test "x$enable_shared" = "xyes" && test "x$ac_have_pthread_h" != "x"; then
166 # NB: don't check for -lpthread here, because then it would be
167 # added to LIBS. For the thread-unaware libmudflap.la, we don't
170 # glibc-related hacks. dlsym() may pick the wrong version of
171 # interposed functions like pthread_create on modern glibc.
172 # We need to find the proper symbol version string, and use
173 # the nonstandard dlvsym().
174 AC_CHECK_FUNCS(dlvsym)
175 AC_CHECK_TOOL(NM, nm)
176 if test "x$ac_cv_have_dlvsym" != "x"; then
177 # Try compiling a simple pthreads program. Find the shared libraries it
178 # ends up with. Then use "nm" on those libraries to extract the
179 # default symbol versioning suffix ("@@"), if any. But that's tricky.
180 # Rather, run nm on the resulting executable. Unfortunately, autoconf
181 # doesn't appear to have a macro that builds a test executable for
182 # subsequent analysis ... so we do it by hand here.
183 cat >> conftest.c << EOF
185 int main () { void *p = (void *) & pthread_create; return (int) p; }
188 LIBS="$LIBS -lpthread"
189 pthread_create_version="\"\""
190 AC_MSG_CHECKING(pthread_create symbol version)
191 if eval $ac_link 2>&5 && test -s conftest${ac_exeext}; then
192 version=`$NM conftest${ac_exeect} | grep 'pthread_create@@' | sed -e 's/^.*@@//'`
193 if test "x$version" != "x"; then
194 pthread_create_version="\"$version\""
197 AC_MSG_RESULT($pthread_create_version)
201 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_VERSION, $pthread_create_version, [pthread_create symbol version])
204 # Figure out whether the compiler supports "-ffunction-sections -fdata-sections",
205 # similarly to how libstdc++ does it
206 ac_test_CFLAGS="${CFLAGS+set}"
207 ac_save_CFLAGS="$CFLAGS"
209 # Check for -ffunction-sections -fdata-sections
210 AC_MSG_CHECKING([for gcc that supports -ffunction-sections -fdata-sections])
211 CFLAGS='-Werror -ffunction-sections -fdata-sections'
212 AC_TRY_COMPILE(, [int foo;], [ac_fdsections=yes], [ac_fdsections=no])
213 if test "$ac_test_CFLAGS" = set; then
214 CFLAGS="$ac_save_CFLAGS"
216 # this is the suspicious part
219 if test x"$ac_fdsections" = x"yes"; then
220 SECTION_FLAGS='-ffunction-sections -fdata-sections'
222 AC_MSG_RESULT($ac_fdsections)
223 AC_SUBST(SECTION_FLAGS)
226 # Check for the name of the symbol used for the entry point.
227 AC_CACHE_CHECK([for the name of the symbol used for the entry point],
228 [mudflap_cv_entry_point], [
229 for name in _start __start unknown; do
230 AC_LINK_IFELSE([AC_LANG_PROGRAM([extern char $name;], [$name = 0;])],
233 mudflap_cv_entry_point="$name"])
234 if test "$mudflap_cv_entry_point" = unknown; then
235 AC_MSG_ERROR([none of the known symbol names works])
237 AC_DEFINE_UNQUOTED([ENTRY_POINT], [$mudflap_cv_entry_point],
238 [Define to the name of the symbol used for the entry point.])
241 if test ${multilib} = yes; then
242 multilib_arg="--enable-multilib"
247 # See if we support thread-local storage.
250 AC_CONFIG_FILES([Makefile testsuite/Makefile testsuite/mfconfig.exp])