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