1 # This hook executes the following tasks:
2 # - strips ELF binaries/libraries
3 # - generates -dbg pkgs
6 local dname
= fname
= dbgfile
=
8 [ -n "$nodebug" ] && return 0
10 dname
=${1%/*}/ ; dname
=${dname#$PKGDESTDIR}
12 dbgfile
="${dname}/${fname}"
14 mkdir
-p "${PKGDESTDIR}/usr/lib/debug/${dname}"
15 $OBJCOPY --only-keep-debug --compress-debug-sections \
16 "$1" "${PKGDESTDIR}/usr/lib/debug/${dbgfile}"
18 msg_red
"${pkgver}: failed to create dbg file: ${dbgfile}\n"
21 chmod 644 "${PKGDESTDIR}/usr/lib/debug/${dbgfile}"
25 local dname
= fname
= dbgfile
=
27 [ -n "$nodebug" ] && return 0
29 dname
=${1%/*}/ ; dname
=${dname#$PKGDESTDIR}
31 dbgfile
="${dname}/${fname}"
33 $OBJCOPY --add-gnu-debuglink="${PKGDESTDIR}/usr/lib/debug/${dbgfile}" "$1"
35 msg_red
"${pkgver}: failed to attach dbg to ${dbgfile}\n"
41 local _pkgname
= _destdir
=
43 [ -n "$nodebug" ] && return 0
44 [ ! -d "${PKGDESTDIR}/usr/lib/debug" ] && return 0
46 _pkgname
="${pkgname}-dbg-${version}"
47 _destdir
="${XBPS_DESTDIR}/${XBPS_CROSS_TRIPLET}/${_pkgname}"
48 mkdir
-p "${_destdir}/usr/lib"
49 mv ${PKGDESTDIR}/usr
/lib
/debug
${_destdir}/usr
/lib
51 msg_red
"$pkgver: failed to create debug pkg\n"
54 printf "${pkgver} " >> ${_destdir}/rdeps
55 rmdir --ignore-fail-on-non-empty "${PKGDESTDIR}/usr/lib" 2>/dev
/null
60 local fname
= x
= f
= _soname
= STRIPCMD
=
62 if [ -n "$nostrip" ]; then
66 STRIPCMD
=/usr
/bin
/$STRIP
68 find ${PKGDESTDIR} -type f |
while read -r f
; do
69 if [[ $f =~ ^
${PKGDESTDIR}/usr
/lib
/debug
/ ]]; then
74 for x
in ${nostrip_files}; do
75 if [ "$x" = "$fname" -o "$x" = "${f#$PKGDESTDIR}" ]; then
80 if [ -n "$found" ]; then
84 case "$(file -bi "$f")" in
85 application
/x-executable
*)
87 if [[ $
(file $f) =~
"statically linked" ]]; then
89 if ! $STRIPCMD "$f"; then
90 msg_red
"$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
93 echo " Stripped static executable: ${f#$PKGDESTDIR}"
96 if ! $STRIPCMD "$f"; then
97 msg_red
"$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
100 echo " Stripped executable: ${f#$PKGDESTDIR}"
102 for x
in ${nopie_files}; do
103 if [ "$x" = "${f#$PKGDESTDIR}" ]; then
108 if [ -z "$nopie" ] && [ -z "$nopie_found" ]; then
109 msg_red
"$pkgver: non-PIE executable found in PIE build: ${f#$PKGDESTDIR}\n"
115 application
/x-sharedlib
*|application
/x-pie-executable
*)
116 local type="$(file -b "$f")"
117 if [[ $type =~
"no machine" ]]; then
118 # using ELF as a container format (e.g. guile)
119 echo " Ignoring ELF file without machine set: ${f#$PKGDESTDIR}"
126 if ! $STRIPCMD --strip-unneeded "$f"; then
127 msg_red
"$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
130 if [[ $type =~
"interpreter " ]]; then
131 echo " Stripped position-independent executable: ${f#$PKGDESTDIR}"
133 echo " Stripped library: ${f#$PKGDESTDIR}"
137 application
/x-archive
*)
139 if ! $STRIPCMD --strip-debug "$f"; then
140 msg_red
"$pkgver: failed to strip ${f#$PKGDESTDIR}\n"
143 echo " Stripped static library: ${f#$PKGDESTDIR}";;