Files
scratchpkg/functions/options
2018-02-22 17:08:52 +08:00

116 lines
1.9 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
find . -type f ! -name "*.gz" -exec gzip -9 -f {} \; 2>/dev/null
for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done
)
fi
done
if [ -d usr/share/info ]; then
(cd usr/share/info
find . -type f ! -name "*.gz" -exec gzip -9 -f {} \; 2>/dev/null
)
fi
}