Files
scratchpkg/functions/options
2018-06-22 16:36:05 +08:00

134 lines
2.2 KiB
Bash

#!/bin/bash
opt_array() {
for i in ${options[@]}; do
if [[ "$i" = "$1" ]]; then
# enable
return 0
elif [[ "$i" = "!$1" ]]; then
# disable
return 1
fi
done
for i in ${OPTIONS[@]}; do
if [[ "$i" = "$1" ]]; then
# enable
return 0
elif [[ "$i" = "!$1" ]]; then
# disable
return 1
fi
done
return 2
}
check_options() {
opt_array $1
case $? in
0) [ $2 = y ] && return ;;
1) [ $2 = n ] && return ;;
*) return 2 ;;
esac
}
removedocs() {
msg2 "Removing docs..."
for dir in ${DOC_DIRS[@]}; do
[ -d $dir ] && rm -fr $dir
done
}
removeemptydirs() {
msg2 "Removing empty directories..."
find . -type d -empty -delete
}
removelibtool() {
msg2 "Removing libtool files..."
find . ! -type d -name "*.la" -delete
}
purgefiles() {
msg2 "Purging unwanted files..."
for option in ${PURGE_FILES[@]}; do
if [ -e $option ]; then
rm -fr $option
fi
done
}
strip_files() {
msg2 "Stripping binaries & libraries..."
find . -type f 2>/dev/null | while read -r binary ; do
case "$(file -bi "$binary")" in
*application/x-sharedlib*) # Libraries (.so)
strip --strip-unneeded "$binary" ;;
*application/x-archive*) # Libraries (.a)
strip --strip-debug "$binary" ;;
*application/x-object*)
case "$binary" in
*.ko) # Kernel module
strip --strip-unneeded "$binary" ;;
*)
continue;;
esac;;
*application/x-executable*) # Binaries
strip --strip-all "$binary" ;;
*)
continue ;;
esac
done
}
compressinfomanpages() {
msg2 "Compressing man & info pages..."
for mandir in ${MAN_DIRS[@]}; do
if [ -d $mandir ]; then
(cd $mandir
for file in $(find . -type f); do
if [ "$file" = "${file%%.gz}" ]; then
gzip -9 "$file"
fi
done
for i in $(find . -type l) ; do
FILE="${i%%.gz}.gz"
TARGET="$(readlink $i)"
TARGET="${TARGET##*/}"
TARGET="${TARGET%%.gz}.gz"
DIR=$(dirname "$FILE")
rm -f $i
if [ -e "$DIR/$TARGET" ]; then
ln -sf $TARGET $FILE
fi
done
)
fi
done
if [ -d usr/share/info ]; then
(cd usr/share/info
for file in $(find . -type f); do
if [ "$file" = "${file%%.gz}" ]; then
gzip -9 "$file"
fi
done
)
fi
}