2014-02-12 17:26:40 +01:00
|
|
|
# This hook executes the following tasks:
|
|
|
|
# - strips ELF binaries/libraries
|
|
|
|
# - generates -dbg pkgs
|
|
|
|
# - generates shlib-provides file for xbps-create(8)
|
|
|
|
|
|
|
|
make_debug() {
|
|
|
|
local dname= fname= dbgfile=
|
|
|
|
|
2014-04-08 17:59:26 +02:00
|
|
|
[ -z "$XBPS_DEBUG_PKGS" ] && return 0
|
2014-02-12 17:26:40 +01:00
|
|
|
|
|
|
|
dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g")
|
|
|
|
fname="$(basename $1)"
|
|
|
|
dbgfile="${dname}/${fname}"
|
|
|
|
|
|
|
|
mkdir -p "${PKGDESTDIR}/usr/lib/debug/${dname}"
|
|
|
|
$OBJCOPY --only-keep-debug --compress-debug-sections \
|
|
|
|
"$1" "${PKGDESTDIR}/usr/lib/debug/${dbgfile}"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "${pkgver}: failed to create dbg file: ${dbgfile}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
chmod 644 "${PKGDESTDIR}/usr/lib/debug/${dbgfile}"
|
|
|
|
}
|
|
|
|
|
|
|
|
attach_debug() {
|
|
|
|
local dname= fname= dbgfile=
|
|
|
|
|
2014-04-08 17:59:26 +02:00
|
|
|
[ -z "$XBPS_DEBUG_PKGS" ] && return 0
|
2014-02-12 17:26:40 +01:00
|
|
|
|
|
|
|
dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g")
|
|
|
|
fname="$(basename $1)"
|
|
|
|
dbgfile="${dname}/${fname}"
|
|
|
|
|
|
|
|
$OBJCOPY --add-gnu-debuglink="${PKGDESTDIR}/usr/lib/debug/${dbgfile}" "$1"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "${pkgver}: failed to attach dbg to ${dbgfile}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
create_debug_pkg() {
|
|
|
|
local _pkgname= _destdir=
|
|
|
|
|
2014-04-08 17:59:26 +02:00
|
|
|
[ -z "$XBPS_DEBUG_PKGS" ] && return 0
|
2014-02-12 17:26:40 +01:00
|
|
|
[ ! -d "${PKGDESTDIR}/usr/lib/debug" ] && return 0
|
|
|
|
|
|
|
|
_pkgname="${pkgname}-dbg-${version}"
|
|
|
|
_destdir="${XBPS_DESTDIR}/${XBPS_CROSS_TRIPLET}/${_pkgname}"
|
|
|
|
mkdir -p "${_destdir}/usr/lib"
|
|
|
|
mv ${PKGDESTDIR}/usr/lib/debug ${_destdir}/usr/lib
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to create debug pkg\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
rmdir --ignore-fail-on-non-empty "${PKGDESTDIR}/usr/lib" 2>/dev/null
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
hook() {
|
|
|
|
local fname= x= f= _soname=
|
|
|
|
|
2014-02-13 17:12:09 +01:00
|
|
|
if [ -n "$nostrip" -o -n "$noarch" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2014-02-12 17:26:40 +01:00
|
|
|
find ${PKGDESTDIR} -type f | while read f; do
|
|
|
|
fname=$(basename "$f")
|
|
|
|
for x in ${nostrip_files}; do
|
|
|
|
if [ "$x" = "$fname" ]; then
|
|
|
|
found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -n "$found" ]; then
|
|
|
|
unset found
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
case "$(file -bi "$f")" in
|
|
|
|
application/x-executable*)
|
|
|
|
if echo "$(file $f)" | grep -q "statically linked"; then
|
|
|
|
# static binary
|
|
|
|
$STRIP "$f"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo " Stripped static executable: ${f#$PKGDESTDIR}"
|
|
|
|
else
|
|
|
|
make_debug "$f"
|
|
|
|
$STRIP "$f"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo " Stripped executable: ${f#$PKGDESTDIR}"
|
|
|
|
attach_debug "$f"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
application/x-sharedlib*)
|
|
|
|
# shared library
|
|
|
|
make_debug "$f"
|
|
|
|
$STRIP --strip-unneeded "$f"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo " Stripped library: ${f#$PKGDESTDIR}"
|
2014-03-19 09:03:21 +01:00
|
|
|
_soname=$(${OBJDUMP} -p "$f"|grep SONAME|awk '{print $2}')
|
2014-04-03 10:30:56 +02:00
|
|
|
pattern="^lib[[:alnum:]_-]+(.*)+\.so(\.[0-9]+)*$"
|
2014-04-02 10:16:16 +02:00
|
|
|
if [[ ${_soname} =~ $pattern ]]; then
|
|
|
|
if [ ! -e ${PKGDESTDIR}/usr/lib/${fname} ]; then
|
2014-04-01 15:14:43 +02:00
|
|
|
continue
|
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
echo "${_soname}" >> ${PKGDESTDIR}/.shlib-provides
|
|
|
|
fi
|
|
|
|
attach_debug "$f"
|
|
|
|
;;
|
|
|
|
application/x-archive*)
|
|
|
|
$STRIP --strip-debug "$f"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo " Stripped static library: ${f#$PKGDESTDIR}";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -s "$PKGDESTDIR/.shlib-provides" ]; then
|
|
|
|
cat $PKGDESTDIR/.shlib-provides | tr '\n' ' ' > $PKGDESTDIR/shlib-provides
|
|
|
|
echo >> $PKGDESTDIR/shlib-provides
|
|
|
|
rm -f $PKGDESTDIR/.shlib-provides
|
|
|
|
fi
|
|
|
|
|
|
|
|
create_debug_pkg
|
|
|
|
return $?
|
|
|
|
}
|