1# ============================================================================
2#  http://www.gnu.org/software/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 = $PACKAGE_CFLAGS (as set at the point in configure.ac)
18#     $6 = $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 3 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#serial 12
62
63AC_DEFUN([AX_CREATE_PKGCONFIG_INFO],[dnl
64AS_VAR_PUSHDEF([PKGCONFIG_suffix],[ax_create_pkgconfig_suffix])dnl
65AS_VAR_PUSHDEF([PKGCONFIG_libdir],[ax_create_pkgconfig_libdir])dnl
66AS_VAR_PUSHDEF([PKGCONFIG_libfile],[ax_create_pkgconfig_libfile])dnl
67AS_VAR_PUSHDEF([PKGCONFIG_libname],[ax_create_pkgconfig_libname])dnl
68AS_VAR_PUSHDEF([PKGCONFIG_version],[ax_create_pkgconfig_version])dnl
69AS_VAR_PUSHDEF([PKGCONFIG_description],[ax_create_pkgconfig_description])dnl
70AS_VAR_PUSHDEF([PKGCONFIG_requires],[ax_create_pkgconfig_requires])dnl
71AS_VAR_PUSHDEF([PKGCONFIG_pkglibs],[ax_create_pkgconfig_pkglibs])dnl
72AS_VAR_PUSHDEF([PKGCONFIG_libs],[ax_create_pkgconfig_libs])dnl
73AS_VAR_PUSHDEF([PKGCONFIG_ldflags],[ax_create_pkgconfig_ldflags])dnl
74AS_VAR_PUSHDEF([PKGCONFIG_cppflags],[ax_create_pkgconfig_cppflags])dnl
75AS_VAR_PUSHDEF([PKGCONFIG_generate],[ax_create_pkgconfig_generate])dnl
76AS_VAR_PUSHDEF([PKGCONFIG_src_libdir],[ax_create_pkgconfig_src_libdir])dnl
77AS_VAR_PUSHDEF([PKGCONFIG_src_headers],[ax_create_pkgconfig_src_headers])dnl
78
79# we need the expanded forms...
80test "x$prefix" = xNONE && prefix=$ac_default_prefix
81test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
82
83AC_MSG_CHECKING(our pkgconfig libname)
84test ".$PKGCONFIG_libname" != "." || \
85PKGCONFIG_libname="ifelse($1,,${PACKAGE_NAME},`basename $1 .pc`)"
86test ".$PKGCONFIG_libname" != "." || \
87PKGCONFIG_libname="$PACKAGE"
88PKGCONFIG_libname=`eval echo "$PKGCONFIG_libname"`
89PKGCONFIG_libname=`eval echo "$PKGCONFIG_libname"`
90AC_MSG_RESULT($PKGCONFIG_libname)
91
92AC_MSG_CHECKING(our pkgconfig version)
93test ".$PKGCONFIG_version" != "." || \
94PKGCONFIG_version="${PACKAGE_VERSION}"
95test ".$PKGCONFIG_version" != "." || \
96PKGCONFIG_version="$VERSION"
97PKGCONFIG_version=`eval echo "$PKGCONFIG_version"`
98PKGCONFIG_version=`eval echo "$PKGCONFIG_version"`
99AC_MSG_RESULT($PKGCONFIG_version)
100
101AC_MSG_CHECKING(our pkgconfig_libdir)
102test ".$pkgconfig_libdir" = "." && \
103pkgconfig_libdir='${libdir}/pkgconfig'
104PKGCONFIG_libdir=`eval echo "$pkgconfig_libdir"`
105PKGCONFIG_libdir=`eval echo "$PKGCONFIG_libdir"`
106PKGCONFIG_libdir=`eval echo "$PKGCONFIG_libdir"`
107AC_MSG_RESULT($pkgconfig_libdir)
108test "$pkgconfig_libdir" != "$PKGCONFIG_libdir" && (
109AC_MSG_RESULT(expanded our pkgconfig_libdir... $PKGCONFIG_libdir))
110AC_SUBST([pkgconfig_libdir])
111
112AC_MSG_CHECKING(our pkgconfig_libfile)
113test ".$pkgconfig_libfile" != "." || \
114pkgconfig_libfile="ifelse($1,,$PKGCONFIG_libname.pc,`basename $1`)"
115PKGCONFIG_libfile=`eval echo "$pkgconfig_libfile"`
116PKGCONFIG_libfile=`eval echo "$PKGCONFIG_libfile"`
117AC_MSG_RESULT($pkgconfig_libfile)
118test "$pkgconfig_libfile" != "$PKGCONFIG_libfile" && (
119AC_MSG_RESULT(expanded our pkgconfig_libfile... $PKGCONFIG_libfile))
120AC_SUBST([pkgconfig_libfile])
121
122AC_MSG_CHECKING(our package / suffix)
123PKGCONFIG_suffix="$program_suffix"
124test ".$PKGCONFIG_suffix" != .NONE || PKGCONFIG_suffix=""
125AC_MSG_RESULT(${PACKAGE_NAME} / ${PKGCONFIG_suffix})
126
127AC_MSG_CHECKING(our pkgconfig description)
128PKGCONFIG_description="ifelse($4,,$PACKAGE_SUMMARY,$4)"
129test ".$PKGCONFIG_description" != "." || \
130PKGCONFIG_description="$PKGCONFIG_libname Library"
131PKGCONFIG_description=`eval echo "$PKGCONFIG_description"`
132PKGCONFIG_description=`eval echo "$PKGCONFIG_description"`
133AC_MSG_RESULT($PKGCONFIG_description)
134
135AC_MSG_CHECKING(our pkgconfig requires)
136PKGCONFIG_requires="ifelse($2,,$PACKAGE_REQUIRES,$2)"
137PKGCONFIG_requires=`eval echo "$PKGCONFIG_requires"`
138PKGCONFIG_requires=`eval echo "$PKGCONFIG_requires"`
139AC_MSG_RESULT($PKGCONFIG_requires)
140
141AC_MSG_CHECKING(our pkgconfig ext libs)
142PKGCONFIG_pkglibs="$PACKAGE_LIBS"
143test ".$PKGCONFIG_pkglibs" != "." || PKGCONFIG_pkglibs="-l$PKGCONFIG_libname"
144PKGCONFIG_libs="ifelse($3,,$PKGCONFIG_pkglibs $LIBS,$3)"
145PKGCONFIG_libs=`eval echo "$PKGCONFIG_libs"`
146PKGCONFIG_libs=`eval echo "$PKGCONFIG_libs"`
147AC_MSG_RESULT($PKGCONFIG_libs)
148
149AC_MSG_CHECKING(our pkgconfig cppflags)
150PKGCONFIG_cppflags="ifelse($5,,$PACKAGE_CFLAGS,$5)"
151PKGCONFIG_cppflags=`eval echo "$PKGCONFIG_cppflags"`
152PKGCONFIG_cppflags=`eval echo "$PKGCONFIG_cppflags"`
153AC_MSG_RESULT($PKGCONFIG_cppflags)
154
155AC_MSG_CHECKING(our pkgconfig ldflags)
156PKGCONFIG_ldflags="ifelse($6,,$PACKAGE_LDFLAGS,$5)"
157PKGCONFIG_ldflags=`eval echo "$PKGCONFIG_ldflags"`
158PKGCONFIG_ldflags=`eval echo "$PKGCONFIG_ldflags"`
159AC_MSG_RESULT($PKGCONFIG_ldflags)
160
161test ".$PKGCONFIG_generate" != "." || \
162PKGCONFIG_generate="ifelse($1,,$PKGCONFIG_libname.pc,$1)"
163PKGCONFIG_generate=`eval echo "$PKGCONFIG_generate"`
164PKGCONFIG_generate=`eval echo "$PKGCONFIG_generate"`
165test "$pkgconfig_libfile" != "$PKGCONFIG_generate" && (
166AC_MSG_RESULT(generate the pkgconfig later... $PKGCONFIG_generate))
167
168if test ".$PKGCONFIG_src_libdir" = "." ; then
169PKGCONFIG_src_libdir=`pwd`
170PKGCONFIG_src_libdir=`AS_DIRNAME("$PKGCONFIG_src_libdir/$PKGCONFIG_generate")`
171test ! -d $PKGCONFIG_src_libdir/src || \
172PKGCONFIG_src_libdir="$PKGCONFIG_src_libdir/src"
173case ".$objdir" in
174*libs) PKGCONFIG_src_libdir="$PKGCONFIG_src_libdir/$objdir" ;; esac
175AC_MSG_RESULT(noninstalled pkgconfig -L $PKGCONFIG_src_libdir)
176fi
177
178if test ".$PKGCONFIG_src_headers" = "." ; then
179PKGCONFIG_src_headers=`pwd`
180v="$ac_top_srcdir" ;
181test ".$v" != "." || v="$ax_spec_dir"
182test ".$v" != "." || v="$srcdir"
183case "$v" in /*) PKGCONFIG_src_headers="" ;; esac
184PKGCONFIG_src_headers=`AS_DIRNAME("$PKGCONFIG_src_headers/$v/x")`
185test ! -d $PKGCONFIG_src_headers/incl[]ude || \
186PKGCONFIG_src_headers="$PKGCONFIG_src_headers/incl[]ude"
187AC_MSG_RESULT(noninstalled pkgconfig -I $PKGCONFIG_src_headers)
188fi
189
190
191dnl AC_CONFIG_COMMANDS crap disallows to use $PKGCONFIG_libfile here...
192AC_CONFIG_COMMANDS([$ax_create_pkgconfig_generate],[
193pkgconfig_generate="$ax_create_pkgconfig_generate"
194if test ! -f "$pkgconfig_generate.in"
195then generate="true"
196elif grep ' generated by configure ' $pkgconfig_generate.in >/dev/null
197then generate="true"
198else generate="false";
199fi
200if $generate ; then
201AC_MSG_NOTICE(creating $pkgconfig_generate.in)
202cat > $pkgconfig_generate.in <<AXEOF
203# generated by configure / remove this line to disable regeneration
204prefix=@prefix@
205exec_prefix=@exec_prefix@
206bindir=@bindir@
207libdir=@libdir@
208datarootdir=@datarootdir@
209datadir=@datadir@
210sysconfdir=@sysconfdir@
211includedir=@includedir@
212package=@PACKAGE@
213suffix=@suffix@
214
215Name: @PACKAGE_NAME@
216Description: @PACKAGE_DESCRIPTION@
217Version: @PACKAGE_VERSION@
218Requires: @PACKAGE_REQUIRES@
219Libs: -L\${libdir} @LDFLAGS@ @LIBS@
220Cflags: -I\${includedir} @CPPFLAGS@
221AXEOF
222fi # DONE generate $pkgconfig_generate.in
223AC_MSG_NOTICE(creating $pkgconfig_generate)
224cat >conftest.sed <<AXEOF
225s|@prefix@|${pkgconfig_prefix}|
226s|@exec_prefix@|${pkgconfig_execprefix}|
227s|@bindir@|${pkgconfig_bindir}|
228s|@libdir@|${pkgconfig_libdir}|
229s|@datarootdir@|${pkgconfig_datarootdir}|
230s|@datadir@|${pkgconfig_datadir}|
231s|@sysconfdir@|${pkgconfig_sysconfdir}|
232s|@includedir@|${pkgconfig_includedir}|
233s|@suffix@|${pkgconfig_suffix}|
234s|@PACKAGE@|${pkgconfig_package}|
235s|@PACKAGE_NAME@|${pkgconfig_libname}|
236s|@PACKAGE_DESCRIPTION@|${pkgconfig_description}|
237s|@PACKAGE_VERSION@|${pkgconfig_version}|
238s|@PACKAGE_REQUIRES@|${pkgconfig_requires}|
239s|@LIBS@|${pkgconfig_libs}|
240s|@LDFLAGS@|${pkgconfig_ldflags}|
241s|@CPPFLAGS@|${pkgconfig_cppflags}|
242AXEOF
243sed -f conftest.sed  $pkgconfig_generate.in > $pkgconfig_generate
244if test ! -s $pkgconfig_generate ; then
245    AC_MSG_ERROR([$pkgconfig_generate is empty])
246fi ; rm conftest.sed # DONE generate $pkgconfig_generate
247pkgconfig_uninstalled=`echo $pkgconfig_generate |sed 's/.pc$/-uninstalled.pc/'`
248AC_MSG_NOTICE(creating $pkgconfig_uninstalled)
249cat >conftest.sed <<AXEOF
250s|@prefix@|${pkgconfig_prefix}|
251s|@exec_prefix@|${pkgconfig_execprefix}|
252s|@bindir@|${pkgconfig_bindir}|
253s|@libdir@|${pkgconfig_src_libdir}|
254s|@datarootdir@|${pkgconfig_datarootdir}|
255s|@datadir@|${pkgconfig_datadir}|
256s|@sysconfdir@|${pkgconfig_sysconfdir}|
257s|@includedir@|${pkgconfig_src_headers}|
258s|@suffix@|${pkgconfig_suffix}|
259s|@PACKAGE@|${pkgconfig_package}|
260s|@PACKAGE_NAME@|${pkgconfig_libname}|
261s|@PACKAGE_DESCRIPTION@|${pkgconfig_description}|
262s|@PACKAGE_VERSION@|${pkgconfig_version}|
263s|@PACKAGE_REQUIRES@|${pkgconfig_requires}|
264s|@LIBS@|${pkgconfig_libs}|
265s|@LDFLAGS@|${pkgconfig_ldflags}|
266s|@CPPFLAGS@|${pkgconfig_cppflags}|
267AXEOF
268sed -f conftest.sed $pkgconfig_generate.in > $pkgconfig_uninstalled
269if test ! -s $pkgconfig_uninstalled ; then
270    AC_MSG_ERROR([$pkgconfig_uninstalled is empty])
271fi ; rm conftest.sed # DONE generate $pkgconfig_uninstalled
272           pkgconfig_requires_add=`echo ${pkgconfig_requires}`
273if test ".$pkgconfig_requires_add" != "." ; then
274           pkgconfig_requires_add="pkg-config $pkgconfig_requires_add"
275    else   pkgconfig_requires_add=":" ; fi
276pkgconfig_uninstalled=`echo $pkgconfig_generate |sed 's/.pc$/-uninstalled.sh/'`
277AC_MSG_NOTICE(creating $pkgconfig_uninstalled)
278cat >conftest.sed <<AXEOF
279s|@prefix@|\"${pkgconfig_prefix}\"|
280s|@exec_prefix@|\"${pkgconfig_execprefix}\"|
281s|@bindir@|\"${pkgconfig_bindir}\"|
282s|@libdir@|\"${pkgconfig_src_libdir}\"|
283s|@datarootdir@|\"${pkgconfig_datarootdir}\"|
284s|@datadir@|\"${pkgconfig_datadir}\"|
285s|@sysconfdir@|\"${pkgconfig_sysconfdir}\"|
286s|@includedir@|\"${pkgconfig_src_headers}\"|
287s|@suffix@|\"${pkgconfig_suffix}\"|
288s|@PACKAGE@|\"${pkgconfig_package}\"|
289s|@PACKAGE_NAME@|\"${pkgconfig_libname}\"|
290s|@PACKAGE_DESCRIPTION@|\"${pkgconfig_description}\"|
291s|@PACKAGE_VERSION@|\"${pkgconfig_version}\"|
292s|@PACKAGE_REQUIRES@|\"${pkgconfig_requires}\"|
293s|@LIBS@|\"${pkgconfig_libs}\"|
294s|@LDFLAGS@|\"${pkgconfig_ldflags}\"|
295s|@CPPFLAGS@|\"${pkgconfig_cppflags}\"|
296s>Name:>for option\\; do case \"\$option\" in --list-all|--name) echo >
297s>Description: *>\\;\\; --help) pkg-config --help \\; echo Buildscript Of >
298s>Version: *>\\;\\; --modversion|--version) echo >
299s>Requires:>\\;\\; --requires) echo $pkgconfig_requires_add>
300s>Libs: *>\\;\\; --libs) echo >
301s>Cflags: *>\\;\\; --cflags) echo >
302/--libs)/a\\
303       $pkgconfig_requires_add
304/--cflags)/a\\
305       $pkgconfig_requires_add\\
306;; --variable=*) eval echo '\$'\`echo \$option | sed -e 's/.*=//'\`\\
307;; --uninstalled) exit 0 \\
308;; *) ;; esac done
309AXEOF
310sed -f conftest.sed  $pkgconfig_generate.in > $pkgconfig_uninstalled
311if test ! -s $pkgconfig_uninstalled ; then
312    AC_MSG_ERROR([$pkgconfig_uninstalled is empty])
313fi ; rm conftest.sed # DONE generate $pkgconfig_uninstalled
314],[
315dnl AC_CONFIG_COMMANDS crap, the AS_PUSHVAR defines are invalid here...
316ax_create_pkgconfig_generate="$ax_create_pkgconfig_generate"
317pkgconfig_prefix='$prefix'
318pkgconfig_execprefix='$exec_prefix'
319pkgconfig_bindir='$bindir'
320pkgconfig_libdir='$libdir'
321pkgconfig_includedir='$includedir'
322pkgconfig_datarootdir='$datarootdir'
323pkgconfig_datadir='$datadir'
324pkgconfig_sysconfdir='$sysconfdir'
325pkgconfig_suffix='$ax_create_pkgconfig_suffix'
326pkgconfig_package='$PACKAGE_NAME'
327pkgconfig_libname='$ax_create_pkgconfig_libname'
328pkgconfig_description='$ax_create_pkgconfig_description'
329pkgconfig_version='$ax_create_pkgconfig_version'
330pkgconfig_requires='$ax_create_pkgconfig_requires'
331pkgconfig_libs='$ax_create_pkgconfig_libs'
332pkgconfig_ldflags='$ax_create_pkgconfig_ldflags'
333pkgconfig_cppflags='$ax_create_pkgconfig_cppflags'
334pkgconfig_src_libdir='$ax_create_pkgconfig_src_libdir'
335pkgconfig_src_headers='$ax_create_pkgconfig_src_headers'
336])dnl
337AS_VAR_POPDEF([PKGCONFIG_suffix])dnl
338AS_VAR_POPDEF([PKGCONFIG_libdir])dnl
339AS_VAR_POPDEF([PKGCONFIG_libfile])dnl
340AS_VAR_POPDEF([PKGCONFIG_libname])dnl
341AS_VAR_POPDEF([PKGCONFIG_version])dnl
342AS_VAR_POPDEF([PKGCONFIG_description])dnl
343AS_VAR_POPDEF([PKGCONFIG_requires])dnl
344AS_VAR_POPDEF([PKGCONFIG_pkglibs])dnl
345AS_VAR_POPDEF([PKGCONFIG_libs])dnl
346AS_VAR_POPDEF([PKGCONFIG_ldflags])dnl
347AS_VAR_POPDEF([PKGCONFIG_cppflags])dnl
348AS_VAR_POPDEF([PKGCONFIG_generate])dnl
349AS_VAR_POPDEF([PKGCONFIG_src_libdir])dnl
350AS_VAR_POPDEF([PKGCONFIG_src_headers])dnl
351])
352