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