Ticket #149: brp-strip.os2.diff

File brp-strip.os2.diff, 5.9 KB (added by dmik, 9 years ago)
  • brp-strip.os2

    old new  
    1 #!/usr/bin/sh
     1#!/bin/sh
     2
     3#
     4# Strip debug info and compress OS/2 binaries and DLLs using emxomfstrip and lxlite tools.
     5#
     6# Usage: brp-strip.os2 [--[no-]compress] [--[no-]debuginfo]
     7#            [-n|--names <wildcard1[,wildcard2...]>]
     8#            [-i|--include <wildcard1[,wildcard2...]>]
     9#            [-x|--exclude <wildcard1[,wildcard2...]>]
     10#
     11# The --no-compress and --no-debuginfo flags completely disable lxlite and emxomfstrip
     12# invocation, respectively. The -n flag overrides the default list of files that will be
     13# compressed and stripped (see FILENAMES below). The -i flag includes additional files
     14# in this list, the -x flag allows to exclude specific files from processing (applied
     15# after processing the -n and -i flags). The --compress flag makes all subsequent
     16# -n/-i/-x flags operate only on the file list passed to lxlite, without affecting the
     17# strip operation. The --debuginfo flag makes these flags operate on the emxomfstrip
     18# file list, without affecting compression.
     19#
     20# Note that until debug info stripping is completely disabled with --no-debuginfo,
     21# this script will cause emxomstrip to put debug info in separate *.dbg files and will
     22# write all resulting file names into a file list which is to be used by the
     23# %debug_package macro to generate the debug package.
     24#
     25
    226# If using normal root, avoid changing anything.
    3 if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
     27if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" -o "$RPM_BUILD_ROOT" = "/@unixroot" ]; then
    428        exit 0
    529fi
    630
    731NO_COMPRESS=
    832NO_DEBUGINFO=
    933
    10 while test "$1" != "" ; do
     34FILENAMES="*.exe,*.dll,*.pyd"
     35FILENAMES_EXCLUDE=
     36
     37COMPRESS_FILENAMES=
     38COMPRESS_FILENAMES_EXCLUDE=
     39
     40DEBUGINFO_FILENAMES=
     41DEBUGINFO_DFILENAMES_EXCLUDE=
     42
     43dbgext="dbg"
     44dbgfilelist=debugfiles.list
     45
     46var="FILENAMES"
     47
     48while [ -n "$1" ] ; do
    1149    case "$1" in
    1250    --no-compress)
    1351        NO_COMPRESS=1
     52        COMPRESS_FILENAMES=
     53        COMPRESS_FILENAMES_EXCLUDE=
    1454    ;;
    1555    --no-debuginfo)
    1656        NO_DEBUGINFO=1
     57        DEBUGINFO_FILENAMES=
     58        DEBUGINFO_DFILENAMES_EXCLUDE=
     59    ;;
     60    --compress)
     61        NO_COMPRESS=
     62        COMPRESS_FILENAMES="$FILENAMES"
     63        COMPRESS_FILENAMES_EXCLUDE="$FILENAMES_EXCLUDE"
     64        var="COMPRESS_FILENAMES"
     65    ;;
     66    --debuginfo)
     67        NO_DEBUGINFO=
     68        DEBUGINFO_FILENAMES="$FILENAMES"
     69        DEBUGINFO_DFILENAMES_EXCLUDE="$FILENAMES_EXCLUDE"
     70        var="DEBUGINFO_FILENAMES"
     71    ;;
     72    --names|-n)
     73        [ -n "$2" ] && { eval ${var}="\$2" ; shift ; }
     74    ;;
     75    --include|-i)
     76        [ -n "$2" ] && { eval ${var}="\${${var}:+\$${var},}\$2" ; shift ; }
     77    ;;
     78    --exclude|-x)
     79        [ -n "$2" ] && { eval ${var}_EXCLUDE="\${${var}_EXCLUDE:+\$${var}_EXCLUDE,}\$2" ; shift ; }
    1780    ;;
    1881    esac
    1982    shift
     
    2184
    2285# Exit early if nothing to do
    2386[ -n "$NO_COMPRESS" -a -n "$NO_DEBUGINFO" ] && exit
     87[ -z "$FILENAMES" -a -z "$COMPRESS_FILENAMES" -a -z "$DEBUGINFO_FILENAMES" ] && exit
    2488
    25 # Strip and pack OS/2 binaries and DLLs
    26 for f in `find $RPM_BUILD_ROOT -type f -name "*.exe" -o -name "*.dll"`; do
    27         [ -z "$NO_DEBUGINFO" ] && emxomfstrip -D "${f%.*}.dbg" $f
    28         [ -z "$NO_COMPRESS" ] && lxlite /ml1 /mf2 /ydd /yxd /b- "$f"
    29 done
     89sed_names="sed -e 's/^/-name \"/' -e 's/,/\" -o -name \"/g' -e 's/$/\"/'"
     90
     91find_name_args=`echo "$FILENAMES" | eval $sed_names`
     92
     93[ -n "$FILENAMES_EXCLUDE" ] && \
     94    find_name_args="\( $find_name_args \) -a ! \( "`echo "$FILENAMES_EXCLUDE" | eval $sed_names`" \)"
     95
     96if [ -n "$COMPRESS_FILENAMES" ] ; then
     97    if [ "$COMPRESS_FILENAMES" != "$FILENAMES" -o "$COMPRESS_FILENAMES_EXCLUDE" != "$FILENAMES_EXCLUDE" ] ; then
     98        c_find_name_args=`echo "$COMPRESS_FILENAMES" | eval $sed_names`
     99
     100        [ -n "$COMPRESS_FILENAMES_EXCLUDE" ] && \
     101            c_find_name_args="\( $c_find_name_args \) -a ! \( "`echo "$COMPRESS_FILENAMES_EXCLUDE" | eval $sed_names`" \)"
     102    fi
     103fi
     104
     105if [ -n "$DEBUGINFO_FILENAMES" ] ; then
     106    if [ "$DEBUGINFO_FILENAMES" != "$FILENAMES" -o "$DEBUGINFO_FILENAMES_EXCLUDE" != "$FILENAMES_EXCLUDE" ] ; then
     107        d_find_name_args=`echo "$DEBUGINFO_FILENAMES" | eval $sed_names`
     108
     109        [ -n "$DEBUGINFO_FILENAMES_EXCLUDE" ] && \
     110            d_find_name_args="\( $d_find_name_args \) -a ! \( "`echo "$DEBUGINFO_FILENAMES_EXCLUDE" | eval $sed_names`" \)"
     111    fi
     112fi
     113
     114if [ -n "$c_find_name_args" -o -n "$d_find_name_args" ] ; then
     115    [ -z "$c_find_name_args" ] && c_find_name_args="$find_name_args"
     116    [ -z "$d_find_name_args" ] && d_find_name_args="$find_name_args"
     117    if [ "$c_find_name_args" = "$d_find_name_args" ] ; then
     118        find_name_args="$c_find_name_args"
     119        c_find_name_args=
     120        d_find_name_args=
     121    else
     122        find_name_args=
     123    fi
     124fi
     125
     126# Now do the job.
     127
     128if [ -n "$find_name_args" ] ; then
     129    # Single file set (emxomfstrip must come first!)
     130    for f in `eval find \"$RPM_BUILD_ROOT\" -type f $find_name_args`; do
     131        [ -z "$NO_DEBUGINFO" ] && emxomfstrip -D "${f%.*}.$dbgext" $f
     132        [ -z "$NO_COMPRESS" ] && lxlite /ml1 /mf2 /ydd /yxd /b- "$f"
     133    done
     134else
     135    # Two different file sets (emxomfstrip must come first!)
     136    if [ -n "$d_find_name_args" ] ; then
     137        for f in `eval find \"$RPM_BUILD_ROOT\" -type f $d_find_name_args`; do
     138            emxomfstrip -D "${f%.*}.$dbgext" $f
     139        done
     140    fi
     141    if [ -n "$c_find_name_args" ] ; then
     142        for f in `eval find \"$RPM_BUILD_ROOT\" -type f $c_find_name_args`; do
     143            lxlite /ml1 /mf2 /ydd /yxd /b- "$f"
     144        done
     145    fi
     146fi
     147
     148[ -z "$NO_DEBUGINFO" ] && \
     149    find "$RPM_BUILD_ROOT" -type f -name "*.$dbgext" | sed -e "s|^$RPM_BUILD_ROOT||" > "./$dbgfilelist"
     150
     151exit 0