Changeset 129


Ignore:
Timestamp:
Oct 21, 2007, 5:22:47 PM (12 years ago)
Author:
rainer
Message:

Detect whether the OS supports posix threads.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/aclocal.m4

    r120 r129  
    15311531])
    15321532
     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
     1619AC_DEFUN([ACX_PTHREAD], [
     1620AC_REQUIRE([AC_CANONICAL_HOST])
     1621AC_LANG_SAVE
     1622AC_LANG_C
     1623acx_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:
     1632if 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"
     1646fi
     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
     1658acx_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
     1680case "${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        ;;
     1693esac
     1694
     1695if test x"$acx_pthread_ok" = xno; then
     1696for 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=""
     1751done
     1752fi
     1753
     1754# Various other checks:
     1755if 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
     1795else
     1796        PTHREAD_CC="$CC"
     1797fi
     1798
     1799AC_SUBST(PTHREAD_LIBS)
     1800AC_SUBST(PTHREAD_CFLAGS)
     1801AC_SUBST(PTHREAD_CC)
     1802
     1803# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
     1804if 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        :
     1807else
     1808        acx_pthread_ok=no
     1809        $2
     1810fi
     1811AC_LANG_RESTORE
     1812])dnl ACX_PTHREAD
     1813
    15331814dnl *-*wedit:notab*-*  Please keep this as the last line.
    15341815
  • trunk/configure.ac

    r127 r129  
    1313dnl start
    1414dnl
    15 AM_INIT_AUTOMAKE(samhain, 2.3.8)
     15AM_INIT_AUTOMAKE(samhain, 2.3.7)
    1616AC_CANONICAL_HOST
    1717
     
    746746)
    747747
     748
     749dnl
     750dnl  NETWORK OPTIONS
     751dnl
     752AC_ARG_ENABLE(network,
     753        [  --enable-network=[[client|server]]   compile client or server [[no]]],
     754        [
     755        if test "x$enable_network" = xclient; then
     756                mytclient="-DSH_WITH_CLIENT"
     757                yulectl_prg=
     758                setpwd_prg="samhain_setpwd"
     759                sh_main_prg="samhain"
     760                if test "x${sh_have_gmp}" = xyes
     761                then
     762                        LIBS="-lgmp $LIBS"
     763                fi
     764dnl             AC_CHECK_HEADER(sys/capability.h,
     765dnl                             [AC_CHECK_LIB(cap, cap_get_proc,,sh_use_lcaps="no")],
     766dnl                             [sh_use_lcaps="no"])
     767        elif test "x$enable_network" = xserver; then
     768                mytclient="-DSH_WITH_SERVER"
     769                yulectl_prg="yulectl"
     770                setpwd_prg="samhain_setpwd"
     771                sh_main_prg="yule"
     772                if test "x${sh_have_gmp}" = xyes
     773                then
     774                        LIBS="-lgmp $LIBS"
     775                fi
     776                sh_use_lcaps="undef"
     777        elif test "x$enable_network" = xno; then
     778                mytclient="-DSH_STANDALONE"
     779                yulectl_prg=
     780                setpwd_prg=
     781                sh_main_prg="samhain"
     782dnl             AC_CHECK_HEADER(sys/capability.h,
     783dnl                             [AC_CHECK_LIB(cap, cap_get_proc,,sh_use_lcaps="no")],
     784dnl                             [sh_use_lcaps="no"])
     785        else
     786                AC_MSG_ERROR([--enable-network=WHAT: WHAT must be client, server, or no])
     787        fi
     788        ],
     789        [
     790        mytclient="-DSH_STANDALONE"
     791        setpwd_prg=
     792        yulectl_prg=
     793        sh_main_prg="samhain"
     794dnl     AC_CHECK_HEADER(sys/capability.h,
     795dnl                     [AC_CHECK_LIB(cap, cap_get_proc,,sh_use_lcaps="no")],
     796dnl                     [sh_use_lcaps="no"])
     797        ],
     798)
     799
     800if test x"${mytclient}" = x-DSH_STANDALONE -o x"${mytclient}" = x-DSH_WITH_CLIENT;
     801then
     802        ACX_PTHREAD
     803        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
     804        LIBS="$PTHREAD_LIBS $LIBS"
     805        CC="$PTHREAD_CC"
     806fi
     807       
     808AC_SUBST(setpwd_prg)
     809AC_SUBST(yulectl_prg)
     810AC_SUBST(sh_main_prg)
     811AC_SUBST(mytclient)
     812
     813# needed for the rpm spec
     814clmytclient=`echo ${mytclient} | sed s%\-%%`
     815AC_SUBST(clmytclient)
    748816
    749817AC_ARG_ENABLE(static,
     
    14271495
    14281496
    1429 dnl
    1430 dnl  NETWORK OPTIONS
    1431 dnl
    1432 
    1433 
    1434 AC_ARG_ENABLE(network,
    1435         [  --enable-network=[[client|server]]   compile client or server [[no]]],
    1436         [
    1437         if test "x$enable_network" = xclient; then
    1438                 mytclient="-DSH_WITH_CLIENT"
    1439                 yulectl_prg=
    1440                 setpwd_prg="samhain_setpwd"
    1441                 sh_main_prg="samhain"
    1442                 if test "x${sh_have_gmp}" = xyes
    1443                 then
    1444                         LIBS="-lgmp $LIBS"
    1445                 fi
    1446 dnl             AC_CHECK_HEADER(sys/capability.h,
    1447 dnl                             [AC_CHECK_LIB(cap, cap_get_proc,,sh_use_lcaps="no")],
    1448 dnl                             [sh_use_lcaps="no"])
    1449         elif test "x$enable_network" = xserver; then
    1450                 mytclient="-DSH_WITH_SERVER"
    1451                 yulectl_prg="yulectl"
    1452                 setpwd_prg="samhain_setpwd"
    1453                 sh_main_prg="yule"
    1454                 if test "x${sh_have_gmp}" = xyes
    1455                 then
    1456                         LIBS="-lgmp $LIBS"
    1457                 fi
    1458                 sh_use_lcaps="undef"
    1459         elif test "x$enable_network" = xno; then
    1460                 mytclient="-DSH_STANDALONE"
    1461                 yulectl_prg=
    1462                 setpwd_prg=
    1463                 sh_main_prg="samhain"
    1464 dnl             AC_CHECK_HEADER(sys/capability.h,
    1465 dnl                             [AC_CHECK_LIB(cap, cap_get_proc,,sh_use_lcaps="no")],
    1466 dnl                             [sh_use_lcaps="no"])
    1467         else
    1468                 AC_MSG_ERROR([--enable-network=WHAT: WHAT must be client, server, or no])
    1469         fi
    1470         ],
    1471         [
    1472         mytclient="-DSH_STANDALONE"
    1473         setpwd_prg=
    1474         yulectl_prg=
    1475         sh_main_prg="samhain"
    1476 dnl     AC_CHECK_HEADER(sys/capability.h,
    1477 dnl                     [AC_CHECK_LIB(cap, cap_get_proc,,sh_use_lcaps="no")],
    1478 dnl                     [sh_use_lcaps="no"])
    1479         ],
    1480 )
    1481 AC_SUBST(setpwd_prg)
    1482 AC_SUBST(yulectl_prg)
    1483 AC_SUBST(sh_main_prg)
    1484 AC_SUBST(mytclient)
    1485 
    1486 # needed for the rpm spec
    1487 clmytclient=`echo ${mytclient} | sed s%\-%%`
    1488 AC_SUBST(clmytclient)
    1489 
    14901497AC_ARG_ENABLE(udp,
    14911498        [  --enable-udp                 server can listen on port 514/udp [[no]]],
Note: See TracChangeset for help on using the changeset viewer.