OSDN Git Service

configure.ac (AC_CHECK_HEADERS): Add dirent.h
[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 # For libtool versioning info, format is CURRENT:REVISION:AGE
12 libtool_VERSION=1:0:0
13 AC_SUBST(libtool_VERSION)
14
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 ],
18 [case "$enableval" in
19  yes) version_specific_libs=yes ;;
20  no)  version_specific_libs=no ;;
21  *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
22  esac],
23 [version_specific_libs=no])
24 AC_MSG_RESULT($version_specific_libs)
25
26 AM_MAINTAINER_MODE
27 AC_EXEEXT
28
29 AM_ENABLE_MULTILIB(, ..)
30
31 target_alias=${target_alias-$target}
32 AC_SUBST(target_alias)
33
34 AC_CONFIG_HEADERS(config.h)
35
36 AC_LANG_C
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.
41
42 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
43 m4_define([_AC_ARG_VAR_PRECIOUS],[])
44 AC_PROG_CC
45 m4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
46
47 AC_SUBST(CFLAGS)
48
49 if test "x$GCC" != "xyes"; then
50   AC_MSG_ERROR([libmudflap must be built with GCC])
51 fi
52 AC_PROG_CPP
53
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])
57 AC_TRY_COMPILE([
58 #define _GNU_SOURCE
59 #include <dlfcn.h>
60 ],
61 [void *foo = dlsym (RTLD_NEXT, "exit");],
62 [AC_MSG_RESULT(yes)],
63 [AC_MSG_RESULT(no)
64 enable_shared=no])
65
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)
69
70 dnl Check for 64-bit stdio calls related to Large File Support
71 AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64)
72
73 dnl Check for nonstandard functions
74 AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname)
75
76 dnl Check for glibc ctype functions
77 AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc)
78
79 AC_TRY_COMPILE([#include <sys/types.h>
80 #include <sys/ipc.h>
81 #include <sys/sem.h>],[union semun foo;], [mf_have_semun=1], [mf_have_semun=0])
82 if test $mf_have_semun = 1
83 then
84   AC_DEFINE(HAVE_UNION_SEMUN, 1, [union semun defined in sys/ipc.h or sys/sem.h])
85 fi
86
87
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.])
93    AC_MSG_RESULT(yes)],
94   [AC_MSG_RESULT(no)])
95
96 AC_LIBTOOL_DLOPEN
97 AM_PROG_LIBTOOL
98 AC_SUBST(enable_shared)
99 AC_SUBST(enable_static)
100
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
104 then
105    MF_HAVE_UINTPTR_T=1
106 else
107    AC_TRY_COMPILE([#include <sys/types.h>], [uintptr_t k = 0;],
108         [MF_HAVE_UINTPTR_T=1], [MF_HAVE_UINTPTR_T=0])
109 fi
110 AC_SUBST(MF_HAVE_UINTPTR_T)
111
112 if test ! -d pth
113 then
114   # libmudflapth objects are built in this subdirectory
115   mkdir pth
116 fi
117
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
122 ],[
123 ac_have_pthread_h=
124 ])
125 AM_CONDITIONAL(LIBMUDFLAPTH, [test "x$ac_have_pthread_h" != "x"])
126 if test "x$ac_have_pthread_h" != "x"
127 then
128         build_libmudflapth=1
129 else
130         build_libmudflapth=0
131 fi
132 AC_SUBST(build_libmudflapth)
133
134 AC_CHECK_LIB(dl, dlsym)
135
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)
141
142 # Calculate toolexeclibdir
143 # Also toolexecdir, though it's only used in toolexeclibdir
144 case ${version_specific_libs} in
145   yes)
146     # Need the gcc compiler version to know where to install libraries
147     # and header files if --enable-version-specific-runtime-libs option
148     # is selected.
149     toolexecdir='$(libdir)/gcc/$(target_alias)'
150     toolexeclibdir='$(toolexecdir)/'${gcc_version}'$(MULTISUBDIR)'
151     ;;
152   no)
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'
158     else
159       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
160       toolexeclibdir='$(libdir)'
161     fi
162     multi_os_directory=`$CC -print-multi-os-directory`
163     case $multi_os_directory in
164       .) ;; # Avoid trailing /.
165       *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
166     esac
167     ;;
168 esac
169 AC_SUBST(toolexecdir)
170 AC_SUBST(toolexeclibdir)
171
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
175   # want it there.
176
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
191 #include <pthread.h>
192 int main () { void *p = (void *) & pthread_create; return (int) p; }
193 EOF
194     oldLIBS="$LIBS"
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\""
202       fi
203     fi
204     AC_MSG_RESULT($pthread_create_version)
205     LIBS="$oldLIBS"
206   fi
207 fi
208 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_VERSION, $pthread_create_version, [pthread_create symbol version])
209
210
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"
215
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"
222 else
223   # this is the suspicious part
224   CFLAGS=""
225 fi
226 if test x"$ac_fdsections" = x"yes"; then
227   SECTION_FLAGS='-ffunction-sections -fdata-sections'
228 fi
229 AC_MSG_RESULT($ac_fdsections)
230 AC_SUBST(SECTION_FLAGS)
231
232
233 if test ${multilib} = yes; then
234   multilib_arg="--enable-multilib"
235 else
236   multilib_arg=
237 fi
238
239 AC_CONFIG_FILES([Makefile testsuite/Makefile testsuite/mfconfig.exp mf-runtime.h])
240 AC_OUTPUT