1 dnl SMB Build Environment LD Checks
2 dnl -------------------------------------------------------
3 dnl Copyright (C) Stefan (metze) Metzmacher 2004
4 dnl Copyright (C) Jelmer Vernooij 2006
5 dnl Released under the GNU GPL
6 dnl -------------------------------------------------------
9 AC_PATH_PROG(PROG_LD,ld)
13 AC_PATH_PROG(PROG_AR, ar)
22 AC_SUBST(SHLD_UNDEF_FLAGS)
27 # Assume non-shared by default and override below
28 # these are the defaults, good for lots of systems
39 # allow for --with-hostld=gcc
40 AC_ARG_WITH(hostld,[ --with-hostld=linker choose host linker],
43 if test z"$cross_compiling" = "yes"; then
50 AC_MSG_CHECKING([whether to try to build shared libraries on $host_os])
52 # and these are for particular systems
56 SHLD_FLAGS="-shared -Wl,-Bsymbolic"
57 SHLD_UNDEF_FLAGS="-Wl,--allow-shlib-undefined"
58 LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
60 SONAMEFLAG="-Wl,-soname="
66 if test "${GCC}" = "yes"; then
68 SONAMEFLAG="-Wl,-soname="
69 if test "${ac_cv_prog_gnu_ld}" = "yes"; then
70 LDFLAGS="$LDFLAGS -Wl,-E"
74 ## ${CFLAGS} added for building 64-bit shared
75 ## libs using Sun's Compiler
76 SHLD_FLAGS="-G \${CFLAGS}"
83 PICFLAG="-KPIC" # Is this correct for SunOS
85 *netbsd* | *freebsd* | *dragonfly* )
87 LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
88 SONAMEFLAG="-Wl,-soname,"
92 # disabled because us4 fails to link libtorture.so
94 LDFLAGS="$LDFLAGS -Wl,-Bdynamic"
95 SONAMEFLAG="-Wl,-soname,"
99 # disabled because us4 fails to link libtorture.so
101 SHLD_FLAGS="-set_version sgi1.0 -shared"
102 SONAMEFLAG="-soname "
104 if test "${GCC}" = "yes"; then
111 # disabled because us4 fails to link libtorture.so
113 SHLD_FLAGS="-Wl,-G,-bexpall,-bbigtoc"
114 LDFLAGS="$LDFLAGS -Wl,-brtl,-bexpall,-bbigtoc"
115 # as AIX code is always position independent...
119 # Use special PIC flags for the native HP-UX compiler.
120 if test $ac_cv_prog_cc_Ae = yes; then
122 SHLD_FLAGS="-b -Wl,-B,symbolic,-b,-z"
124 PICFLAG="+z +ESnolit"
125 elif test "${GCC}" = "yes"; then
126 BLDSHARED="true" # I hope this is correct
129 if test "$host_cpu" = "ia64"; then
132 LDFLAGS="$LDFLAGS -Wl,-E,+b/usr/local/lib/hpux32:/usr/lib/hpux32"
135 LDFLAGS="$LDFLAGS -Wl,-E,+b/usr/local/lib:/usr/lib"
139 # disabled because tru64 fails to link libtorture.so
141 SONAMEFLAG="-Wl,-soname,"
146 SONAMEFLAG="-Wl,-soname,"
151 SHLD_FLAGS="-bundle -flat_namespace -undefined suppress"
156 AC_MSG_RESULT($BLDSHARED)
158 AC_MSG_CHECKING([LD])
160 AC_MSG_CHECKING([LDFLAGS])
161 AC_MSG_RESULT([$LDFLAGS])
165 AC_MSG_CHECKING([STLD])
166 AC_MSG_RESULT([$STLD])
167 AC_MSG_CHECKING([STLD_FLAGS])
168 AC_MSG_RESULT([$STLD_FLAGS])
170 AC_ARG_ENABLE(shared,
171 [ --disable-shared Disable testing for building shared libraries],
172 [],[enable_shared=yes])
174 if test x"$enable_shared" = x"no" -o x"$enable_shared" = x"false"; then
178 #######################################################
179 # test whether building a shared library actually works
180 if test $BLDSHARED = true; then
182 AC_MSG_CHECKING([SHLD])
183 AC_MSG_RESULT([$SHLD])
184 AC_MSG_CHECKING([SHLD_FLAGS])
185 AC_MSG_RESULT([$SHLD_FLAGS])
187 AC_MSG_CHECKING([SHLIBEXT])
188 AC_MSG_RESULT([$SHLIBEXT])
189 AC_MSG_CHECKING([SONAMEFLAG])
190 AC_MSG_RESULT([$SONAMEFLAG])
192 AC_MSG_CHECKING([PICFLAG])
193 AC_MSG_RESULT([$PICFLAG])
195 AC_CACHE_CHECK([whether building shared libraries actually works],
196 [ac_cv_shlib_works],[
198 # try building a trivial shared library
199 ${CC} ${CFLAGS} ${PICFLAG} -c ${srcdir-.}/build/tests/shlib.c -o shlib.o &&
200 ${SHLD} `eval echo ${SHLD_FLAGS} ` -o shlib.${SHLIBEXT} shlib.o &&
201 ac_cv_shlib_works=yes
202 rm -f shlib.${SHLIBEXT} shlib.o
204 if test $ac_cv_shlib_works = no; then
209 if test $BLDSHARED != true; then
210 SHLD="shared-libraries-disabled"
211 SHLD_FLAGS="shared-libraries-disabled"
212 SHLIBEXT="shared_libraries_disabled"
213 SONAMEFLAG="shared-libraries-disabled"
215 AC_MSG_CHECKING([SHLD])
216 AC_MSG_RESULT([$SHLD])
217 AC_MSG_CHECKING([SHLD_FLAGS])
218 AC_MSG_RESULT([$SHLD_FLAGS])
220 AC_MSG_CHECKING([SHLIBEXT])
221 AC_MSG_RESULT([$SHLIBEXT])
222 AC_MSG_CHECKING([SONAMEFLAG])
223 AC_MSG_RESULT([$SONAMEFLAG])
225 AC_MSG_CHECKING([PICFLAG])
226 AC_MSG_RESULT([$PICFLAG])
229 AC_DEFINE_UNQUOTED(SHLIBEXT, "$SHLIBEXT", [Shared library extension])
231 AC_MSG_CHECKING([if we can link using the selected flags])
232 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
234 AC_MSG_ERROR([we cannot link with the selected cc and ld flags. Aborting configure]),
235 AC_MSG_WARN([cannot run when cross-compiling]))
242 [ --enable-dso Enable using shared libraries internally (experimental)],
245 if test x"$enable_dso" = x"yes" -a x"$BLDSHARED" != x"true"; then
246 AC_MSG_ERROR([--enable-dso: no support for shared libraries])
249 if test x"$enable_dso" != x"no"; then
253 AC_MSG_CHECKING([if binaries will use shared libraries])
254 AC_MSG_RESULT([$USESHARED])