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