Changeset 129 for trunk/aclocal.m4
- Timestamp:
- Oct 21, 2007, 5:22:47 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/aclocal.m4
r120 r129 1531 1531 ]) 1532 1532 1533 1534 ##### http://autoconf-archive.cryp.to/acx_pthread.html 1535 # 1536 # SYNOPSIS 1537 # 1538 # ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 1539 # 1540 # DESCRIPTION 1541 # 1542 # This macro figures out how to build C programs using POSIX threads. 1543 # It sets the PTHREAD_LIBS output variable to the threads library and 1544 # linker flags, and the PTHREAD_CFLAGS output variable to any special 1545 # C compiler flags that are needed. (The user can also force certain 1546 # compiler flags/libs to be tested by setting these environment 1547 # variables.) 1548 # 1549 # Also sets PTHREAD_CC to any special C compiler that is needed for 1550 # multi-threaded programs (defaults to the value of CC otherwise). 1551 # (This is necessary on AIX to use the special cc_r compiler alias.) 1552 # 1553 # NOTE: You are assumed to not only compile your program with these 1554 # flags, but also link it with them as well. e.g. you should link 1555 # with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS 1556 # $LIBS 1557 # 1558 # If you are only building threads programs, you may wish to use 1559 # these variables in your default LIBS, CFLAGS, and CC: 1560 # 1561 # LIBS="$PTHREAD_LIBS $LIBS" 1562 # CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1563 # CC="$PTHREAD_CC" 1564 # 1565 # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute 1566 # constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to 1567 # that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). 1568 # 1569 # ACTION-IF-FOUND is a list of shell commands to run if a threads 1570 # library is found, and ACTION-IF-NOT-FOUND is a list of commands to 1571 # run it if it is not found. If ACTION-IF-FOUND is not specified, the 1572 # default action will define HAVE_PTHREAD. 1573 # 1574 # Please let the authors know if this macro fails on any platform, or 1575 # if you have any other suggestions or comments. This macro was based 1576 # on work by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) 1577 # (with help from M. Frigo), as well as ac_pthread and hb_pthread 1578 # macros posted by Alejandro Forero Cuervo to the autoconf macro 1579 # repository. We are also grateful for the helpful feedback of 1580 # numerous users. 1581 # 1582 # LAST MODIFICATION 1583 # 1584 # 2007-07-29 1585 # 1586 # COPYLEFT 1587 # 1588 # Copyright (c) 2007 Steven G. Johnson <stevenj@alum.mit.edu> 1589 # 1590 # This program is free software: you can redistribute it and/or 1591 # modify it under the terms of the GNU General Public License as 1592 # published by the Free Software Foundation, either version 3 of the 1593 # License, or (at your option) any later version. 1594 # 1595 # This program is distributed in the hope that it will be useful, but 1596 # WITHOUT ANY WARRANTY; without even the implied warranty of 1597 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1598 # General Public License for more details. 1599 # 1600 # You should have received a copy of the GNU General Public License 1601 # along with this program. If not, see 1602 # <http://www.gnu.org/licenses/>. 1603 # 1604 # As a special exception, the respective Autoconf Macro's copyright 1605 # owner gives unlimited permission to copy, distribute and modify the 1606 # configure scripts that are the output of Autoconf when processing 1607 # the Macro. You need not follow the terms of the GNU General Public 1608 # License when using or distributing such scripts, even though 1609 # portions of the text of the Macro appear in them. The GNU General 1610 # Public License (GPL) does govern all other use of the material that 1611 # constitutes the Autoconf Macro. 1612 # 1613 # This special exception to the GPL applies to versions of the 1614 # Autoconf Macro released by the Autoconf Macro Archive. When you 1615 # make and distribute a modified version of the Autoconf Macro, you 1616 # may extend this special exception to the GPL to apply to your 1617 # modified version as well. 1618 1619 AC_DEFUN([ACX_PTHREAD], [ 1620 AC_REQUIRE([AC_CANONICAL_HOST]) 1621 AC_LANG_SAVE 1622 AC_LANG_C 1623 acx_pthread_ok=no 1624 1625 # We used to check for pthread.h first, but this fails if pthread.h 1626 # requires special compiler flags (e.g. on True64 or Sequent). 1627 # It gets checked for in the link test anyway. 1628 1629 # First of all, check if the user has set any of the PTHREAD_LIBS, 1630 # etcetera environment variables, and if threads linking works using 1631 # them: 1632 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then 1633 save_CFLAGS="$CFLAGS" 1634 CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1635 save_LIBS="$LIBS" 1636 LIBS="$PTHREAD_LIBS $LIBS" 1637 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) 1638 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) 1639 AC_MSG_RESULT($acx_pthread_ok) 1640 if test x"$acx_pthread_ok" = xno; then 1641 PTHREAD_LIBS="" 1642 PTHREAD_CFLAGS="" 1643 fi 1644 LIBS="$save_LIBS" 1645 CFLAGS="$save_CFLAGS" 1646 fi 1647 1648 # We must check for the threads library under a number of different 1649 # names; the ordering is very important because some systems 1650 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the 1651 # libraries is broken (non-POSIX). 1652 1653 # Create a list of thread flags to try. Items starting with a "-" are 1654 # C compiler flags, and other items are library names, except for "none" 1655 # which indicates that we try without any flags at all, and "pthread-config" 1656 # which is a program returning the flags for the Pth emulation library. 1657 1658 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" 1659 1660 # The ordering *is* (sometimes) important. Some notes on the 1661 # individual items follow: 1662 1663 # pthreads: AIX (must check this before -lpthread) 1664 # none: in case threads are in libc; should be tried before -Kthread and 1665 # other compiler flags to prevent continual compiler warnings 1666 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) 1667 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) 1668 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) 1669 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) 1670 # -pthreads: Solaris/gcc 1671 # -mthreads: Mingw32/gcc, Lynx/gcc 1672 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it 1673 # doesn't hurt to check since this sometimes defines pthreads too; 1674 # also defines -D_REENTRANT) 1675 # ... -mt is also the pthreads flag for HP/aCC 1676 # pthread: Linux, etcetera 1677 # --thread-safe: KAI C++ 1678 # pthread-config: use pthread-config program (for GNU Pth library) 1679 1680 case "${host_cpu}-${host_os}" in 1681 *solaris*) 1682 1683 # On Solaris (at least, for some versions), libc contains stubbed 1684 # (non-functional) versions of the pthreads routines, so link-based 1685 # tests will erroneously succeed. (We need to link with -pthreads/-mt/ 1686 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather 1687 # a function called by this macro, so we could check for that, but 1688 # who knows whether they'll stub that too in a future libc.) So, 1689 # we'll just look for -pthreads and -lpthread first: 1690 1691 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags" 1692 ;; 1693 esac 1694 1695 if test x"$acx_pthread_ok" = xno; then 1696 for flag in $acx_pthread_flags; do 1697 1698 case $flag in 1699 none) 1700 AC_MSG_CHECKING([whether pthreads work without any flags]) 1701 ;; 1702 1703 -*) 1704 AC_MSG_CHECKING([whether pthreads work with $flag]) 1705 PTHREAD_CFLAGS="$flag" 1706 ;; 1707 1708 pthread-config) 1709 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) 1710 if test x"$acx_pthread_config" = xno; then continue; fi 1711 PTHREAD_CFLAGS="`pthread-config --cflags`" 1712 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" 1713 ;; 1714 1715 *) 1716 AC_MSG_CHECKING([for the pthreads library -l$flag]) 1717 PTHREAD_LIBS="-l$flag" 1718 ;; 1719 esac 1720 1721 save_LIBS="$LIBS" 1722 save_CFLAGS="$CFLAGS" 1723 LIBS="$PTHREAD_LIBS $LIBS" 1724 CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1725 1726 # Check for various functions. We must include pthread.h, 1727 # since some functions may be macros. (On the Sequent, we 1728 # need a special flag -Kthread to make this header compile.) 1729 # We check for pthread_join because it is in -lpthread on IRIX 1730 # while pthread_create is in libc. We check for pthread_attr_init 1731 # due to DEC craziness with -lpthreads. We check for 1732 # pthread_cleanup_push because it is one of the few pthread 1733 # functions on Solaris that doesn't have a non-functional libc stub. 1734 # We try pthread_create on general principles. 1735 AC_TRY_LINK([#include <pthread.h>], 1736 [pthread_t th; pthread_join(th, 0); 1737 pthread_attr_init(0); pthread_cleanup_push(0, 0); 1738 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], 1739 [acx_pthread_ok=yes]) 1740 1741 LIBS="$save_LIBS" 1742 CFLAGS="$save_CFLAGS" 1743 1744 AC_MSG_RESULT($acx_pthread_ok) 1745 if test "x$acx_pthread_ok" = xyes; then 1746 break; 1747 fi 1748 1749 PTHREAD_LIBS="" 1750 PTHREAD_CFLAGS="" 1751 done 1752 fi 1753 1754 # Various other checks: 1755 if test "x$acx_pthread_ok" = xyes; then 1756 save_LIBS="$LIBS" 1757 LIBS="$PTHREAD_LIBS $LIBS" 1758 save_CFLAGS="$CFLAGS" 1759 CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1760 1761 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. 1762 AC_MSG_CHECKING([for joinable pthread attribute]) 1763 attr_name=unknown 1764 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do 1765 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;], 1766 [attr_name=$attr; break]) 1767 done 1768 AC_MSG_RESULT($attr_name) 1769 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then 1770 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, 1771 [Define to necessary symbol if this constant 1772 uses a non-standard name on your system.]) 1773 fi 1774 1775 AC_MSG_CHECKING([if more special flags are required for pthreads]) 1776 flag=no 1777 case "${host_cpu}-${host_os}" in 1778 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; 1779 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; 1780 esac 1781 AC_MSG_RESULT(${flag}) 1782 if test "x$flag" != xno; then 1783 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" 1784 fi 1785 1786 LIBS="$save_LIBS" 1787 CFLAGS="$save_CFLAGS" 1788 1789 # More AIX lossage: must compile with xlc_r or cc_r 1790 if test x"$GCC" != xyes; then 1791 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) 1792 else 1793 PTHREAD_CC=$CC 1794 fi 1795 else 1796 PTHREAD_CC="$CC" 1797 fi 1798 1799 AC_SUBST(PTHREAD_LIBS) 1800 AC_SUBST(PTHREAD_CFLAGS) 1801 AC_SUBST(PTHREAD_CC) 1802 1803 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: 1804 if test x"$acx_pthread_ok" = xyes; then 1805 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) 1806 : 1807 else 1808 acx_pthread_ok=no 1809 $2 1810 fi 1811 AC_LANG_RESTORE 1812 ])dnl ACX_PTHREAD 1813 1533 1814 dnl *-*wedit:notab*-* Please keep this as the last line. 1534 1815
Note:
See TracChangeset
for help on using the changeset viewer.