From 30a18ba46b06c43f12c025a65c8a9742e3338c24 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Tue, 14 Jun 2011 22:01:05 +1000 Subject: [PATCH] makepkg: Add UPX compression support 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 Signed-off-by: Allan McRae --- doc/PKGBUILD.5.txt | 3 +++ doc/makepkg.conf.5.txt | 6 +++++- etc/makepkg.conf.in | 5 +++-- scripts/makepkg.sh.in | 16 +++++++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt index c0fa594..bb08d3b 100644 --- a/doc/PKGBUILD.5.txt +++ b/doc/PKGBUILD.5.txt @@ -223,6 +223,9 @@ name. The syntax is: `source=('filename::url')`. *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 9d3ad0a..fcd2f2a 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 01206d1..18df00f 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' \ @@ -930,6 +930,20 @@ 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 UPX...")" + local binary + find . -type f -perm -u+w 2>/dev/null | while read binary ; do + case "$(file -biz "$binary")" in + *compressed-encoding*) # Skip compressed binaries + ;; + *application/x-executable*) # Binaries + upx $UPXFLAGS "$binary" &>/dev/null || + warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}" + esac + done + fi } write_pkginfo() { -- 1.7.5.4