1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 inherit multibuild postgres
5 EXPORT_FUNCTIONS pkg_setup src_prepare src_compile src_install src_test
8 # @ECLASS: postgres-multi.eclass
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
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.
22 *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
26 # @ECLASS-VARIABLE: POSTGRES_COMPAT
29 # A Bash array containing a list of compatible PostgreSQL slots as
30 # defined by the developer. Must be declared before inheriting this
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
36 if ! declare -p POSTGRES_COMPAT &>/dev/null; then
37 die 'Required variable POSTGRES_COMPAT not declared.'
40 # @ECLASS-VARIABLE: _POSTGRES_INTERSECT_SLOTS
43 # A Bash array containing the intersect of POSTGRES_TARGETS and
45 export _POSTGRES_INTERSECT_SLOTS=( )
47 # @FUNCTION: _postgres-multi_multibuild_wrapper
48 # @USAGE: <command> [arg ...]
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
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}"
62 PKG_CONFIG_PATH="$(${PG_CONFIG} --libdir)/pkgconfig"
64 export PKG_CONFIG_PATH
66 $(echo "${@}" | sed "s/@PG_SLOT@/${PG_SLOT}/g")
69 # @FUNCTION: postgres-multi_foreach
70 # @USAGE: <command> [arg ...]
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
80 postgres-multi_foreach() {
81 local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
83 multibuild_foreach_variant \
84 _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
87 # @FUNCTION: postgres-multi_forbest
88 # @USAGE: <command> [arg ...]
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]}")
101 multibuild_foreach_variant \
102 _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
105 # @FUNCTION: postgres-multi_pkg_setup
107 # Initialize internal environment variable(s). This is required if
108 # pkg_setup() is declared in the ebuild.
109 postgres-multi_pkg_setup() {
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}" )
118 if [[ "${#_POSTGRES_INTERSECT_SLOTS[@]}" -eq "0" ]]; then
119 die "One of the postgres_targets_postgresSL_OT use flags must be enabled"
122 einfo "Multibuild variants: ${_POSTGRES_INTERSECT_SLOTS[@]}"
125 # @FUNCTION: postgres-multi_src_prepare
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?"
135 # Check that the slot has been emerged (Should be prevented by
136 # Portage, but won't be caught by /usr/bin/ebuild)
138 for slot in ${_POSTGRES_INTERSECT_SLOTS[@]} ; do
139 if [[ -z $(which pg_config${slot/.} 2> /dev/null) ]] ; then
141 eerror "postgres_targets_postgres${slot/.} use flag is enabled, but hasn't been emerged."
143 die "a postgres_targets use flag is enabled, but not emerged"
148 0|1|2|3|4|5) epatch_user ;;
152 local MULTIBUILD_VARIANT
153 local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
154 multibuild_copy_sources
157 # @FUNCTION: postgres-multi_src_compile
159 # Runs `emake' in each build directory
160 postgres-multi_src_compile() {
161 postgres-multi_foreach emake
164 # @FUNCTION: postgres-multi_src_install
166 # Runs `emake install DESTDIR="${D}"' in each build directory.
167 postgres-multi_src_install() {
168 postgres-multi_foreach emake install DESTDIR="${D}"
171 # @FUNCTION: postgres-multi_src_test
173 # Runs `emake installcheck' in each build directory.
174 postgres-multi_src_test() {
175 postgres-multi_foreach emake installcheck