1 dnl Borrowed from Transcode (http://www.transcoding.org/cgi-bin/transcode)
3 dnl PKG_INIT(rptfile, errfile)
8 pkg_err_file="pkg_err_file"
9 pkg_rpt_file="pkg_rpt_file"
11 if test x"$1" != x"" ; then
14 echo -n > $pkg_rpt_file
16 if test x"$2" != x"" ; then
19 echo -n > $pkg_err_file
23 dnl PKG_ERROR(name, object, req-enable, pkg, url, [error message])
30 if test x"$3" = x"required" ; then
31 prob="requirement failed"
33 prob="option '--enable-$1' failed"
36 cat >> $pkg_err_file <<EOF
38 $2 can be found in the following packages:
45 dnl PKG_CHECK(pkg-name, def-enabled, var-name, pkgconfig-name, conf-script,
46 dnl header, lib, symbol)
47 dnl Test for pkg-name, and define var-name_CFLAGS and var-name_LIBS
48 dnl and HAVE_var-name if found
50 dnl 1 name name of package; required (pkg-config name if applicable)
51 dnl 2 req-enable enable by default, 'required', 'yes' or 'no'; required
52 dnl 3 var-name name stub for variables, preferably uppercase; required
53 dnl 4 conf-script name of "-config" script or 'no'
54 dnl 5 header header file to check or 'none'
55 dnl 6 lib library to check or 'none'
56 dnl 7 symbol symbol from the library to check or ''
57 dnl 8 pkg package (pkg-config name if applicable)
58 dnl 9 url homepage for the package
62 if test x"$2" != x"required" ; then
63 AC_MSG_CHECKING([whether $1 support is requested])
65 AC_HELP_STRING([--enable-$1],
66 [build with $1 support ($2)]),
67 [case "${enableval}" in
70 *) AC_MSG_ERROR(bad value ${enableval} for --enable-$1) ;;
73 AC_MSG_RESULT($enable_$1)
78 AC_ARG_WITH($1-prefix,
79 AC_HELP_STRING([--with-$1-prefix=PFX],
80 [prefix where $1 is installed (/usr)]),
81 w_$1_p="$withval", w_$1_p="")
83 AC_ARG_WITH($1-includes,
84 AC_HELP_STRING([--with-$1-includes=DIR],
85 [directory where $1 headers ($5) are installed (/usr/include)]),
86 w_$1_i="$withval", w_$1_i="")
89 AC_HELP_STRING([--with-$1-libs=DIR],
90 [directory where $1 libararies (lib$6.so) are installed (/usr/lib)]),
91 w_$1_l="$withval", w_$1_l="")
96 if test x"$enable_$1" = x"yes" ; then
101 AC_MSG_CHECKING([for pkgconfig support for $1])
102 if test x"$PKG_CONFIG" != x"no" ; then
103 if $PKG_CONFIG $8 --exists ; then
107 AC_MSG_RESULT($pkg_config_$1)
111 if test x"$4" != x"no" ; then
112 if test x"$w_$1_p" != x"" ; then
113 if test -x $w_$1_p/bin/$4 ; then
114 $1_config="$w_$1_p/bin/$4"
117 AC_PATH_PROG($1_config, $4, no)
122 # get and test the _CFLAGS
124 AC_MSG_CHECKING([how to determine $3_CFLAGS])
125 if test x"$w_$1_i" != x"" ; then
129 if test x"$pkg_config_$1" != x"no" ; then
130 $1_ii="`$PKG_CONFIG $8 --cflags`"
131 AC_MSG_RESULT(pkg-config)
133 if test x"$$1_config" != x"no" ; then
134 $1_ii="`$$1_config --cflags`"
135 AC_MSG_RESULT($$1_config)
137 if test x"$w_$1_p" != x"" ; then
138 $1_ii="-I$w_$1_p/include"
139 AC_MSG_RESULT(prefix)
141 $1_ii="-I/usr/include"
142 AC_MSG_RESULT(default)
150 -I*) ipaths="$ipaths $i" ;;
155 $1_ii="`echo $$1_ii | sed -e 's/ */ /g'`"
156 $3_EXTRA_CFLAGS="$$3_EXTRA_CFLAGS $xi"
157 $3_EXTRA_CFLAGS="`echo $$3_EXTRA_CFLAGS | sed -e 's/ */ /g'`"
159 if test x"$5" != x"none" ; then
160 save_CPPFLAGS="$CPPFLAGS"
161 CPPFLAGS="$CPPFLAGS $$1_ii"
162 AC_CHECK_HEADER([$5],
163 [$3_CFLAGS="$$1_ii"],
164 [PKG_ERROR($1, $5, $2, $8, $9, [cannot compile $5])])
165 CPPFLAGS="$save_CPPFLAGS"
168 # get and test the _LIBS
170 AC_MSG_CHECKING([how to determine $3_LIBS])
171 if test x"$w_$1_l" != x"" ; then
175 if test x"$pkg_config_$1" != x"no" ; then
176 $1_ll="`$PKG_CONFIG $8 --libs`"
177 AC_MSG_RESULT(pkg-config)
179 if test x"$$1_config" != x"no" ; then
180 $1_ll="`$$1_config --libs`"
181 AC_MSG_RESULT($$1_config)
183 if test x"$w_$1_p" != x"" ; then
184 $1_ll="-L$w_$1_p${deflib}"
185 AC_MSG_RESULT(prefix)
187 $1_ll="-L/usr${deflib}"
188 AC_MSG_RESULT(default)
193 lpaths="" ; xlibs="" ; xlf=""
196 -L*) lpaths="$lpaths $l" ;;
197 -l*) test x"$l" != x"-l$6" && xlibs="$xlibs $l" ;;
202 $1_ll="`echo $$1_ll | sed -e 's/ */ /g'`"
204 for i in $xlibs $xlf ; do
205 echo " $$3_EXTRA_LIBS " | grep -vq " $i " && xl="$xl $i"
207 $3_EXTRA_LIBS="$$3_EXTRA_LIBS $xl"
208 $3_EXTRA_LIBS="`echo $$3_EXTRA_LIBS | sed -e 's/ */ /g'`"
210 if test x"$6" != x"none" ; then
211 save_LDFLAGS="$LDFLAGS"
212 LDFLAGS="$LDFLAGS $$1_ll"
213 AC_CHECK_LIB([$6], [$7],
214 [$3_LIBS="$$1_ll -l$6 $$3_EXTRA_LIBS"],
215 [PKG_ERROR($1, lib$6, $2, $8, $9, [cannot link against lib$6])],
217 LDFLAGS="$save_LDFLAGS"
220 if test x"$this_pkg_err" = x"no" ; then