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 Gibson <bryce@gibson-consulting.com.au>
Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Allan McRae 2011-06-14 22:01:05 +10:00 committed by Dan McGee
parent b899099327
commit b803a33a8f
4 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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() {