2021-04-22

cook - strip_packages

 

# compressor - module of the SliTaz Cook
cookutils annotate modules/compressor @ rev 1146

al@865 1 #!/bin/sh
al@865 2 #
al@865 3 # compressor - module of the SliTaz Cook
al@865 4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
....

al@865 757 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
al@865 758 # as removing unneeded files like in Python packages. Cross compiled binaries
al@865 759 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
al@865 760 # Stripping can be disabled with COOKOPTS="!strip"
al@865 761
al@865 762 strip_package() {

http://hg.slitaz.org/cookutils/annotate/db1cfeb9ac36/modules/compressor#l757

# Cook - A tool to cook and generate SliTaz packages.
cookutils view cook @ rev 701

# Find and strip: --strip-all (-s) or --strip-debug on static libs as well
# as removing unneeded files like in Python packages. Cross compiled binaries
# must be stripped with cross-tools aka $ARCH-slitaz-*-strip
strip_package() {

http://hg.slitaz.org/cookutils/file/1d55332252d7/cook#l436

 

https://forum.slitaz.org/topic/slitaz-future/page/11?replies=164#post-50013 

 ----

 http://hg.slitaz.org/cookutils/file/1d55332252d7/cook#l436

# Find and strip: --strip-all (-s) or --strip-debug on static libs as well
# as removing unneeded files like in Python packages. Cross compiled binaries
# must be stripped with cross-tools aka $ARCH-slitaz-*-strip
strip_package() {
    case "$ARCH" in
        arm*|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
        *) export STRIP=strip ;;
    esac
    _n "Executing strip on all files..."
    for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
    do
        if [ -d "$dir" ]; then
            find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
        fi
    done
    find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
    find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
    status

    # Remove Python .pyc and .pyo from packages.
    if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
        _n "Removing Python compiled files..."
        find $fs -type f -name "*.pyc" -delete 2>/dev/null
        find $fs -type f -name "*.pyo" -delete 2>/dev/null
        status
    fi

    # Remove Perl perllocal.pod and .packlist from packages.
    if echo "$DEPENDS" | fgrep -q "perl"; then
        _n "Removing Perl compiled files..."
        find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
        find $fs -type f -name ".packlist" -delete 2>/dev/null
        status
    fi
}
 

----

http://hg.slitaz.org/cookutils/file/db1cfeb9ac36/modules/compressor#l757

# Find and strip: --strip-all (-s) or --strip-debug on static libs as well
# as removing unneeded files like in Python packages. Cross compiled binaries
# must be stripped with cross-tools aka $ARCH-slitaz-*-strip
# Stripping can be disabled with COOKOPTS="!strip"

strip_package() {
    [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return

    local i ifs="$IFS"
    IFS=$'\n'

    case "$ARCH" in
        arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
        *)           export STRIP='strip' ;;
    esac
    action 'Executing strip on all files...'
    size0=0
    size1=0
    time0=$(get_time)
    oldsize=$(sizes strip)


    # GNU strip (GNU Binutils)
    # -p --preserve-dates                 Copy modified/access timestamps to the output
    # -s --strip-all                      Remove all symbols and relocation information
    #    --strip-unneeded                 Remove all symbols not needed by relocations
    # -D --enable-deterministic-archives  Produce deterministic output when stripping archives
    # -g -S -d --strip-debug              Remove all debugging symbols & sections

    # Strip executable files
    while read i; do
        $STRIP -ps "$i" 2>/dev/null
    done <<EOT
$(find_elf EXEC)
EOT

    # Strip shared libraries
    while read i; do
        case $i in
            *.dbg) ;; # skip library.so.*.dbg debugging symbols
            *) $STRIP -p --strip-unneeded "$i" 2>/dev/null;;
        esac
    done <<EOT
$(find_elf DYN)
EOT

    # Strip static libraries
    # See also: https://wiki.debian.org/ReproducibleBuilds/TimestampsInStaticLibraries
    find $install -name '*.a' -exec $STRIP -pdD '{}' 2>/dev/null \;


    # Remove Python *.pyc and *.pyo
    find $install -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null

    # Remove both with the empty subfolders:
    # 1. Perl perllocal.pod and .packlist (unconditionally)
    local perlfiles="$(find $install -type f \( -name 'perllocal.pod' -o -name '.packlist' \))"
    # 2. Perl *.pod (if not disabled)
    [ "${COOKOPTS/!rmpod/}" == "$COOKOPTS" ] &&
        perlfiles="$perlfiles"$'\n'"$(find $install -type f -name '*.pod')"
    echo "$perlfiles" | sort -u | xargs rm -f 2>/dev/null
    echo "$perlfiles" | sort -u | awk 'BEGIN{FS=OFS="/"}{$NF="";print}' \
    | xargs rmdir -p --ignore-fail-on-non-empty 2>/dev/null

    # Strip documentation inside Perl files (*.pm and *.pl) (if not disabled)
    [ "${COOKOPTS/!perlz/}" == "$COOKOPTS" ] &&
        find $install -type f \( -name '*.pm' -o -name '*.pl' \) -exec sed -i '/^=/,/^=cut/d' '{}' \;

    newsize=$(sizes strip)

    comp_summary "$time0" "$oldsize" "$newsize"
    IFS="$ifs"
}