2 dnl ## GNU Pth - The GNU Portable Threads
3 dnl ## Copyright (c) 1999-2006 Ralf S. Engelschall <rse@engelschall.com>
5 dnl ## This file is part of GNU Pth, a non-preemptive thread scheduling
6 dnl ## library which can be found at http://www.gnu.org/software/pth/.
8 dnl ## This library is free software; you can redistribute it and/or
9 dnl ## modify it under the terms of the GNU Lesser General Public
10 dnl ## License as published by the Free Software Foundation; either
11 dnl ## version 2.1 of the License, or (at your option) any later version.
13 dnl ## This library is distributed in the hope that it will be useful,
14 dnl ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 dnl ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 dnl ## Lesser General Public License for more details.
18 dnl ## You should have received a copy of the GNU Lesser General Public
19 dnl ## License along with this library; if not, write to the Free Software
20 dnl ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 dnl ## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
23 dnl ## pth.m4: Autoconf macro for locating GNU Pth from within
24 dnl ## configure.ac of third-party software packages
29 dnl ## AC_CHECK_PTH([MIN-VERSION [, # minimum Pth version, e.g. 1.2.0
30 dnl ## DEFAULT-WITH-PTH [, # default value for --with-pth option
31 dnl ## DEFAULT-WITH-PTH-TEST [,# default value for --with-pth-test option
32 dnl ## EXTEND-VARS [, # whether CFLAGS/LDFLAGS/etc are extended
33 dnl ## ACTION-IF-FOUND [, # action to perform if Pth was found
34 dnl ## ACTION-IF-NOT-FOUND # action to perform if Pth was not found
37 dnl ## AC_CHECK_PTH(1.2.0)
38 dnl ## AC_CHECK_PTH(1.2.0,,,no,CFLAGS="$CFLAGS -DHAVE_PTH $PTH_CFLAGS")
39 dnl ## AC_CHECK_PTH(1.2.0,yes,yes,yes,CFLAGS="$CFLAGS -DHAVE_PTH")
42 dnl # auxilliary macros
43 AC_DEFUN([_AC_PTH_ERROR], [dnl
44 AC_MSG_RESULT([*FAILED*])
45 m4_define(_ac_pth_line,dnl
46 "+------------------------------------------------------------------------+")
47 echo " _ac_pth_line" 1>&2
48 cat <<EOT | sed -e 's/^[[ ]]*/ | /' -e 's/>>/ /' 1>&2
51 echo " _ac_pth_line" 1>&2
54 AC_DEFUN([_AC_PTH_VERBOSE], [dnl
55 if test ".$verbose" = .yes; then
60 AC_DEFUN([AC_CHECK_PTH], [dnl
63 AC_REQUIRE([AC_PROG_CC])dnl
64 AC_REQUIRE([AC_PROG_CPP])dnl
70 AC_SUBST(PTH_CPPFLAGS)
74 dnl # command line options
75 AC_MSG_CHECKING(for GNU Pth)
78 [ --with-pth[=ARG] Build with GNU Pth Library (default=]ifelse([$2],,yes,$2)[)],dnl
80 with_pth="ifelse([$2],,yes,$2)"
82 AC_ARG_WITH(pth-test,dnl
83 [ --with-pth-test Perform GNU Pth Sanity Test (default=]ifelse([$3],,yes,$3)[)],dnl
85 with_pth_test="ifelse([$3],,yes,$3)"
87 _AC_PTH_VERBOSE([+ Command Line Options:])
88 _AC_PTH_VERBOSE([ o --with-pth=$with_pth])
89 _AC_PTH_VERBOSE([ o --with-pth-test=$with_pth_test])
92 if test ".$with_pth" != .no; then
99 _pth_subdir_opts=`echo $with_pth | sed -e 's/^subdir:[^ ]*[ ]*//'`
100 with_pth=`echo $with_pth | sed -e 's/^subdir:\([^ ]*\).*$/\1/'`
111 if test ".$with_pth" = .yes; then
112 # via config script in $PATH
114 _pth_version=`(pth-config --version) 2>/dev/null |\
115 sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
117 if test ".$_pth_version" != .; then
118 _pth_location=`pth-config --prefix`
119 _pth_type='installed'
120 _pth_cppflags=`pth-config --cflags`
121 _pth_cflags=`pth-config --cflags`
122 _pth_ldflags=`pth-config --ldflags`
123 _pth_libs=`pth-config --libs --all`
125 elif test -d "$with_pth"; then
126 with_pth=`echo $with_pth | sed -e 's;/*$;;'`
128 # via locally included source tree
129 if test ".$_pth_subdir" = .yes; then
130 _pth_location="$with_pth"
132 _pth_cppflags="-I$with_pth"
133 _pth_cflags="-I$with_pth"
134 if test -f "$with_pth/ltconfig"; then
135 _pth_ldflags="-L$with_pth/.libs"
137 _pth_ldflags="-L$with_pth"
141 _pth_version=`grep '^const char PTH_Hello' $with_pth/pth_vers.c |\
142 sed -e 's;^.*Version[ ]*\([0-9]*\.[0-9]*[.ab][0-9]*\)[ ].*$;\1;'`
145 ac_configure_args="$ac_configure_args --enable-subdir $_pth_subdir_opts"
148 # via config script under a specified directory
149 # (a standard installation, but not a source tree)
150 if test ".$_pth_found" = .no; then
151 for _dir in $with_pth/bin $with_pth; do
152 if test -f "$_dir/pth-config"; then
153 test -f "$_dir/pth-config.in" && continue # pth-config in source tree!
155 _pth_version=`($_dir/pth-config --version) 2>/dev/null |\
156 sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
158 if test ".$_pth_version" != .; then
159 _pth_location=`$_dir/pth-config --prefix`
160 _pth_type="installed"
161 _pth_cppflags=`$_dir/pth-config --cflags`
162 _pth_cflags=`$_dir/pth-config --cflags`
163 _pth_ldflags=`$_dir/pth-config --ldflags`
164 _pth_libs=`$_dir/pth-config --libs --all`
171 # in any subarea under a specified directory
172 # (either a special installation or a Pth source tree)
173 if test ".$_pth_found" = .no; then
176 for _file in x `find $with_pth -name "pth.h" -type f -print`; do
177 test .$_file = .x && continue
178 _dir=`echo $_file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
179 _pth_version=`($_dir/pth-config --version) 2>/dev/null |\
180 sed -e 's/^.*\([0-9]\.[0-9]*[ab.][0-9]*\).*$/\1/'`
181 if test ".$_pth_version" = .; then
182 _pth_version=`grep '^#define PTH_VERSION_STR' $_file |\
183 sed -e 's;^#define[ ]*PTH_VERSION_STR[ ]*"\([0-9]*\.[0-9]*[.ab][0-9]*\)[ ].*$;\1;'`
185 _pth_cppflags="-I$_dir"
186 _pth_cflags="-I$_dir"
187 _pth_found=`expr $_pth_found + 1`
189 for _file in x `find $with_pth -name "libpth.[aso]" -type f -print`; do
190 test .$_file = .x && continue
191 _dir=`echo $_file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'`
192 _pth_ldflags="-L$_dir"
194 _pth_found=`expr $_pth_found + 1`
197 if test ".$_pth_found" = .2; then
198 _pth_location="$with_pth"
199 _pth_type="uninstalled"
205 _AC_PTH_VERBOSE([+ Determined Location:])
206 _AC_PTH_VERBOSE([ o path: $_pth_location])
207 _AC_PTH_VERBOSE([ o type: $_pth_type])
208 if test ".$_pth_version" = .; then
209 if test ".$with_pth" != .yes; then
211 Unable to locate GNU Pth under $with_pth.
212 Please specify the correct path to either a GNU Pth installation tree
213 (use --with-pth=DIR if you used --prefix=DIR for installing GNU Pth in
214 the past) or to a GNU Pth source tree (use --with-pth=DIR if DIR is a
215 path to a pth-X.Y.Z/ directory; but make sure the package is already
216 built, i.e., the "configure; make" step was already performed there).])
219 Unable to locate GNU Pth in any system-wide location (see \$PATH).
220 Please specify the correct path to either a GNU Pth installation tree
221 (use --with-pth=DIR if you used --prefix=DIR for installing GNU Pth in
222 the past) or to a GNU Pth source tree (use --with-pth=DIR if DIR is a
223 path to a pth-X.Y.Z/ directory; but make sure the package is already
224 built, i.e., the "configure; make" step was already performed there).])
228 dnl # Check whether the found version is sufficiently new
230 _req_version="ifelse([$1],,1.0.0,$1)"
231 for _var in _pth_version _req_version; do
232 eval "_val=\"\$${_var}\""
233 _major=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\1/'`
234 _minor=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\2/'`
235 _rtype=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\3/'`
236 _micro=`echo $_val | sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\([[ab.]]\)\([[0-9]]*\)/\4/'`
242 _hex=`echo dummy | awk '{ printf("%d%02d%1d%02d", major, minor, rtype, micro); }' \
243 "major=$_major" "minor=$_minor" "rtype=$_rtype" "micro=$_micro"`
244 eval "${_var}_hex=\"\$_hex\""
246 _AC_PTH_VERBOSE([+ Determined Versions:])
247 _AC_PTH_VERBOSE([ o existing: $_pth_version -> 0x$_pth_version_hex])
248 _AC_PTH_VERBOSE([ o required: $_req_version -> 0x$_req_version_hex])
250 if test ".$_pth_version_hex" != .; then
251 if test ".$_req_version_hex" != .; then
252 if test $_pth_version_hex -ge $_req_version_hex; then
257 if test ".$_ok" = .0; then
259 Found Pth version $_pth_version, but required at least version $_req_version.
260 Upgrade Pth under $_pth_location to $_req_version or higher first, please.])
263 dnl # Perform Pth Sanity Compile Check
265 if test ".$with_pth_test" = .yes; then
266 _ac_save_CPPFLAGS="$CPPFLAGS"
267 _ac_save_CFLAGS="$CFLAGS"
268 _ac_save_LDFLAGS="$LDFLAGS"
269 _ac_save_LIBS="$LIBS"
270 CPPFLAGS="$CPPFLAGS $_pth_cppflags"
271 CFLAGS="$CFLAGS $_pth_cflags"
272 LDFLAGS="$LDFLAGS $_pth_ldflags"
273 LIBS="$LIBS $_pth_libs"
274 _AC_PTH_VERBOSE([+ Test Build Environment:])
275 _AC_PTH_VERBOSE([ o CPPFLAGS=\"$CPPFLAGS\"])
276 _AC_PTH_VERBOSE([ o CFLAGS=\"$CFLAGS\"])
277 _AC_PTH_VERBOSE([ o LDFLAGS=\"$LDFLAGS\"])
278 _AC_PTH_VERBOSE([ o LIBS=\"$LIBS\"])
280 m4_define(_code1, [dnl
284 m4_define(_code2, [dnl
285 int main(int argc, char *argv[])
288 if (!(fp = fopen("conftestval", "w")))
294 if (!(fp = fopen("conftestval", "w")))
301 _AC_PTH_VERBOSE([+ Performing Sanity Checks:])
302 _AC_PTH_VERBOSE([ o pre-processor test])
303 AC_TRY_CPP(_code1, _ok=yes, _ok=no)
304 if test ".$_ok" != .yes; then
306 Found GNU Pth $_pth_version under $_pth_location, but
307 was unable to perform a sanity pre-processor check. This means
308 the GNU Pth header pth.h was not found.
309 We used the following build environment:
311 >> CPPFLAGS="$CPPFLAGS"
312 See config.log for possibly more details.])
314 _AC_PTH_VERBOSE([ o link check])
315 AC_TRY_LINK(_code1, _code2, _ok=yes, _ok=no)
316 if test ".$_ok" != .yes; then
318 Found GNU Pth $_pth_version under $_pth_location, but
319 was unable to perform a sanity linker check. This means
320 the GNU Pth library libpth.a was not found.
321 We used the following build environment:
324 >> LDFLAGS="$LDFLAGS"
326 See config.log for possibly more details.])
328 _AC_PTH_VERBOSE([ o run-time check])
329 AC_TRY_RUN(_code1 _code2, _ok=`cat conftestval`, _ok=no, _ok=no)
330 if test ".$_ok" != .yes; then
331 if test ".$_ok" = .no; then
333 Found GNU Pth $_pth_version under $_pth_location, but
334 was unable to perform a sanity execution check. This usually
335 means that the GNU Pth shared library libpth.so is present
336 but \$LD_LIBRARY_PATH is incomplete to execute a Pth test.
337 In this case either disable this test via --without-pth-test,
338 or extend \$LD_LIBRARY_PATH, or build GNU Pth as a static
339 library only via its --disable-shared Autoconf option.
340 We used the following build environment:
343 >> LDFLAGS="$LDFLAGS"
345 See config.log for possibly more details.])
348 Found GNU Pth $_pth_version under $_pth_location, but
349 was unable to perform a sanity run-time check. This usually
350 means that the GNU Pth library failed to work and possibly
351 caused a core dump in the test program. In this case it
352 is strongly recommended that you re-install GNU Pth and this
353 time make sure that it really passes its "make test" procedure.
354 We used the following build environment:
357 >> LDFLAGS="$LDFLAGS"
359 See config.log for possibly more details.])
362 _extendvars="ifelse([$4],,yes,$4)"
363 if test ".$_extendvars" != .yes; then
364 CPPFLAGS="$_ac_save_CPPFLAGS"
365 CFLAGS="$_ac_save_CFLAGS"
366 LDFLAGS="$_ac_save_LDFLAGS"
367 LIBS="$_ac_save_LIBS"
370 _extendvars="ifelse([$4],,yes,$4)"
371 if test ".$_extendvars" = .yes; then
372 if test ".$_pth_subdir" = .yes; then
373 CPPFLAGS="$CPPFLAGS $_pth_cppflags"
374 CFLAGS="$CFLAGS $_pth_cflags"
375 LDFLAGS="$LDFLAGS $_pth_ldflags"
376 LIBS="$LIBS $_pth_libs"
380 PTH_CPPFLAGS="$_pth_cppflags"
381 PTH_CFLAGS="$_pth_cflags"
382 PTH_LDFLAGS="$_pth_ldflags"
383 PTH_LIBS="$_pth_libs"
384 AC_SUBST(PTH_CPPFLAGS)
386 AC_SUBST(PTH_LDFLAGS)
388 _AC_PTH_VERBOSE([+ Final Results:])
389 _AC_PTH_VERBOSE([ o PTH_CPPFLAGS=\"$PTH_CPPFLAGS\"])
390 _AC_PTH_VERBOSE([ o PTH_CFLAGS=\"$PTH_CFLAGS\"])
391 _AC_PTH_VERBOSE([ o PTH_LDFLAGS=\"$PTH_LDFLAGS\"])
392 _AC_PTH_VERBOSE([ o PTH_LIBS=\"$PTH_LIBS\"])
394 if test ".$with_pth" != .no; then
395 AC_MSG_RESULT([version $_pth_version, $_pth_type under $_pth_location])
396 ifelse([$5], , :, [$5])
399 ifelse([$6], , :, [$6])