From 01799e1e18073a267f4eb4246ae2509722f556ae Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Tue, 30 Sep 2008 22:48:52 +0200
Subject: [PATCH] Multiple changes to gnu_configure style packages, as well as
 other changes to allow better linking flags in future packages through
 pkg-config.

Removed the PKGFS_TEMPLATESDIR, PKGFS_DEPSDIR and others that weren't
too useful. Instead use a single PKGFS_DISTRIBUTIONDIR on which all
those directories/files can be found.

Added a template helper for pkg-config, that changes a pkg-config file
after it's installed to produce correct linker paths.

More helpers could be added in the future.

--HG--
extra : convert_revision : a42fd2e72915a4219714de92579011bca2b0f4a6
---
 helper-templates/pkg-config-transform.sh | 26 ++++++++
 pkgfs.conf                               | 26 ++++----
 pkgfs.sh                                 | 82 +++++++++++++-----------
 templates/curl-7.18.0.tmpl               |  1 +
 templates/glib-2.18.1.tmpl               |  5 ++
 templates/irssi-0.8.12.tmpl              |  4 +-
 templates/libidn-1.9.tmpl                |  1 +
 templates/mc-4.6.1.tmpl                  |  4 +-
 templates/pcre-7.8.tmpl                  |  1 +
 templates/ruby-1.8.7-p72.tmpl            |  4 +-
 10 files changed, 98 insertions(+), 56 deletions(-)
 create mode 100755 helper-templates/pkg-config-transform.sh

diff --git a/helper-templates/pkg-config-transform.sh b/helper-templates/pkg-config-transform.sh
new file mode 100755
index 00000000000..d176ebde96c
--- /dev/null
+++ b/helper-templates/pkg-config-transform.sh
@@ -0,0 +1,26 @@
+#! /bin/sh
+#
+# This script will transform the pkg-config files with correct
+# directories pointing at PKGFS_MASTERDIR specified in the config file.
+#
+
+: ${sed_cmd:=/usr/bin/sed}
+: ${mv_cmd:=/bin/mv}
+
+transform_pkgconfig_file()
+{
+	local file="$1"
+
+	[ -z "$file" ] && return 1
+
+	$sed_cmd	\
+		-e "s|^exec_prefix=$PKGFS_DESTDIR/$pkgname.*$|exec_prefix=\${prefix}|" \
+		-e "s|-L\${libdir}|-L\${libdir} -Wl,-R\${libdir}|" \
+		$file > $file.in && \
+	$mv_cmd $file.in $file
+	[ "$?" -eq 0 ] && \
+		echo "=> Transformed pkg-config file: $(basename $file)."
+}
+
+transform_pkgconfig_file "$1"
+exit 0
diff --git a/pkgfs.conf b/pkgfs.conf
index 41aa37791fe..3777d093380 100644
--- a/pkgfs.conf
+++ b/pkgfs.conf
@@ -2,37 +2,33 @@
 # Configuration file for pkgfs.
 #
 
+# Global directory where the pkgfs distribution files are stored.
+# Templates, patches, helpers and dependency files should all be
+# in that directory.
+#
+PKGFS_DISTRIBUTIONDIR=$HOME/pkgfs
+
 #
 # Global master directory: this is where all symlinks will be
 # created pointing at packages installed in PKGFS_DESTDIR.
 #
-PKGFS_MASTERDIR=$HOME/pkgfs
+PKGFS_MASTERDIR=$PKGFS_DISTRIBUTIONDIR/depot
 
 #
 # Global destination directory: this is where all packages will be
 # installed.
 #
-PKGFS_DESTDIR=$HOME/pkgfs/packages
+PKGFS_DESTDIR=$PKGFS_DISTRIBUTIONDIR/packages
 
 #
 # Global directory where source files will be extracted to.
 #
-PKGFS_BUILDDIR=$HOME/pkgfs/builddir
+PKGFS_BUILDDIR=$PKGFS_DISTRIBUTIONDIR/builddir
 
 #
