| | 222 | |
| | 223 | # The next part tries to detect GCC inconsistency with -shared on some |
| | 224 | # architectures and systems. The problem is that in certain |
| | 225 | # configurations, when -shared is specified, GCC "forgets" to |
| | 226 | # internally use various flags which are still necessary. |
| | 227 | |
| | 228 | # First, check whether caller wants us to skip -shared checks |
| | 229 | # this is useful |
| | 230 | AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies]) |
| | 231 | if test x"$3" = x1; then |
| | 232 | AC_MSG_RESULT([no]) |
| | 233 | else |
| | 234 | AC_MSG_RESULT([yes]) |
| | 235 | |
| | 236 | # In order not to create several levels of indentation, we test |
| | 237 | # the value of "$ok" until we find out the cure or run out of |
| | 238 | # ideas. |
| | 239 | ok="no" |
| | 240 | |
| | 241 | # |
| | 242 | # Prepare the flags |
| | 243 | # |
| | 244 | save_CFLAGS="$CFLAGS" |
| | 245 | save_LIBS="$LIBS" |
| | 246 | save_CC="$CC" |
| | 247 | # Try with the flags determined by the earlier checks. |
| | 248 | # |
| | 249 | # -Wl,-z,defs forces link-time symbol resolution, so that the |
| | 250 | # linking checks with -shared actually have any value |
| | 251 | # |
| | 252 | # FIXME: -fPIC is required for -shared on many architectures, |
| | 253 | # so we specify it here, but the right way would probably be to |
| | 254 | # properly detect whether it is actually required. |
| | 255 | CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS" |
| | 256 | LIBS="$PTHREAD_LIBS $LIBS" |
| | 257 | CC="$PTHREAD_CC" |
| | 258 | |
| | 259 | AC_MSG_CHECKING([whether -pthread is sufficient with -shared]) |
| | 260 | AC_TRY_LINK([#include <pthread.h>], |
| | 261 | [pthread_t th; pthread_join(th, 0); |
| | 262 | pthread_attr_init(0); pthread_cleanup_push(0, 0); |
| | 263 | pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], |
| | 264 | [ok=yes]) |
| | 265 | |
| | 266 | if test "x$ok" = xyes; then |
| | 267 | AC_MSG_RESULT([yes]) |
| | 268 | else |
| | 269 | AC_MSG_RESULT([no]) |
| | 270 | fi |
| | 271 | |
| | 272 | # |
| | 273 | # Linux gcc on some architectures such as mips/mipsel forgets |
| | 274 | # about -lpthread |
| | 275 | # |
| | 276 | if test x"$ok" = xno; then |
| | 277 | AC_MSG_CHECKING([whether -lpthread fixes that]) |
| | 278 | LIBS="-lpthread $PTHREAD_LIBS $save_LIBS" |
| | 279 | AC_TRY_LINK([#include <pthread.h>], |
| | 280 | [pthread_t th; pthread_join(th, 0); |
| | 281 | pthread_attr_init(0); pthread_cleanup_push(0, 0); |
| | 282 | pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], |
| | 283 | [ok=yes]) |
| | 284 | |
| | 285 | if test "x$ok" = xyes; then |
| | 286 | AC_MSG_RESULT([yes]) |
| | 287 | PTHREAD_LIBS="-lpthread $PTHREAD_LIBS" |
| | 288 | else |
| | 289 | AC_MSG_RESULT([no]) |
| | 290 | fi |
| | 291 | fi |
| | 292 | # |
| | 293 | # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc |
| | 294 | # |
| | 295 | if test x"$ok" = xno; then |
| | 296 | AC_MSG_CHECKING([whether -lc_r fixes that]) |
| | 297 | LIBS="-lc_r $PTHREAD_LIBS $save_LIBS" |
| | 298 | AC_TRY_LINK([#include <pthread.h>], |
| | 299 | [pthread_t th; pthread_join(th, 0); |
| | 300 | pthread_attr_init(0); pthread_cleanup_push(0, 0); |
| | 301 | pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], |
| | 302 | [ok=yes]) |
| | 303 | |
| | 304 | if test "x$ok" = xyes; then |
| | 305 | AC_MSG_RESULT([yes]) |
| | 306 | PTHREAD_LIBS="-lc_r $PTHREAD_LIBS" |
| | 307 | else |
| | 308 | AC_MSG_RESULT([no]) |
| | 309 | fi |
| | 310 | fi |
| | 311 | if test x"$ok" = xno; then |
| | 312 | # OK, we have run out of ideas |
| | 313 | AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries]) |
| | 314 | |
| | 315 | # so it's not safe to assume that we may use pthreads |
| | 316 | acx_pthread_ok=no |
| | 317 | fi |
| | 318 | |
| | 319 | CFLAGS="$save_CFLAGS" |
| | 320 | LIBS="$save_LIBS" |
| | 321 | CC="$save_CC" |
| | 322 | fi |