[pacman-dev] [PATCH] makepkg: Add UPX compression support
Allan McRae
allan at archlinux.org
Wed Jun 22 04:54:08 EDT 2011
This patch enables the automatic compression of executable binaries
using UPX when the 'upx' options is specified in makepkg.conf or the
PKGBUILD. Additional arguments can be passed to UPX by specifying
the UPXFLAGS variable.
Original-patch-by: Bryce Gibson <bryce at gibson-consulting.com.au>
Signed-off-by: Allan McRae <allan at archlinux.org>
---
doc/PKGBUILD.5.txt | 3 +++
doc/makepkg.conf.5.txt | 6 +++++-
etc/makepkg.conf.in | 5 +++--
scripts/makepkg.sh.in | 13 ++++++++++++-
4 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt
index 24e1a12..4d76121 100644
--- a/doc/PKGBUILD.5.txt
+++ b/doc/PKGBUILD.5.txt
@@ -231,6 +231,9 @@ version. Appending the version yourself disables auto detection.
*zipman*;;
Compress man and info pages with gzip.
+ *upx*;;
+ Compress binary executable files using UPX.
+
*ccache*;;
Allow the use of ccache during build. More useful in its negative
form `!ccache` with select packages that have problems building
diff --git a/doc/makepkg.conf.5.txt b/doc/makepkg.conf.5.txt
index 3ce4759..48f5ef5 100644
--- a/doc/makepkg.conf.5.txt
+++ b/doc/makepkg.conf.5.txt
@@ -114,7 +114,7 @@ Options
Specify a key to use for gpg signing instead of the default key in the
keyring. Can be overridden with makepkg's `--key` option.
-**OPTIONS=(**strip !docs libtool emptydirs zipman**)**::
+**OPTIONS=(**strip docs libtool emptydirs zipman purge !upx**)**::
This array contains options that affect the default packaging. They are
equivalent to options that can be placed in the PKGBUILD; the defaults are
shown here. All options should always be left in the array; to enable or
@@ -146,6 +146,10 @@ Options
Remove files specified by the `PURGE_TARGETS` variable from the
package.
+ *upx*;;
+ Compress binary executable files using UPX. Additional options
+ can be passed to UPX by specifying the `UPXFLAGS` variable.
+
**INTEGRITY_CHECK=(**check1 ...**)**::
File integrity checks to use. Multiple checks may be specified; this
affects both generation and checking. The current valid options are:
diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in
index 9a790fc..42ae940 100644
--- a/etc/makepkg.conf.in
+++ b/etc/makepkg.conf.in
@@ -60,7 +60,7 @@ BUILDENV=(fakeroot !distcc color !ccache check !sign)
# These are default values for the options=() settings
#########################################################################
#
-# Default: OPTIONS=(strip docs libtool emptydirs zipman purge)
+# Default: OPTIONS=(strip docs libtool emptydirs zipman purge !upx)
# A negated option will do the opposite of the comments below.
#
#-- strip: Strip symbols from binaries/libraries
@@ -69,8 +69,9 @@ BUILDENV=(fakeroot !distcc color !ccache check !sign)
#-- emptydirs: Leave empty directories in packages
#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
#-- purge: Remove files specified by PURGE_TARGETS
+#-- upx: Compress binary executable files using UPX
#
-OPTIONS=(strip docs libtool emptydirs zipman purge)
+OPTIONS=(strip docs libtool emptydirs zipman purge !upx)
#-- File integrity checks to use. Valid: md5, sha1, sha256, sha384, sha512
INTEGRITY_CHECK=(md5)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 78cd4cf..b0247bd 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -44,7 +44,7 @@ startdir="$PWD"
srcdir="$startdir/src"
pkgdir="$startdir/pkg"
-packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
+packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge' 'upx')
other_options=('ccache' 'distcc' 'buildflags' 'makeflags')
splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
@@ -940,6 +940,17 @@ tidy_install() {
msg2 "$(gettext "Removing empty directories...")"
find . -depth -type d -empty -delete
fi
+
+ if [[ $(check_option upx) = "y" ]]; then
+ msg2 "$(gettext "Compressing binaries with %s...")" "UPX"
+ local binary
+ find . -type f -perm -u+w 2>/dev/null | while read binary ; do
+ if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then
+ upx $UPXFLAGS "$binary" &>/dev/null ||
+ warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}"
+ fi
+ done
+ fi
}
find_libdepends() {
--
1.7.5.4
More information about the pacman-dev
mailing list