summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2009-01-17 02:45:02 +0100
committerDan McGee <dan@archlinux.org>2009-01-17 02:45:02 +0100
commit3d49d88009341d5cacbbe08fb4f6f6af3ed76ae1 (patch)
tree968ee9b752f02af850494df1c7197f21a9e2f33d
parenta9f030e84c96d57fbcbc7e8af5fc897515ef79e7 (diff)
parente946ee7745a839c0cd9244a3d9b50a3ea15143f9 (diff)
downloadpacman-3d49d88009341d5cacbbe08fb4f6f6af3ed76ae1.tar.gz
pacman-3d49d88009341d5cacbbe08fb4f6f6af3ed76ae1.tar.xz
Merge branch 'am/splitpkg'
* am/splitpkg: makepkg: implement creation of split packages makepkg: Optional argument for run_package and create_package makepkg: hack around tee in run_package function makepkg: add functions for backup and restore of package fields makepkg: add optional package function makepkg: Add PKGBUILD-split.proto
-rw-r--r--Makefile.am2
-rw-r--r--PKGBUILD-split.proto55
-rw-r--r--doc/PKGBUILD.5.txt8
-rw-r--r--scripts/makepkg.sh.in154
4 files changed, 205 insertions, 14 deletions
diff --git a/Makefile.am b/Makefile.am
index ed9a34d3..2f5e7a7b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,7 +12,7 @@ EXTRA_DIST = HACKING
# Sample makepkg prototype files
pkgdatadir = ${datadir}/${PACKAGE}
-dist_pkgdata_DATA = PKGBUILD.proto proto.install ChangeLog.proto
+dist_pkgdata_DATA = PKGBUILD.proto PKGBUILD-split.proto proto.install ChangeLog.proto
# run the pactest test suite and vercmp tests
check-local: pactest src/pacman src/util
diff --git a/PKGBUILD-split.proto b/PKGBUILD-split.proto
new file mode 100644
index 00000000..35fb22b9
--- /dev/null
+++ b/PKGBUILD-split.proto
@@ -0,0 +1,55 @@
+# This is an example of a PKGBUILD for splitting packages. Use this as a
+# start to creating your own, and remove these comments. For more information,
+# see 'man PKGBUILD'. NOTE: Please fill out the license field for your package!
+# If it is unknown, then please put 'unknown'.
+
+# Contributor: Your Name <youremail@domain.com>
+pkgname=('pkg1' 'pkg2')
+pkgver=VERSION
+pkgrel=1
+pkgdesc=""
+arch=()
+url=""
+license=('GPL')
+groups=()
+depends=()
+makedepends=()
+provides=()
+conflicts=()
+replaces=()
+backup=()
+options=()
+install=
+source=($pkgname-$pkgver.tar.gz)
+noextract=()
+md5sums=() #generate with 'makepkg -g'
+
+build() {
+ cd "$srcdir/$pkgname-$pkgver"
+ ./configure --prefix=/usr
+ make || return 1
+}
+
+package_pkg1() {
+ # options and directives that can be overridden
+ pkgdesc=""
+ license=()
+ groups=()
+ depends=()
+ optdepends=()
+ provides=()
+ conflicts=()
+ replaces=()
+ backup=()
+ options=()
+ install=
+
+ make DESTDIR="$pkgdir/" install-pkg1
+}
+
+package_pkg2() {
+ # options and directives overrides
+ pkgdesc=""
+
+ make DESTDIR="$pkgdir/" install-pkg2
+}
diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt
index 96c7a505..04eacfac 100644
--- a/doc/PKGBUILD.5.txt
+++ b/doc/PKGBUILD.5.txt
@@ -256,6 +256,14 @@ If you create any variables of your own in the build function, it is
recommended to use the bash `local` keyword to scope the variable to inside
the build function.
+package() Function
+------------------
+An optional package() function can be specified in addition to the build() function.
+This function is run immediately after the build() function. When specified in
+combination with the fakeroot BUILDENV option in linkman:makepkg.conf[5], fakeroot
+usage will be limited to running the packaging stage. The build() function will be
+run as the user calling makepkg.
+
Install/Upgrade/Remove Scripting
--------------------------------
Pacman has the ability to store and execute a package-specific script when it
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index e9e38b3a..1e990de3 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -42,9 +42,12 @@ BUILDSCRIPT='@BUILDSCRIPT@'
startdir="$PWD"
srcdir="$startdir/src"
pkgdir="$startdir/pkg"
+
packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
other_options=('ccache' 'distcc' 'makeflags' 'force')
-readonly -a packaging_options other_options
+splitpkg_overrides=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \
+ 'conflicts' 'replaces' 'backup' 'options' 'install')
+readonly -a packaging_options other_options splitpkg_overrides
# Options
ASROOT=0
@@ -64,6 +67,7 @@ LOGGING=0
SOURCEONLY=0
IGNOREARCH=0
HOLDVER=0
+SPLITPKG=0
# Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
# when dealing with svn/cvs/etc PKGBUILDs.
@@ -682,7 +686,7 @@ run_build() {
local ret=0
if [ "$LOGGING" = "1" ]; then
- BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log"
+ BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-build.log"
if [ -f "$BUILDLOG" ]; then
local i=1
while true; do
@@ -710,6 +714,63 @@ run_build() {
fi
}
+run_package() {
+ if [ -z "$1" ]; then
+ pkgfunc="package"
+ nameofpkg="$pkgname"
+ else
+ pkgfunc="package_$1"
+ nameofpkg="$1"
+ fi
+
+ # clear user-specified makeflags if requested
+ if [ "$(check_option makeflags)" = "n" ]; then
+ MAKEFLAGS=""
+ fi
+
+ msg "$(gettext "Starting %s()...")" "$pkgfunc"
+ cd "$srcdir"
+
+ # ensure all necessary build variables are exported
+ export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
+
+ local ret=0
+ if [ "$LOGGING" = "1" ]; then
+ BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"
+ if [ -f "$BUILDLOG" ]; then
+ local i=1
+ while true; do
+ if [ -f "$BUILDLOG.$i" ]; then
+ i=$(($i +1))
+ else
+ break
+ fi
+ done
+ mv "$BUILDLOG" "$BUILDLOG.$i"
+ fi
+
+ # ensure overridden package variables suvrive tee with split packages
+ logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
+ mknod "$logpipe" p
+ exec 3>&1
+ tee "$BUILDLOG" < "$logpipe" &
+ exec 1>"$logpipe" 2>"$logpipe"
+ $pkgfunc 2>&1 || ret=$?
+ sync
+ exec 1>&3 2>&3 3>&-
+ rm "$logpipe"
+ else
+ $pkgfunc 2>&1 || ret=$?
+ fi
+
+ if [ $ret -gt 0 ]; then
+ error "$(gettext "Packaging Failed.")"
+ plain "$(gettext "Aborting...")"
+ remove_deps
+ exit 2 # $E_BUILD_FAILED
+ fi
+}
+
tidy_install() {
cd "$pkgdir"
msg "$(gettext "Tidying install...")"
@@ -793,6 +854,12 @@ tidy_install() {
}
create_package() {
+ if [ -z "$1" ]; then
+ nameofpkg="$pkgname"
+ else
+ nameofpkg="$1"
+ fi
+
if [ ! -d "$pkgdir" ]; then
error "$(gettext "Missing pkg/ directory.")"
plain "$(gettext "Aborting...")"
@@ -817,7 +884,7 @@ create_package() {
echo "# using $(fakeroot -v)" >>.PKGINFO
fi
echo "# $(LC_ALL=C date -u)" >>.PKGINFO
- echo "pkgname = $pkgname" >>.PKGINFO
+ echo "pkgname = $nameofpkg" >>.PKGINFO
echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
echo "pkgdesc = $pkgdesc" >>.PKGINFO
echo "url = $url" >>.PKGINFO
@@ -901,7 +968,7 @@ create_package() {
"$PKGEXT" ;;
esac
- local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
+ local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
# when fileglobbing, we want * in an empty directory to expand to
# the null string rather than itself
@@ -1139,6 +1206,24 @@ devel_update() {
fi
}
+backup_package_variables() {
+ for var in ${splitpkg_overrides[@]}; do
+ indirect="${var}_backup"
+ eval "${indirect}=\"${!var}\""
+ done
+}
+
+restore_package_variables() {
+ for var in ${splitpkg_overrides[@]}; do
+ indirect="${var}_backup"
+ if [ -n "${!indirect}" ]; then
+ eval "${var}=\"${!indirect}\""
+ else
+ unset ${var}
+ fi
+ done
+}
+
# getopt like parser
parse_options() {
local short_options=$1; shift;
@@ -1481,6 +1566,10 @@ if [ "$GENINTEG" = "1" ]; then
exit 0 # $E_OK
fi
+if [ "${#pkgname[@]}" -gt "1" ]; then
+ SPLITPKG=1
+fi
+
# check for no-no's in the build script
if [ -z "$pkgname" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgname"
@@ -1569,13 +1658,29 @@ fi
# Run the bare minimum in fakeroot
if [ "$INFAKEROOT" = "1" ]; then
- if [ "$REPKG" = "0" ]; then
- run_build
- tidy_install
+ if [ "$SPLITPKG" = "0" ]; then
+ if [ "$REPKG" = "0" ]; then
+ if [ "$(type -t package)" != "function" ]; then
+ run_build
+ else
+ run_package
+ fi
+ tidy_install
+ fi
+ create_package
+ else
+ for pkg in ${pkgname[@]}; do
+ pkgdir="$pkgdir/$pkg"
+ mkdir -p "$pkgdir"
+ backup_package_variables
+ run_package $pkg
+ tidy_install
+ create_package $pkg
+ restore_package_variables
+ pkgdir="${pkgdir%/*}"
+ done
fi
- create_package
-
msg "$(gettext "Leaving fakeroot environment.")"
exit 0 # $E_OK
fi
@@ -1659,14 +1764,37 @@ else
# if we are root or if fakeroot is not enabled, then we don't use it
if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then
- if [ "$REPKG" = "0" ]; then
+ if [ "$SPLITPKG" = "0" ]; then
+ if [ "$REPKG" = "0" ]; then
+ devel_update
+ run_build
+ if [ "$(type -t package)" == "function" ]; then
+ run_package
+ fi
+ tidy_install
+ fi
+ create_package
+ else
devel_update
run_build
- tidy_install
+ for pkg in ${pkgname[@]}; do
+ pkgdir="$pkgdir/$pkg"
+ mkdir -p "$pkgdir"
+ backup_package_variables
+ run_package $pkg
+ tidy_install
+ create_package $pkg
+ restore_package_variables
+ pkgdir="${pkgdir%/*}"
+ done
fi
-
- create_package
else
+ if [ "$(type -t package)" == "function" -o "$SPLITPKG" = "1" ]; then
+ devel_update
+ run_build
+ cd "$startdir"
+ fi
+
msg "$(gettext "Entering fakeroot environment...")"
if [ "$newpkgver" != "" ]; then