Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 1 | include meson.inc |
| 2 | |
| 3 | inherit meson-routines |
| 4 | inherit nativesdk |
| 5 | |
| 6 | SRC_URI += "file://meson-setup.py \ |
| 7 | file://meson-wrapper" |
| 8 | |
| 9 | # The cross file logic is similar but not identical to that in meson.bbclass, |
| 10 | # since it's generating for an SDK rather than a cross-compile. Important |
| 11 | # differences are: |
| 12 | # - We can't set vars like CC, CXX, etc. yet because they will be filled in with |
| 13 | # real paths by meson-setup.sh when the SDK is extracted. |
| 14 | # - Some overrides aren't needed, since the SDK injects paths that take care of |
| 15 | # them. |
| 16 | def var_list2str(var, d): |
| 17 | items = d.getVar(var).split() |
| 18 | return items[0] if len(items) == 1 else ', '.join(repr(s) for s in items) |
| 19 | |
| 20 | def generate_native_link_template(d): |
| 21 | val = ['-L@{OECORE_NATIVE_SYSROOT}${libdir_native}', |
| 22 | '-L@{OECORE_NATIVE_SYSROOT}${base_libdir_native}', |
| 23 | '-Wl,-rpath-link,@{OECORE_NATIVE_SYSROOT}${libdir_native}', |
| 24 | '-Wl,-rpath-link,@{OECORE_NATIVE_SYSROOT}${base_libdir_native}', |
| 25 | '-Wl,--allow-shlib-undefined' |
| 26 | ] |
| 27 | build_arch = d.getVar('BUILD_ARCH') |
| 28 | if 'x86_64' in build_arch: |
| 29 | loader = 'ld-linux-x86-64.so.2' |
| 30 | elif 'i686' in build_arch: |
| 31 | loader = 'ld-linux.so.2' |
| 32 | elif 'aarch64' in build_arch: |
| 33 | loader = 'ld-linux-aarch64.so.1' |
| 34 | elif 'ppc64le' in build_arch: |
| 35 | loader = 'ld64.so.2' |
| 36 | |
| 37 | if loader: |
| 38 | val += ['-Wl,--dynamic-linker=@{OECORE_NATIVE_SYSROOT}${base_libdir_native}/' + loader] |
| 39 | |
| 40 | return repr(val) |
| 41 | |
| 42 | do_install:append() { |
| 43 | install -d ${D}${datadir}/meson |
| 44 | |
| 45 | cat >${D}${datadir}/meson/meson.native.template <<EOF |
| 46 | [binaries] |
| 47 | c = ${@meson_array('BUILD_CC', d)} |
| 48 | cpp = ${@meson_array('BUILD_CXX', d)} |
| 49 | ar = ${@meson_array('BUILD_AR', d)} |
| 50 | nm = ${@meson_array('BUILD_NM', d)} |
| 51 | strip = ${@meson_array('BUILD_STRIP', d)} |
| 52 | readelf = ${@meson_array('BUILD_READELF', d)} |
| 53 | pkgconfig = 'pkg-config-native' |
| 54 | |
| 55 | [built-in options] |
| 56 | c_args = ['-isystem@{OECORE_NATIVE_SYSROOT}${includedir_native}' , ${@var_list2str('BUILD_OPTIMIZATION', d)}] |
| 57 | c_link_args = ${@generate_native_link_template(d)} |
| 58 | cpp_args = ['-isystem@{OECORE_NATIVE_SYSROOT}${includedir_native}' , ${@var_list2str('BUILD_OPTIMIZATION', d)}] |
| 59 | cpp_link_args = ${@generate_native_link_template(d)} |
| 60 | [properties] |
| 61 | sys_root = '@OECORE_NATIVE_SYSROOT' |
| 62 | EOF |
| 63 | |
| 64 | cat >${D}${datadir}/meson/meson.cross.template <<EOF |
| 65 | [binaries] |
| 66 | c = @CC |
| 67 | cpp = @CXX |
| 68 | ar = @AR |
| 69 | nm = @NM |
| 70 | strip = @STRIP |
| 71 | pkgconfig = 'pkg-config' |
| 72 | |
| 73 | [built-in options] |
| 74 | c_args = @CFLAGS |
| 75 | c_link_args = @LDFLAGS |
| 76 | cpp_args = @CPPFLAGS |
| 77 | cpp_link_args = @LDFLAGS |
| 78 | |
| 79 | [properties] |
| 80 | needs_exe_wrapper = true |
| 81 | sys_root = @OECORE_TARGET_SYSROOT |
| 82 | |
| 83 | [host_machine] |
| 84 | system = '${SDK_OS}' |
| 85 | cpu_family = '${@meson_cpu_family("SDK_ARCH", d)}' |
| 86 | cpu = '${SDK_ARCH}' |
| 87 | endian = '${@meson_endian("SDK", d)}' |
| 88 | EOF |
| 89 | |
| 90 | install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d |
| 91 | install -m 0755 ${WORKDIR}/meson-setup.py ${D}${SDKPATHNATIVE}/post-relocate-setup.d/ |
| 92 | |
| 93 | # We need to wrap the real meson with a thin env setup wrapper. |
| 94 | mv ${D}${bindir}/meson ${D}${bindir}/meson.real |
| 95 | install -m 0755 ${WORKDIR}/meson-wrapper ${D}${bindir}/meson |
| 96 | } |
| 97 | |
| 98 | RDEPENDS:${PN} += "\ |
| 99 | nativesdk-ninja \ |
| 100 | nativesdk-python3 \ |
| 101 | nativesdk-python3-setuptools \ |
| 102 | " |
| 103 | |
| 104 | FILES:${PN} += "${datadir}/meson ${SDKPATHNATIVE}" |