New file. This defines GNOME_CHECK_PKGCONFIG, GNOME_REQUIRE_PKGCONFIG and
authorMartin Baulig <martin@home-of-linux.org>
Wed, 22 Nov 2000 11:30:26 +0000 (11:30 +0000)
committerMartin Baulig <martin@src.gnome.org>
Wed, 22 Nov 2000 11:30:26 +0000 (11:30 +0000)
2000-11-22  Martin Baulig  <martin@home-of-linux.org>

* gnome-pkgconfig.m4: New file. This defines
GNOME_CHECK_PKGCONFIG, GNOME_REQUIRE_PKGCONFIG and
GNOME_PKGCONFIG_* macros from pkg-config.

svn path=/trunk/; revision=1469

macros2/ChangeLog
macros2/Makefile.am
macros2/gnome-pkgconfig.m4 [new file with mode: 0644]

index 202974e..0f9ceb4 100644 (file)
@@ -1,3 +1,9 @@
+2000-11-22  Martin Baulig  <martin@home-of-linux.org>
+
+       * gnome-pkgconfig.m4: New file. This defines
+       GNOME_CHECK_PKGCONFIG, GNOME_REQUIRE_PKGCONFIG and
+       GNOME_PKGCONFIG_* macros from pkg-config.
+
 2000-11-21  Martin Baulig  <baulig@suse.de>
 
        * gnome-support.m4, need-declaration.m4: Removed.
index 1a56948..1f384d0 100644 (file)
@@ -4,7 +4,7 @@ GNOME2_MACROS=                                  \
        compiler-flags.m4 gnome-common.m4 gnome-cxx-check.m4 \
        gnome-fileutils.m4 gnome-gettext.m4 gnome-gnorba-check.m4 \
        gnome-pthread-check.m4 gnome-x-checks.m4 gnome.m4 linger.m4 \
-       check-utmp.m4
+       check-utmp.m4 gnome-pkgconfig.m4
 
 EXTRA_DIST=$(GNOME2_MACROS) autogen.sh
 MAINTAINERCLEANFILES=macros2.dep