-# Global directory where the source distfiles are stored.
+# Global directory where source distribution files are stored.
 #
-PKGFS_SRC_DISTDIR=$HOME/pkgfs/distdir
-
-#
-# Global directory where templates and patches are stored.
-#
-PKGFS_TEMPLATESDIR=$HOME/pkgfs/templates
-
-#
-# Global directory where the dependency database files are stored.
-#
-PKGFS_DEPSDIR=$HOME/pkgfs/dependencies
+PKGFS_SRCDISTDIR=$PKGFS_DISTRIBUTIONDIR/srcdistdir
 
 #
 # Path to the xstow program.
diff --git a/pkgfs.sh b/pkgfs.sh
index 270631ae4b1..b1a78b3348f 100755
--- a/pkgfs.sh
+++ b/pkgfs.sh
@@ -66,6 +66,22 @@
 : ${xstow_version:=xstow-0.6.1-unstable}
 : ${xstow_args:=-ap}
 
+set_defvars()
+{
+	# Directories
+	: ${PKGFS_TEMPLATESDIR:=$PKGFS_DISTRIBUTIONDIR/templates}
+	: ${PKGFS_DEPSDIR:=$PKGFS_DISTRIBUTIONDIR/dependencies}
+	: ${PKGFS_TMPLHELPDIR:=$PKGFS_DISTRIBUTIONDIR/helper-templates}
+
+	local DDIRS="PKGFS_DEPSDIR PKGFS_TEMPLATESDIR PKGFS_TMPLHELPDIR"
+	for i in ${DDIRS}; do
+		if [ ! -d "$PKGFS_DEPSDIR" ]; then
+			echo "**** ERROR: cannot find $i, aborting ***"
+			exit 1
+		fi
+	done
+}
+
 usage()
 {
 	cat << _EOF
@@ -96,9 +112,6 @@ check_path()
 	eval local orig="$1"
 
 	case "$orig" in
-	$PKGFS_TEMPLATESDIR)
-		orig="$PKGFS_TEMPLATESDIR/$orig"
-		;;
 	/)
 		;;
 	/*)
@@ -118,7 +131,6 @@ run_file()
 
 	check_path "$file"
 	. $path_fixed
-
 }
 
 #
@@ -218,7 +230,7 @@ apply_tmpl_patches()
 
 			cd $pkg_builddir && $patch_cmd < $patch 2>/dev/null
 			if [ "$?" -eq 0 ]; then
-				echo ">> Patch applied: \`$i'."
+				echo "=> Patch applied: \`$i'."
 			else
 				echo -n "*** ERROR: couldn't apply patch '$i'"
 				echo ", aborting ***"
@@ -239,20 +251,8 @@ check_config_vars()
 		exit 1
 	fi
 
-	if [ ! -d "$PKGFS_DEPSDIR" ]; then
-		echo -n "**** ERROR: PKGFS_DEPSDIR not set in configuration "
-		echo "file, aborting ***"
-		exit 1
-	fi
-
-	if [ ! -d "$PKGFS_TEMPLATESDIR" ]; then
-		echo -n "*** ERROR: PKGFS_TEMPLATESDIR cannot be read"
-		echo ", aborting ***"
-		exit 1
-	fi
-
 	local PKGFS_VARS="PKGFS_MASTERDIR PKGFS_DESTDIR PKGFS_BUILDDIR \
-			  PKGFS_SRC_DISTDIR"
+			  PKGFS_SRCDISTDIR"
 
 	for f in ${PKGFS_VARS}; do
 		eval val="\$$f"
@@ -313,7 +313,7 @@ check_tmpl_vars()
 		exit 1
 	fi
 
-	dfile="$PKGFS_SRC_DISTDIR/$dfile"
+	dfile="$PKGFS_SRCDISTDIR/$dfile"
 
 	case "$extract_sufx" in
 	.tar.bz2|.tar.gz|.tgz|.tbz)
@@ -353,7 +353,7 @@ check_rmd160_cksum()
 	fi
 
 	origsum="$checksum"
-	dfile="$PKGFS_SRC_DISTDIR/$dfile"
+	dfile="$PKGFS_SRCDISTDIR/$dfile"
 	filesum="$($cksum_cmd $dfile | $awk_cmd '{print $4}')"
 	if [ "$origsum" != "$filesum" ]; then
 		echo "*** WARNING: checksum doesn't match (rmd160) ***"
@@ -376,7 +376,7 @@ fetch_tmpl_sources()
 
 	for f in "$file"; do
 		file2="$f$extract_sufx"
-		if [ -f "$PKGFS_SRC_DISTDIR/$file2" ]; then
+		if [ -f "$PKGFS_SRCDISTDIR/$file2" ]; then
 			check_rmd160_cksum $f
 			if [ "$?" -eq 0 ]; then
 				if [ -n "$only_fetch" ]; then
@@ -387,11 +387,11 @@ fetch_tmpl_sources()
 			fi
 		fi
 
-		echo ">>> Fetching \`$file2' source tarball"
+		echo "==> Fetching \`$file2' source tarball"
 
-		cd $PKGFS_SRC_DISTDIR && $fetch_cmd $url/$file2
+		cd $PKGFS_SRCDISTDIR && $fetch_cmd $url/$file2
 		if [ "$?" -ne 0 ]; then
-			if [ ! -f $PKGFS_SRC_DISTDIR/$file2 ]; then
+			if [ ! -f $PKGFS_SRCDISTDIR/$file2 ]; then
 				echo -n "*** ERROR: couldn't fetch '$file2', "
 				echo	"aborting ***"
 			else
@@ -411,7 +411,7 @@ extract_tmpl_sources()
 {
 	[ -z "$pkgname" ] && return 1
 
-	echo ">>> Extracting \`$pkgname' into $PKGFS_BUILDDIR."
+	echo "==> Extracting \`$pkgname' into $PKGFS_BUILDDIR."
 
 	$extract_cmd
 	if [ "$?" -ne 0 ]; then
@@ -468,7 +468,7 @@ build_tmpl_sources()
 	# Apply patches if requested by template file
 	apply_tmpl_patches
 
-	echo ">>> Building \`$pkgname' (be patient, may take a while)"
+	echo "==> Building \`$pkgname' (be patient, may take a while)"
 
 	#
 	# For now, just set LDFLAGS.
@@ -489,12 +489,9 @@ build_tmpl_sources()
 		# Pass consistent arguments to not have unexpected
 		# surprises later.
 		#
-		./configure	--prefix="$PKGFS_MASTERDIR" \
-				--exec-prefix="$PKGFS_DESTDIR/$pkgname" \
-				--mandir="$PKGFS_DESTDIR/$pkgname/man" \
+		./configure	--prefix="$PKGFS_MASTERDIR"		\
+				--mandir="$PKGFS_DESTDIR/$pkgname/man"	\
 				--infodir="$PKGFS_DESTDIR/$pkgname/share/info" \
-				--libdir="$PKGFS_MASTERDIR/lib" \
-				--includedir="$PKGFS_MASTERDIR/include" \
 				${configure_args}
 
 	#
@@ -538,14 +535,20 @@ build_tmpl_sources()
 		exit 1
 	fi
 
+	# Transform pkg-config files if requested by template.
+	for i in ${pkgconfig_override}; do
+		local tmpf="$PKGFS_DESTDIR/$pkgname/lib/pkgconfig/$i"
+		[ -f "$tmpf" ] && $PKGFS_TMPLHELPDIR/pkg-config-transform.sh ${tmpf}
+	done
+
 	unset LDFLAGS PKG_CONFIG
 
-	echo ">>> Installed \`$pkgname' into $PKGFS_DESTDIR/$pkgname."
+	echo "==> Installed \`$pkgname' into $PKGFS_DESTDIR/$pkgname."
 
 	if [ -d "$pkg_builddir" -a -z "$dontrm_builddir" ]; then
 		$rm_cmd -rf $pkg_builddir
 		[ "$?" -eq 0 ] && \
-			echo ">> Removed \`$pkgname' build directory."
+			echo "=> Removed \`$pkgname' build directory."
 	fi
 
 	cd $PKGFS_BUILDDIR
@@ -576,7 +579,7 @@ stow_tmpl()
 		echo "*** ERROR: couldn't create symlinks for \`$pkg' ***"
 		exit 1
 	else
-		echo ">>> Created \`$pkg' symlinks into master directory."
+		echo "==> Created \`$pkg' symlinks into master directory."
 	fi
 
 	xstow_args="$real_xstowargs"
@@ -605,7 +608,7 @@ unstow_tmpl()
 		exit 1
 	else
 		$rm_cmd -f $PKGFS_DESTDIR/$pkg/share/info/dir
-		echo ">>> Removed \`$pkg' symlinks from master directory."
+		echo "==> Removed \`$pkg' symlinks from master directory."
 	fi
 
 	installed_tmpl_handler unregister $pkg
@@ -663,7 +666,7 @@ install_dependency_tmpl()
 	doing_deps=true
 
 	tmp_pkgn=${pkgdepf%%-deps.db}
-	echo ">>> Required dependencies for $(basename $tmp_pkgn):"
+	echo "==> Required dependencies for $(basename $tmp_pkgn):"
 
 	add_dependency_tolist $pkgdepf
 
@@ -671,7 +674,7 @@ install_dependency_tmpl()
 		# skip dup deps
 		check_installed_tmpl $i
 		[ "$?" -eq 0 ] && continue
-		echo ">>> Installing dependency: $i"
+		echo "=> Installing dependency: $i"
 		install_tmpl "${i%-deps.db}"
 	done
 
@@ -886,8 +889,11 @@ if [ -z "$target" ]; then
 	usage
 fi
 
-# Check configuration vars before anyting else.
+#
+# Check configuration vars before anyting else, and set defaults vars.
+#
 check_config_vars
+set_defvars
 
 # Main switch
 case "$target" in
diff --git a/templates/curl-7.18.0.tmpl b/templates/curl-7.18.0.tmpl
index 394f72f9b47..1ac1bf135b3 100755
--- a/templates/curl-7.18.0.tmpl
+++ b/templates/curl-7.18.0.tmpl
@@ -3,6 +3,7 @@ pkgname=curl-7.18.0
 extract_sufx=".tar.bz2"
 url=http://curl.haxx.se/download/
 build_style=gnu_configure
+pkgconfig_override="libcurl.pc"
 short_desc="Client that groks URLs"
 maintainer="Juan RP <xtraeme@gmail.com>"
 checksum=f25ec844e7ef6221719439b3214fd3c3a42f5604
diff --git a/templates/glib-2.18.1.tmpl b/templates/glib-2.18.1.tmpl
index 7c49d5d9359..f126650193d 100755
--- a/templates/glib-2.18.1.tmpl
+++ b/templates/glib-2.18.1.tmpl
@@ -9,6 +9,11 @@ make_cmd="$PKGFS_MASTERDIR/bin/gmake"
 configure_args="--disable-fam --with-pcre=system"
 configure_env="ac_cv_func_statfs=no"
 build_style=gnu_configure
+pkgconfig_override="glib-2.0-uninstalled.pc glib-2.0.pc
+ gmodule-2.0-uninstalled.pc gmodule-2.0.pc gmodule-export-2.0.pc
+ gmodule-no-export-2.0-uninstalled.pc gmodule-no-export-2.0.pc
+ gobject-2.0-uninstalled.pc gobject-2.0.pc gthread-2.0-uninstalled.pc
+ gthread-2.0.pc gio-2.0.pc gio-unix-2.0.pc"
 short_desc="The GNU library of C routines"
 maintainer="Juan RP <xtraeme@gmail.com>"
 checksum=264b37584419d983685910adde8f7b282eccc1ad
diff --git a/templates/irssi-0.8.12.tmpl b/templates/irssi-0.8.12.tmpl
index 928a0b72fe7..32b7a28bd0c 100755
--- a/templates/irssi-0.8.12.tmpl
+++ b/templates/irssi-0.8.12.tmpl
@@ -2,7 +2,9 @@
 pkgname=irssi-0.8.12
 extract_sufx=".tar.bz2"
 url=http://www.irssi.org/files
-configure_args="--with-terminfo --with-proxy --without-curses"
+configure_args="--with-terminfo --with-proxy --without-curses
+ --with-perl-lib=$PKGFS_MASTERDIR/lib/perl5/site_perl"
+
 build_style=gnu_configure
 short_desc="Secure and modular IRC client with text mode user interface"
 maintainer="Juan RP <xtraeme@gmail.com>"
diff --git a/templates/libidn-1.9.tmpl b/templates/libidn-1.9.tmpl
index cad4dd130de..3cc3c4de306 100755
--- a/templates/libidn-1.9.tmpl
+++ b/templates/libidn-1.9.tmpl
@@ -3,6 +3,7 @@ pkgname=libidn-1.9
 extract_sufx=".tar.gz"
 url=http://ftp.gnu.org/gnu/libidn
 build_style=gnu_configure
+pkgconfig_override="libidn.pc"
 configure_env="EMACS=/bin/false"
 configure_args="--disable-csharp --disable-java"
 short_desc="Internationalized Domain Names command line tool"
diff --git a/templates/mc-4.6.1.tmpl b/templates/mc-4.6.1.tmpl
index e460f8754ba..1c026a03d30 100755
--- a/templates/mc-4.6.1.tmpl
+++ b/templates/mc-4.6.1.tmpl
@@ -3,8 +3,10 @@ pkgname=mc-4.6.1
 extract_sufx=".tar.gz"
 url=http://www.ibiblio.org/pub/Linux/utils/file/managers/mc
 build_style=gnu_configure
+# Override datadir to get the correct directory.
 configure_args="--without-ext2undel --with-screen=mcslang
- --enable-charset --without-libiconv-prefix --without-libintl-prefix"
+ --enable-charset --without-libiconv-prefix --without-libintl-prefix
+ --datadir=$PKGFS_DESTDIR/$pkgname/share"
 
 configure_env="gt_cv_func_gnugettext_libintl=yes
  gt_cv_func_gnugettext1_libintl=yes gt_cv_func_gnugettext2_libintl=yes"
diff --git a/templates/pcre-7.8.tmpl b/templates/pcre-7.8.tmpl
index d21c7e1bd5f..227deda9157 100755
--- a/templates/pcre-7.8.tmpl
+++ b/templates/pcre-7.8.tmpl
@@ -3,6 +3,7 @@ pkgname=pcre-7.8
 extract_sufx=".tar.bz2"
 url=http://kent.dl.sourceforge.net/sourceforge/pcre
 build_style=gnu_configure
+pkgconfig_override="libpcre.pc libpcrecpp.pc"
 configure_args="--enable-utf8 --enable-unicode-properties"
 short_desc="Perl Compatible Regular Expressions"
 maintainer="Juan RP <xtraeme@gmail.com>"
diff --git a/templates/ruby-1.8.7-p72.tmpl b/templates/ruby-1.8.7-p72.tmpl
index becb0e7b1bf..b461d7b1665 100644
--- a/templates/ruby-1.8.7-p72.tmpl
+++ b/templates/ruby-1.8.7-p72.tmpl
@@ -3,7 +3,9 @@ pkgname=ruby-1.8.7-p72
 extract_sufx=".tar.bz2"
 url=ftp://ftp.ruby-lang.org/pub/ruby/1.8
 build_style=gnu_configure
-configure_args="--enable-pthread --enable-shared"
+# Override --exec-prefix to install it into the correct location.
+configure_args="--enable-pthread --enable-shared
+ --exec-prefix=$PKGFS_DESTDIR/$pkgname"
 short_desc="Ruby programming language"
 maintainer="Daniel Horecki <morr@morr.pl>"
 checksum=07bf0d6987ba111aed988093c569fb66ba54891b