From 6c4b0fc9e44ea3b9449e171404c1b2037d15d01e Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 31 Jul 2007 12:06:34 +0300 Subject: [PATCH] Extract pkgconfig and libtool dependencies automatically. Ported from rpm5.org work of Jeff Johnson. --- build/rpmfc.c | 36 +++++++++++++++++++++++++++++++++--- build/rpmfc.h | 2 ++ macros.in | 6 ++++++ scripts/Makefile.am | 3 ++- scripts/libtooldeps.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ scripts/pkgconfigdeps.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 scripts/libtooldeps.sh create mode 100755 scripts/pkgconfigdeps.sh diff --git a/build/rpmfc.c b/build/rpmfc.c index 1266935..0017af3 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -463,6 +463,9 @@ static struct rpmfcTokens_s rpmfcTokens[] = { /* XXX "python 2.3 byte-compiled" */ { "python ", RPMFC_PYTHON|RPMFC_INCLUDE }, + { "libtool library ", RPMFC_LIBTOOL|RPMFC_INCLUDE }, + { "pkgconfig ", RPMFC_PKGCONFIG|RPMFC_INCLUDE }, + /* XXX .NET executables and libraries. file(1) cannot differ from win32 * executables unfortunately :( */ { "PE executable", RPMFC_MONO|RPMFC_INCLUDE }, @@ -739,7 +742,21 @@ static int rpmfcSCRIPT(rpmfc fc) if (is_executable) #endif xx = rpmfcHelper(fc, 'R', "python"); - } + } else + if (fc->fcolor->vals[fc->ix] & RPMFC_LIBTOOL) { + xx = rpmfcHelper(fc, 'P', "libtool"); +#ifdef NOTYET + if (is_executable) +#endif + xx = rpmfcHelper(fc, 'R', "libtool"); + } else + if (fc->fcolor->vals[fc->ix] & RPMFC_PKGCONFIG) { + xx = rpmfcHelper(fc, 'P', "pkgconfig"); +#ifdef NOTYET + if (is_executable) +#endif + xx = rpmfcHelper(fc, 'R', "pkgconfig"); + } else if (fc->fcolor->vals[fc->ix] & RPMFC_MONO) { xx = rpmfcHelper(fc, 'P', "mono"); if (is_executable) @@ -1093,6 +1110,8 @@ static struct rpmfcApplyTbl_s rpmfcApplyTable[] = { { rpmfcELF, RPMFC_ELF }, { rpmfcSCRIPT, (RPMFC_SCRIPT|RPMFC_PERL) }, { rpmfcSCRIPT, (RPMFC_SCRIPT|RPMFC_PYTHON) }, + { rpmfcSCRIPT, (RPMFC_SCRIPT|RPMFC_PKGCONFIG) }, + { rpmfcSCRIPT, (RPMFC_SCRIPT|RPMFC_LIBTOOL) }, { rpmfcSCRIPT, RPMFC_MONO }, { NULL, 0 } }; @@ -1258,10 +1277,21 @@ assert(s != NULL); case S_IFLNK: case S_IFREG: default: +#define _suffix(_s, _x) \ + (slen >= sizeof(_x) && !strcmp((_s)+slen-(sizeof(_x)-1), (_x))) + /* XXX all files with extension ".pm" are perl modules for now. */ -/*@-branchstate@*/ - if (slen >= sizeof(".pm") && !strcmp(s+slen-(sizeof(".pm")-1), ".pm")) + if (_suffix(s, ".pm")) ftype = "Perl5 module source text"; + + /* XXX all files with extension ".la" are libtool for now. */ + else if (_suffix(s, ".la")) + ftype = "libtoo library file"; + + /* XXX all files with extension ".pc" are pkgconfig for now. */ + else if (_suffix(s, ".pc")) + ftype = "pkgconfig file"; + /* XXX skip all files in /dev/ which are (or should be) %dev dummies. */ else if (slen >= fc->brlen+sizeof("/dev/") && !strncmp(s+fc->brlen, "/dev/", sizeof("/dev/")-1)) ftype = ""; diff --git a/build/rpmfc.h b/build/rpmfc.h index 377861e..b408012 100644 --- a/build/rpmfc.h +++ b/build/rpmfc.h @@ -53,6 +53,8 @@ enum FCOLOR_e { RPMFC_ELF64 = (1 << 1), #define RPMFC_ELF (RPMFC_ELF32|RPMFC_ELF64) + RPMFC_PKGCONFIG = (1 << 5), + RPMFC_LIBTOOL = (1 << 6), RPMFC_MODULE = (1 << 7), RPMFC_EXECUTABLE = (1 << 8), RPMFC_SCRIPT = (1 << 9), diff --git a/macros.in b/macros.in index e8360b4..fb3280a 100644 --- a/macros.in +++ b/macros.in @@ -441,6 +441,12 @@ print (t)\ %__mono_provides @RPMCONFIGDIR@/mono-find-provides %{_builddir}/%{?buildsubdir} %{buildroot} %{_libdir} %__mono_requires @RPMCONFIGDIR@/mono-find-requires %{_builddir}/%{?buildsubdir} %{buildroot} %{_libdir} +%__libtool_provides @RPMCONFIGDIR@/libtooldeps.sh --provides %{buildroot} %{name} +%__libtool_requires @RPMCONFIGDIR@/libtooldeps.sh --requires %{buildroot} %{name} + +%__pkgconfig_provides @RPMCONFIGDIR@/pkgconfigdeps.sh --provides +%__pkgconfig_requires @RPMCONFIGDIR@/pkgconfigdeps.sh --requires + # # fixowner, fixgroup, and fixperms are run at the end of hardcoded setup # These macros are necessary only for legacy compatibility, and have moved diff --git a/scripts/Makefile.am b/scripts/Makefile.am index db23b14..21bc969 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -23,7 +23,8 @@ EXTRA_DIST = \ macros.perl.in macros.python.in \ macros.php.in find-requires.php find-provides.php \ find-php-provides find-php-requires \ - mono-find-requires mono-find-provides + mono-find-requires mono-find-provides \ + pkgconfigdeps.sh libtooldeps.sh installprefix = $(DESTDIR) diff --git a/scripts/libtooldeps.sh b/scripts/libtooldeps.sh new file mode 100644 index 0000000..d8937c8 --- /dev/null +++ b/scripts/libtooldeps.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +[ $# -ge 2 ] || { + cat > /dev/null + exit 0 +} + +case $1 in +-P|--provides) + shift + RPM_BUILD_ROOT="$1" + while read possible + do + case "$possible" in + *.la) + if grep -iq '^# Generated by ltmain.sh' "$possible" 2> /dev/null ; then + possible="`echo ${possible} | sed -e s,${RPM_BUILD_ROOT}/,/,`" + echo "libtool($possible)" + fi + ;; + esac + done + ;; +-R|--requires) + while read possible ; do + case "$possible" in + *.la) + for dep in `grep '^dependency_libs='"$possible" 2> /dev/null | \ + sed -e "s,^dependency_libs='\(.*\)',\1,g"` + do + case "$dep" in + /*.la) + echo "libtool($dep)" + ;; + esac + done + ;; + esac + done + ;; +esac +exit 0 diff --git a/scripts/pkgconfigdeps.sh b/scripts/pkgconfigdeps.sh new file mode 100755 index 0000000..7a81234 --- /dev/null +++ b/scripts/pkgconfigdeps.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +pkgconfig=/usr/bin/pkg-config +test -x $pkgconfig || { + cat > /dev/null + exit 0 +} + +[ $# -ge 1 ] || { + cat > /dev/null + exit 0 +} + +case $1 in +-P|--provides) + while read filename ; do + case "${filename}" in + *.pc) + # Query the dependencies of the package. + $pkgconfig --print-provides "$filename" 2> /dev/null | while read n r v ; do + # We have a dependency. Make a note that we need the pkgconfig + # tool for this package. + echo "pkgconfig($n)" "$r" "$v" + done + ;; + esac + done + ;; +-R|--requires) + while read filename ; do + case "${filename}" in + *.pc) + $pkgconfig --print-requires "$filename" 2> /dev/null | while read n r v ; do + i="`expr $i + 1`" + [ $i -eq 1 ] && echo "pkgconfig" + echo "pkgconfig($n)" "$r" "$v" + done + esac + done + ;; +esac +exit 0 -- 2.7.4