summaryrefslogtreecommitdiff
path: root/scripts/libmakepkg/tidy
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/libmakepkg/tidy')
-rw-r--r--scripts/libmakepkg/tidy/docs.sh.in37
-rw-r--r--scripts/libmakepkg/tidy/emptydirs.sh.in38
-rw-r--r--scripts/libmakepkg/tidy/libtool.sh.in38
-rw-r--r--scripts/libmakepkg/tidy/optipng.sh.in44
-rw-r--r--scripts/libmakepkg/tidy/purge.sh.in45
-rw-r--r--scripts/libmakepkg/tidy/staticlibs.sh.in43
-rw-r--r--scripts/libmakepkg/tidy/strip.sh.in117
-rw-r--r--scripts/libmakepkg/tidy/upx.sh.in46
-rw-r--r--scripts/libmakepkg/tidy/zipman.sh.in61
9 files changed, 469 insertions, 0 deletions
diff --git a/scripts/libmakepkg/tidy/docs.sh.in b/scripts/libmakepkg/tidy/docs.sh.in
new file mode 100644
index 00000000..a9791302
--- /dev/null
+++ b/scripts/libmakepkg/tidy/docs.sh.in
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# docs.sh - Remove documentation files from the package
+#
+# Copyright (c) 2008-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_DOCS_SH" ] && return
+LIBMAKEPKG_TIDY_DOCS_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+packaging_options+=('docs')
+tidy_remove+=('tidy_docs')
+
+tidy_docs() {
+ if check_option "docs" "n" && [[ -n ${DOC_DIRS[*]} ]]; then
+ msg2 "$(gettext "Removing doc files...")"
+ rm -rf -- ${DOC_DIRS[@]}
+ fi
+}
diff --git a/scripts/libmakepkg/tidy/emptydirs.sh.in b/scripts/libmakepkg/tidy/emptydirs.sh.in
new file mode 100644
index 00000000..c7103e9e
--- /dev/null
+++ b/scripts/libmakepkg/tidy/emptydirs.sh.in
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# emptydirs.sh - Remove empty directories from the package
+#
+# Copyright (c) 2013-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_EMPTYDIRS_SH" ] && return
+LIBMAKEPKG_TIDY_EMPTYDIRS_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('emptydirs')
+tidy_remove+=('tidy_emptydirs')
+
+tidy_emptydirs() {
+ if check_option "emptydirs" "n"; then
+ msg2 "$(gettext "Removing empty directories...")"
+ find . -depth -type d -exec rmdir '{}' + 2>/dev/null
+ fi
+}
diff --git a/scripts/libmakepkg/tidy/libtool.sh.in b/scripts/libmakepkg/tidy/libtool.sh.in
new file mode 100644
index 00000000..b9c62452
--- /dev/null
+++ b/scripts/libmakepkg/tidy/libtool.sh.in
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# libtool.sh - Remove libtool files from the package
+#
+# Copyright (c) 2013-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_LIBTOOL_SH" ] && return
+LIBMAKEPKG_TIDY_LIBTOOL_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('libtool')
+tidy_remove+=('tidy_libtool')
+
+tidy_libtool() {
+ if check_option "libtool" "n"; then
+ msg2 "$(gettext "Removing "%s" files...")" "libtool"
+ find . ! -type d -name "*.la" -exec rm -f -- '{}' +
+ fi
+}
diff --git a/scripts/libmakepkg/tidy/optipng.sh.in b/scripts/libmakepkg/tidy/optipng.sh.in
new file mode 100644
index 00000000..f739a823
--- /dev/null
+++ b/scripts/libmakepkg/tidy/optipng.sh.in
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# optipng.sh - Compress PNG files using optpng
+#
+# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_OPTIPNG_SH" ] && return
+LIBMAKEPKG_TIDY_OPTIPNG_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('optipng')
+tidy_modify+=('tidy_optipng')
+
+tidy_optipng() {
+ 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
+}
diff --git a/scripts/libmakepkg/tidy/purge.sh.in b/scripts/libmakepkg/tidy/purge.sh.in
new file mode 100644
index 00000000..948f001d
--- /dev/null
+++ b/scripts/libmakepkg/tidy/purge.sh.in
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# purge.sh - Remove unwanted files from the package
+#
+# Copyright (c) 2008-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_PURGE_SH" ] && return
+LIBMAKEPKG_TIDY_PURGE_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('purge')
+tidy_remove+=('tidy_purge')
+
+tidy_purge() {
+ if check_option "purge" "y" && [[ -n ${PURGE_TARGETS[*]} ]]; then
+ msg2 "$(gettext "Purging unwanted files...")"
+ local pt
+ for pt in "${PURGE_TARGETS[@]}"; do
+ if [[ ${pt} = "${pt//\/}" ]]; then
+ find . ! -type d -name "${pt}" -exec rm -f -- '{}' +
+ else
+ rm -f ${pt}
+ fi
+ done
+ fi
+}
diff --git a/scripts/libmakepkg/tidy/staticlibs.sh.in b/scripts/libmakepkg/tidy/staticlibs.sh.in
new file mode 100644
index 00000000..4849aba9
--- /dev/null
+++ b/scripts/libmakepkg/tidy/staticlibs.sh.in
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# staticlibs.sh - Remove static library files from the package
+#
+# Copyright (c) 2013-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_STATICLIBS_SH" ] && return
+LIBMAKEPKG_TIDY_STATICLIBS_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('staticlibs')
+tidy_remove+=('tidy_staticlibs')
+
+tidy_staticlibs() {
+ if check_option "staticlibs" "n"; then
+ msg2 "$(gettext "Removing static library files...")"
+ local l
+ while read -rd '' l; do
+ if [[ -f "${l%.a}.so" || -h "${l%.a}.so" ]]; then
+ rm "$l"
+ fi
+ done < <(find . ! -type d -name "*.a" -print0)
+ fi
+}
diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in
new file mode 100644
index 00000000..12a7eee3
--- /dev/null
+++ b/scripts/libmakepkg/tidy/strip.sh.in
@@ -0,0 +1,117 @@
+#!/bin/bash
+#
+# strip.sh - Strip debugging symbols from binary files
+#
+# Copyright (c) 2007-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_STRIP_SH" ] && return
+LIBMAKEPKG_TIDY_STRIP_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('strip' 'debug')
+tidy_modify+=('tidy_strip')
+
+
+build_id() {
+ LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }'
+}
+
+strip_file() {
+ local binary=$1; shift
+
+ if check_option "debug" "y"; then
+ local bid=$(build_id "$binary")
+
+ # has this file already been stripped
+ if [[ -n "$bid" ]]; then
+ if [[ -f "$dbgdir/.build-id/${bid:0:2}/${bid:2}.debug" ]]; then
+ return
+ fi
+ elif [[ -f "$dbgdir/$binary.debug" ]]; then
+ return
+ fi
+
+ mkdir -p "$dbgdir/${binary%/*}"
+ objcopy --only-keep-debug "$binary" "$dbgdir/$binary.debug"
+ objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary"
+
+ # create any needed hardlinks
+ while read -rd '' file ; do
+ if [[ "${binary}" -ef "${file}" && ! -f "$dbgdir/${file}.debug" ]]; then
+ mkdir -p "$dbgdir/${file%/*}"
+ ln "$dbgdir/${binary}.debug" "$dbgdir/${file}.debug"
+ fi
+ done < <(find . -type f -perm -u+w -print0 2>/dev/null)
+
+ if [[ -n "$bid" ]]; then
+ local target
+ mkdir -p "$dbgdir/.build-id/${bid:0:2}"
+
+ target="../../../../../${binary#./}"
+ target="${target/..\/..\/usr\/lib\/}"
+ target="${target/..\/usr\/}"
+ ln -s "$target" "$dbgdir/.build-id/${bid:0:2}/${bid:2}"
+
+ target="../../${binary#./}.debug"
+ ln -s "$target" "$dbgdir/.build-id/${bid:0:2}/${bid:2}.debug"
+ fi
+ fi
+
+ strip $@ "$binary"
+}
+
+
+tidy_strip() {
+ if check_option "strip" "y"; then
+ msg2 "$(gettext "Stripping unneeded symbols from binaries and libraries...")"
+ # make sure library stripping variables are defined to prevent excess stripping
+ [[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
+ [[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
+
+ if check_option "debug" "y"; then
+ dbgdir="$pkgdir-@DEBUGSUFFIX@/usr/lib/debug"
+ mkdir -p "$dbgdir"
+ fi
+
+ local binary strip_flags
+ find . -type f -perm -u+w -print0 2>/dev/null | while read -rd '' binary ; do
+ case "$(file -bi "$binary")" in
+ *application/x-sharedlib*) # Libraries (.so)
+ strip_flags="$STRIP_SHARED";;
+ *application/x-archive*) # Libraries (.a)
+ strip_flags="$STRIP_STATIC";;
+ *application/x-object*)
+ case "$binary" in
+ *.ko) # Kernel module
+ strip_flags="$STRIP_SHARED";;
+ *)
+ continue;;
+ esac;;
+ *application/x-executable*) # Binaries
+ strip_flags="$STRIP_BINARIES";;
+ *)
+ continue ;;
+ esac
+ strip_file "$binary" ${strip_flags}
+ done
+ fi
+}
diff --git a/scripts/libmakepkg/tidy/upx.sh.in b/scripts/libmakepkg/tidy/upx.sh.in
new file mode 100644
index 00000000..49104658
--- /dev/null
+++ b/scripts/libmakepkg/tidy/upx.sh.in
@@ -0,0 +1,46 @@
+#!/bin/bash
+#
+# upx.sh - Compress package binaries with UPX
+#
+# Copyright (c) 2011-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_UPX_SH" ] && return
+LIBMAKEPKG_TIDY_UPX_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('upx')
+tidy_modify+=('tidy_upx')
+
+tidy_upx() {
+ 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 -r binary ; do
+ case "$(file --brief --mime-type "$binary")" in
+ 'application/x-executable' | 'application/x-dosexec')
+ upx "${UPXFLAGS[@]}" "$binary" &>/dev/null ||
+ warning "$(gettext "Could not compress binary : %s")" "${binary/$pkgdir\//}"
+ ;;
+ esac
+ done
+ fi
+}
diff --git a/scripts/libmakepkg/tidy/zipman.sh.in b/scripts/libmakepkg/tidy/zipman.sh.in
new file mode 100644
index 00000000..a08a60fa
--- /dev/null
+++ b/scripts/libmakepkg/tidy/zipman.sh.in
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+# zipman.sh - Compress man and info pages
+#
+# Copyright (c) 2011-2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[ -n "$LIBMAKEPKG_TIDY_ZIPMAN_SH" ] && return
+LIBMAKEPKG_TIDY_ZIPMAN_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/option.sh"
+
+
+packaging_options+=('zipman')
+tidy_modify+=('tidy_zipman')
+
+tidy_zipman() {
+ if check_option "zipman" "y" && [[ -n ${MAN_DIRS[*]} ]]; then
+ msg2 "$(gettext "Compressing man and info pages...")"
+ local file files inode link
+ while read -rd ' ' inode; do
+ read file
+ find ${MAN_DIRS[@]} -type l 2>/dev/null |
+ while read -r link ; do
+ if [[ "${file}" -ef "${link}" ]] ; then
+ rm -f "$link" "${link}.gz"
+ if [[ ${file%/*} = ${link%/*} ]]; then
+ ln -s -- "${file##*/}.gz" "${link}.gz"
+ else
+ ln -s -- "/${file}.gz" "${link}.gz"
+ fi
+ fi
+ done
+ if [[ -z ${files[$inode]} ]]; then
+ files[$inode]=$file
+ gzip -9 -n -f "$file"
+ else
+ rm -f "$file"
+ ln "${files[$inode]}.gz" "${file}.gz"
+ chmod 644 "${file}.gz"
+ fi
+ done < <(find ${MAN_DIRS[@]} -type f \! -name "*.gz" \! -name "*.bz2" \
+ -exec @INODECMD@ '{}' + 2>/dev/null)
+ fi
+}