OSDN Git Service

04020b2c8397c3836162ee5497fc57857cb53e86
[pf3gnuchains/gcc-fork.git] / libmudflap / configure.ac
1 # Process this file with autoconf to produce a configure script, like so:
2 # aclocal && autoconf && autoheader && automake
3
4 AC_PREREQ(2.59)
5 AC_INIT(libmudflap, 1.0)
6 AC_CONFIG_SRCDIR(mf-runtime.c)
7 AC_CANONICAL_SYSTEM
8
9 AM_INIT_AUTOMAKE
10
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 ],
14 [case "$enableval" in
15  yes) version_specific_libs=yes ;;
16  no)  version_specific_libs=no ;;
17  *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
18  esac],
19 [version_specific_libs=no])
20 AC_MSG_RESULT($version_specific_libs)
21
22 AM_MAINTAINER_MODE
23 AC_EXEEXT
24
25 AM_ENABLE_MULTILIB(, ..)
26
27 target_alias=${target_alias-$target}
28 AC_SUBST(target_alias)
29
30 AC_CONFIG_HEADERS(config.h)
31
32 AC_LANG_C
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.
37
38 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
39 m4_define([_AC_ARG_VAR_PRECIOUS],[])
40 AC_PROG_CC
41 m4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
42
43 AC_SUBST(CFLAGS)
44
45 if test "x$GCC" != "xyes"; then
46   AC_MSG_ERROR([libmudflap must be built with GCC])
47 fi
48 AC_PROG_CPP
49
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])
53 AC_TRY_COMPILE([
54 #define _GNU_SOURCE
55 #include <dlfcn.h>
56 ],
57 [void *foo = dlsym (RTLD_NEXT, "exit");],
58 [AC_MSG_RESULT(yes)],
59 [AC_MSG_RESULT(no)
60 enable_shared=no])
61
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 sys/socket.h ctype.h mntent.h \
64   sys/socket.h netinet/in.h arpa/inet.h dlfcn.h)
65
66 AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal)
67 AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64)
68 AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname)
69 AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc)
70 AC_CHECK_FUNCS(getlogin cuserid getpwnam getpwuid getpwent getgrnam getgrgid getgrent)
71 AC_CHECK_FUNCS(getlogin_r getpwnam_r getpwuid_r getgrnam_r getgrgid_r)
72 AC_CHECK_FUNCS(getservent getservbyname getservbyport getaddrinfo gai_strerror)
73 AC_CHECK_FUNCS(getprotoent getprotobyname getprotobynumber)
74 AC_CHECK_FUNCS(getmntent setmntent addmntent)
75 AC_CHECK_FUNCS(inet_ntoa)
76
77 AC_TRY_COMPILE([#include <sys/types.h>
78 #include <sys/ipc.h>
79 #include <sys/sem.h>],[union semun foo;], [mf_have_semun=1], [mf_have_semun=0])
80 if test $mf_have_semun = 1
81 then
82   AC_DEFINE(HAVE_UNION_SEMUN, 1, [union semun defined in sys/ipc.h or sys/sem.h])
83 fi
84
85
86 AC_MSG_CHECKING([for socklen_t in sys/socket.h])
87 AC_TRY_COMPILE([#define _POSIX_PII_SOCKET
88 #include <sys/types.h>
89 #include <sys/socket.h>], [socklen_t x = 5;],
90   [AC_DEFINE(HAVE_SOCKLEN_T, 1, [Define it socklen_t typedef is in sys/socket.h.])
91    AC_MSG_RESULT(yes)],
92   [AC_MSG_RESULT(no)])
93
94 AC_LIBTOOL_DLOPEN
95 AM_PROG_LIBTOOL
96 AC_SUBST(enable_shared)
97 AC_SUBST(enable_static)
98
99 AC_CHECK_HEADER(stdint.h, [MF_HAVE_STDINT_H=1], [MF_HAVE_STDINT_H=0])
100 AC_SUBST(MF_HAVE_STDINT_H)
101 if test $MF_HAVE_STDINT_H = 1
102 then
103    MF_HAVE_UINTPTR_T=1
104 else
105    AC_TRY_COMPILE([#include <sys/types.h>], [uintptr_t k = 0;],
106         [MF_HAVE_UINTPTR_T=1], [MF_HAVE_UINTPTR_T=0])
107 fi
108 AC_SUBST(MF_HAVE_UINTPTR_T)
109
110 if test ! -d pth
111 then
112   # libmudflapth objects are built in this subdirectory
113   mkdir pth
114 fi
115
116 pthread_create_version='""'
117 AC_CHECK_HEADER(pthread.h,[
118 AC_DEFINE_UNQUOTED(HAVE_PTHREAD_H, 1, [define if you have <pthread.h>])
119 ac_have_pthread_h=yes
120 ],[
121 ac_have_pthread_h=
122 ])
123 AM_CONDITIONAL(LIBMUDFLAPTH, [test "x$ac_have_pthread_h" != "x"])
124 if test "x$ac_have_pthread_h" != "x"
125 then
126         build_libmudflapth=1
127 else
128         build_libmudflapth=0
129 fi
130 AC_SUBST(build_libmudflapth)
131
132 AC_CHECK_LIB(dl, dlsym)
133
134 # Process the option "--enable-version-specific-runtime-libs"
135 gcc_version_trigger=${srcdir}/../gcc/version.c
136 gcc_version_full=`grep version_string ${gcc_version_trigger} | sed -e 's/.*\"\([[^ \"]]*\)[[ \"]].*/\1/'`
137 gcc_version=`echo ${gcc_version_full} | sed -e 's/\([^ ]*\) .*/\1/'`
138 AC_SUBST(gcc_version)
139
140 # Calculate toolexeclibdir
141 # Also toolexecdir, though it's only used in toolexeclibdir
142 case ${version_specific_libs} in
143   yes)
144     # Need the gcc compiler version to know where to install libraries
145     # and header files if --enable-version-specific-runtime-libs option
146     # is selected.
147     toolexecdir='$(libdir)/gcc/$(target_alias)'
148     toolexeclibdir='$(toolexecdir)/'${gcc_version}'$(MULTISUBDIR)'
149     ;;
150   no)
151     if test -n "$with_cross_host" &&
152        test x"$with_cross_host" != x"no"; then
153       # Install a library built with a cross compiler in tooldir, not libdir.
154       toolexecdir='$(exec_prefix)/$(target_alias)'
155       toolexeclibdir='$(toolexecdir)/lib'
156     else
157       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
158       toolexeclibdir='$(libdir)'
159     fi
160     multi_os_directory=`$CC -print-multi-os-directory`
161     case $multi_os_directory in
162       .) ;; # Avoid trailing /.
163       *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
164     esac
165     ;;
166 esac
167 AC_SUBST(toolexecdir)
168 AC_SUBST(toolexeclibdir)
169
170 if test "x$enable_shared" = "xyes" && test "x$ac_have_pthread_h" != "x"; then
171   # NB: don't check for -lpthread here, because then it would be
172   # added to LIBS.  For the thread-unaware libmudflap.la, we don't
173   # want it there.
174
175   # glibc-related hacks.  dlsym() may pick the wrong version of
176   # interposed functions like pthread_create on modern glibc.
177   # We need to find the proper symbol version string, and use
178   # the nonstandard dlvsym().
179   AC_CHECK_FUNCS(dlvsym)
180   AC_CHECK_TOOL(NM, nm)
181   if test "x$ac_cv_have_dlvsym" != "x"; then
182     # Try compiling a simple pthreads program.  Find the shared libraries it
183     # ends up with.  Then use "nm" on those libraries to extract the
184     # default symbol versioning suffix ("@@"), if any.  But that's tricky.
185     # Rather, run nm on the resulting executable.  Unfortunately, autoconf
186     # doesn't appear to have a macro that builds a test executable for
187     # subsequent analysis ... so we do it by hand here.
188     cat >> conftest.c << EOF
189 #include <pthread.h>
190 int main () { void *p = (void *) & pthread_create; return (int) p; }
191 EOF
192     oldLIBS="$LIBS"
193     LIBS="$LIBS -lpthread"
194     pthread_create_version="\"\""
195     AC_MSG_CHECKING(pthread_create symbol version)
196     if eval $ac_link 2>&5 && test -s conftest${ac_exeext}; then
197       version=`$NM conftest${ac_exeect} | grep 'pthread_create@@' | sed -e 's/^.*@@//'`
198       if test "x$version" != "x"; then
199         pthread_create_version="\"$version\""
200       fi
201     fi
202     AC_MSG_RESULT($pthread_create_version)
203     LIBS="$oldLIBS"
204   fi
205 fi
206 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_VERSION, $pthread_create_version, [pthread_create symbol version])
207
208
209 # Figure out whether the compiler supports "-ffunction-sections -fdata-sections",
210 # similarly to how libstdc++ does it
211 ac_test_CFLAGS="${CFLAGS+set}"
212 ac_save_CFLAGS="$CFLAGS"
213
214 # Check for -ffunction-sections -fdata-sections
215 AC_MSG_CHECKING([for gcc that supports -ffunction-sections -fdata-sections])
216 CFLAGS='-Werror -ffunction-sections -fdata-sections'
217 AC_TRY_COMPILE(, [int foo;], [ac_fdsections=yes], [ac_fdsections=no])
218 if test "$ac_test_CFLAGS" = set; then
219   CFLAGS="$ac_save_CFLAGS"
220 else
221   # this is the suspicious part
222   CFLAGS=""
223 fi
224 if test x"$ac_fdsections" = x"yes"; then
225   SECTION_FLAGS='-ffunction-sections -fdata-sections'
226 fi
227 AC_MSG_RESULT($ac_fdsections)
228 AC_SUBST(SECTION_FLAGS)
229
230
231 if test ${multilib} = yes; then
232   multilib_arg="--enable-multilib"
233 else
234   multilib_arg=
235 fi
236
237 AC_CONFIG_FILES([Makefile testsuite/Makefile testsuite/mfconfig.exp mf-runtime.h])
238 AC_OUTPUT