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