Upstream tarball 20080701
[amule.git] / m4 / libupnp.m4
blob6ea19cda18c7180c746a5ed1dde40d7c3bcc6448
2 # This file is part of the libupnp library project.
4 # Copyright (c) 2008 Marcelo Roberto Jimenez (mroberto@users.sf.net)
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
21 dnl --------------------------------------------------------------------------
22 dnl LIBUPNP_CHECK([VERSION = 1.6.6], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
23 dnl
24 dnl Check for the libupnp library
25 dnl --------------------------------------------------------------------------
26 dnl
27 dnl This macro sets these variables:
28 dnl - LIBUPNP_PREFIX
29 dnl     This is the user or system directory where libupnp is installed.
30 dnl - LIBUPNP_VERSION_STRING
31 dnl     Something like "1.6.7"
32 dnl - LIBUPNP_VERSION_NUMBER
33 dnl     Something like 1006007
34 dnl - LIBUPNP_STYLE
35 dnl     "prefix" or "system"
36 dnl - LIBUPNP_CPPFLAGS
37 dnl     Flags to be added to CPPFLAGS
38 dnl - LIBUPNP_CFLAGS
39 dnl     Flags to be added to CFLAGS
40 dnl - LIBUPNP_LDFLAGS
41 dnl     Flags to be added to LDFLAGS
42 dnl - LIBUPNP_LDADD
43 dnl     Library to be added to LDADD
44 dnl
45 dnl The LIBUPNP_CPPFLAGS, LIBUPNP_LDFLAGS and LIBUPNP_LIBS variables are also substituted.
46 dnl
47 AC_DEFUN([LIBUPNP_CHECK],
48 [dnl
49 m4_define([MIN_LIBUPNP_VERSION], [m4_ifval([$1], [$1], [1.6.6])])dnl
51 dnl     Test for --with
52         AC_ARG_WITH(
53                 [libupnp-prefix],
54                 [AS_HELP_STRING(
55                         [--with-libupnp-prefix=PREFIX],
56                         [UPnP library location])],
57                 [LIBUPNP_PREFIX="$withval"])
59 dnl     Check for the presence
60         AC_MSG_CHECKING([for libupnp presence])
61         AS_IF([test -n "$LIBUPNP_PREFIX"],[dnl
62                 LIBUPNP_STYLE=prefix
63                 LIBUPNP_VERSION_STRING=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --modversion)
64                 AS_IF([test -n "LIBUPNP_VERSION_STRING"], [dnl
65                         result=yes
66                         resultstr=" (prefix specified in --with-libupnp-prefix=PREFIX)"dnl
67                 ], [dnl
68                         result=no
69                         resultstr=" (maybe an invalid prefix was specified in --with-libupnp-prefix=PREFIX)"dnl
70                 ])dnl
71         ],[dnl
72                 LIBUPNP_PREFIX=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --prefix)
73                 LIBUPNP_STYLE=system
74                 LIBUPNP_VERSION_STRING=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --modversion)
75                 AS_IF([test -n "LIBUPNP_VERSION_STRING"], [dnl
76                         result=yes
77                         resultstr=" (installed in the system)"dnl
78                 ], [dnl
79                         result=no
80                         resultstr=" (try to use --with-libupnp-prefix=PREFIX)"dnl
81                 ])dnl
82         ])
83         AC_MSG_RESULT([$result$resultstr])
85         AS_IF([test x$result = xyes],[dnl
86 dnl             Ok, we know that libupnp is in the system, check for the mininum library version required.
87                 AC_MSG_CHECKING([for libupnp version >= MIN_LIBUPNP_VERSION])
88                 # Find out the libupnp version and check against the minimum required
89                 LIBUPNP_VERSION_NUMBER=`echo $LIBUPNP_VERSION_STRING | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
90                 minvers=`echo MIN_LIBUPNP_VERSION | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`
92                 AS_IF([test -n "$LIBUPNP_VERSION_NUMBER" && test "$LIBUPNP_VERSION_NUMBER" -ge $minvers], [dnl
93                         result=yes
94                         resultstr=" (version $LIBUPNP_VERSION_STRING)"
95                         LIBUPNP_CPPFLAGS=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --cflags-only-I)
96                         LIBUPNP_CFLAGS=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --cflags-only-other)
97                         LIBUPNP_LDFLAGS=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --libs-only-other)
98                         LIBUPNP_LDADD=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --libs-only-L)
99                         LIBUPNP_LDADD="$LIBUPNP_LDADD $(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --libs-only-l)"
100                         AH_TEMPLATE([LIBUPNP_INCLUDE_PREFIX], [Define this to the include prefix of libupnp])
101                         AC_DEFINE_UNQUOTED([LIBUPNP_INCLUDE_PREFIX], $LIBUPNP_INCLUDE_PREFIX)dnl
102                 ], [dnl
103                         result=no
104                         resultstr=" (version $LIBUPNP_VERSION_STRING is not new enough)"dnl
105                 ])
106                 AC_MSG_RESULT([$result$resultstr])
107         ])
109 dnl     Execute the right action.
110         m4_ifval([$2$3], [AS_IF([test ${result:-no} = yes], [$2], [$3])])
112 dnl Exported symbols
113 AC_SUBST([LIBUPNP_CPPFLAGS])dnl
114 AC_SUBST([LIBUPNP_CFLAGS])dnl
115 AC_SUBST([LIBUPNP_LDFLAGS])dnl
116 AC_SUBST([LIBUPNP_LDADD])dnl
117 m4_undefine([MIN_LIBUPNP_VERSION])dnl