[pacman-dev] [PATCH 1/1] add option to optimize PNG images with optipng
From: Christian Hesse <mail@eworm.de> This can decrease package size by optimizing PNG image size. Images are just stored with better compression and/or filter options. The actual image content is not altered. Additionally this can automatically fix broken PNG images which caused some trouble lately. Signed-off-by: Christian Hesse <mail@eworm.de> --- contrib/PKGBUILD.vim | 2 +- doc/PKGBUILD.5.txt | 3 +++ doc/makepkg.conf.5.txt | 5 ++++- etc/makepkg.conf.in | 5 +++-- scripts/makepkg.sh.in | 21 ++++++++++++++++++++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/contrib/PKGBUILD.vim b/contrib/PKGBUILD.vim index 9157063..4d520ac 100644 --- a/contrib/PKGBUILD.vim +++ b/contrib/PKGBUILD.vim @@ -211,7 +211,7 @@ hi def link pbValidSha512sums Number " options syn keyword pb_k_options options contained -syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained +syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|optipng\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained syn match pbOptionsNeg /\!/ contained syn match pbOptionsDeprec /no/ contained syn region pbOptionsGroup start=/^options=(/ end=/)/ contains=pb_k_options,pbOptions,pbOptionsNeg,pbOptionsDeprec,pbIllegalOption diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt index c95c41d..10980ab 100644 --- a/doc/PKGBUILD.5.txt +++ b/doc/PKGBUILD.5.txt @@ -296,6 +296,9 @@ underscore and the architecture name e.g., 'replaces_x86_64=()'. *upx*;; Compress binary executable files using UPX. + *optipng*;; + Optimize PNG images with optipng. + *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 5bd3a4a..50ccd17 100644 --- a/doc/makepkg.conf.5.txt +++ b/doc/makepkg.conf.5.txt @@ -140,7 +140,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 staticlibs emptydirs zipman purge !upx**)**:: +**OPTIONS=(**strip docs libtool staticlibs emptydirs zipman purge !upx !optipng**)**:: This array contains options that affect 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 @@ -181,6 +181,9 @@ Options Compress binary executable files using UPX. Additional options can be passed to UPX by specifying the `UPXFLAGS` variable. + *optipng*;; + Optimize PNG images with optipng. + *debug*;; Add the user-specified debug flags as specified in DEBUG_CFLAGS and DEBUG_CXXFLAGS to their counterpart buildflags. Creates a separate diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index 19f673d..71ec624 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -71,7 +71,7 @@ BUILDENV=(!distcc color !ccache check !sign) # These are default values for the options=() settings ######################################################################### # -# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug) # A negated option will do the opposite of the comments below. # #-- strip: Strip symbols from binaries/libraries @@ -82,9 +82,10 @@ BUILDENV=(!distcc color !ccache check !sign) #-- 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 +#-- optipng: Optimize PNG images with optipng #-- debug: Add debugging flags as specified in DEBUG_* variables # -OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug) #-- 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 00beb76..3823325 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -49,7 +49,7 @@ declare -r startdir="$PWD" LIBRARY=${LIBRARY:-'@libmakepkgdir@'} packaging_options=('strip' 'docs' 'libtool' 'staticlibs' 'emptydirs' 'zipman' - 'purge' 'upx' 'debug') + 'purge' 'upx' 'optipng' 'debug') other_options=('ccache' 'distcc' 'buildflags' 'makeflags') splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' 'backup' @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r png ; do + if [[ $(file -bi "$png") = *'image/png'* ]]; then + optipng "$png" &>/dev/null || + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}" + fi + done + fi } find_libdepends() { @@ -3008,6 +3019,14 @@ check_software() { fi fi + # optipng - PNG image optimization + if check_option "optipng" "y"; then + if ! type -p optipng >/dev/null; then + error "$(gettext "Cannot find the %s binary required for optimizing PNG images.")" "optipng" + ret=1 + fi + fi + # distcc - compilation with distcc if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then if ! type -p distcc >/dev/null; then -- 2.2.2
On 22.01.2015 09:36, Christian Hesse wrote:
--- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r png ; do + if [[ $(file -bi "$png") = *'image/png'* ]]; then
Better use "file -b --mime-type" and get rid of the globs.
+ optipng "$png" &>/dev/null || + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}" + fi + done + fi }
find_libdepends() {
On 24/01/15 00:40, Florian Pritz wrote:
On 22.01.2015 09:36, Christian Hesse wrote:
--- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r png ; do + if [[ $(file -bi "$png") = *'image/png'* ]]; then
Better use "file -b --mime-type" and get rid of the globs.
hrm... is there a reason why we don't use this elsewhere in makepkg?
+ optipng "$png" &>/dev/null ||
Do this: optipng $OPTIPNGFLAGS "$png" &>/dev/null || then people can specify options they want to pass to optipng - see the upx option. A
+ warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}" + fi + done + fi }
find_libdepends() {
Allan McRae <allan@archlinux.org> on Sat, 2015/01/24 16:17:
On 24/01/15 00:40, Florian Pritz wrote:
On 22.01.2015 09:36, Christian Hesse wrote:
--- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r png ; do + if [[ $(file -bi "$png") = *'image/png'* ]]; then
Better use "file -b --mime-type" and get rid of the globs.
Agreed.
hrm... is there a reason why we don't use this elsewhere in makepkg?
My code is based on the upx functionality. So we want to change it there as well?
+ optipng "$png" &>/dev/null ||
Do this:
optipng $OPTIPNGFLAGS "$png" &>/dev/null ||
then people can specify options they want to pass to optipng - see the upx option.
Sounds reasonable. I will prepare a new patch.
+ warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}" + fi + done + fi }
find_libdepends() {
-- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);}
From: Christian Hesse <mail@eworm.de> This can decrease package size by optimizing PNG image size. Images are just stored with better compression and/or filter options. The actual image content is not altered. Additionally this can automatically fix broken PNG images which caused some trouble lately. Signed-off-by: Christian Hesse <mail@eworm.de> --- contrib/PKGBUILD.vim | 2 +- doc/PKGBUILD.5.txt | 3 +++ doc/makepkg.conf.5.txt | 6 +++++- etc/makepkg.conf.in | 5 +++-- scripts/makepkg.sh.in | 21 ++++++++++++++++++++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/contrib/PKGBUILD.vim b/contrib/PKGBUILD.vim index 9157063..4d520ac 100644 --- a/contrib/PKGBUILD.vim +++ b/contrib/PKGBUILD.vim @@ -211,7 +211,7 @@ hi def link pbValidSha512sums Number " options syn keyword pb_k_options options contained -syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained +syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|optipng\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained syn match pbOptionsNeg /\!/ contained syn match pbOptionsDeprec /no/ contained syn region pbOptionsGroup start=/^options=(/ end=/)/ contains=pb_k_options,pbOptions,pbOptionsNeg,pbOptionsDeprec,pbIllegalOption diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt index c95c41d..10980ab 100644 --- a/doc/PKGBUILD.5.txt +++ b/doc/PKGBUILD.5.txt @@ -296,6 +296,9 @@ underscore and the architecture name e.g., 'replaces_x86_64=()'. *upx*;; Compress binary executable files using UPX. + *optipng*;; + Optimize PNG images with optipng. + *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 5bd3a4a..859e5d7 100644 --- a/doc/makepkg.conf.5.txt +++ b/doc/makepkg.conf.5.txt @@ -140,7 +140,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 staticlibs emptydirs zipman purge !upx**)**:: +**OPTIONS=(**strip docs libtool staticlibs emptydirs zipman purge !upx !optipng**)**:: This array contains options that affect 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 @@ -181,6 +181,10 @@ Options Compress binary executable files using UPX. Additional options can be passed to UPX by specifying the `UPXFLAGS` variable. + *optipng*;; + Optimize PNG images with optipng. Additional options can be passed + to optipng by specifying the `OPTIPNGFLAGS` variable. + *debug*;; Add the user-specified debug flags as specified in DEBUG_CFLAGS and DEBUG_CXXFLAGS to their counterpart buildflags. Creates a separate diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index 19f673d..71ec624 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -71,7 +71,7 @@ BUILDENV=(!distcc color !ccache check !sign) # These are default values for the options=() settings ######################################################################### # -# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug) # A negated option will do the opposite of the comments below. # #-- strip: Strip symbols from binaries/libraries @@ -82,9 +82,10 @@ BUILDENV=(!distcc color !ccache check !sign) #-- 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 +#-- optipng: Optimize PNG images with optipng #-- debug: Add debugging flags as specified in DEBUG_* variables # -OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug) #-- 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 00beb76..2a5fbde 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -49,7 +49,7 @@ declare -r startdir="$PWD" LIBRARY=${LIBRARY:-'@libmakepkgdir@'} packaging_options=('strip' 'docs' 'libtool' 'staticlibs' 'emptydirs' 'zipman' - 'purge' 'upx' 'debug') + 'purge' 'upx' 'optipng' 'debug') other_options=('ccache' 'distcc' 'buildflags' 'makeflags') splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' 'backup' @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r png ; do + if [[ $(file --brief --mime-type "$png") = 'image/png' ]]; then + optipng $OPTIPNGFLAGS "$png" &>/dev/null || + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}" + fi + done + fi } find_libdepends() { @@ -3008,6 +3019,14 @@ check_software() { fi fi + # optipng - PNG image optimization + if check_option "optipng" "y"; then + if ! type -p optipng >/dev/null; then + error "$(gettext "Cannot find the %s binary required for optimizing PNG images.")" "optipng" + ret=1 + fi + fi + # distcc - compilation with distcc if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then if ! type -p distcc >/dev/null; then -- 2.2.2
On Jan 24, 2015 1:48 PM, "Christian Hesse" <list@eworm.de> wrote:
From: Christian Hesse <mail@eworm.de>
This can decrease package size by optimizing PNG image size. Images are just stored with better compression and/or filter options. The actual image content is not altered.
Additionally this can automatically fix broken PNG images which caused some trouble lately.
Signed-off-by: Christian Hesse <mail@eworm.de> --- contrib/PKGBUILD.vim | 2 +- doc/PKGBUILD.5.txt | 3 +++ doc/makepkg.conf.5.txt | 6 +++++- etc/makepkg.conf.in | 5 +++-- scripts/makepkg.sh.in | 21 ++++++++++++++++++++- 5 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/contrib/PKGBUILD.vim b/contrib/PKGBUILD.vim index 9157063..4d520ac 100644 --- a/contrib/PKGBUILD.vim +++ b/contrib/PKGBUILD.vim @@ -211,7 +211,7 @@ hi def link pbValidSha512sums Number
" options syn keyword pb_k_options options contained -syn match pbOptions
+syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|optipng\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained syn match pbOptionsNeg /\!/ contained syn match pbOptionsDeprec /no/ contained syn region pbOptionsGroup start=/^options=(/ end=/)/ contains=pb_k_options,pbOptions,pbOptionsNeg,pbOptionsDeprec,pbIllegalOption diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt index c95c41d..10980ab 100644 --- a/doc/PKGBUILD.5.txt +++ b/doc/PKGBUILD.5.txt @@ -296,6 +296,9 @@ underscore and the architecture name e.g., 'replaces_x86_64=()'. *upx*;; Compress binary executable files using UPX.
+ *optipng*;; + Optimize PNG images with optipng. + *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 5bd3a4a..859e5d7 100644 --- a/doc/makepkg.conf.5.txt +++ b/doc/makepkg.conf.5.txt @@ -140,7 +140,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 staticlibs emptydirs zipman purge !upx**)**:: +**OPTIONS=(**strip docs libtool staticlibs emptydirs zipman purge !upx !optipng**)**:: This array contains options that affect 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 @@ -181,6 +181,10 @@ Options Compress binary executable files using UPX. Additional
/\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained options
can be passed to UPX by specifying the `UPXFLAGS`
variable.
+ *optipng*;; + Optimize PNG images with optipng. Additional options can
+ to optipng by specifying the `OPTIPNGFLAGS` variable. + *debug*;; Add the user-specified debug flags as specified in DEBUG_CFLAGS and DEBUG_CXXFLAGS to their counterpart buildflags. Creates a separate diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index 19f673d..71ec624 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -71,7 +71,7 @@ BUILDENV=(!distcc color !ccache check !sign) # These are default values for the options=() settings ######################################################################### # -# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug) # A negated option will do the opposite of the comments below. # #-- strip: Strip symbols from binaries/libraries @@ -82,9 +82,10 @@ BUILDENV=(!distcc color !ccache check !sign) #-- 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 +#-- optipng: Optimize PNG images with optipng #-- debug: Add debugging flags as specified in DEBUG_* variables # -OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug)
#-- 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 00beb76..2a5fbde 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -49,7 +49,7 @@ declare -r startdir="$PWD" LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
packaging_options=('strip' 'docs' 'libtool' 'staticlibs' 'emptydirs' 'zipman' - 'purge' 'upx' 'debug') + 'purge' 'upx' 'optipng' 'debug') other_options=('ccache' 'distcc' 'buildflags' 'makeflags') splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' 'backup' @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r
be passed png ; do
+ if [[ $(file --brief --mime-type "$png") = 'image/png' ]]; then + optipng $OPTIPNGFLAGS "$png" &>/dev/null || + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}"
+ fi + done + fi }
find_libdepends() { @@ -3008,6 +3019,14 @@ check_software() { fi fi
+ # optipng - PNG image optimization + if check_option "optipng" "y"; then + if ! type -p optipng >/dev/null; then + error "$(gettext "Cannot find the %s binary required for optimizing PNG images.")" "optipng" + ret=1 + fi + fi + # distcc - compilation with distcc if check_buildenv "distcc" "y" && ! check_option "distcc" "n";
I really dislike that we're using a simple var instead of an array here. Is there a strong reason not to do this? then
if ! type -p distcc >/dev/null; then -- 2.2.2
Dave Reisner <d@falconindy.com> on Sat, 2015/01/24 15:38:
+ if [[ $(file --brief --mime-type "$png") = 'image/png' ]]; then + optipng $OPTIPNGFLAGS "$png" &>/dev/null || + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}"
I really dislike that we're using a simple var instead of an array here. Is there a strong reason not to do this?
So you would prefer "${OPTIPNGFLAGS[@]}"? Again, this is adopted from upx and UPXFLAGS which is just a simple var. I am fine with using an array, in fact I would prefer it. Want a new patch? How about UPXFLAGS? Do we want to change it there? -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);}
On Jan 24, 2015 3:58 PM, "Christian Hesse" <list@eworm.de> wrote:
Dave Reisner <d@falconindy.com> on Sat, 2015/01/24 15:38:
+ if [[ $(file --brief --mime-type "$png") = 'image/png' ]]; then + optipng $OPTIPNGFLAGS "$png"
|| + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}"
I really dislike that we're using a simple var instead of an array here. Is there a strong reason not to do this?
So you would prefer "${OPTIPNGFLAGS[@]}"? Again, this is adopted from upx and UPXFLAGS which is just a simple var.
I am fine with using an array, in fact I would prefer it. Want a new
&>/dev/null patch?
How about UPXFLAGS? Do we want to change it there?
I'd certainly prefer that but I don't know how others feel about breaking backwards compatibility.
-- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Chris get my mail address: */=0;b=c[a++];) putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);}
On 25/01/15 07:26, Dave Reisner wrote:
On Jan 24, 2015 3:58 PM, "Christian Hesse" <list@eworm.de> wrote:
Dave Reisner <d@falconindy.com> on Sat, 2015/01/24 15:38:
+ if [[ $(file --brief --mime-type "$png") = 'image/png' ]]; then + optipng $OPTIPNGFLAGS "$png"
|| + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}"
I really dislike that we're using a simple var instead of an array here. Is there a strong reason not to do this?
So you would prefer "${OPTIPNGFLAGS[@]}"? Again, this is adopted from upx and UPXFLAGS which is just a simple var.
I am fine with using an array, in fact I would prefer it. Want a new
&>/dev/null patch?
How about UPXFLAGS? Do we want to change it there?
I'd certainly prefer that but I don't know how others feel about breaking backwards compatibility.
Break it - I am sure no-one is using this functionality... And it matches our other variables like COMPRESSGZ. This should also be noted in the documentation. A.
From: Christian Hesse <mail@eworm.de> Signed-off-by: Christian Hesse <mail@eworm.de> --- doc/makepkg.conf.5.txt | 4 ++-- scripts/makepkg.sh.in | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/makepkg.conf.5.txt b/doc/makepkg.conf.5.txt index 5bd3a4a..5e34b91 100644 --- a/doc/makepkg.conf.5.txt +++ b/doc/makepkg.conf.5.txt @@ -178,8 +178,8 @@ Options package. *upx*;; - Compress binary executable files using UPX. Additional options - can be passed to UPX by specifying the `UPXFLAGS` variable. + Compress binary executable files using UPX. Additional options + can be passed to UPX by specifying the `UPXFLAGS` array variable. *debug*;; Add the user-specified debug flags as specified in DEBUG_CFLAGS and diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 00beb76..72f5b04 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1912,8 +1912,8 @@ tidy_install() { msg2 "$(gettext "Compressing binaries with %s...")" "UPX" local binary find . -type f -perm -u+w 2>/dev/null | while read -r binary ; do - if [[ $(file -bi "$binary") = *'application/x-executable'* ]]; then - upx $UPXFLAGS "$binary" &>/dev/null || + if [[ $(file --brief --mime-type "$binary") = 'application/x-executable' ]]; then + upx "${UPXFLAGS[@]}" "$binary" &>/dev/null || warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}" fi done -- 2.2.2
From: Christian Hesse <mail@eworm.de> This can decrease package size by optimizing PNG image size. Images are just stored with better compression and/or filter options. The actual image content is not altered. Additionally this can automatically fix broken PNG images which caused some trouble lately. Signed-off-by: Christian Hesse <mail@eworm.de> --- contrib/PKGBUILD.vim | 2 +- doc/PKGBUILD.5.txt | 3 +++ doc/makepkg.conf.5.txt | 6 +++++- etc/makepkg.conf.in | 5 +++-- scripts/makepkg.sh.in | 21 ++++++++++++++++++++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/contrib/PKGBUILD.vim b/contrib/PKGBUILD.vim index 9157063..4d520ac 100644 --- a/contrib/PKGBUILD.vim +++ b/contrib/PKGBUILD.vim @@ -211,7 +211,7 @@ hi def link pbValidSha512sums Number " options syn keyword pb_k_options options contained -syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained +syn match pbOptions /\(no\)\?\(strip\|docs\|libtool\|emptydirs\|zipman\|purge\|upx\|optipng\|fakeroot\|distcc\|color\|ccache\|check\|sign\|makeflags\|buildflags\)/ contained syn match pbOptionsNeg /\!/ contained syn match pbOptionsDeprec /no/ contained syn region pbOptionsGroup start=/^options=(/ end=/)/ contains=pb_k_options,pbOptions,pbOptionsNeg,pbOptionsDeprec,pbIllegalOption diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt index c95c41d..10980ab 100644 --- a/doc/PKGBUILD.5.txt +++ b/doc/PKGBUILD.5.txt @@ -296,6 +296,9 @@ underscore and the architecture name e.g., 'replaces_x86_64=()'. *upx*;; Compress binary executable files using UPX. + *optipng*;; + Optimize PNG images with optipng. + *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 5e34b91..ac5791f 100644 --- a/doc/makepkg.conf.5.txt +++ b/doc/makepkg.conf.5.txt @@ -140,7 +140,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 staticlibs emptydirs zipman purge !upx**)**:: +**OPTIONS=(**strip docs libtool staticlibs emptydirs zipman purge !upx !optipng**)**:: This array contains options that affect 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 @@ -181,6 +181,10 @@ Options Compress binary executable files using UPX. Additional options can be passed to UPX by specifying the `UPXFLAGS` array variable. + *optipng*;; + Optimize PNG images with optipng. Additional options can be passed + to optipng by specifying the `OPTIPNGFLAGS` array variable. + *debug*;; Add the user-specified debug flags as specified in DEBUG_CFLAGS and DEBUG_CXXFLAGS to their counterpart buildflags. Creates a separate diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index 19f673d..71ec624 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -71,7 +71,7 @@ BUILDENV=(!distcc color !ccache check !sign) # These are default values for the options=() settings ######################################################################### # -# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +# Default: OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug) # A negated option will do the opposite of the comments below. # #-- strip: Strip symbols from binaries/libraries @@ -82,9 +82,10 @@ BUILDENV=(!distcc color !ccache check !sign) #-- 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 +#-- optipng: Optimize PNG images with optipng #-- debug: Add debugging flags as specified in DEBUG_* variables # -OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !debug) +OPTIONS=(strip docs libtool staticlibs emptydirs zipman purge !upx !optipng !debug) #-- 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 72f5b04..ee940e5 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -49,7 +49,7 @@ declare -r startdir="$PWD" LIBRARY=${LIBRARY:-'@libmakepkgdir@'} packaging_options=('strip' 'docs' 'libtool' 'staticlibs' 'emptydirs' 'zipman' - 'purge' 'upx' 'debug') + 'purge' 'upx' 'optipng' 'debug') other_options=('ccache' 'distcc' 'buildflags' 'makeflags') splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' 'backup' @@ -1918,6 +1918,17 @@ tidy_install() { fi done fi + + if check_option "optipng" "y"; then + msg2 "$(gettext "Optimizing PNG images...")" + local png + find . -type f -iname "*.png" 2>/dev/null | while read -r png ; do + if [[ $(file --brief --mime-type "$png") = 'image/png' ]]; then + optipng "${OPTIPNGFLAGS[@]}" "$png" &>/dev/null || + warning "$(gettext "Could not optimize PNG image : %s")" "${png/$pkgdir\//}" + fi + done + fi } find_libdepends() { @@ -3008,6 +3019,14 @@ check_software() { fi fi + # optipng - PNG image optimization + if check_option "optipng" "y"; then + if ! type -p optipng >/dev/null; then + error "$(gettext "Cannot find the %s binary required for optimizing PNG images.")" "optipng" + ret=1 + fi + fi + # distcc - compilation with distcc if check_buildenv "distcc" "y" && ! check_option "distcc" "n"; then if ! type -p distcc >/dev/null; then -- 2.2.2
Am 22.01.2015 09:36, schrieb Christian Hesse:
From: Christian Hesse <mail@eworm.de>
This can decrease package size by optimizing PNG image size. Images are just stored with better compression and/or filter options. The actual image content is not altered.
Additionally this can automatically fix broken PNG images which caused some trouble lately.
Signed-off-by: Christian Hesse <mail@eworm.de>
I am not sure it is wise to use such a feature on Arch. One could say it alters the package in a way that was not intended by upstream. And similar to other downstream patches we add: It would be better for every user of such software if those png files are optimized by the upstream project. Especially if they are broken. One could implement a namcap rule that checks for broken pngs or those that can be optimized. Greetings, Pierre -- Pierre Schmitz, https://pierre-schmitz.com
On 25/01/15 16:45, Pierre Schmitz wrote:
Am 22.01.2015 09:36, schrieb Christian Hesse:
From: Christian Hesse <mail@eworm.de>
This can decrease package size by optimizing PNG image size. Images are just stored with better compression and/or filter options. The actual image content is not altered.
Additionally this can automatically fix broken PNG images which caused some trouble lately.
Signed-off-by: Christian Hesse <mail@eworm.de>
I am not sure it is wise to use such a feature on Arch. One could say it alters the package in a way that was not intended by upstream. And similar to other downstream patches we add: It would be better for every user of such software if those png files are optimized by the upstream project. Especially if they are broken.
One could implement a namcap rule that checks for broken pngs or those that can be optimized.
Whether or not such a feature is used in Arch is a separate conversation, and I doubt we would even enable it. But note that this is just a compression method, much like using gzip in man and info pages. Allan
Am 25.01.2015 07:58, schrieb Allan McRae:
Whether or not such a feature is used in Arch is a separate conversation, and I doubt we would even enable it. But note that this is just a compression method, much like using gzip in man and info pages.
Sure, just wanted to point this out. Also optipng is not loss-less like gzip as you cannot reconstruct the original; esp. if you strip out meta data. Anyway, I am fine with adding such feature. I wonder if we could implement such filters without modifyng the makepkg code. Might be worth if we like to add more in future. Greetings, Pierre -- Pierre Schmitz, https://pierre-schmitz.com
participants (5)
-
Allan McRae
-
Christian Hesse
-
Dave Reisner
-
Florian Pritz
-
Pierre Schmitz