1 # Copyright 1999-2017 Gentoo Foundation
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 # @BLURB: An eclass to build PostgreSQL-related packages against multiple slots
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.
21 *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
25 # @ECLASS-VARIABLE: POSTGRES_COMPAT
28 # A Bash array containing a list of compatible PostgreSQL slots as
29 # defined by the developer. Must be declared before inheriting this
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
35 if ! declare -p POSTGRES_COMPAT &>/dev/null; then
36 die 'Required variable POSTGRES_COMPAT not declared.'
39 # @ECLASS-VARIABLE: _POSTGRES_INTERSECT_SLOTS
42 # A Bash array containing the intersect of POSTGRES_TARGETS and
44 export _POSTGRES_INTERSECT_SLOTS=( )
46 # @FUNCTION: _postgres-multi_multibuild_wrapper
47 # @USAGE: <command> [arg ...]
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
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}"
61 PKG_CONFIG_PATH="$(${PG_CONFIG} --libdir)/pkgconfig"
63 export PKG_CONFIG_PATH
65 $(echo "${@}" | sed "s/@PG_SLOT@/${PG_SLOT}/g")
68 # @FUNCTION: postgres-multi_foreach
69 # @USAGE: <command> [arg ...]
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
79 postgres-multi_foreach() {
80 local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
82 multibuild_foreach_variant \
83 _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
86 # @FUNCTION: postgres-multi_forbest
87 # @USAGE: <command> [arg ...]
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]}")
100 multibuild_foreach_variant \
101 _postgres-multi_multibuild_wrapper run_in_build_dir ${@}
104 # @FUNCTION: postgres-multi_pkg_setup
106 # Initialize internal environment variable(s). This is required if
107 # pkg_setup() is declared in the ebuild.
108 postgres-multi_pkg_setup() {
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}" )
117 if [[ "${#_POSTGRES_INTERSECT_SLOTS[@]}" -eq "0" ]]; then
118 die "One of the postgres_targets_postgresSL_OT use flags must be enabled"
121 einfo "Multibuild variants: ${_POSTGRES_INTERSECT_SLOTS[@]}"
124 # @FUNCTION: postgres-multi_src_prepare
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?"
134 # Check that the slot has been emerged (Should be prevented by
135 # Portage, but won't be caught by /usr/bin/ebuild)
137 for slot in ${_POSTGRES_INTERSECT_SLOTS[@]} ; do
138 if [[ -z $(which pg_config${slot/.} 2> /dev/null) ]] ; then
140 eerror "postgres_targets_postgres${slot/.} use flag is enabled, but hasn't been emerged."
142 die "a postgres_targets use flag is enabled, but not emerged"
147 0|1|2|3|4|5) epatch_user ;;
151 local MULTIBUILD_VARIANT
152 local MULTIBUILD_VARIANTS=("${_POSTGRES_INTERSECT_SLOTS[@]}")
153 multibuild_copy_sources
156 # @FUNCTION: postgres-multi_src_compile
158 # Runs `emake' in each build directory
159 postgres-multi_src_compile() {
160 postgres-multi_foreach emake
163 # @FUNCTION: postgres-multi_src_install
165 # Runs `emake install DESTDIR="${D}"' in each build directory.
166 postgres-multi_src_install() {
167 postgres-multi_foreach emake install DESTDIR="${D}"
170 # @FUNCTION: postgres-multi_src_test
172 # Runs `emake installcheck' in each build directory.
173 postgres-multi_src_test() {
174 postgres-multi_foreach emake installcheck