-
Notifications
You must be signed in to change notification settings - Fork 14
/
generate-gcc-meson-cross-file.sh
executable file
·107 lines (93 loc) · 2.91 KB
/
generate-gcc-meson-cross-file.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
## generate-gcc-meson-cross-file.sh
#
# This generates a cross file to configure meson for cross-compiling with GCC.
#
# Docs:
# - https://mesonbuild.com/Cross-compilation.html
# - https://mesonbuild.com/Machine-files.html
set -e
set -x
set -o pipefail
if ! [ "$#" -ge 2 ]; then
echo "Usage: $0 <target> <prefix_dir> <march> <mabi> <mcmodel> <cflags...>"
exit 2
fi;
## Take configuration from arguments
# This is the gcc target triple
toolchain_target="${1}"
# This is the directory where the toolchain has been installed.
toolchain_dest="${2}"
# -march option default value
march="${3}"
# -mabi option default value
mabi="${4}"
# -mcmodel option default value
mcmodel="${5}"
# Remaining cflags for build configurations
toolchain_cflags=("${@:6}")
# Meson uses the driver when both compiling and linking, which may need flags to
# identify exactly how to set up paths and defaults for both.
meson_driver_flags=""
for flag in "${toolchain_cflags[@]}"; do
if [ -z "${meson_driver_flags}" ]; then
meson_driver_flags+="'${flag}'";
else
meson_driver_flags+=", '${flag}'"
fi
done
config_dest="${toolchain_dest}/meson-${toolchain_target}-gcc.txt"
sysroot_config="";
system_name=""
case "${toolchain_target}" in
riscv*-*-linux-gnu)
sysroot_config="sys_root = toolchain_path / '${toolchain_target}/sysroot'";
system_name="linux";
;;
riscv*-*-elf)
system_name="bare metal";
;;
esac;
tee "${config_dest}" <<CONFIG
# Autogenerated by ${0} on $(date -u)
# Problems? See the bug reporting instructions in the file buildinfo.
#
# If you have relocated this toolchain, update "toolchain_path" accordingly.
[constants]
toolchain_path = '${toolchain_dest}'
march = '${march}'
mabi = '${mabi}'
mcmodel = '${mcmodel}'
default_extra_args = [${meson_driver_flags}]
default_args = ['-march=' + march, '-mabi=' + mabi, '-mcmodel=' + mcmodel] + default_extra_args
default_c_args = default_args
default_c_link_args = default_args
default_cpp_args = default_args
default_cpp_link_args = default_args
[binaries]
c = toolchain_path / 'bin/riscv32-unknown-elf-gcc'
cpp = toolchain_path / 'bin/riscv32-unknown-elf-g++'
ar = toolchain_path / 'bin/riscv32-unknown-elf-ar'
ld = toolchain_path / 'bin/riscv32-unknown-elf-ld'
objdump = toolchain_path / 'bin/riscv32-unknown-elf-objdump'
objcopy = toolchain_path / 'bin/riscv32-unknown-elf-objcopy'
strip = toolchain_path / 'bin/riscv32-unknown-elf-strip'
as = toolchain_path / 'bin/riscv32-unknown-elf-as'
[properties]
needs_exe_wrapper = true
has_function_printf = false
${sysroot_config}
[built-in options]
c_args = default_c_args
c_link_args = default_c_link_args
cpp_args = default_cpp_args
cpp_link_args = default_cpp_link_args
[host_machine]
system = '${system_name}'
cpu_family = '${toolchain_target%%-*}'
cpu = 'ibex'
endian = 'little'
CONFIG