1dnl @synopsis GP_CHECK_POPT(FLAG)
2dnl
3dnl Check whether libpopt is available.
4dnl FLAG must be one of
5dnl    "mandatory"
6dnl    "default-enabled"
7dnl    "default-disabled"
8dnl
9AC_DEFUN([GP_CHECK_POPT],[
10#
11# [GP_CHECK_POPT]
12#
13AC_REQUIRE([GP_CONFIG_MSG])dnl
14m4_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:
18Illegal argument to $0: `$1'
19Valid values are: mandatory, default-enabled, default-disabled
20])m4_exit(1)])dnl
21])dnl
22dnl
23AC_DEFUN([_GP_CHECK_POPT],[
24m4_if([$1],[mandatory],[
25try_popt=yes
26require_popt=yes
27],[
28try_popt=auto
29require_popt=no
30AC_ARG_ENABLE([popt],
31[AS_HELP_STRING([--$1-popt],[Do not use popt])],
32[ if   test "x$enableval" = xno \
33    || test "x$enableval" = xoff \
34    || test "x$enableval" = xfalse;
35  then
36    try_popt=no
37    require_popt=no
38  elif test "x$enableval" = xyes \
39    || test "x$enableval" = xon \
40    || test "x$enableval" = xtrue
41  then
42    try_popt=yes
43    require_popt=yes
44  fi
45])dnl
46])dnl
47
48AC_MSG_CHECKING([whether popt is required])
49AC_MSG_RESULT([${require_popt}])
50
51if test "$require_popt" != yes; then
52	AC_MSG_CHECKING([whether popt is requested])
53	AC_MSG_RESULT([${try_popt}])
54fi
55
56dnl Implicit AC_SUBST
57AC_ARG_VAR([POPT_CFLAGS],[cppflags to compile with libpopt])dnl
58AC_ARG_VAR([POPT_LIBS],[location of libpopt to link against])dnl
59
60have_popt=no
61
62if 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        case "$MSYSTEM" in
68         MINGW32)
69		if test -n "/mingw32"; then
70			:
71		elif test -d "/mingw32/include"; then
72			CPPFLAGS="-I/mingw32/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         ;;
80         MINGW64)
81		if test -n "${popt_prefix}"; then
82			:
83		elif test -d "/mingw64/include"; then
84			CPPFLAGS="-I/mingw64/include ${CPPFLAGS}"
85		else
86			continue
87		fi
88		ac_cv_header_popt_h=""
89		unset ac_cv_header_popt_h
90		AC_CHECK_HEADER([popt.h], [popth_found=yes])
91         ;;
92         *)
93           for popt_prefix in "" /usr /usr/local
94           do
95		if test -n "${popt_prefix}"; then
96			:
97		elif test -d "${popt_prefix}/include"; then
98			CPPFLAGS="-I${popt_prefix}/include ${CPPFLAGS}"
99		else
100			continue
101		fi
102		ac_cv_header_popt_h=""
103		unset ac_cv_header_popt_h
104		AC_CHECK_HEADER([popt.h], [popth_found=yes])
105		if test "$popth_found" = yes; then break; fi
106	   done
107         ;;
108        esac
109	CPPFLAGS="$CPPFLAGS_save"
110	if test "$popth_found" = "yes"; then
111		if test "$popt_prefix" = ""; then
112			POPT_CFLAGS=""
113		else
114			POPT_CFLAGS="-I${popt_prefix}/include"
115		fi
116	elif test "$require_popt" = "yes"; then
117		AC_MSG_ERROR([
118* Cannot autodetect popt.h
119*
120* Set POPT_CFLAGS and POPT_LIBS correctly.
121])
122	fi
123
124	# try to find options to link against popt
125	LDFLAGS_save="$LDFLAGS"
126	popt_links=no
127        case "$MSYSTEM" in
128         MINGW32)
129#		for ldir in "" lib; do
130			popt_libdir="/mingw32/lib"
131			if test "${popt_libdir}" = "/"; then
132				popt_libdir=""
133			elif test -d "${popt_libdir}"; then
134				LDFLAGS="-L${popt_libdir} ${LDFLAGS}"
135			else
136				continue
137			fi
138			# Avoid caching of results
139			ac_cv_lib_popt_poptStuffArgs=""
140			unset ac_cv_lib_popt_poptStuffArgs
141			AC_CHECK_LIB([popt], [poptStuffArgs], [popt_links=yes])
142         ;;
143         MINGW64)
144			popt_libdir="/mingw64/lib"
145			if test "${popt_libdir}" = "/"; then
146				popt_libdir=""
147			elif test -d "${popt_libdir}"; then
148				LDFLAGS="-L${popt_libdir} ${LDFLAGS}"
149			else
150				continue
151			fi
152			# Avoid caching of results
153			ac_cv_lib_popt_poptStuffArgs=""
154			unset ac_cv_lib_popt_poptStuffArgs
155			AC_CHECK_LIB([popt], [poptStuffArgs], [popt_links=yes])
156          ;;
157         *)
158	    for popt_prefix in /usr "" /usr/local; do
159		# We could have "/usr" and "lib64" at the beginning of the
160		# lists. Then the first tested location would
161		# incidentally be the right one on 64bit systems, and
162		# thus work around a bug in libtool on 32bit systems:
163		#
164		# 32bit libtool doesn't know about 64bit systems, and so the
165		# compilation will fail when linking a 32bit library from
166		# /usr/lib to a 64bit binary.
167		#
168		# This hack has been confirmed to workwith a
169		# 32bit Debian Sarge and 64bit Fedora Core 3 system.
170		for ldir in lib64 "" lib; do
171			popt_libdir="${popt_prefix}/${ldir}"
172			if test "${popt_libdir}" = "/"; then
173				popt_libdir=""
174			elif test -d "${popt_libdir}"; then
175				LDFLAGS="-L${popt_libdir} ${LDFLAGS}"
176			else
177				continue
178			fi
179			# Avoid caching of results
180			ac_cv_lib_popt_poptStuffArgs=""
181			unset ac_cv_lib_popt_poptStuffArgs
182			AC_CHECK_LIB([popt], [poptStuffArgs], [popt_links=yes])
183			if test "$popt_links" = yes; then break; fi
184		done
185		if test "$popt_links" = yes; then break; fi
186	  done
187         ;;
188        esac
189	LDFLAGS="$LDFLAGS_save"
190	if test "$popt_links" = "yes"; then
191		if test "$popt_libdir" = ""; then
192			POPT_LIBS="-lpopt"
193		else
194			POPT_LIBS="-L${popt_libdir} -lpopt"
195		fi
196		have_popt=yes
197	elif test "$require_popt" = "yes"; then
198		AC_MSG_ERROR([
199* Cannot autodetect library directory containing popt
200*
201* Set POPT_CFLAGS and POPT_LIBS correctly.
202])
203	fi
204elif test "x$POPT_CFLAGS" != "x" && test "x$POPT_LIBS" != "x"; then
205    # just use the user specivied option
206    popt_msg="yes (user specified)"
207    have_popt=yes
208else
209	AC_MSG_ERROR([
210* Fatal: Either set both POPT_CFLAGS and POPT_LIBS or neither.
211])
212fi
213
214AC_MSG_CHECKING([if popt is functional])
215if test "$require_popt$have_popt" = "yesno"; then
216	AC_MSG_RESULT([no, but required])
217	AC_MSG_ERROR([
218* popt library not found
219* Fatal: ${PACKAGE_NAME} (${PACKAGE_TARNAME}) requires popt
220* Please install it and/or set POPT_CFLAGS and POPT_LIBS.
221])
222fi
223AC_MSG_RESULT([${have_popt}])
224
225GP_CONFIG_MSG([use popt library], [${have_popt}])
226if test "$have_popt" = "yes"; then
227	AC_DEFINE([HAVE_POPT],[1],[whether the popt library is available])
228	GP_CONFIG_MSG([popt libs],[${POPT_LIBS}])
229	GP_CONFIG_MSG([popt cppflags],[${POPT_CFLAGS}])
230fi
231AM_CONDITIONAL([HAVE_POPT],[test "$have_popt" = "yes"])
232])dnl
233dnl
234dnl Please do not remove this:
235dnl filetype: 7595380e-eff3-49e5-90ab-e40f1d544639
236dnl I use this to find all the different instances of this file which
237dnl are supposed to be synchronized.
238dnl
239dnl Local Variables:
240dnl mode: autoconf
241dnl End:
242