Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / m4 / ax_create_pkgconfig_info.m4
1 # ===========================================================================
2 #    http://www.nongnu.org/autoconf-archive/ax_create_pkgconfig_info.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_CREATE_PKGCONFIG_INFO [(outputfile, [requires [,libs [,summary [,cflags [, ldflags]]]]])]
8 #
9 # DESCRIPTION
10 #
11 #   Defaults:
12 #
13 #     $1 = $PACKAGE_NAME.pc
14 #     $2 = (empty)
15 #     $3 = $PACKAGE_LIBS $LIBS (as set at that point in configure.ac)
16 #     $4 = $PACKAGE_SUMMARY (or $1 Library)
17 #     $5 = $CPPFLAGS $PACKAGE_CFLAGS (as set at the point in configure.ac)
18 #     $6 = $LDFLAGS $PACKAGE_LDFLAGS (as set at the point in configure.ac)
19 #
20 #     PACKAGE_NAME defaults to $PACKAGE if not set.
21 #     PACKAGE_LIBS defaults to -l$PACKAGE_NAME if not set.
22 #
23 #   The resulting file is called $PACKAGE.pc.in / $PACKAGE.pc
24 #
25 #   You will find this macro most useful in conjunction with
26 #   ax_spec_defaults that can read good initializers from the .spec file. In
27 #   consequencd, most of the generatable installable stuff can be made from
28 #   information being updated in a single place for the whole project.
29 #
30 # LICENSE
31 #
32 #   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
33 #   Copyright (c) 2008 Sven Verdoolaege <skimo@kotnet.org>
34 #
35 #   This program is free software; you can redistribute it and/or modify it
36 #   under the terms of the GNU General Public License as published by the
37 #   Free Software Foundation; either version 2 of the License, or (at your
38 #   option) any later version.
39 #
40 #   This program is distributed in the hope that it will be useful, but
41 #   WITHOUT ANY WARRANTY; without even the implied warranty of
42 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
43 #   Public License for more details.
44 #
45 #   You should have received a copy of the GNU General Public License along
46 #   with this program. If not, see <http://www.gnu.org/licenses/>.
47 #
48 #   As a special exception, the respective Autoconf Macro's copyright owner
49 #   gives unlimited permission to copy, distribute and modify the configure
50 #   scripts that are the output of Autoconf when processing the Macro. You
51 #   need not follow the terms of the GNU General Public License when using
52 #   or distributing such scripts, even though portions of the text of the
53 #   Macro appear in them. The GNU General Public License (GPL) does govern
54 #   all other use of the material that constitutes the Autoconf Macro.
55 #
56 #   This special exception to the GPL applies to versions of the Autoconf
57 #   Macro released by the Autoconf Archive. When you make and distribute a
58 #   modified version of the Autoconf Macro, you may extend this special
59 #   exception to the GPL to apply to your modified version as well.
60
61 AC_DEFUN([AX_CREATE_PKGCONFIG_INFO],[dnl
62 AS_VAR_PUSHDEF([PKGCONFIG_suffix],[ax_create_pkgconfig_suffix])dnl
63 AS_VAR_PUSHDEF([PKGCONFIG_libdir],[ax_create_pkgconfig_libdir])dnl
64 AS_VAR_PUSHDEF([PKGCONFIG_libfile],[ax_create_pkgconfig_libfile])dnl
65 AS_VAR_PUSHDEF([PKGCONFIG_libname],[ax_create_pkgconfig_libname])dnl
66 AS_VAR_PUSHDEF([PKGCONFIG_version],[ax_create_pkgconfig_version])dnl
67 AS_VAR_PUSHDEF([PKGCONFIG_description],[ax_create_pkgconfig_description])dnl
68 AS_VAR_PUSHDEF([PKGCONFIG_requires],[ax_create_pkgconfig_requires])dnl
69 AS_VAR_PUSHDEF([PKGCONFIG_pkglibs],[ax_create_pkgconfig_pkglibs])dnl
70 AS_VAR_PUSHDEF([PKGCONFIG_libs],[ax_create_pkgconfig_libs])dnl
71 AS_VAR_PUSHDEF([PKGCONFIG_ldflags],[ax_create_pkgconfig_ldflags])dnl
72 AS_VAR_PUSHDEF([PKGCONFIG_cppflags],[ax_create_pkgconfig_cppflags])dnl
73 AS_VAR_PUSHDEF([PKGCONFIG_generate],[ax_create_pkgconfig_generate])dnl
74 AS_VAR_PUSHDEF([PKGCONFIG_src_libdir],[ax_create_pkgconfig_src_libdir])dnl
75 AS_VAR_PUSHDEF([PKGCONFIG_src_headers],[ax_create_pkgconfig_src_headers])dnl
76
77 # we need the expanded forms...
78 test "x$prefix" = xNONE && prefix=$ac_default_prefix
79 test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
80
81 AC_MSG_CHECKING(our pkgconfig libname)
82 test ".$PKGCONFIG_libname" != "." || \
83 PKGCONFIG_libname="ifelse($1,,${PACKAGE_NAME},`basename $1 .pc`)"
84 test ".$PKGCONFIG_libname" != "." || \
85 PKGCONFIG_libname="$PACKAGE"
86 PKGCONFIG_libname=`eval echo "$PKGCONFIG_libname"`
87 PKGCONFIG_libname=`eval echo "$PKGCONFIG_libname"`
88 AC_MSG_RESULT($PKGCONFIG_libname)
89
90 AC_MSG_CHECKING(our pkgconfig version)
91 test ".$PKGCONFIG_version" != "." || \
92 PKGCONFIG_version="${PACKAGE_VERSION}"
93 test ".$PKGCONFIG_version" != "." || \
94 PKGCONFIG_version="$VERSION"
95 PKGCONFIG_version=`eval echo "$PKGCONFIG_version"`
96 PKGCONFIG_version=`eval echo "$PKGCONFIG_version"`
97 AC_MSG_RESULT($PKGCONFIG_version)
98
99 AC_MSG_CHECKING(our pkgconfig_libdir)
100 test ".$pkgconfig_libdir" = "." && \
101 pkgconfig_libdir='${libdir}/pkgconfig'
102 PKGCONFIG_libdir=`eval echo "$pkgconfig_libdir"`
103 PKGCONFIG_libdir=`eval echo "$PKGCONFIG_libdir"`
104 PKGCONFIG_libdir=`eval echo "$PKGCONFIG_libdir"`
105 AC_MSG_RESULT($pkgconfig_libdir)
106 test "$pkgconfig_libdir" != "$PKGCONFIG_libdir" && (
107 AC_MSG_RESULT(expanded our pkgconfig_libdir... $PKGCONFIG_libdir))
108 AC_SUBST([pkgconfig_libdir])
109
110 AC_MSG_CHECKING(our pkgconfig_libfile)
111 test ".$pkgconfig_libfile" != "." || \
112 pkgconfig_libfile="ifelse($1,,$PKGCONFIG_libname.pc,`basename $1`)"
113 PKGCONFIG_libfile=`eval echo "$pkgconfig_libfile"`
114 PKGCONFIG_libfile=`eval echo "$PKGCONFIG_libfile"`
115 AC_MSG_RESULT($pkgconfig_libfile)
116 test "$pkgconfig_libfile" != "$PKGCONFIG_libfile" && (
117 AC_MSG_RESULT(expanded our pkgconfig_libfile... $PKGCONFIG_libfile))
118 AC_SUBST([pkgconfig_libfile])
119
120 AC_MSG_CHECKING(our package / suffix)
121 PKGCONFIG_suffix="$program_suffix"
122 test ".$PKGCONFIG_suffix" != .NONE || PKGCONFIG_suffix=""
123 AC_MSG_RESULT(${PACKAGE_NAME} / ${PKGCONFIG_suffix})
124
125 AC_MSG_CHECKING(our pkgconfig description)
126 PKGCONFIG_description="ifelse($4,,$PACKAGE_SUMMARY,$4)"
127 test ".$PKGCONFIG_description" != "." || \
128 PKGCONFIG_description="$PKGCONFIG_libname Library"
129 PKGCONFIG_description=`eval echo "$PKGCONFIG_description"`
130 PKGCONFIG_description=`eval echo "$PKGCONFIG_description"`
131 AC_MSG_RESULT($PKGCONFIG_description)
132
133 AC_MSG_CHECKING(our pkgconfig requires)
134 PKGCONFIG_requires="ifelse($2,,$PACKAGE_REQUIRES,$2)"
135 PKGCONFIG_requires=`eval echo "$PKGCONFIG_requires"`
136 PKGCONFIG_requires=`eval echo "$PKGCONFIG_requires"`
137 AC_MSG_RESULT($PKGCONFIG_requires)
138
139 AC_MSG_CHECKING(our pkgconfig ext libs)
140 PKGCONFIG_pkglibs="$PACKAGE_LIBS"
141 test ".$PKGCONFIG_pkglibs" != "." || PKGCONFIG_pkglibs="-l$PKGCONFIG_libname"
142 PKGCONFIG_libs="ifelse($3,,$PKGCONFIG_pkglibs $LIBS,$3)"
143 PKGCONFIG_libs=`eval echo "$PKGCONFIG_libs"`
144 PKGCONFIG_libs=`eval echo "$PKGCONFIG_libs"`
145 AC_MSG_RESULT($PKGCONFIG_libs)
146
147 AC_MSG_CHECKING(our pkgconfig cppflags)
148 PKGCONFIG_cppflags="ifelse($5,,$CPPFLAGS $PACKAGE_CFLAGS,$5)"
149 PKGCONFIG_cppflags=`eval echo "$PKGCONFIG_cppflags"`
150 PKGCONFIG_cppflags=`eval echo "$PKGCONFIG_cppflags"`
151 AC_MSG_RESULT($PKGCONFIG_cppflags)
152
153 AC_MSG_CHECKING(our pkgconfig ldflags)
154 PKGCONFIG_ldflags="ifelse($6,,$LDFLAGS $PACKAGE_LDFLAGS,$5)"
155 PKGCONFIG_ldflags=`eval echo "$PKGCONFIG_ldflags"`
156 PKGCONFIG_ldflags=`eval echo "$PKGCONFIG_ldflags"`
157 AC_MSG_RESULT($PKGCONFIG_ldflags)
158
159 test ".$PKGCONFIG_generate" != "." || \
160 PKGCONFIG_generate="ifelse($1,,$PKGCONFIG_libname.pc,$1)"
161 PKGCONFIG_generate=`eval echo "$PKGCONFIG_generate"`
162 PKGCONFIG_generate=`eval echo "$PKGCONFIG_generate"`
163 test "$pkgconfig_libfile" != "$PKGCONFIG_generate" && (
164 AC_MSG_RESULT(generate the pkgconfig later... $PKGCONFIG_generate))
165
166 if test ".$PKGCONFIG_src_libdir" = "." ; then
167 PKGCONFIG_src_libdir=`pwd`
168 PKGCONFIG_src_libdir=`AS_DIRNAME("$PKGCONFIG_src_libdir/$PKGCONFIG_generate")`
169 test ! -d $PKGCONFIG_src_libdir/src || \
170 PKGCONFIG_src_libdir="$PKGCONFIG_src_libdir/src"
171 case ".$objdir" in
172 *libs) PKGCONFIG_src_libdir="$PKGCONFIG_src_libdir/$objdir" ;; esac
173 AC_MSG_RESULT(noninstalled pkgconfig -L $PKGCONFIG_src_libdir)
174 fi
175
176 if test ".$PKGCONFIG_src_headers" = "." ; then
177 PKGCONFIG_src_headers=`pwd`
178 v="$ac_top_srcdir" ;
179 test ".$v" != "." || v="$ax_spec_dir"
180 test ".$v" != "." || v="$srcdir"
181 case "$v" in /*) PKGCONFIG_src_headers="" ;; esac
182 PKGCONFIG_src_headers=`AS_DIRNAME("$PKGCONFIG_src_headers/$v/x")`
183 test ! -d $PKGCONFIG_src_headers/incl[]ude || \
184 PKGCONFIG_src_headers="$PKGCONFIG_src_headers/incl[]ude"
185 AC_MSG_RESULT(noninstalled pkgconfig -I $PKGCONFIG_src_headers)
186 fi
187
188
189 dnl AC_CONFIG_COMMANDS crap disallows to use $PKGCONFIG_libfile here...
190 AC_CONFIG_COMMANDS([$ax_create_pkgconfig_generate],[
191 pkgconfig_generate="$ax_create_pkgconfig_generate"
192 if test ! -f "$pkgconfig_generate.in"
193 then generate="true"
194 elif grep ' generated by configure ' $pkgconfig_generate.in >/dev/null
195 then generate="true"
196 else generate="false";
197 fi
198 if $generate ; then
199 AC_MSG_NOTICE(creating $pkgconfig_generate.in)
200 cat > $pkgconfig_generate.in <<AXEOF
201 # generated by configure / remove this line to disable regeneration
202 prefix=@prefix@
203 exec_prefix=@exec_prefix@
204 bindir=@bindir@
205 libdir=@libdir@
206 datarootdir=@datarootdir@
207 datadir=@datadir@
208 sysconfdir=@sysconfdir@
209 includedir=@includedir@
210 package=@PACKAGE@
211 suffix=@suffix@
212
213 Name: @PACKAGE_NAME@
214 Description: @PACKAGE_DESCRIPTION@
215 Version: @PACKAGE_VERSION@
216 Requires: @PACKAGE_REQUIRES@
217 Libs: -L\${libdir} @LDFLAGS@ @LIBS@
218 Cflags: -I\${includedir} @CPPFLAGS@
219 AXEOF
220 fi # DONE generate $pkgconfig_generate.in
221 AC_MSG_NOTICE(creating $pkgconfig_generate)
222 cat >conftest.sed <<AXEOF
223 s|@prefix@|${pkgconfig_prefix}|
224 s|@exec_prefix@|${pkgconfig_execprefix}|
225 s|@bindir@|${pkgconfig_bindir}|
226 s|@libdir@|${pkgconfig_libdir}|
227 s|@datarootdir@|${pkgconfig_datarootdir}|
228 s|@datadir@|${pkgconfig_datadir}|
229 s|@sysconfdir@|${pkgconfig_sysconfdir}|
230 s|@includedir@|${pkgconfig_includedir}|
231 s|@suffix@|${pkgconfig_suffix}|
232 s|@PACKAGE@|${pkgconfig_package}|
233 s|@PACKAGE_NAME@|${pkgconfig_libname}|
234 s|@PACKAGE_DESCRIPTION@|${pkgconfig_description}|
235 s|@PACKAGE_VERSION@|${pkgconfig_version}|
236 s|@PACKAGE_REQUIRES@|${pkgconfig_requires}|
237 s|@LIBS@|${pkgconfig_libs}|
238 s|@LDFLAGS@|${pkgconfig_ldflags}|
239 s|@CPPFLAGS@|${pkgconfig_cppflags}|
240 AXEOF
241 sed -f conftest.sed  $pkgconfig_generate.in > $pkgconfig_generate
242 if test ! -s $pkgconfig_generate ; then
243     AC_MSG_ERROR([$pkgconfig_generate is empty])
244 fi ; rm conftest.sed # DONE generate $pkgconfig_generate
245 pkgconfig_uninstalled=`echo $pkgconfig_generate |sed 's/.pc$/-uninstalled.pc/'`
246 AC_MSG_NOTICE(creating $pkgconfig_uninstalled)
247 cat >conftest.sed <<AXEOF
248 s|@prefix@|${pkgconfig_prefix}|
249 s|@exec_prefix@|${pkgconfig_execprefix}|
250 s|@bindir@|${pkgconfig_bindir}|
251 s|@libdir@|${pkgconfig_src_libdir}|
252 s|@datarootdir@|${pkgconfig_datarootdir}|
253 s|@datadir@|${pkgconfig_datadir}|
254 s|@sysconfdir@|${pkgconfig_sysconfdir}|
255 s|@includedir@|${pkgconfig_src_headers}|
256 s|@suffix@|${pkgconfig_suffix}|
257 s|@PACKAGE@|${pkgconfig_package}|
258 s|@PACKAGE_NAME@|${pkgconfig_libname}|
259 s|@PACKAGE_DESCRIPTION@|${pkgconfig_description}|
260 s|@PACKAGE_VERSION@|${pkgconfig_version}|
261 s|@PACKAGE_REQUIRES@|${pkgconfig_requires}|
262 s|@LIBS@|${pkgconfig_libs}|
263 s|@LDFLAGS@|${pkgconfig_ldflags}|
264 s|@CPPFLAGS@|${pkgconfig_cppflags}|
265 AXEOF
266 sed -f conftest.sed $pkgconfig_generate.in > $pkgconfig_uninstalled
267 if test ! -s $pkgconfig_uninstalled ; then
268     AC_MSG_ERROR([$pkgconfig_uninstalled is empty])
269 fi ; rm conftest.sed # DONE generate $pkgconfig_uninstalled
270            pkgconfig_requires_add=`echo ${pkgconfig_requires}`
271 if test ".$pkgconfig_requires_add" != "." ; then
272            pkgconfig_requires_add="pkg-config $pkgconfig_requires_add"
273     else   pkgconfig_requires_add=":" ; fi
274 pkgconfig_uninstalled=`echo $pkgconfig_generate |sed 's/.pc$/-uninstalled.sh/'`
275 AC_MSG_NOTICE(creating $pkgconfig_uninstalled)
276 cat >conftest.sed <<AXEOF
277 s|@prefix@|\"${pkgconfig_prefix}\"|
278 s|@exec_prefix@|\"${pkgconfig_execprefix}\"|
279 s|@bindir@|\"${pkgconfig_bindir}\"|
280 s|@libdir@|\"${pkgconfig_src_libdir}\"|
281 s|@datarootdir@|\"${pkgconfig_datarootdir}\"|
282 s|@datadir@|\"${pkgconfig_datadir}\"|
283 s|@sysconfdir@|\"${pkgconfig_sysconfdir}\"|
284 s|@includedir@|\"${pkgconfig_src_headers}\"|
285 s|@suffix@|\"${pkgconfig_suffix}\"|
286 s|@PACKAGE@|\"${pkgconfig_package}\"|
287 s|@PACKAGE_NAME@|\"${pkgconfig_libname}\"|
288 s|@PACKAGE_DESCRIPTION@|\"${pkgconfig_description}\"|
289 s|@PACKAGE_VERSION@|\"${pkgconfig_version}\"|
290 s|@PACKAGE_REQUIRES@|\"${pkgconfig_requires}\"|
291 s|@LIBS@|\"${pkgconfig_libs}\"|
292 s|@LDFLAGS@|\"${pkgconfig_ldflags}\"|
293 s|@CPPFLAGS@|\"${pkgconfig_cppflags}\"|
294 s>Name:>for option\\; do case \"\$option\" in --list-all|--name) echo >
295 s>Description: *>\\;\\; --help) pkg-config --help \\; echo Buildscript Of >
296 s>Version: *>\\;\\; --modversion|--version) echo >
297 s>Requires:>\\;\\; --requires) echo $pkgconfig_requires_add>
298 s>Libs: *>\\;\\; --libs) echo >
299 s>Cflags: *>\\;\\; --cflags) echo >
300 /--libs)/a\\
301        $pkgconfig_requires_add
302 /--cflags)/a\\
303        $pkgconfig_requires_add\\
304 ;; --variable=*) eval echo '\$'\`echo \$option | sed -e 's/.*=//'\`\\
305 ;; --uninstalled) exit 0 \\
306 ;; *) ;; esac done
307 AXEOF
308 sed -f conftest.sed  $pkgconfig_generate.in > $pkgconfig_uninstalled
309 if test ! -s $pkgconfig_uninstalled ; then
310     AC_MSG_ERROR([$pkgconfig_uninstalled is empty])
311 fi ; rm conftest.sed # DONE generate $pkgconfig_uninstalled
312 ],[
313 dnl AC_CONFIG_COMMANDS crap, the AS_PUSHVAR defines are invalid here...
314 ax_create_pkgconfig_generate="$ax_create_pkgconfig_generate"
315 pkgconfig_prefix='$prefix'
316 pkgconfig_execprefix='$exec_prefix'
317 pkgconfig_bindir='$bindir'
318 pkgconfig_libdir='$libdir'
319 pkgconfig_includedir='$includedir'
320 pkgconfig_datarootdir='$datarootdir'
321 pkgconfig_datadir='$datadir'
322 pkgconfig_sysconfdir='$sysconfdir'
323 pkgconfig_suffix='$ax_create_pkgconfig_suffix'
324 pkgconfig_package='$PACKAGE_NAME'
325 pkgconfig_libname='$ax_create_pkgconfig_libname'
326 pkgconfig_description='$ax_create_pkgconfig_description'
327 pkgconfig_version='$ax_create_pkgconfig_version'
328 pkgconfig_requires='$ax_create_pkgconfig_requires'
329 pkgconfig_libs='$ax_create_pkgconfig_libs'
330 pkgconfig_ldflags='$ax_create_pkgconfig_ldflags'
331 pkgconfig_cppflags='$ax_create_pkgconfig_cppflags'
332 pkgconfig_src_libdir='$ax_create_pkgconfig_src_libdir'
333 pkgconfig_src_headers='$ax_create_pkgconfig_src_headers'
334 ])dnl
335 AS_VAR_POPDEF([PKGCONFIG_suffix])dnl
336 AS_VAR_POPDEF([PKGCONFIG_libdir])dnl
337 AS_VAR_POPDEF([PKGCONFIG_libfile])dnl
338 AS_VAR_POPDEF([PKGCONFIG_libname])dnl
339 AS_VAR_POPDEF([PKGCONFIG_version])dnl
340 AS_VAR_POPDEF([PKGCONFIG_description])dnl
341 AS_VAR_POPDEF([PKGCONFIG_requires])dnl
342 AS_VAR_POPDEF([PKGCONFIG_pkglibs])dnl
343 AS_VAR_POPDEF([PKGCONFIG_libs])dnl
344 AS_VAR_POPDEF([PKGCONFIG_ldflags])dnl
345 AS_VAR_POPDEF([PKGCONFIG_cppflags])dnl
346 AS_VAR_POPDEF([PKGCONFIG_generate])dnl
347 AS_VAR_POPDEF([PKGCONFIG_src_libdir])dnl
348 AS_VAR_POPDEF([PKGCONFIG_src_headers])dnl
349 ])