/
brp-strip
executable file
·49 lines (40 loc) · 1.37 KB
/
brp-strip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
# If using normal root, avoid changing anything.
if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then
exit 0
fi
STRIP=${1:-strip}
NCPUS=${RPM_BUILD_NCPUS:-1}
# 32 was chosen as a compromise between reducing the overhead of starting new
# processes and distributing the work load evenly over as much processors as
# possible
MAX_ARGS=32
case `uname -a` in
Darwin*) exit 0 ;;
*) ;;
esac
# Below is the explanation of commands in the order of their appearance
# Ignore /usr/lib/debug entries
# Ignore all ruby, python, and js source files
# Ignore all go(guile objects & golang) files
# Consider files with only single link
# Run the file command to find relevant non-stripped binaries, with bundle size of 32
# Ignore all 'no machine' files
# Only operate on non-stripped binaries
strip_elf_binaries()
{
local nlinks="${1}"
local nprocs="${2}"
find "$RPM_BUILD_ROOT" -type f \
! -regex "${RPM_BUILD_ROOT}/*usr/lib/debug.*" \
! -name "*.py" ! -name "*.js" ! -name "*.rb" \
! -name "*.go" -links "${nlinks}" -print0 | \
xargs -0 -r -P${nprocs} -n${MAX_ARGS} sh -c "file \"\$@\" | \
sed -n -e 's/^\(.*\):[ ]*ELF.*, not stripped.*/\1/p' | \
grep -v 'no machine' | \
xargs -I\{\} $STRIP -g \{\}" ARG0
}
# strip all binaries with single link
strip_elf_binaries "1" "${NCPUS}"
# strip all binaries with more than 1 link
strip_elf_binaries "+1" "1"