1 |
commit: ef894cec8dee3758cfde620b87d10b2774419cdf |
2 |
Author: Mike Gilbert <floppym <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Apr 25 18:55:39 2020 +0000 |
4 |
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 2 21:37:51 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ef894cec |
7 |
|
8 |
meson.eclass: implement support for native machine files |
9 |
|
10 |
Using a native file avoids putting meson into cross-compiler mode for |
11 |
multilib builds. |
12 |
|
13 |
Reference: https://mesonbuild.com/Machine-files.html |
14 |
Reference: https://mesonbuild.com/Native-environments.html |
15 |
|
16 |
Bug: https://bugs.gentoo.org/719382 |
17 |
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org> |
18 |
|
19 |
eclass/meson.eclass | 107 ++++++++++++++++++++++++++++++++++++++++++---------- |
20 |
1 file changed, 87 insertions(+), 20 deletions(-) |
21 |
|
22 |
diff --git a/eclass/meson.eclass b/eclass/meson.eclass |
23 |
index 423a497e840..7b1a6a9735b 100644 |
24 |
--- a/eclass/meson.eclass |
25 |
+++ b/eclass/meson.eclass |
26 |
@@ -125,17 +125,17 @@ _meson_env_array() { |
27 |
python -c "${__MESON_ARRAY_PARSER}" "$@" |
28 |
} |
29 |
|
30 |
-# @FUNCTION: _meson_create_cross_file |
31 |
+# @FUNCTION: _meson_get_machine_info |
32 |
+# @USAGE: <tuple> |
33 |
+# @RETURN: system/cpu_family/cpu variables |
34 |
# @INTERNAL |
35 |
# @DESCRIPTION: |
36 |
-# Creates a cross file. meson uses this to define settings for |
37 |
-# cross-compilers. This function is called from meson_src_configure. |
38 |
-_meson_create_cross_file() { |
39 |
- # Reference: http://mesonbuild.com/Cross-compilation.html |
40 |
+# Translate toolchain tuple into machine values for meson. |
41 |
+_meson_get_machine_info() { |
42 |
+ local tuple=$1 |
43 |
|
44 |
# system roughly corresponds to uname -s (lowercase) |
45 |
- local system=unknown |
46 |
- case ${CHOST} in |
47 |
+ case ${tuple} in |
48 |
*-aix*) system=aix ;; |
49 |
*-cygwin*) system=cygwin ;; |
50 |
*-darwin*) system=darwin ;; |
51 |
@@ -145,19 +145,29 @@ _meson_create_cross_file() { |
52 |
*-solaris*) system=sunos ;; |
53 |
esac |
54 |
|
55 |
- local cpu_family=$(tc-arch) |
56 |
+ cpu_family=$(tc-arch "${tuple}") |
57 |
case ${cpu_family} in |
58 |
amd64) cpu_family=x86_64 ;; |
59 |
arm64) cpu_family=aarch64 ;; |
60 |
esac |
61 |
|
62 |
# This may require adjustment based on CFLAGS |
63 |
- local cpu=${CHOST%%-*} |
64 |
+ cpu=${tuple%%-*} |
65 |
+} |
66 |
+ |
67 |
+# @FUNCTION: _meson_create_cross_file |
68 |
+# @RETURN: path to cross file |
69 |
+# @INTERNAL |
70 |
+# @DESCRIPTION: |
71 |
+# Creates a cross file. meson uses this to define settings for |
72 |
+# cross-compilers. This function is called from meson_src_configure. |
73 |
+_meson_create_cross_file() { |
74 |
+ local system cpu_family cpu |
75 |
+ _meson_get_machine_info "${CHOST}" |
76 |
|
77 |
- local needs_exe_wrapper=false |
78 |
- tc-is-cross-compiler && needs_exe_wrapper=true |
79 |
+ local fn=${T}/meson.${CHOST}.ini |
80 |
|
81 |
- cat > "${T}/meson.${CHOST}.${ABI}" <<-EOF |
82 |
+ cat > "${fn}" <<-EOF |
83 |
[binaries] |
84 |
ar = $(_meson_env_array "$(tc-getAR)") |
85 |
c = $(_meson_env_array "$(tc-getCC)") |
86 |
@@ -181,16 +191,67 @@ _meson_create_cross_file() { |
87 |
objc_link_args = $(_meson_env_array "${OBJCFLAGS} ${LDFLAGS}") |
88 |
objcpp_args = $(_meson_env_array "${OBJCXXFLAGS} ${CPPFLAGS}") |
89 |
objcpp_link_args = $(_meson_env_array "${OBJCXXFLAGS} ${LDFLAGS}") |
90 |
- needs_exe_wrapper = ${needs_exe_wrapper} |
91 |
+ needs_exe_wrapper = true |
92 |
sys_root = '${SYSROOT}' |
93 |
- pkg_config_libdir = '${PKG_CONFIG_LIBDIR-${EPREFIX}/usr/$(get_libdir)/pkgconfig}' |
94 |
+ pkg_config_libdir = '${EPREFIX}/usr/$(get_libdir)/pkgconfig' |
95 |
|
96 |
[host_machine] |
97 |
system = '${system}' |
98 |
cpu_family = '${cpu_family}' |
99 |
cpu = '${cpu}' |
100 |
- endian = '$(tc-endian)' |
101 |
+ endian = '$(tc-endian "${CHOST}")' |
102 |
+ EOF |
103 |
+ |
104 |
+ echo "${fn}" |
105 |
+} |
106 |
+ |
107 |
+# @FUNCTION: _meson_create_native_file |
108 |
+# @RETURN: path to native file |
109 |
+# @INTERNAL |
110 |
+# @DESCRIPTION: |
111 |
+# Creates a native file. meson uses this to define settings for |
112 |
+# native compilers. This function is called from meson_src_configure. |
113 |
+_meson_create_native_file() { |
114 |
+ local system cpu_family cpu |
115 |
+ _meson_get_machine_info "${CBUILD}" |
116 |
+ |
117 |
+ local fn=${T}/meson.${CBUILD}.ini |
118 |
+ |
119 |
+ cat > "${fn}" <<-EOF |
120 |
+ [binaries] |
121 |
+ ar = $(_meson_env_array "$(tc-getBUILD_AR)") |
122 |
+ c = $(_meson_env_array "$(tc-getBUILD_CC)") |
123 |
+ cpp = $(_meson_env_array "$(tc-getBUILD_CXX)") |
124 |
+ fortran = $(_meson_env_array "$(tc-getBUILD_PROG FC gfortran)") |
125 |
+ llvm-config = '$(tc-getBUILD_PROG LLVM_CONFIG llvm-config)' |
126 |
+ objc = $(_meson_env_array "$(tc-getBUILD_PROG OBJC cc)") |
127 |
+ objcpp = $(_meson_env_array "$(tc-getBUILD_PROG OBJCXX c++)") |
128 |
+ pkgconfig = '$(tc-getBUILD_PKG_CONFIG)' |
129 |
+ strip = $(_meson_env_array "$(tc-getBUILD_STRIP)") |
130 |
+ windres = $(_meson_env_array "$(tc-getBUILD_PROG RC windres)") |
131 |
+ |
132 |
+ [properties] |
133 |
+ c_args = $(_meson_env_array "${BUILD_CFLAGS} ${BUILD_CPPFLAGS}") |
134 |
+ c_link_args = $(_meson_env_array "${BUILD_CFLAGS} ${BUILD_LDFLAGS}") |
135 |
+ cpp_args = $(_meson_env_array "${BUILD_CXXFLAGS} ${BUILD_CPPFLAGS}") |
136 |
+ cpp_link_args = $(_meson_env_array "${BUILD_CXXFLAGS} ${BUILD_LDFLAGS}") |
137 |
+ fortran_args = $(_meson_env_array "${BUILD_FCFLAGS}") |
138 |
+ fortran_link_args = $(_meson_env_array "${BUILD_FCFLAGS} ${BUILD_LDFLAGS}") |
139 |
+ objc_args = $(_meson_env_array "${BUILD_OBJCFLAGS} ${BUILD_CPPFLAGS}") |
140 |
+ objc_link_args = $(_meson_env_array "${BUILD_OBJCFLAGS} ${BUILD_LDFLAGS}") |
141 |
+ objcpp_args = $(_meson_env_array "${BUILD_OBJCXXFLAGS} ${BUILD_CPPFLAGS}") |
142 |
+ objcpp_link_args = $(_meson_env_array "${BUILD_OBJCXXFLAGS} ${BUILD_LDFLAGS}") |
143 |
+ needs_exe_wrapper = false |
144 |
+ pkg_config_libdir = '${EPREFIX}/usr/$(get_libdir)/pkgconfig' |
145 |
+ |
146 |
+ [build_machine] |
147 |
+ system = '${system}' |
148 |
+ cpu_family = '${cpu_family}' |
149 |
+ cpu = '${cpu}' |
150 |
+ endian = '$(tc-endian "${CHOST}")' |
151 |
EOF |
152 |
+ |
153 |
+ echo "${fn}" |
154 |
} |
155 |
|
156 |
# @FUNCTION: meson_use |
157 |
@@ -226,6 +287,11 @@ meson_feature() { |
158 |
meson_src_configure() { |
159 |
debug-print-function ${FUNCNAME} "$@" |
160 |
|
161 |
+ tc-export_build_env |
162 |
+ : ${BUILD_FCFLAGS:=${FCFLAGS}} |
163 |
+ : ${BUILD_OBJCFLAGS:=${OBJCFLAGS}} |
164 |
+ : ${BUILD_OBJCXXFLAGS:=${OBJCXXFLAGS}} |
165 |
+ |
166 |
local mesonargs=( |
167 |
meson setup |
168 |
--buildtype plain |
169 |
@@ -234,12 +300,13 @@ meson_src_configure() { |
170 |
--prefix "${EPREFIX}/usr" |
171 |
--sysconfdir "${EPREFIX}/etc" |
172 |
--wrap-mode nodownload |
173 |
- --pkg-config-path="${PKG_CONFIG_PATH-${EPREFIX}/usr/share/pkgconfig}" |
174 |
+ --build.pkg-config-path="${EPREFIX}/usr/share/pkgconfig" |
175 |
+ --pkg-config-path="${EPREFIX}/usr/share/pkgconfig" |
176 |
+ --native-file "$(_meson_create_native_file)" |
177 |
) |
178 |
|
179 |
- if tc-is-cross-compiler || [[ ${ABI} != ${DEFAULT_ABI-${ABI}} ]]; then |
180 |
- _meson_create_cross_file || die "unable to write meson cross file" |
181 |
- mesonargs+=( --cross-file "${T}/meson.${CHOST}.${ABI}" ) |
182 |
+ if tc-is-cross-compiler; then |
183 |
+ mesonargs+=( --cross-file "$(_meson_create_cross_file)" ) |
184 |
fi |
185 |
|
186 |
BUILD_DIR="${BUILD_DIR:-${WORKDIR}/${P}-build}" |
187 |
@@ -273,7 +340,7 @@ meson_src_configure() { |
188 |
python_export_utf8_locale |
189 |
|
190 |
echo "${mesonargs[@]}" >&2 |
191 |
- tc-env_build "${mesonargs[@]}" || die |
192 |
+ "${mesonargs[@]}" || die |
193 |
} |
194 |
|
195 |
# @FUNCTION: meson_src_compile |