| 1 |
# Copyright 1999-2013 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/multilib-build.eclass,v 1.8 2013/03/04 19:30:28 mgorny Exp $ |
| 4 |
|
| 5 |
# @ECLASS: multilib-build.eclass |
| 6 |
# @MAINTAINER: |
| 7 |
# Michał Górny <mgorny@gentoo.org> |
| 8 |
# @BLURB: flags and utility functions for building multilib packages |
| 9 |
# @DESCRIPTION: |
| 10 |
# The multilib-build.eclass exports USE flags and utility functions |
| 11 |
# necessary to build packages for multilib in a clean and uniform |
| 12 |
# manner. |
| 13 |
# |
| 14 |
# Please note that dependency specifications for multilib-capable |
| 15 |
# dependencies shall use the USE dependency string in ${MULTILIB_USEDEP} |
| 16 |
# to properly request multilib enabled. |
| 17 |
|
| 18 |
if [[ ! ${_MULTILIB_BUILD} ]]; then |
| 19 |
|
| 20 |
# EAPI=5 is required for meaningful MULTILIB_USEDEP. |
| 21 |
case ${EAPI:-0} in |
| 22 |
5) ;; |
| 23 |
*) die "EAPI=${EAPI} is not supported" ;; |
| 24 |
esac |
| 25 |
|
| 26 |
inherit multibuild multilib |
| 27 |
|
| 28 |
# @ECLASS-VARIABLE: _MULTILIB_FLAGS |
| 29 |
# @INTERNAL |
| 30 |
# @DESCRIPTION: |
| 31 |
# The list of multilib flags and corresponding ABI values. |
| 32 |
_MULTILIB_FLAGS=( |
| 33 |
abi_x86_32:x86 |
| 34 |
abi_x86_64:amd64 |
| 35 |
abi_x86_x32:x32 |
| 36 |
) |
| 37 |
|
| 38 |
# @ECLASS-VARIABLE: MULTILIB_USEDEP |
| 39 |
# @DESCRIPTION: |
| 40 |
# The USE-dependency to be used on dependencies (libraries) needing |
| 41 |
# to support multilib as well. |
| 42 |
# |
| 43 |
# Example use: |
| 44 |
# @CODE |
| 45 |
# RDEPEND="dev-libs/libfoo[${MULTILIB_USEDEP}] |
| 46 |
# net-libs/libbar[ssl,${MULTILIB_USEDEP}]" |
| 47 |
# @CODE |
| 48 |
|
| 49 |
_multilib_build_set_globals() { |
| 50 |
local flags=( "${_MULTILIB_FLAGS[@]%:*}" ) |
| 51 |
local usedeps=${flags[@]/%/(-)?} |
| 52 |
|
| 53 |
IUSE=${flags[*]} |
| 54 |
MULTILIB_USEDEP=${usedeps// /,} |
| 55 |
} |
| 56 |
_multilib_build_set_globals |
| 57 |
|
| 58 |
# @FUNCTION: multilib_get_enabled_abis |
| 59 |
# @DESCRIPTION: |
| 60 |
# Return the ordered list of enabled ABIs if multilib builds |
| 61 |
# are enabled. The best (most preferred) ABI will come last. |
| 62 |
# |
| 63 |
# If multilib is disabled, the default ABI will be returned |
| 64 |
# in order to enforce consistent testing with multilib code. |
| 65 |
multilib_get_enabled_abis() { |
| 66 |
debug-print-function ${FUNCNAME} "${@}" |
| 67 |
|
| 68 |
local abis=( $(get_all_abis) ) |
| 69 |
|
| 70 |
local abi i found |
| 71 |
for abi in "${abis[@]}"; do |
| 72 |
for i in "${_MULTILIB_FLAGS[@]}"; do |
| 73 |
local m_abi=${i#*:} |
| 74 |
local m_flag=${i%:*} |
| 75 |
|
| 76 |
if [[ ${m_abi} == ${abi} ]] && use "${m_flag}"; then |
| 77 |
echo "${abi}" |
| 78 |
found=1 |
| 79 |
fi |
| 80 |
done |
| 81 |
done |
| 82 |
|
| 83 |
if [[ ! ${found} ]]; then |
| 84 |
# ${ABI} can be used to override the fallback (multilib-portage), |
| 85 |
# ${DEFAULT_ABI} is the safe fallback. |
| 86 |
local abi=${ABI:-${DEFAULT_ABI}} |
| 87 |
|
| 88 |
debug-print "${FUNCNAME}: no ABIs enabled, fallback to ${abi}" |
| 89 |
debug-print "${FUNCNAME}: ABI=${ABI}, DEFAULT_ABI=${DEFAULT_ABI}" |
| 90 |
echo ${abi} |
| 91 |
fi |
| 92 |
} |
| 93 |
|
| 94 |
# @FUNCTION: _multilib_multibuild_wrapper |
| 95 |
# @USAGE: <argv>... |
| 96 |
# @INTERNAL |
| 97 |
# @DESCRIPTION: |
| 98 |
# Initialize the environment for ABI selected for multibuild. |
| 99 |
_multilib_multibuild_wrapper() { |
| 100 |
debug-print-function ${FUNCNAME} "${@}" |
| 101 |
|
| 102 |
local ABI=${MULTIBUILD_VARIANT} |
| 103 |
multilib_toolchain_setup "${ABI}" |
| 104 |
"${@}" |
| 105 |
} |
| 106 |
|
| 107 |
# @FUNCTION: multilib_foreach_abi |
| 108 |
# @USAGE: <argv>... |
| 109 |
# @DESCRIPTION: |
| 110 |
# If multilib support is enabled, sets the toolchain up for each |
| 111 |
# supported ABI along with the ABI variable and correct BUILD_DIR, |
| 112 |
# and runs the given commands with them. |
| 113 |
# |
| 114 |
# If multilib support is disabled, it just runs the commands. No setup |
| 115 |
# is done. |
| 116 |
multilib_foreach_abi() { |
| 117 |
debug-print-function ${FUNCNAME} "${@}" |
| 118 |
|
| 119 |
local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) ) |
| 120 |
multibuild_foreach_variant _multilib_multibuild_wrapper "${@}" |
| 121 |
} |
| 122 |
|
| 123 |
# @FUNCTION: multilib_parallel_foreach_abi |
| 124 |
# @USAGE: <argv>... |
| 125 |
# @DESCRIPTION: |
| 126 |
# If multilib support is enabled, sets the toolchain up for each |
| 127 |
# supported ABI along with the ABI variable and correct BUILD_DIR, |
| 128 |
# and runs the given commands with them. The commands are run |
| 129 |
# in parallel with number of jobs being determined from MAKEOPTS. |
| 130 |
# |
| 131 |
# If multilib support is disabled, it just runs the commands. No setup |
| 132 |
# is done. |
| 133 |
# |
| 134 |
# Useful for running configure scripts. |
| 135 |
multilib_parallel_foreach_abi() { |
| 136 |
debug-print-function ${FUNCNAME} "${@}" |
| 137 |
|
| 138 |
local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) ) |
| 139 |
multibuild_parallel_foreach_variant _multilib_multibuild_wrapper "${@}" |
| 140 |
} |
| 141 |
|
| 142 |
# @FUNCTION: multilib_for_best_abi |
| 143 |
# @USAGE: <argv>... |
| 144 |
# @DESCRIPTION: |
| 145 |
# Runs the given command with setup for the 'best' (usually native) ABI. |
| 146 |
multilib_for_best_abi() { |
| 147 |
debug-print-function ${FUNCNAME} "${@}" |
| 148 |
|
| 149 |
local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) ) |
| 150 |
|
| 151 |
multibuild_for_best_variant _multilib_multibuild_wrapper "${@}" |
| 152 |
} |
| 153 |
|
| 154 |
# @FUNCTION: multilib_check_headers |
| 155 |
# @DESCRIPTION: |
| 156 |
# Check whether the header files are consistent between ABIs. |
| 157 |
# |
| 158 |
# This function needs to be called after each ABI's installation phase. |
| 159 |
# It obtains the header file checksums and compares them with previous |
| 160 |
# runs (if any). Dies if header files differ. |
| 161 |
multilib_check_headers() { |
| 162 |
_multilib_header_cksum() { |
| 163 |
[[ -d ${ED}usr/include ]] && \ |
| 164 |
find "${ED}"usr/include -type f \ |
| 165 |
-exec cksum {} + | sort -k2 |
| 166 |
} |
| 167 |
|
| 168 |
local cksum=$(_multilib_header_cksum) |
| 169 |
local cksum_file=${T}/.multilib_header_cksum |
| 170 |
|
| 171 |
if [[ -f ${cksum_file} ]]; then |
| 172 |
local cksum_prev=$(< "${cksum_file}") |
| 173 |
|
| 174 |
if [[ ${cksum} != ${cksum_prev} ]]; then |
| 175 |
echo "${cksum}" > "${cksum_file}.new" |
| 176 |
|
| 177 |
eerror "Header files have changed between ABIs." |
| 178 |
|
| 179 |
if type -p diff &>/dev/null; then |
| 180 |
eerror "$(diff -du "${cksum_file}" "${cksum_file}.new")" |
| 181 |
else |
| 182 |
eerror "Old checksums in: ${cksum_file}" |
| 183 |
eerror "New checksums in: ${cksum_file}.new" |
| 184 |
fi |
| 185 |
|
| 186 |
die "Header checksum mismatch, aborting." |
| 187 |
fi |
| 188 |
else |
| 189 |
echo "${cksum}" > "${cksum_file}" |
| 190 |
fi |
| 191 |
} |
| 192 |
|
| 193 |
_MULTILIB_BUILD=1 |
| 194 |
fi |