blob: d1980a00975b4bd89fc4a1141c36f518cc1c9f3f [file] [log] [blame]
Patrick Williams975a06f2022-10-21 14:42:47 -05001LICENSE = "Apache-2.0 & BSD-3-Clause & MIT & Zlib"
2
3LIC_FILES_CHKSUM = "file://LICENSE;md5=f87516e0b698007e9e75a1fe1012b390 \
4 file://buildtools/libcxx/LICENSE.TXT;md5=55d89dd7eec8d3b4204b680e27da3953 \
5 file://buildtools/libcxx/utils/google-benchmark/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57 \
6 file://buildtools/libcxxabi/LICENSE.TXT;md5=7b9334635b542c56868400a46b272b1e \
7 file://buildtools/libunwind/LICENSE.TXT;md5=f66970035d12f196030658b11725e1a1 \
8 file://buildtools/protobuf/LICENSE;md5=37b5762e07f0af8c74ce80a8bda4266b \
9 file://buildtools/zlib/LICENSE;md5=f09575dbfb09420642318b413159496f \
10 file://debian/copyright;md5=4e08364c82141f181de69d0a2b89d612 \
11 file://python/LICENSE;md5=c602a632c34ade9c78a976734077bce7"
12
Patrick Williams2390b1b2022-11-03 13:47:49 -050013SRC_URI:append = " \
Patrick Williams975a06f2022-10-21 14:42:47 -050014 git://github.com/protocolbuffers/protobuf.git;branch=3.9.x;protocol=https;destsuffix=git/buildtools/protobuf;name=protobuf \
15 git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git;protocol=https;destsuffix=git/buildtools/libcxx;branch=main;name=libcxx \
16 git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxxabi.git;protocol=https;destsuffix=git/buildtools/libcxxabi;branch=main;name=libcxxabi \
17 git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libunwind.git;protocol=https;destsuffix=git/buildtools/libunwind;branch=main;name=libunwind \
18 git://android.googlesource.com/platform/external/zlib.git;branch=master;protocol=https;destsuffix=git/buildtools/zlib;name=zlib \
19 https://storage.googleapis.com/perfetto/gn-linux64-1968-0725d782;subdir=git/buildtools/;name=gn \
20 file://0001-Remove-check_build_deps-build-steps.patch "
21
Patrick Williams975a06f2022-10-21 14:42:47 -050022SRCREV_protobuf = "6a59a2ad1f61d9696092f79b6d74368b4d7970a3"
23SRCREV_libcxx = "d9040c75cfea5928c804ab7c235fed06a63f743a"
24SRCREV_libcxxabi = "196ba1aaa8ac285d94f4ea8d9836390a45360533"
25SRCREV_libunwind = "d999d54f4bca789543a2eb6c995af2d9b5a1f3ed"
26SRCREV_zlib = "5c85a2da4c13eda07f69d81a1579a5afddd35f59"
27SRC_URI[gn.sha256sum] = "f706aaa0676e3e22f5fc9ca482295d7caee8535d1869f99efa2358177b64f5cd"
28
Patrick Williams2390b1b2022-11-03 13:47:49 -050029require perfetto.inc
30
Patrick Williams975a06f2022-10-21 14:42:47 -050031DEPENDS += " ninja-native"
32
33COMPATIBLE_HOST = "(i.86|x86_64|aarch64|arm).*-linux*"
34
35FILES:${PN}:append = " \
36 ${bindir}/tracebox \
37 "
38
Patrick Williams975a06f2022-10-21 14:42:47 -050039B = "${WORKDIR}/build"
40
41# Run the GN (Generate Ninja) script, and replace the compiler flags where applicable
42do_configure () {
43 # Configuration needs to be done from the source directory
44 cd ${S}
45 # Rename a few build tools if they have not been renamed
46 cd buildtools
47 x="gn-linux64-1968-0725d782"
48 [ -f $x ] && mkdir linux64 && mv $x linux64/gn
49 chmod +x linux64/gn
50 cd ..
51
52 CC_BIN=`echo $CC | awk '{print $1}'`
53 CXX_BIN=`echo $CXX | awk '{print $1}'`
54 STRIP_BIN=`echo $STRIP | awk '{print $1}'`
55
56 ARGS="is_debug=false " # Tell gn to use release mode
57
58 if [ -z `echo ${TOOLCHAIN} | grep clang` ]; then
59 ARGS=$ARGS" is_clang=false"
60 else
61 ARGS=$ARGS" is_clang=true"
62 fi
63
64 # Architecture parameter accepted by Perfetto
65 arch=${TARGET_ARCH}
66 if [ $arch = "i686" ]; then
67 arch="x86"
68 elif [ $arch = "x86_64" ]; then
69 arch="x64"
70 elif [ $arch = "aarch64" ]; then
71 arch="arm64"
72 fi
Patrick Williams975a06f2022-10-21 14:42:47 -050073
74 ARGS=$ARGS" target_os=\"linux\""
75 ARGS=$ARGS" target_cpu=\"$arch\""
Andrew Geissler517393d2023-01-13 08:55:19 -060076 ARGS=$ARGS" target_cc=\"$CC_BIN ${TUNE_CCARGS}\""
77 ARGS=$ARGS" target_cxx=\"$CXX_BIN -std=c++11 ${TUNE_CCARGS}\""
Patrick Williams975a06f2022-10-21 14:42:47 -050078 ARGS=$ARGS" target_strip=\"$STRIP_BIN\"" #
79 ARGS=$ARGS" target_sysroot=\"${RECIPE_SYSROOT}\""
Andrew Geissler517393d2023-01-13 08:55:19 -060080 ARGS=$ARGS" target_linker=\"$CC_BIN ${TUNE_CCARGS} ${LDFLAGS}\""
Patrick Williams975a06f2022-10-21 14:42:47 -050081 ARGS=$ARGS" target_ar=\"$AR\""
82 ARGS="'$ARGS'"
83 cmd="tools/gn gen --args=$ARGS ${B}"
84
85 echo $cmd
86 # Use eval, not just call $cmd, due to escaping of single quotation marks
87 eval $cmd
88
89 cd ${B}
90 # Eliminate a few incompatible build flags
91 REPLACES="s/-Wl,--icf=all//g"
92 REPLACES=$REPLACES";s/-Werror//g"
Patrick Williams975a06f2022-10-21 14:42:47 -050093 REPLACES=$REPLACES";s/-fcolor-diagnostics//g"
94 REPLACES=$REPLACES";s/=format-security//g"
95 REPLACES=$REPLACES";s/-fdiagnostics-show-template-tree//g"
96 REPLACES=$REPLACES";s/-D_FORTIFY_SOURCE=2//g"
97 REPLACES=$REPLACES";s/-fuse-ld=\S*//g"
98
99 find . -name "*.ninja" | xargs sed $REPLACES -i
100
101 # If using the clang toolchain: use the clang host-side binaries built by Bitbake
102 if [ "${TOOLCHAIN}" = "clang" ]; then
Andrew Geissler517393d2023-01-13 08:55:19 -0600103 BB_CLANGXX="${BUILD_CXX} ${BUILD_LDFLAGS}"
104 BB_CLANG="${BUILD_CC}"
Patrick Williams975a06f2022-10-21 14:42:47 -0500105 BB_LLVM_OBJCOPY="${RECIPE_SYSROOT_NATIVE}/usr/bin/llvm-objcopy"
106
Andrew Geissler517393d2023-01-13 08:55:19 -0600107 HOST_CLANGXX="${STAGING_DIR_NATIVE}/usr/bin/clang++ -stdlib=libc++ -rtlib=libgcc -unwindlib=libgcc"
108 HOST_CLANG="${STAGING_DIR_NATIVE}/usr/bin/clang"
Patrick Williams975a06f2022-10-21 14:42:47 -0500109 HOST_LLVM_OBJCOPY="${STAGING_DIR_NATIVE}/usr/bin/llvm-objcopy"
110
111 cd gcc_like_host
112 REPLACES="s:\S*clang++ :$HOST_CLANGXX :g"
113 REPLACES=$REPLACES";s:\S*clang :$HOST_CLANG :g"
114 REPLACES=$REPLACES";s:\S*llvm-objcopy :$HOST_LLVM_OBJCOPY :g"
115 find . -name "*.ninja" | xargs sed "$REPLACES" -i
116 cd ..
117 fi
118 # Done processing the Ninja files
119
120 # Workaround for the functions not supported by musl
121 if [ "${TCLIBC}" = "musl" ]; then
122 sed -e 's/strtoll_l(__a, \&__p2, __base, _LIBCPP_GET_C_LOCALE)/strtoll(__a, \&__p2, __base)/g' \
123 -e 's/strtoull_l(__a, \&__p2, __base, _LIBCPP_GET_C_LOCALE)/strtoull(__a, \&__p2, __base)/g' \
124 ${S}/buildtools/libcxx/include/locale -i
125 fi
126}
127
128# Perfetto generates a few different binaries, such as traced and traced_probes and perfetto.
129# The "tracebox" is a busybox that combines the 3 above and provides a single stop for trace capture, so we only build "tracebox" here.
130do_compile () {
131 cd ${B}
132 ninja -C . tracebox
133}
134
135do_install () {
136 BIN_DIR=${D}${bindir}
137
138 install -d -m0755 $BIN_DIR
139 install ${B}/tracebox $BIN_DIR/tracebox
140}