2014-02-12 17:26:40 +01:00
|
|
|
# This hook executes the following tasks:
|
|
|
|
# - strips ELF binaries/libraries
|
|
|
|
# - generates -dbg pkgs
|
|
|
|
|
|
|
|
make_debug() {
|
|
|
|
local dname= fname= dbgfile=
|
|
|
|
|
2014-11-16 11:52:36 +01:00
|
|
|
[ -n "$nodebug" ] && return 0
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2019-04-13 22:47:05 +02:00
|
|
|
dname=${1%/*}/ ; dname=${dname#$PKGDESTDIR}
|
2015-09-11 07:55:40 +02:00
|
|
|
fname="${1##*/}"
|
2014-02-12 17:26:40 +01:00
|
|
|
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-11-16 11:52:36 +01:00
|
|
|
[ -n "$nodebug" ] && return 0
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2019-04-13 22:47:05 +02:00
|
|
|
dname=${1%/*}/ ; dname=${dname#$PKGDESTDIR}
|
2015-09-11 07:55:40 +02:00
|
|
|
fname="${1##*/}"
|
2014-02-12 17:26:40 +01:00
|
|
|
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-11-16 11:52:36 +01:00
|
|
|
[ -n "$nodebug" ] && 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
|
2018-03-05 13:47:43 +01:00
|
|
|
printf "${pkgver} " >> ${_destdir}/rdeps
|
2014-02-12 17:26:40 +01:00
|
|
|
rmdir --ignore-fail-on-non-empty "${PKGDESTDIR}/usr/lib" 2>/dev/null
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
hook() {
|
2015-04-28 09:47:39 +02:00
|
|
|
local fname= x= f= _soname= STRIPCMD=
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2021-01-20 12:55:11 +01:00
|
|
|
if [ -n "$nostrip" ]; then
|
2014-02-13 17:12:09 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2015-04-28 09:47:39 +02:00
|
|
|
STRIPCMD=/usr/bin/$STRIP
|
|
|
|
|
2014-02-12 17:26:40 +01:00
|
|
|
find ${PKGDESTDIR} -type f | while read f; do
|
2015-05-23 07:27:43 +02:00
|
|
|
if [[ $f =~ ^${PKGDESTDIR}/usr/lib/debug/ ]]; then
|
2014-09-27 07:19:42 +02:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2015-09-11 07:55:40 +02:00
|
|
|
fname=${f##*/}
|
2014-02-12 17:26:40 +01:00
|
|
|
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*)
|
2014-10-12 08:56:32 +02:00
|
|
|
chmod +w "$f"
|
2019-04-14 07:11:27 +02:00
|
|
|
if [[ $(file $f) =~ "statically linked" ]]; then
|
2014-02-12 17:26:40 +01:00
|
|
|
# static binary
|
2015-04-28 09:47:39 +02:00
|
|
|
$STRIPCMD "$f"
|
2014-02-12 17:26:40 +01:00
|
|
|
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"
|
2015-04-28 09:47:39 +02:00
|
|
|
$STRIPCMD "$f"
|
2014-02-12 17:26:40 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo " Stripped executable: ${f#$PKGDESTDIR}"
|
2017-11-29 01:20:30 +01:00
|
|
|
unset nopie_found
|
|
|
|
for x in ${nopie_files}; do
|
|
|
|
if [ "$x" = "${f#$PKGDESTDIR}" ]; then
|
|
|
|
nopie_found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -z "$nopie" ] && [ -z "$nopie_found" ]; then
|
2016-05-17 14:58:33 +02:00
|
|
|
msg_red "$pkgver: non-PIE executable found in PIE build: ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
attach_debug "$f"
|
|
|
|
fi
|
|
|
|
;;
|
2018-04-16 14:37:49 +02:00
|
|
|
application/x-sharedlib*|application/x-pie-executable*)
|
2021-01-28 01:18:07 +01:00
|
|
|
local type="$(file -b "$f")"
|
|
|
|
if [[ $type =~ "no machine" ]]; then
|
|
|
|
# using ELF as a container format (e.g. guile)
|
|
|
|
echo " Ignoring ELF file without machine set: ${f#$PKGDESTDIR}"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2014-10-12 08:56:32 +02:00
|
|
|
chmod +w "$f"
|
2014-02-12 17:26:40 +01:00
|
|
|
# shared library
|
|
|
|
make_debug "$f"
|
2015-04-28 09:47:39 +02:00
|
|
|
$STRIPCMD --strip-unneeded "$f"
|
2014-02-12 17:26:40 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
2021-01-28 01:18:07 +01:00
|
|
|
if [[ $type =~ "interpreter " ]]; then
|
2015-03-07 20:54:10 +01:00
|
|
|
echo " Stripped position-independent executable: ${f#$PKGDESTDIR}"
|
|
|
|
else
|
|
|
|
echo " Stripped library: ${f#$PKGDESTDIR}"
|
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
attach_debug "$f"
|
|
|
|
;;
|
|
|
|
application/x-archive*)
|
2014-10-12 08:56:32 +02:00
|
|
|
chmod +w "$f"
|
2015-04-28 09:47:39 +02:00
|
|
|
$STRIPCMD --strip-debug "$f"
|
2014-02-12 17:26:40 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo " Stripped static library: ${f#$PKGDESTDIR}";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
create_debug_pkg
|
|
|
|
return $?
|
|
|
|
}
|