OSDN Git Service

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