net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / db.eclass
1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4 # This is a common location for functions used in the sys-libs/db ebuilds
5 #
6 # Bugs: maintainer-needed@gentoo.org
7
8 inherit eutils multilib
9
10 IUSE="doc test examples"
11
12 EXPORT_FUNCTIONS src_test
13
14 DEPEND="test? ( >=dev-lang/tcl-8.4 )"
15
16 RDEPEND=""
17
18 db_fix_so() {
19         LIB="${ROOT}/usr/$(get_libdir)"
20
21         cd "${LIB}"
22
23         # first clean up old symlinks
24         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so' -exec rm \{} \;
25         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so.[23]' -exec rm \{} \;
26         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*a' -exec rm \{} \;
27
28         # now rebuild all the correct ones
29         for ext in so a; do
30                 for name in libdb libdb_{cxx,tcl,java,sql,stl}; do
31                         target=`find . -maxdepth 1 -type f -name "${name}-*.${ext}" |sort -n |tail -n 1`
32                         [ -n "${target}" ] && ln -sf ${target//.\//} ${name}.${ext}
33                 done;
34         done;
35
36         # db[23] gets some extra-special stuff
37         if [ -f libdb1.so.2 ]; then
38                 ln -sf libdb1.so.2 libdb.so.2
39                 ln -sf libdb1.so.2 libdb1.so
40                 ln -sf libdb1.so.2 libdb-1.so
41         fi
42         # what do we do if we ever get 3.3 ?
43         for i in libdb libdb_{cxx,tcl,java,sql,stl}; do
44                 if [ -f $i-3.2.so ]; then
45                         ln -sf $i-3.2.so $i-3.so
46                         ln -sf $i-3.2.so $i.so.3
47                 fi
48         done
49
50         # do the same for headers now
51         # but since there are only two of them, just overwrite them
52         cd "${ROOT}"/usr/include
53         target=`find . -maxdepth 1 -type d -name 'db[0-9]*' | sort -n |cut -d/ -f2- | tail -n1`
54         if [ -n "${target}" ] && [ -e "${target}/db.h" ] && ( ! [[ -e db.h ]] || [[ -h db.h ]] ); then
55                 einfo "Creating db.h symlinks to ${target}"
56                 ln -sf "${target}"/db.h .
57                 ln -sf "${target}"/db_185.h .
58         elif [ ! -e "${target}/db.h" ]; then
59                 if [ -n "${target}" ]; then
60                         ewarn "Could not find ${target}/db.h"
61                 elif [ -h db.h ]; then
62                         einfo "Apparently you just removed the last instance of $PN. Removing the symlinks"
63                         rm -f db.h db_185.h
64                 fi
65         fi
66 }
67
68 db_src_install_doc() {
69         # not everybody wants this wad of documentation as it is primarily API docs
70         if use doc; then
71                 dodir /usr/share/doc/${PF}/html
72                 mv "${D}"/usr/docs/* "${D}"/usr/share/doc/${PF}/html/
73                 rm -rf "${D}"/usr/docs
74         else
75                 rm -rf "${D}"/usr/docs
76         fi
77
78         db_src_install_examples
79 }
80
81 db_src_install_examples() {
82         if use examples ; then
83                 local langs="c cxx stl"
84                 [[ "${IUSE/java}" != "${IUSE}" ]] \
85                         && use java \
86                         && langs="${langs} java"
87                 for i in $langs ; do
88                         destdir="/usr/share/doc/${PF}/"
89                         src="${S}/../examples_${i}/"
90                         if [ -f "${src}" ]; then
91                                 dodir "${destdir}"
92                                 cp -ra "${src}" "${D}${destdir}/"
93                         fi
94                 done
95         fi
96 }
97
98 db_src_install_usrbinslot() {
99         # slot all program names to avoid overwriting
100         for fname in "${D}"/usr/bin/db*
101         do
102                 dn="$(dirname "${fname}")"
103                 bn="$(basename "${fname}")"
104                 bn="${bn/db/db${SLOT}}"
105                 mv "${fname}" "${dn}/${bn}" || \
106                         die "Failed to rename ${fname} to ${dn}/${bn}"
107         done
108 }
109
110 db_src_install_headerslot() {
111         # install all headers in a slotted location
112         dodir /usr/include/db${SLOT}
113         mv "${D}"/usr/include/*.h "${D}"/usr/include/db${SLOT}/
114 }
115
116 db_src_install_usrlibcleanup() {
117         LIB="${D}/usr/$(get_libdir)"
118         # Clean out the symlinks so that they will not be recorded in the
119         # contents (bug #60732)
120
121         if [ "${D}" = "" ]; then
122                 die "Calling clean_links while \$D not defined"
123         fi
124
125         if [ -e "${LIB}"/libdb.a ] && [ ! -e "${LIB}"/libdb-${SLOT}.a ]; then
126                 einfo "Moving libdb.a to a versioned name"
127                 mv "${LIB}/libdb.a" "${LIB}/libdb-${SLOT}.a"
128         fi
129
130         if [ -e "${LIB}"/libdb_cxx.a ] && [ ! -e "${LIB}"/libdb_cxx-${SLOT}.a ]; then
131                 einfo "Moving libdb_cxx.a to a versioned name"
132                 mv "${LIB}/libdb_cxx.a" "${LIB}/libdb_cxx-${SLOT}.a"
133         fi
134
135         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so' -exec rm \{} \;
136         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so.[23]' -exec rm \{} \;
137         einfo "removing unversioned static archives"
138         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*a' -exec rm \{} \;
139
140         rm -f \
141                 "${D}"/usr/include/{db,db_185}.h \
142                 "${LIB}"/libdb{,_{cxx,sql,stl,java,tcl}}.a
143 }
144
145 db_src_test() {
146         if [[ $UID -eq 0 ]]; then
147                 M="You must run the testsuite as non-root, skipping"
148                 ewarn "${M}"
149                 elog "${M}"
150                 return 0
151         fi
152
153         if use tcl; then
154                 einfo "Running sys-libs/db testsuite"
155                 ewarn "This can take 6+ hours on modern machines"
156                 # Fix stuff that fails with relative paths, and upstream moving files
157                 # around...
158                 local test_parallel=''
159                 for t in \
160                         "${S}"/test/parallel.tcl \
161                         "${S}"/../test/parallel.tcl \
162                         "${S}"/test/tcl/parallel.tcl \
163                         "${S}"/../test/tcl/parallel.tcl \
164                         ; do
165                         [[ -f "${t}" ]] && test_parallel="${t}" && break
166                 done
167
168                 sed -ri \
169                         -e '/regsub .test_path ./s,(regsub),#\1,g' \
170                         -e '/regsub .src_root ./s,(regsub),#\1,g' \
171                         -e '/regsub .tcl_utils ./s,(regsub),#\1,g' \
172                         "${test_parallel}"
173                 cd "${S}"
174                 for t in \
175                         ../test/test.tcl \
176                         ../test/tcl/test.tcl \
177                         ; do
178                         [[ -f "${t}" ]] && testbase="${t}" && break
179                 done
180                 echo "source ${t}" > testrunner.tcl
181                 echo "run_parallel $(makeopts_jobs) run_std" >> testrunner.tcl
182
183                 tclsh testrunner.tcl
184                 egrep -qs '^FAIL' ALL.OUT* && die "Some tests failed, please see ${S}/ALL.OUT*"
185         else
186                 eerror "You must have USE=tcl to run the sys-libs/db testsuite."
187         fi
188 }