kde-apps/ksirk: x86 stable (bug #661810)
[gentoo.git] / eclass / db.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: db.eclass
5 # @MAINTAINER:
6 # base-system@gentoo.org
7 # @BLURB: Internal eclass used by sys-libs/db ebuilds
8
9 inherit eutils multilib multiprocessing
10
11 IUSE="doc test examples"
12
13 EXPORT_FUNCTIONS src_test
14
15 DEPEND="test? ( >=dev-lang/tcl-8.4 )"
16
17 RDEPEND=""
18
19 db_fix_so() {
20         has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
21         LIB="${EROOT}/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 "${EROOT}"/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         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
72         # not everybody wants this wad of documentation as it is primarily API docs
73         if use doc; then
74                 dodir /usr/share/doc/${PF}/html
75                 mv "${ED}"/usr/docs/* "${ED}"/usr/share/doc/${PF}/html/
76                 rm -rf "${ED}"/usr/docs
77         else
78                 rm -rf "${ED}"/usr/docs
79         fi
80
81         db_src_install_examples
82 }
83
84 db_src_install_examples() {
85         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
86         if use examples ; then
87                 local langs="c cxx stl"
88                 [[ "${IUSE/java}" != "${IUSE}" ]] \
89                         && use java \
90                         && langs="${langs} java"
91                 for i in $langs ; do
92                         destdir="/usr/share/doc/${PF}/"
93                         src="${S}/../examples_${i}/"
94                         if [ -f "${src}" ]; then
95                                 dodir "${destdir}"
96                                 cp -ra "${src}" "${ED}${destdir}/"
97                         fi
98                 done
99         fi
100 }
101
102 db_src_install_usrbinslot() {
103         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
104         # slot all program names to avoid overwriting
105         for fname in "${ED}"/usr/bin/db*
106         do
107                 dn="$(dirname "${fname}")"
108                 bn="$(basename "${fname}")"
109                 bn="${bn/db/db${SLOT}}"
110                 mv "${fname}" "${dn}/${bn}" || \
111                         die "Failed to rename ${fname} to ${dn}/${bn}"
112         done
113 }
114
115 db_src_install_headerslot() {
116         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
117         # install all headers in a slotted location
118         dodir /usr/include/db${SLOT}
119         mv "${ED}"/usr/include/*.h "${ED}"/usr/include/db${SLOT}/
120 }
121
122 db_src_install_usrlibcleanup() {
123         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
124         LIB="${ED}/usr/$(get_libdir)"
125         # Clean out the symlinks so that they will not be recorded in the
126         # contents (bug #60732)
127
128         if [ "${ED}" = "" ]; then
129                 die "Calling clean_links while \$ED not defined"
130         fi
131
132         if [ -e "${LIB}"/libdb.a ] && [ ! -e "${LIB}"/libdb-${SLOT}.a ]; then
133                 einfo "Moving libdb.a to a versioned name"
134                 mv "${LIB}/libdb.a" "${LIB}/libdb-${SLOT}.a"
135         fi
136
137         if [ -e "${LIB}"/libdb_cxx.a ] && [ ! -e "${LIB}"/libdb_cxx-${SLOT}.a ]; then
138                 einfo "Moving libdb_cxx.a to a versioned name"
139                 mv "${LIB}/libdb_cxx.a" "${LIB}/libdb_cxx-${SLOT}.a"
140         fi
141
142         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so' -exec rm \{} \;
143         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so.[23]' -exec rm \{} \;
144         einfo "removing unversioned static archives"
145         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*a' -exec rm \{} \;
146
147         rm -f \
148                 "${ED}"/usr/include/{db,db_185}.h \
149                 "${LIB}"/libdb{,_{cxx,sql,stl,java,tcl}}.a
150 }
151
152 db_src_test() {
153         if [[ $UID -eq 0 ]]; then
154                 M="You must run the testsuite as non-root, skipping"
155                 ewarn "${M}"
156                 elog "${M}"
157                 return 0
158         fi
159
160         if use tcl; then
161                 einfo "Running sys-libs/db testsuite"
162                 ewarn "This can take 6+ hours on modern machines"
163                 # Fix stuff that fails with relative paths, and upstream moving files
164                 # around...
165                 local test_parallel=''
166                 for t in \
167                         "${S}"/test/parallel.tcl \
168                         "${S}"/../test/parallel.tcl \
169                         "${S}"/test/tcl/parallel.tcl \
170                         "${S}"/../test/tcl/parallel.tcl \
171                         ; do
172                         [[ -f "${t}" ]] && test_parallel="${t}" && break
173                 done
174
175                 sed -ri \
176                         -e '/regsub .test_path ./s,(regsub),#\1,g' \
177                         -e '/regsub .src_root ./s,(regsub),#\1,g' \
178                         -e '/regsub .tcl_utils ./s,(regsub),#\1,g' \
179                         "${test_parallel}"
180                 cd "${S}"
181                 for t in \
182                         ../test/test.tcl \
183                         ../test/tcl/test.tcl \
184                         ; do
185                         [[ -f "${t}" ]] && testbase="${t}" && break
186                 done
187                 echo "source ${t}" > testrunner.tcl
188                 echo "run_parallel $(makeopts_jobs) run_std" >> testrunner.tcl
189
190                 tclsh testrunner.tcl
191                 egrep -qs '^FAIL' ALL.OUT* && die "Some tests failed, please see ${S}/ALL.OUT*"
192         else
193                 eerror "You must have USE=tcl to run the sys-libs/db testsuite."
194         fi
195 }