Debian Codegraph @

debian/genshlibs

raw
1 #! /bin/sh
2 #
3 # generate shlibs/symbols files for samba packages
4 #
5 # samba ships a mix of:
6 # public libraries with stable ABI in /usr/lib
7 # public libraries in /usr/lib
8 # public python libraries in /usr/lib
9 # private libraries in /usr/lib/samba/
10 # plugins in /usr/lib/samba/*/
11 #
12 # For public libraries with stable ABI we generate symbols files.
13 # These are listed in d/package.symbols files.
14 # For other librries, we only need to generate shlibs files
15 # with basic version information so that dpkg-shlibdeps will find them.
16 # Here, for libs without .symbols file, we have 2 choices:
17 # for public libraries we generate ($pkg >> $version) dependency in
18 # shlibs file, but for private libs the relation is equality (=).
19 # We do not process plugins, and we do not process python objects.
20 #
21 # dh_makeshlibs is too difficult to use here, we have much simpler approach.
22 # We know exactly where our libs resides (dh_makeshlibs looks everywhere)
23 # and we know filename patterns to recognize our shared libs.
24 # dh_makeshlibs can not be used to generate symbols files for *some* libraries
25 # (it is either all if .symbols is provided, or nothing if not).
26 # It is easier to take strightforward approach than to fight a tool.
27
28 set -e
29 umask 022
30
31 : ${DEB_VERSION:=$(dpkg-parsechangelog -S Version)}
32 : ${DEB_HOST_MULTIARCH:=$(dpkg-architecture -qDEB_HOST_MULTIARCH)}
33
34 # arguments in form pkg1=custom-version pkg2=version2...
35 # to override ${DEB_VERSION} for the given packages
36 custvers="$*"
37
38 lib=usr/lib/${DEB_HOST_MULTIARCH} # the only library directory
39 smblib=$lib/samba # samba private libraries
40
41 rc=0
42
43 # process all packages but skip those without libs of interst
44 for pkg in $(dh_listpackages); do
45 pd=debian/$pkg # package directory
46
47 # find library directories
48 libs=
49 for x in $lib $smblib ; do
50 [ -d $pd/$x ] && libs="$libs $x"
51 done
52 [ -n "$libs" ] || continue
53 # find libraries in library dirs (search for libfoo.so.NN names)
54 libs="$(cd $pd; find $libs -maxdepth 1 -regex '.*\.so.[0-9]+')"
55 [ -n "$libs" ] || continue
56
57 ver=${DEB_VERSION}
58 for x in $custvers; do
59 case "$x" in
60 ( $pkg=* ) ver=${x#*=}; break;;
61 esac
62 done
63 echo "${0##*/}: processing $pkg $ver"
64
65 # generate shlibs file: for public libs use >>$ver, for private =$ver
66 mkdir -p $pd/DEBIAN
67 for x in $libs; do
68 case "$x" in
69 ($smblib/*) rel="= $ver";;
70 (*) rel=">> $ver~";;
71 esac
72 x=${x##*/}
73 echo "${x%.so.*} ${x#**.so.} $pkg ($rel)"
74 done | LC_ALL=C sort > $pd/DEBIAN/shlibs
75
76 # see if we have any public (eg, not in /usr/lib/samba/) libs
77 if echo "$libs" | fgrep -qv $smblib/; then
78 # generate ldconfig trigger activation
79 x=debian/.debhelper/generated/$pkg/triggers
80 y="activate-noawait ldconfig"
81 mkdir -p ${x%/*}
82 if [ ! -f $x ] || ! grep -q "^$y" $x; then
83 echo "# Triggers added by Samba:$0 ${DEB_VERSION}
84 $y" >> $x
85 fi
86 fi
87
88 # packages without .symbols file need no further processing
89 [ -f debian/$pkg.symbols ] || continue
90
91 # process libraries listed in .symbols files with dpkg-gensymbols
92 # find libraries listed in .symbols, find full path of them in $libs
93 # and construct -e$filename argument list in $checklibs for dpkg-gensymbols
94 symlibs=$(sed -n -r 's/^([a-z][^ ]*) .*/\1/p' debian/$pkg.symbols)
95 checklibs=
96 for x in $symlibs; do
97 for y in $libs; do
98 case $y in (*/$x) checklibs="$checklibs -e$pd/$y"; break;; esac
99 done
100 done
101 # dpkg-gensymbols will detect listed but missing libs
102 # here we continue if dpkg-gensymbols failed to collect all errors
103 x=0; dpkg-gensymbols -c4 -p$pkg -P$pd -v$ver -l$smblib $checklibs || x=$?
104 if [ $x = 0 ]; then :
105 elif [ $x = 2 ]; then rc=1
106 else exit 1
107 fi
108
109 done
110
111 exit $rc