kde5.eclass: Cleanup obsolete blocker
[gentoo.git] / eclass / postgres-multi.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 inherit multibuild postgres
5 EXPORT_FUNCTIONS pkg_setup src_prepare src_compile src_install src_test
6
7
8 # @ECLASS: postgres-multi.eclass
9 # @MAINTAINER:
10 # PostgreSQL <pgsql-bugs@gentoo.org>
11 # @AUTHOR: Aaron W. Swenson <titanofold@gentoo.org>
12 # @BLURB: An eclass to build PostgreSQL-related packages against multiple slots
13 # @DESCRIPTION:
14 # postgres-multi enables ebuilds, particularly PostgreSQL extensions, to
15 # build and install for one or more PostgreSQL slots as specified by
16 # POSTGRES_TARGETS use flags.
17
18
19 case ${EAPI:-0} in
20         5|6) ;;
21         *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
22 esac
23
24
25 # @ECLASS-VARIABLE: POSTGRES_COMPAT
26 # @REQUIRED
27 # @DESCRIPTION:
28 # A Bash array containing a list of compatible PostgreSQL slots as
29 # defined by the developer. Must be declared before inheriting this
30 # eclass. Example:
31 #@CODE
32 #POSTGRES_COMPAT=( 9.2 9.3 9.4 9.5 9.6 10 )
33 #POSTGRES_COMPAT=( 9.{2,3} 9.{4..6} 10 ) # Same as previous
34 #@CODE
35 if ! declare -p POSTGRES_COMPAT &>/dev/null; then
36         die 'Required variable POSTGRES_COMPAT not declared.'
37 fi
38
39 # @ECLASS-VARIABLE: _POSTGRES_INTERSECT_SLOTS
40 # @INTERNAL
41 # @DESCRIPTION:
42 # A Bash array containing the intersect of POSTGRES_TARGETS and
43 # POSTGRES_COMPAT.
44 export _POSTGRES_INTERSECT_SLOTS=( )
45
46 # @FUNCTION: _postgres-multi_multibuild_wrapper
47 # @USAGE: <command> [arg ...]
48 # @INTERNAL
49 # @DESCRIPTION:
50 # For the given variant, set the values of the PG_SLOT, PG_CONFIG, and
51 # PKG_CONFIG_PATH environment variables accordingly and replace any
52 # appearance of @PG_SLOT@ in the command and arguments with value of
53 # ${PG_SLOT}.
54 _postgres-multi_multibuild_wrapper() {
55         debug-print-function ${FUNCNAME} "${@}"
56         export PG_SLOT=${MULTIBUILD_VARIANT}
57         export PG_CONFIG=$(which pg_config${MULTIBUILD_VARIANT//./})
58         if [[ -n ${PKG_CONFIG_PATH} ]] ; then
59                 PKG_CONFIG_PATH="$(${PG_CONFIG} --libdir)/pkgconfig:${PKG_CONFIG_PATH}"
60         else
61                 PKG_CONFIG_PATH="$(${PG_CONFIG} --libdir)/pkgconfig"
62         fi
63         export PKG_CONFIG_PATH
64
65         $(echo "${@}" | sed "s/@PG_SLOT@/${PG_SLOT}/g")
66 }
67
68 # @FUNCTION: postgres-multi_foreach
69 # @USAGE: <command> [arg ...]
70 # @DESCRIPTION:
71 # Run the given command in the package's build directory for each
72 # PostgreSQL slot in the intersect of POSTGRES_TARGETS and
73 # POSTGRES_COMPAT. The PG_CONFIG and PKG_CONFIG_PATH environment
74 # variables are updated on each iteration to point to the matching
75 # pg_config command and pkg-config metadata files, respectively, for the
76 # current slot. Any appearance of @PG_SLOT@ in the command or arguments
77 # will be substituted with the slot (e.g., 9.5) of the current
78 # iteration.
79 postgres-multi_foreach() {
80         local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
81
82         multibuild_foreach_variant \
83                 _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
84 }
85
86 # @FUNCTION: postgres-multi_forbest
87 # @USAGE: <command> [arg ...]
88 # @DESCRIPTION:
89 # Run the given command in the package's build directory for the highest
90 # slot in the intersect of POSTGRES_COMPAT and POSTGRES_TARGETS. The
91 # PG_CONFIG and PKG_CONFIG_PATH environment variables are set to the
92 # matching pg_config command and pkg-config metadata files,
93 # respectively. Any appearance of @PG_SLOT@ in the command or arguments
94 # will be substituted with the matching slot (e.g., 9.5).
95 postgres-multi_forbest() {
96         # POSTGRES_COMPAT is reverse sorted once in postgres.eclass so
97         # element 0 has the highest slot version.
98         local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[0]}")
99
100         multibuild_foreach_variant \
101                 _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
102 }
103
104 # @FUNCTION: postgres-multi_pkg_setup
105 # @DESCRIPTION:
106 # Initialize internal environment variable(s). This is required if
107 # pkg_setup() is declared in the ebuild.
108 postgres-multi_pkg_setup() {
109         local user_slot
110
111         # _POSTGRES_COMPAT is created in postgres.eclass
112         for user_slot in "${_POSTGRES_COMPAT[@]}"; do
113                 use "postgres_targets_postgres${user_slot/\./_}" && \
114                         _POSTGRES_INTERSECT_SLOTS+=( "${user_slot}" )
115         done
116
117         if [[ "${#_POSTGRES_INTERSECT_SLOTS[@]}" -eq "0" ]]; then
118                 die "One of the postgres_targets_postgresSL_OT use flags must be enabled"
119         fi
120
121         einfo "Multibuild variants: ${_POSTGRES_INTERSECT_SLOTS[@]}"
122 }
123
124 # @FUNCTION: postgres-multi_src_prepare
125 # @DESCRIPTION:
126 # Calls eapply_user then copies ${S} into a build directory for each
127 # intersect of POSTGRES_TARGETS and POSTGRES_COMPAT.
128 postgres-multi_src_prepare() {
129         if [[ "${#_POSTGRES_INTERSECT_SLOTS[@]}" -eq "0" ]]; then
130                 eerror "Internal array _POSTGRES_INTERSECT_SLOTS is empty."
131                 die "Did you forget to call postgres-multi_pkg_setup?"
132         fi
133
134         # Check that the slot has been emerged (Should be prevented by
135         # Portage, but won't be caught by /usr/bin/ebuild)
136         local slot
137         for slot in ${_POSTGRES_INTERSECT_SLOTS[@]} ; do
138                 if [[ -z $(which pg_config${slot/.} 2> /dev/null) ]] ; then
139                         eerror
140                         eerror "postgres_targets_postgres${slot/.} use flag is enabled, but hasn't been emerged."
141                         eerror
142                         die "a postgres_targets use flag is enabled, but not emerged"
143                 fi
144         done
145
146         case ${EAPI:-0} in
147                 0|1|2|3|4|5) epatch_user ;;
148                 6) eapply_user ;;
149         esac
150
151         local MULTIBUILD_VARIANT
152         local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
153         multibuild_copy_sources
154 }
155
156 # @FUNCTION: postgres-multi_src_compile
157 # @DESCRIPTION:
158 # Runs `emake' in each build directory
159 postgres-multi_src_compile() {
160         postgres-multi_foreach emake
161 }
162
163 # @FUNCTION: postgres-multi_src_install
164 # @DESCRIPTION:
165 # Runs `emake install DESTDIR="${D}"' in each build directory.
166 postgres-multi_src_install() {
167         postgres-multi_foreach emake install DESTDIR="${D}"
168 }
169
170 # @FUNCTION: postgres-multi_src_test
171 # @DESCRIPTION:
172 # Runs `emake installcheck' in each build directory.
173 postgres-multi_src_test() {
174         postgres-multi_foreach emake installcheck
175 }