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.
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])
24 dnl Check for the libupnp library
25 dnl --------------------------------------------------------------------------
27 dnl This macro sets these variables:
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
35 dnl "prefix" or "system"
36 dnl - LIBUPNP_CPPFLAGS
37 dnl Flags to be added to CPPFLAGS
39 dnl Flags to be added to CFLAGS
41 dnl Flags to be added to LDFLAGS
43 dnl Library to be added to LDADD
45 dnl The LIBUPNP_CPPFLAGS, LIBUPNP_LDFLAGS and LIBUPNP_LIBS variables are also substituted.
47 AC_DEFUN([LIBUPNP_CHECK],
49 m4_define([MIN_LIBUPNP_VERSION], [m4_ifval([$1], [$1], [1.6.6])])dnl
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
63 LIBUPNP_VERSION_STRING=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --modversion)
64 AS_IF([test -n "LIBUPNP_VERSION_STRING"], [dnl
66 resultstr=" (prefix specified in --with-libupnp-prefix=PREFIX)"dnl
69 resultstr=" (maybe an invalid prefix was specified in --with-libupnp-prefix=PREFIX)"dnl
72 LIBUPNP_PREFIX=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --prefix)
74 LIBUPNP_VERSION_STRING=$(PKG_CONFIG_PATH=$LIBUPNP_PREFIX/lib/pkgconfig pkg-config libupnp --modversion)
75 AS_IF([test -n "LIBUPNP_VERSION_STRING"], [dnl
77 resultstr=" (installed in the system)"dnl
80 resultstr=" (try to use --with-libupnp-prefix=PREFIX)"dnl
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
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
104 resultstr=" (version $LIBUPNP_VERSION_STRING is not new enough)"dnl
106 AC_MSG_RESULT([$result$resultstr])
109 dnl Execute the right action.
110 m4_ifval([$2$3], [AS_IF([test ${result:-no} = yes], [$2], [$3])])
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