diff --git a/macros2/gnome-pkgconfig.m4 b/macros2/gnome-pkgconfig.m4
new file mode 100644 (file)
index 0000000..93d7f6c
--- /dev/null
@@ -0,0 +1,166 @@
+dnl
+dnl GNOME_CHECK_PKGCONFIG (script-if-enabled, [failflag])
+dnl
+AC_DEFUN([GNOME_CHECK_PKGCONFIG],[
+       AC_PATH_PROG(PKG_CONFIG, pkg-config)
+       have_pkgconfig=no
+       if test -x "$PKG_CONFIG" ; then
+           have_pkgconfig=yes
+       else
+           PKG_CONFIG=
+       fi
+       AC_MSG_CHECKING(for pkg-config)
+       if test $have_pkgconfig = yes ; then
+           AC_MSG_RESULT(yes)
+       else
+           AC_MSG_RESULT(not found)
+           if test x$2 = xfail; then
+               AC_MSG_ERROR([
+*** You need the latest pkg-config.
+*** Get the latest version of pkg-config from
+*** http://pkgconfig.sourceforce.net.])
+           fi
+       fi
+       AC_SUBST(PKG_CONFIG)
+])
+
+dnl
+dnl GNOME_REQUIRE_PKGCONFIG
+dnl
+AC_DEFUN([GNOME_REQUIRE_PKGCONFIG],[
+       GNOME_CHECK_PKGCONFIG([], fail)
+])
+
+dnl GNOME_PKGCONFIG_CHECK_VERSION() extracts up to 6 decimal numbers out of given-version
+dnl and required-version, using any non-number letters as delimiters. it then
+dnl compares each of those 6 numbers in order 1..6 to each other, requirering
+dnl all of the 6 given-version numbers to be greater than, or at least equal
+dnl to the corresponding number of required-version.
+dnl GNOME_PKGCONFIG_CHECK_VERSION(given-version, required-version [, match-action] [, else-action])
+AC_DEFUN(GNOME_PKGCONFIG_CHECK_VERSION,[
+AC_REQUIRE([GNOME_REQUIRE_PKGCONFIG])
+[eval `echo "$1:0:0:0:0:0:0" | sed -e 's/^[^0-9]*//' -e 's/[^0-9]\+/:/g' \
+ -e 's/\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):.*/ac_v1=\1 ac_v2=\2 ac_v3=\3 ac_v4=\4 ac_v5=\5 ac_v6=\6/' \
+`]
+[eval `echo "$2:0:0:0:0:0:0" | sed -e 's/^[^0-9]*//' -e 's/[^0-9]\+/:/g' \
+ -e 's/\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):.*/ac_r1=\1 ac_r2=\2 ac_r3=\3 ac_r4=\4 ac_r5=\5 ac_r6=\6/' \
+`]
+ac_vm=[`expr \( $ac_v1 \> $ac_r1 \) \| \( \( $ac_v1 \= $ac_r1 \) \& \(          \
+              \( $ac_v2 \> $ac_r2 \) \| \( \( $ac_v2 \= $ac_r2 \) \& \(         \
+               \( $ac_v3 \> $ac_r3 \) \| \( \( $ac_v3 \= $ac_r3 \) \& \(        \
+                \( $ac_v4 \> $ac_r4 \) \| \( \( $ac_v4 \= $ac_r4 \) \& \(       \
+                 \( $ac_v5 \> $ac_r5 \) \| \( \( $ac_v5 \= $ac_r5 \) \& \(      \
+                  \( $ac_v6 \>= $ac_r6 \)                                       \
+                 \) \)  \
+                \) \)   \
+               \) \)    \
+              \) \)     \
+             \) \)      `]
+case $ac_vm in
+[1)]
+        [$3]
+        ;;
+*[)]
+        [$4]
+        ;;
+esac
+])
+
+dnl Check if the C compiler accepts a certain C flag, and if so adds it to
+dnl CFLAGS
+AC_DEFUN(GNOME_PKGCONFIG_CHECK_CFLAG, [
+  AC_REQUIRE([GNOME_REQUIRE_PKGCONFIG])
+
+  AC_MSG_CHECKING(if C compiler accepts $1)
+  save_CFLAGS="$CFLAGS"
+
+  dnl make sure we add it only once
+  dnl this one doesn't seem to work: *[\ \     ]$1[\ \ ]*) ;;
+  case " $CFLAGS " in
+  *\ $1\ *) echo $ac_n "(already in CFLAGS) ... " ;;
+  *\ $1\       *) echo $ac_n "(already in CFLAGS) ... " ;;
+  *\   $1\ *) echo $ac_n "(already in CFLAGS) ... " ;;
+  *\   $1\     *) echo $ac_n "(already in CFLAGS) ... " ;;
+  *) CFLAGS="$CFLAGS $1" ;;
+  esac
+
+  AC_TRY_COMPILE([#include <stdio.h>], [printf("hello");],
+                [ AC_MSG_RESULT(yes)],dnl
+                [ CFLAGS="$save_CFLAGS" AC_MSG_RESULT(no) ])
+])
+
+dnl add $ACLOCAL_FLAGS (and optionally more dirs) to the aclocal
+dnl commandline, so make can work even if it needs to rerun aclocal
+AC_DEFUN(GNOME_PKGCONFIG_ACLOCALFLAGS,
+[
+  AC_REQUIRE([GNOME_REQUIRE_PKGCONFIG])
+
+  test -n "$ACLOCAL_FLAGS" && ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
+
+  for i in "$1"; do
+    ACLOCAL="$ACLOCAL -I $i"
+  done
+])
+
+AC_DEFUN(GNOME_PKGCONFIG_CHECK_MODULES,
+[
+    AC_REQUIRE([GNOME_REQUIRE_PKGCONFIG])
+
+    name=$1
+    depvar=$3
+
+    AC_MSG_CHECKING(for libraries)
+    pkg_list=""
+    for module in $2 ""; do
+       if test -n "$module"; then
+           if `echo $module |grep -q ":"`; then
+               dnl has version requirement
+               pkg_module_name=`echo $module |sed 's/\(.*\):.*/\1/'`
+               test_version=`echo $module |sed 's/.*:\(.*\)/\1/'`
+
+               msg=`$PKG_CONFIG $pkg_module_name 2>&1`
+               if test -z "$msg"; then
+                   dnl module exists
+                   pkg_version=`$PKG_CONFIG --modversion $pkg_module_name`
+                   GNOME_PKGCONFIG_CHECK_VERSION($pkg_version, $test_version,
+                       dnl has the right version
+                       echo $ac_n "$pkg_module_name "
+                       pkg_list="$pkg_list $pkg_module_name"
+                   ,
+                       AC_MSG_RESULT([($pkg_module_name)])
+                       AC_MSG_ERROR([An old version of $pkg_module_name (version $pkg_version) was found. You need at least version $test_version])
+                   )
+               else
+                   dnl doesn't exist
+                   AC_MSG_RESULT([($pkg_module_name)])
+                   AC_MSG_ERROR([$msg])
+               fi
+           else
+               msg=`$PKG_CONFIG $module 2>&1`
+               if test -z "$msg"; then
+                   echo $ac_n "$module "
+                   pkg_list="$pkg_list $module"
+               else
+                   AC_MSG_RESULT([($module)])
+                   AC_MSG_ERROR([$msg])
+               fi
+           fi
+       fi
+    done
+    AC_MSG_RESULT([])
+    if test -n "$pkg_list"; then
+       eval $name'_CFLAGS'=\"`$PKG_CONFIG --cflags $pkg_list`\"
+       eval $name'_LIBS'=\"`$PKG_CONFIG --libs $pkg_list`\"
+       if test -n "$depvar"; then
+           eval $depvar'_DEPENDS'=\"\$$depname'_DEPENDS' $pkg_list\"
+       else
+           eval $name'_DEPENDS'=\"$pkg_list\"
+       fi
+    fi
+    pkg_varlist=`$PKG_CONFIG --extra-flags $pkg_list`
+    if test -n "$pkg_varlist"; then
+       for pkgvar in $pkg_varlist; do
+           eval ${name}'_'${pkgvar}=\"`$PKG_CONFIG --get-flag $pkgvar $pkg_list`\"
+       done
+    fi
+])