-
Notifications
You must be signed in to change notification settings - Fork 3
/
fix_pkgconfig
executable file
·35 lines (32 loc) · 1.01 KB
/
fix_pkgconfig
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
#!/bin/sh
#
# fix pkgconfig files to trim slashes, as ie. libdir=/usr/lib64/ rather than
# libdir=/usr/lib64 will make pkg-config --libs return -L/usr/lib64
#
# (c) Per Øyvind Karlsen <[email protected]> 2015
# (c) Andrey Bondrov <[email protected]> 2016
if [ -z "$RPM_BUILD_ROOT" ]; then
printf '%s\n' "No build root defined" >&2
exit 1
fi
if [ ! -d "$RPM_BUILD_ROOT" ]; then
printf '%s\n' "Invalid build root" >&2
exit 1
fi
for pc in $(find "$RPM_BUILD_ROOT" -name \*.pc -type f); do
export PKG_CONFIG_PATH="$(dirname $pc)"
pcfile="$(basename $pc)"
pcmodule="$(printf '%s\n' $pcfile|cut -d. -f1)"
for variable in $(pkg-config --print-variables "$pcmodule"); do
dir=$(pkg-config --variable="$variable" "$pcmodule")
if [[ "$dir" == "/"* && -d "$dir" ]]; then
if [ "$dir" != "$(realpath $dir)" ]; then
parentdir=$(dirname ${dir})
subdir=$(basename ${dir})
regexp="-e s|\(${variable}=.*/${subdir}\)/.*\$|\1|g"
sed $regexp $pc |tr -s // / > $pc.new
mv -f $pc.new $pc
fi
fi
done
done