Home | History | Annotate | Download | only in m4m
      1 dnl @synopsis GP_CHECK_POPT(FLAG)
      2 dnl
      3 dnl Check whether libpopt is available.
      4 dnl FLAG must be one of
      5 dnl    "mandatory"
      6 dnl    "default-enabled"
      7 dnl    "default-disabled"
      8 dnl
      9 AC_DEFUN([GP_CHECK_POPT],[
     10 #
     11 # [GP_CHECK_POPT]
     12 #
     13 AC_REQUIRE([GP_CONFIG_MSG])dnl
     14 m4_if([$1],[mandatory],        [_GP_CHECK_POPT([mandatory])],
     15       [$1],[default-enabled],  [_GP_CHECK_POPT([disable])],
     16       [$1],[default-disabled], [_GP_CHECK_POPT([enable])],
     17       [m4_errprint(__file__:__line__:[ Error:
     18 Illegal argument to $0: `$1'
     19 Valid values are: mandatory, default-enabled, default-disabled
     20 ])m4_exit(1)])dnl
     21 ])dnl
     22 dnl
     23 AC_DEFUN([_GP_CHECK_POPT],[
     24 m4_if([$1],[mandatory],[
     25 try_popt=yes
     26 require_popt=yes
     27 ],[
     28 try_popt=auto
     29 require_popt=no
     30 AC_ARG_ENABLE([popt],
     31 [AS_HELP_STRING([--$1-popt],[Do not use popt])],
     32 [ if   test "x$withval" = no \
     33     || test "x$withval" = off \
     34     || test "x$withval" = false; 
     35   then
     36     try_popt=no
     37     require_popt=no
     38   elif test "x$withval" = yes \
     39     || test "x$withval" = on \
     40     || test "x$withval" = true
     41   then
     42     try_popt=yes
     43     require_popt=yes
     44   fi
     45 ])dnl
     46 ])dnl
     47 
     48 AC_MSG_CHECKING([whether popt is required])
     49 AC_MSG_RESULT([${require_popt}])
     50 
     51 if test "$require_popt" != yes; then
     52 	AC_MSG_CHECKING([whether popt is requested])
     53 	AC_MSG_RESULT([${try_popt}])
     54 fi
     55 
     56 dnl Implicit AC_SUBST
     57 AC_ARG_VAR([POPT_CFLAGS],[CPPFLAGS to compile with libpopt])dnl
     58 AC_ARG_VAR([POPT_LIBS],[LDFLAGS to link with libpopt])dnl
     59 
     60 have_popt=no
     61 
     62 if test "x$POPT_CFLAGS" = "x" && test "x$POPT_LIBS" = "x"; then
     63 
     64 	# try to find options to compile popt.h
     65 	CPPFLAGS_save="$CPPFLAGS"
     66 	popth_found=no
     67 	for popt_prefix in "" /usr /usr/local
     68 	do
     69 		if test -n "${popt_prefix}"; then
     70 			:
     71 		elif test -d "${popt_prefix}/include"; then
     72 			CPPFLAGS="-I${popt_prefix}/include ${CPPFLAGS}"
     73 		else
     74 			continue
     75 		fi
     76 		ac_cv_header_popt_h=""
     77 		unset ac_cv_header_popt_h
     78 		AC_CHECK_HEADER([popt.h], [popth_found=yes])
     79 		if test "$popth_found" = yes; then break; fi
     80 	done
     81 	CPPFLAGS="$CPPFLAGS_save"
     82 	if test "$popth_found" = "yes"; then
     83 		if test "$popt_prefix" = ""; then
     84 			POPT_CFLAGS=""
     85 		else
     86 			POPT_CFLAGS="-I${popt_prefix}/include"
     87 		fi
     88 	else
     89 		AC_MSG_ERROR([
     90 * Cannot autodetect popt.h
     91 *
     92 * Set POPT_CFLAGS and POPT_LIBS correctly.
     93 ])
     94 	fi
     95 
     96 	# try to find options to link against popt
     97 	LDFLAGS_save="$LDFLAGS"
     98 	popt_links=no
     99 	for popt_prefix in /usr "" /usr/local; do
    100 		# We could have "/usr" and "lib64" at the beginning of the
    101 		# lists. Then the first tested location would
    102 		# incidentally be the right one on 64bit systems, and
    103 		# thus work around a bug in libtool on 32bit systems:
    104 		#
    105 		# 32bit libtool doesn't know about 64bit systems, and so the
    106 		# compilation will fail when linking a 32bit library from
    107 		# /usr/lib to a 64bit binary.
    108 		#
    109 		# This hack has been confirmed to workwith a
    110 		# 32bit Debian Sarge and 64bit Fedora Core 3 system.
    111 		for ldir in lib64 "" lib; do
    112 			popt_libdir="${popt_prefix}/${ldir}"
    113 			if test "${popt_libdir}" = "/"; then
    114 				popt_libdir=""
    115 			elif test -d "${popt_libdir}"; then
    116 				LDFLAGS="-L${popt_libdir} ${LDFLAGS}"
    117 			else
    118 				continue
    119 			fi
    120 			# Avoid caching of results
    121 			ac_cv_lib_popt_poptStuffArgs=""
    122 			unset ac_cv_lib_popt_poptStuffArgs
    123 			AC_CHECK_LIB([popt], [poptStuffArgs], [popt_links=yes])
    124 			if test "$popt_links" = yes; then break; fi
    125 		done
    126 		if test "$popt_links" = yes; then break; fi
    127 	done
    128 	LDFLAGS="$LDFLAGS_save"
    129 	if test "$popt_links" = "yes"; then
    130 		if test "$popt_libdir" = ""; then
    131 			POPT_LIBS="-lpopt"
    132 		else
    133 			POPT_LIBS="-L${popt_libdir} -lpopt"
    134 		fi
    135 	else
    136 		AC_MSG_ERROR([
    137 * Cannot autodetect library directory containing popt
    138 *
    139 * Set POPT_CFLAGS and POPT_LIBS correctly.
    140 ])
    141 	fi
    142 	have_popt=yes
    143 elif test "x$POPT_CFLAGS" != "x" && test "x$POPT_LIBS" != "x"; then
    144     # just use the user specivied option
    145     popt_msg="yes (user specified)"
    146     have_popt=yes
    147 else
    148 	AC_MSG_ERROR([
    149 * Fatal: Either set both POPT_CFLAGS and POPT_LIBS or neither.
    150 ])
    151 fi
    152 
    153 AC_MSG_CHECKING([if popt is functional])
    154 if test "$require_popt$have_popt" = "yesno"; then
    155 	AC_MSG_RESULT([no, but required])
    156 	AC_MSG_ERROR([
    157 * popt library not found
    158 * Fatal: ${PACKAGE_NAME} (${PACKAGE_TARNAME}) requires popt
    159 * Please install it and/or set POPT_CFLAGS and POPT_LIBS.
    160 ])
    161 fi
    162 AC_MSG_RESULT([${have_popt}])
    163 
    164 GP_CONFIG_MSG([use popt library], [${have_popt}])
    165 if test "$have_popt" = "yes"; then
    166 	AC_DEFINE([HAVE_POPT],[1],[whether the popt library is available])
    167 	GP_CONFIG_MSG([popt libs],[${POPT_LIBS}])
    168 	GP_CONFIG_MSG([popt cppflags],[${POPT_CFLAGS}])
    169 fi
    170 AM_CONDITIONAL([HAVE_POPT],[test "$have_popt" = "yes"])
    171 ])dnl
    172 dnl
    173 dnl Please do not remove this:
    174 dnl filetype: 7595380e-eff3-49e5-90ab-e40f1d544639
    175 dnl I use this to find all the different instances of this file which 
    176 dnl are supposed to be synchronized.
    177 dnl
    178 dnl Local Variables:
    179 dnl mode: autoconf
    180 dnl End:
    181