1 |
--- |
2 |
eclass/meson.eclass | 74 +++++++++++++++++++++++++++++++++++++++++------------ |
3 |
1 file changed, 57 insertions(+), 17 deletions(-) |
4 |
|
5 |
diff --git a/eclass/meson.eclass b/eclass/meson.eclass |
6 |
index 758e4180ba7a..0fdb1d848973 100644 |
7 |
--- a/eclass/meson.eclass |
8 |
+++ b/eclass/meson.eclass |
9 |
@@ -39,8 +39,7 @@ esac |
10 |
|
11 |
if [[ -z ${_MESON_ECLASS} ]]; then |
12 |
|
13 |
-# FIXME: We will need to inherit toolchain-funcs as well to support crossdev. |
14 |
-inherit ninja-utils |
15 |
+inherit ninja-utils toolchain-funcs |
16 |
|
17 |
fi |
18 |
|
19 |
@@ -71,17 +70,52 @@ DEPEND=">=dev-util/meson-0.39.1 |
20 |
# Optional meson arguments as Bash array; this should be defined before |
21 |
# calling meson_src_configure. |
22 |
|
23 |
-# Create a cross file for meson |
24 |
-# fixme: This function should write a cross file as described at the |
25 |
-# following url. |
26 |
-# http://mesonbuild.com/Cross-compilation.html |
27 |
-# _meson_create_cross_file() { |
28 |
-# touch "${T}"/meson.crossfile |
29 |
-# } |
30 |
+# @FUNCTION: _meson_create_cross_file |
31 |
+# @INTERNAL |
32 |
+# @DESCRIPTION: |
33 |
+# Creates a cross file. meson uses this to define settings for |
34 |
+# cross-compilers. This function is called from meson_src_configure. |
35 |
+_meson_create_cross_file() { |
36 |
+ # Reference: http://mesonbuild.com/Cross-compilation.html |
37 |
+ |
38 |
+ # system roughly corresponds to uname -s (lowercase) |
39 |
+ local system=unknown |
40 |
+ case ${CHOST} in |
41 |
+ *-aix*) system=aix ;; |
42 |
+ *-cygwin*) system=cygwin ;; |
43 |
+ *-darwin*) system=darwin ;; |
44 |
+ *-freebsd*) system=freebsd ;; |
45 |
+ *-linux*) system=linux ;; |
46 |
+ *-solaris*) system=sunos ;; |
47 |
+ esac |
48 |
+ |
49 |
+ local cpu_family=$(tc-arch) |
50 |
+ case ${cpu_family} in |
51 |
+ amd64) cpu_family=x86_64 ;; |
52 |
+ arm64) cpu_family=aarch64 ;; |
53 |
+ esac |
54 |
+ |
55 |
+ # This may require adjustment based on CFLAGS |
56 |
+ local cpu=${CHOST%%-*} |
57 |
+ |
58 |
+ cat > "${T}/meson.${CHOST}" <<-EOF |
59 |
+ [binaries] |
60 |
+ ar = '${AR}' |
61 |
+ c = '${CC}' |
62 |
+ cpp = '${CXX}' |
63 |
+ strip = '${STRIP}' |
64 |
+ |
65 |
+ [host_machine] |
66 |
+ system = '${system}' |
67 |
+ cpu_family = '${cpu_family}' |
68 |
+ cpu = '${cpu}' |
69 |
+ endian = '$(tc-endian)' |
70 |
+ EOF |
71 |
+} |
72 |
|
73 |
# @FUNCTION: meson_src_configure |
74 |
# @DESCRIPTION: |
75 |
-# This is the meson_src_configure function |
76 |
+# This is the meson_src_configure function. |
77 |
meson_src_configure() { |
78 |
debug-print-function ${FUNCNAME} "$@" |
79 |
|
80 |
@@ -94,13 +128,19 @@ meson_src_configure() { |
81 |
--sysconfdir "${EPREFIX}/etc" |
82 |
) |
83 |
|
84 |
-# fixme: uncomment this for crossdev support |
85 |
-# if tc-is-cross-compiler; then |
86 |
-# _meson_create_cross_file || die "unable to write meson cross file" |
87 |
-# mesonargs+=( |
88 |
-# --cross-file "${T}"/meson.crossfile |
89 |
-# ) |
90 |
-# fi |
91 |
+ # Both meson(1) and _meson_create_cross_file need these |
92 |
+ tc-export AR CC CXX STRIP |
93 |
+ |
94 |
+ if tc-is-cross-compiler; then |
95 |
+ _meson_create_cross_file || die "unable to write meson cross file" |
96 |
+ mesonargs+=( |
97 |
+ --cross-file "${T}"/meson.${CHOST} |
98 |
+ ) |
99 |
+ # In cross mode, meson uses CC/CXX as the "build" compilers |
100 |
+ local -x AR=$(tc-getBUILD_AR) |
101 |
+ local -x CC=$(tc-getBUILD_CC) |
102 |
+ local -x CXX=$(tc-getBUILD_CXX) |
103 |
+ fi |
104 |
|
105 |
# Append additional arguments from ebuild |
106 |
mesonargs+=("${emesonargs[@]}") |
107 |
-- |
108 |
2.13.0 |