dev-qt/qtopengl: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / db-use.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # This is a common location for functions that aid the use of sys-libs/db
4 #
5 # Bugs: maintainer-needed@gentoo.org
6
7 # multilib is used for get_libname in all EAPI
8 case "${EAPI:-0}" in
9         0|1|2|3|4|5|6) inherit eapi7-ver multilib ;;
10         *) inherit multilib ;;
11 esac
12
13 #Convert a version to a db slot
14 db_ver_to_slot() {
15         if [ $# -ne 1 ]; then
16                 eerror "Function db_ver_to_slot needs one argument" >&2
17                 eerror "args given:" >&2
18                 for f in $@
19                 do
20                         eerror " - \"$@\"" >&2
21                 done
22                 return 1
23         fi
24         # 5.0.x uses 5.0 as slot value, so this replacement will break it;
25         # older sys-libs/db might have been using this but it's no longer
26         # the case, so make it work for latest rather than older stuff.
27         # echo -n "${1/.0/}"
28         echo -n "$1"
29 }
30
31 #Find the version that correspond to the given atom
32 db_findver() {
33         has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
34         if [ $# -ne 1 ]; then
35                 eerror "Function db_findver needs one argument" >&2
36                 eerror "args given:" >&2
37                 for f in $@
38                 do
39                         eerror " - \"$@\"" >&2
40                 done
41                 return 1
42         fi
43
44         PKG="$(best_version $1)"
45         VER="$(ver_cut 1-2 "${PKG/*db-/}")"
46         if [ -d "${EPREFIX}"/usr/include/db$(db_ver_to_slot "$VER") ]; then
47                 #einfo "Found db version ${VER}" >&2
48                 echo -n "$VER"
49                 return 0
50         else
51                 return 1
52         fi
53 }
54
55 # Get the include dir for berkeley db.
56 # This function has two modes. Without any arguments it will give the best
57 # version available. With arguments that form the versions of db packages
58 # to test for, it will aim to find the library corresponding to it.
59
60 db_includedir() {
61         has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
62         if [ $# -eq 0 ]; then
63                 VER="$(db_findver sys-libs/db)" || return 1
64                 VER="$(db_ver_to_slot "$VER")"
65                 echo "include version ${VER}" >&2
66                 if [ -d "${EPREFIX}/usr/include/db${VER}" ]; then
67                         echo -n "${EPREFIX}/usr/include/db${VER}"
68                         return 0
69                 else
70                         eerror "sys-libs/db package requested, but headers not found" >&2
71                         return 1
72                 fi
73         else
74                 #arguments given
75                 for x in $@
76                 do
77                         if VER=$(db_findver "=sys-libs/db-${x}*") &&
78                            [ -d "${EPREFIX}/usr/include/db$(db_ver_to_slot $VER)" ]; then
79                                 echo -n "${EPREFIX}/usr/include/db$(db_ver_to_slot $VER)"
80                                 return 0
81                         fi
82                 done
83                 eerror "No suitable db version found"
84                 return 1
85         fi
86 }
87
88
89 # Get the library name for berkeley db. Something like "db-4.2" will be the
90 # outcome. This function has two modes. Without any arguments it will give
91 # the best version available. With arguments that form the versions of db
92 # packages to test for, it will aim to find the library corresponding to it.
93
94 db_libname() {
95         has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
96         if [ $# -eq 0 ]; then
97                 VER="$(db_findver sys-libs/db)" || return 1
98                 if [ -e "${EPREFIX}/usr/$(get_libdir)/libdb-${VER}$(get_libname)" ]; then
99                         echo -n "db-${VER}"
100                         return 0
101                 else
102                         eerror "sys-libs/db package requested, but library not found" >&2
103                         return 1
104                 fi
105         else
106                 #arguments given
107                 for x in $@
108                 do
109                         if VER=$(db_findver "=sys-libs/db-${x}*"); then
110                                 if [ -e "${EPREFIX}/usr/$(get_libdir)/libdb-${VER}$(get_libname)" ]; then
111                                         echo -n "db-${VER}"
112                                         return 0
113                                 fi
114                         fi
115                 done
116                 eerror "No suitable db version found" >&2
117                 return 1
118         fi
119 }