Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/Mk/Scripts/generate-symbols.sh
16461 views
1
#! /bin/sh
2
# Maintainer: [email protected]
3
#
4
# This script will find all ELF files in STAGEDIR and then strip and move
5
# the symbols to LOCALBASE/lib/debug/<original path>.
6
# For example:
7
# /var/qmail/bin/qmaild -> /usr/local/lib/debug/var/qmail/bin/qmaild.debug
8
# /usr/local/bin/ssh -> /usr/local/lib/debug/usr/local/bin/ssh.debug
9
10
set -o pipefail
11
12
msg() {
13
echo "====> $*"
14
}
15
16
17
if [ -z "${PREFIX}" -o -z "${LOCALBASE}" -o -z "${STAGEDIR}" -o -z "${TMPPLIST}" ]; then
18
echo "PREFIX, LOCALBASE, STAGEDIR and TMPPLIST are required in environment." >&2
19
exit 1
20
fi
21
22
if [ ! -z "${PREPEND_SUBPACKAGE_PREFIX}" ]; then
23
subpkg_prefix="@@debuginfo@@"
24
fi
25
26
# Find all ELF files
27
ELF_FILES=$(mktemp -t elf_files)
28
find ${STAGEDIR} -type f ! -name '*.a' \
29
-exec /usr/bin/readelf -S /dev/null {} + 2>/dev/null | awk ' \
30
/File:/ {sub(/File: /, "", $0); file=$0}
31
/[[:space:]]\.debug_info[[:space:]]*PROGBITS/ {print file}' \
32
> ${ELF_FILES}
33
34
# Create all of the /usr/local/lib/* dirs
35
lib_dir="${STAGEDIR}${LOCALBASE}/lib/debug"
36
sed -e "s,^${STAGEDIR}/,${lib_dir}/," -e 's,/[^/]*$,,' \
37
${ELF_FILES} | sort -u | xargs mkdir -p
38
39
while read -r staged_elf_file; do
40
elf_file_name="${staged_elf_file##*/}"
41
lib_dir_dest="${lib_dir}/${staged_elf_file#${STAGEDIR}/}"
42
# Strip off filename
43
lib_dir_dest="${lib_dir_dest%/*}"
44
# Save symbols to f.debug
45
debug_file_name="${lib_dir_dest}/${elf_file_name}.debug"
46
objcopy --only-keep-debug "${staged_elf_file}" "${debug_file_name}"
47
# Strip and add a reference to f.debug for finding the symbols.
48
objcopy --strip-debug --strip-unneeded \
49
--add-gnu-debuglink="${debug_file_name}" "${staged_elf_file}"
50
msg "Saved symbols for ${staged_elf_file#${STAGEDIR}}"
51
echo "${subpkg_prefix}${debug_file_name#${STAGEDIR}}" >&3
52
done < ${ELF_FILES} 3>> ${TMPPLIST}
53
54
# Need @dir entries if PREFIX != LOCALBASE
55
if [ "${PREFIX}" != "${LOCALBASE}" ] && [ -d "${lib_dir}" ]; then
56
find -sd "${lib_dir}" -type d | sed -e "s,^${STAGEDIR},," \
57
-e 's,^,@dir ,' \
58
>> ${TMPPLIST}
59
fi
60
61
rm -f ${ELF_FILES}
62
63