[Speex-dev] [PATCH] Use pkg-config (if available) to detect libogg. Fall back to old method if pkg-config fails.

Erik de Castro Lopo mle+la at mega-nerd.com
Sun Oct 25 03:24:18 PDT 2009


Hi all,

Here is a patch to user pkg-config (if available) to detect libogg and 
fall back to old method if pkg-config fails.

Pkg-config has the advantage that it can do configured to do the right
thing when cross-compiling.

Erik

---
 Makefile.am     |    4 +-
 autogen.sh      |   15 ++++++++++
 configure.ac    |   14 ++++++++-
 m4/Makefile.am  |    4 ++
 m4/extra_pkg.m4 |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 m4/Makefile.am
 create mode 100644 m4/extra_pkg.m4

diff --git a/Makefile.am b/Makefile.am
index 4b99faf..91bbed9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,9 +13,9 @@ pkgconfig_DATA = speex.pc speexdsp.pc
 EXTRA_DIST = Speex.spec Speex.spec.in Speex.kdevelop speex.m4 speex.pc.in README.blackfin README.symbian README.TI-DSP
 
 #Fools KDevelop into including all files
-SUBDIRS = libspeex include @src@ doc win32 symbian ti
+SUBDIRS = libspeex include @src@ doc win32 symbian ti m4
 
-DIST_SUBDIRS = libspeex include src doc win32 symbian ti
+DIST_SUBDIRS = libspeex include src doc win32 symbian ti m4
 
 rpm: dist
 	rpmbuild -ta ${PACKAGE}-${VERSION}.tar.gz
diff --git a/autogen.sh b/autogen.sh
index 87dc6ab..3ec8b73 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -4,6 +4,8 @@
 
 package="Speex"
 
+ACLOCAL_FLAGS="-I m4"
+
 olddir=`pwd`
 srcdir=`dirname $0`
 test -z "$srcdir" && srcdir=.
@@ -101,6 +103,19 @@ fi
 	DIE=1
 }
 
+
+echo -n "checking for pkg-config ... "
+result="yes"
+(pkg-config --version) < /dev/null > /dev/null 2>&1 || {
+        echo
+        echo "You must have pkg-config installed to compile $package."
+        echo "Download the appropriate package for your distribution."
+		result="no"
+        DIE=1
+}
+echo $result
+
+
 if test "$DIE" -eq 1; then
         exit 1
 fi
diff --git a/configure.ac b/configure.ac
index 3179521..7e70e33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,7 @@ PACKAGE=speex
 
 AC_SUBST(SPEEX_VERSION)
 
+AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
 AM_MAINTAINER_MODE
 
@@ -112,7 +113,16 @@ AC_MSG_RESULT($has_visibility)
 
 AC_CHECK_HEADERS(sys/soundcard.h sys/audioio.h)
 
-XIPH_PATH_OGG([src="src"], [src=""])
+# Test for availablitly of pkg-config.
+PKG_PROG_PKG_CONFIG
+
+if test -n "$PKG_CONFIG"; then
+	PKG_CHECK_MOD_VERSION(OGG, ogg >= 1.1.3, ac_cv_ogg=yes, ac_cv_ogg=no)
+	src=src
+	fi
+if test x$ac_cv_ogg != xyes; then
+	XIPH_PATH_OGG([src="src"], [src=""])
+	fi
 AC_SUBST(src)
 
 AC_CHECK_LIB(m, sin)
@@ -287,7 +297,7 @@ AC_DEFINE([_BUILD_SPEEX], [], [Defined only when Speex itself is build built])
 AC_OUTPUT([Makefile libspeex/Makefile src/Makefile doc/Makefile Speex.spec
            include/Makefile include/speex/Makefile speex.pc speexdsp.pc
            win32/Makefile win32/libspeex/Makefile win32/speexenc/Makefile
-           win32/speexdec/Makefile symbian/Makefile 
+           win32/speexdec/Makefile symbian/Makefile m4/Makefile
            win32/VS2003/Makefile
            win32/VS2003/tests/Makefile
            win32/VS2003/libspeex/Makefile
diff --git a/m4/Makefile.am b/m4/Makefile.am
new file mode 100644
index 0000000..a87e1b8
--- /dev/null
+++ b/m4/Makefile.am
@@ -0,0 +1,4 @@
+## Process this file with automake to produce Makefile.in. -*-Makefile-*-
+
+EXTRA_DIST = extra_pkg.m4
+
diff --git a/m4/extra_pkg.m4 b/m4/extra_pkg.m4
new file mode 100644
index 0000000..a92d090
--- /dev/null
+++ b/m4/extra_pkg.m4
@@ -0,0 +1,85 @@
+# extra_pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-
+# 
+# Copyright (c) 2004 Scott James Remnant <scott at netsplit.com>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# --------------------------------------------------------------
+# PKG_CHECK_MOD_VERSION(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+# [ACTION-IF-NOT-FOUND])
+#
+# This is a very slight modification to the macro PKG_CHECK_MODULES that
+# is in the original pkg.m4 file. It prints the versions in the checking
+# message (erikd at mega-nerd.com).
+
+AC_DEFUN([PKG_CHECK_MOD_VERSION],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
+
+pkg_failed=no
+AC_MSG_CHECKING([for $2 ])
+
+_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
+_PKG_CONFIG([$1][_LIBS], [libs], [$2])
+
+m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
+and $1[]_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.])
+
+if test $pkg_failed = yes; then
+        _PKG_SHORT_ERRORS_SUPPORTED
+        if test $_pkg_short_errors_supported = yes; then
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
+        else 
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
+
+	ifelse([$4], , [AC_MSG_ERROR(dnl
+[Package requirements ($2) were not met:
+
+$$1_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+_PKG_TEXT
+])],
+		[AC_MSG_RESULT([no])
+                $4])
+elif test $pkg_failed = untried; then
+	ifelse([$4], , [AC_MSG_FAILURE(dnl
+[The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+_PKG_TEXT
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.])],
+		[$4])
+else
+	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
+	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
+        AC_MSG_RESULT([yes])
+	ifelse([$3], , :, [$3])
+fi[]dnl
+])# PKG_CHECK_MOD_VERSION
-- 
1.6.3.3



More information about the Speex-dev mailing list