blob: 1670217d697cc138ee8c2b393df2e2985fe5e8a6 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6# NOTE - When using this class the user is responsible for ensuring that
7# TRANSLATED_TARGET_ARCH is added into PN. This ensures that if the TARGET_ARCH
8# is changed, another nativesdk xxx-canadian-cross can be installed
9#
10
11
12# SDK packages are built either explicitly by the user,
13# or indirectly via dependency. No need to be in 'world'.
14EXCLUDE_FROM_WORLD = "1"
15NATIVESDKLIBC ?= "libc-glibc"
16LIBCOVERRIDE = ":${NATIVESDKLIBC}"
17CLASSOVERRIDE = "class-cross-canadian"
18STAGING_BINDIR_TOOLCHAIN = "${STAGING_DIR_NATIVE}${bindir_native}/${SDK_ARCH}${SDK_VENDOR}-${SDK_OS}:${STAGING_DIR_NATIVE}${bindir_native}/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}"
19
20#
21# Update BASE_PACKAGE_ARCH and PACKAGE_ARCHS
22#
23PACKAGE_ARCH = "${SDK_ARCH}-${SDKPKGSUFFIX}"
24BASECANADIANEXTRAOS ?= "linux-musl"
25CANADIANEXTRAOS = "${BASECANADIANEXTRAOS}"
26CANADIANEXTRAVENDOR = ""
27MODIFYTOS ??= "1"
28python () {
29 archs = d.getVar('PACKAGE_ARCHS').split()
30 sdkarchs = []
31 for arch in archs:
32 sdkarchs.append(arch + '-${SDKPKGSUFFIX}')
33 d.setVar('PACKAGE_ARCHS', " ".join(sdkarchs))
34
35 # Allow the following code segment to be disabled, e.g. meta-environment
36 if d.getVar("MODIFYTOS") != "1":
37 return
38
39 if d.getVar("TCLIBC") in [ 'baremetal', 'newlib' ]:
40 return
41
42 tos = d.getVar("TARGET_OS")
43 tos_known = ["mingw32"]
44 extralibcs = [""]
45 if "musl" in d.getVar("BASECANADIANEXTRAOS"):
46 extralibcs.append("musl")
47 if "android" in tos:
48 extralibcs.append("android")
49 for variant in ["", "spe", "x32", "eabi", "n32", "_ilp32"]:
50 for libc in extralibcs:
51 entry = "linux"
52 if variant and libc:
53 entry = entry + "-" + libc + variant
54 elif variant:
55 entry = entry + "-gnu" + variant
56 elif libc:
57 entry = entry + "-" + libc
58 tos_known.append(entry)
59 if tos not in tos_known:
60 bb.fatal("Building cross-candian for an unknown TARGET_SYS (%s), please update cross-canadian.bbclass" % d.getVar("TARGET_SYS"))
61
62 for n in ["PROVIDES", "DEPENDS"]:
63 d.setVar(n, d.getVar(n))
64 d.setVar("STAGING_BINDIR_TOOLCHAIN", d.getVar("STAGING_BINDIR_TOOLCHAIN"))
65 for prefix in ["AR", "AS", "DLLTOOL", "CC", "CXX", "GCC", "LD", "LIPO", "NM", "OBJDUMP", "RANLIB", "STRIP", "WINDRES"]:
66 n = prefix + "_FOR_TARGET"
67 d.setVar(n, d.getVar(n))
68 # This is a bit ugly. We need to zero LIBC/ABI extension which will change TARGET_OS
69 # however we need the old value in some variables. We expand those here first.
70 tarch = d.getVar("TARGET_ARCH")
71 if tarch == "x86_64":
72 d.setVar("LIBCEXTENSION", "")
73 d.setVar("ABIEXTENSION", "")
74 d.appendVar("CANADIANEXTRAOS", " linux-gnux32")
75 for extraos in d.getVar("BASECANADIANEXTRAOS").split():
76 d.appendVar("CANADIANEXTRAOS", " " + extraos + "x32")
77 elif tarch == "powerpc":
78 # PowerPC can build "linux" and "linux-gnuspe"
79 d.setVar("LIBCEXTENSION", "")
80 d.setVar("ABIEXTENSION", "")
81 d.appendVar("CANADIANEXTRAOS", " linux-gnuspe")
82 for extraos in d.getVar("BASECANADIANEXTRAOS").split():
83 d.appendVar("CANADIANEXTRAOS", " " + extraos + "spe")
84 elif tarch == "mips64":
85 d.appendVar("CANADIANEXTRAOS", " linux-gnun32")
86 for extraos in d.getVar("BASECANADIANEXTRAOS").split():
87 d.appendVar("CANADIANEXTRAOS", " " + extraos + "n32")
88 if tarch == "arm" or tarch == "armeb":
89 d.appendVar("CANADIANEXTRAOS", " linux-gnueabi linux-musleabi")
90 d.setVar("TARGET_OS", "linux-gnueabi")
91 else:
92 d.setVar("TARGET_OS", "linux")
93
94 # Also need to handle multilib target vendors
95 vendors = d.getVar("CANADIANEXTRAVENDOR")
96 if not vendors:
97 vendors = all_multilib_tune_values(d, 'TARGET_VENDOR')
98 origvendor = d.getVar("TARGET_VENDOR_MULTILIB_ORIGINAL")
99 if origvendor:
100 d.setVar("TARGET_VENDOR", origvendor)
101 if origvendor not in vendors.split():
102 vendors = origvendor + " " + vendors
103 d.setVar("CANADIANEXTRAVENDOR", vendors)
104}
105MULTIMACH_TARGET_SYS = "${PACKAGE_ARCH}${HOST_VENDOR}-${HOST_OS}"
106
107INHIBIT_DEFAULT_DEPS = "1"
108
109STAGING_DIR_HOST = "${RECIPE_SYSROOT}"
110
111TOOLCHAIN_OPTIONS = " --sysroot=${RECIPE_SYSROOT}"
112
113PATH:append = ":${TMPDIR}/sysroots/${HOST_ARCH}/${bindir_cross}"
114PKGHIST_DIR = "${TMPDIR}/pkghistory/${HOST_ARCH}-${SDKPKGSUFFIX}${HOST_VENDOR}-${HOST_OS}/"
115
116HOST_ARCH = "${SDK_ARCH}"
117HOST_VENDOR = "${SDK_VENDOR}"
118HOST_OS = "${SDK_OS}"
119HOST_PREFIX = "${SDK_PREFIX}"
120HOST_CC_ARCH = "${SDK_CC_ARCH}"
121HOST_LD_ARCH = "${SDK_LD_ARCH}"
122HOST_AS_ARCH = "${SDK_AS_ARCH}"
123
124#assign DPKG_ARCH
125DPKG_ARCH = "${@debian_arch_map(d.getVar('SDK_ARCH'), '')}"
126
127CPPFLAGS = "${BUILDSDK_CPPFLAGS}"
128CFLAGS = "${BUILDSDK_CFLAGS}"
129CXXFLAGS = "${BUILDSDK_CFLAGS}"
130LDFLAGS = "${BUILDSDK_LDFLAGS} \
131 -Wl,-rpath-link,${STAGING_LIBDIR}/.. \
132 -Wl,-rpath,${libdir}/.. "
133
134#
135# We need chrpath >= 0.14 to ensure we can deal with 32 and 64 bit
136# binaries
137#
138DEPENDS:append = " chrpath-replacement-native"
139EXTRANATIVEPATH += "chrpath-native"
140
141# Path mangling needed by the cross packaging
142# Note that we use := here to ensure that libdir and includedir are
143# target paths.
144target_base_prefix := "${base_prefix}"
145target_prefix := "${prefix}"
146target_exec_prefix := "${exec_prefix}"
147target_base_libdir = "${target_base_prefix}/${baselib}"
148target_libdir = "${target_exec_prefix}/${baselib}"
149target_includedir := "${includedir}"
150
151# Change to place files in SDKPATH
152base_prefix = "${SDKPATHNATIVE}"
153prefix = "${SDKPATHNATIVE}${prefix_nativesdk}"
154exec_prefix = "${SDKPATHNATIVE}${prefix_nativesdk}"
155bindir = "${exec_prefix}/bin/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}"
156sbindir = "${bindir}"
157base_bindir = "${bindir}"
158base_sbindir = "${bindir}"
159libdir = "${exec_prefix}/lib/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}"
160libexecdir = "${exec_prefix}/libexec/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}"
161
162FILES:${PN} = "${prefix}"
163
164export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${exec_prefix}/lib/pkgconfig"
165export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
166
167do_populate_sysroot[stamp-extra-info] = ""
168do_packagedata[stamp-extra-info] = ""
169
170USE_NLS = "${SDKUSE_NLS}"
171
172# We have to us TARGET_ARCH but we care about the absolute value
173# and not any particular tune that is enabled.
174TARGET_ARCH[vardepsexclude] = "TUNE_ARCH"
175
176PKGDATA_DIR = "${PKGDATA_DIR_SDK}"
177# If MLPREFIX is set by multilib code, shlibs
178# points to the wrong place so force it
179SHLIBSDIRS = "${PKGDATA_DIR}/nativesdk-shlibs2"
180SHLIBSWORKDIR = "${PKGDATA_DIR}/nativesdk-shlibs2"
181
182cross_canadian_bindirlinks () {
183 for i in linux ${CANADIANEXTRAOS}
184 do
185 for v in ${CANADIANEXTRAVENDOR}
186 do
187 d=${D}${bindir}/../${TARGET_ARCH}$v-$i
188 if [ -d $d ];
189 then
190 continue
191 fi
192 install -d $d
193 for j in `ls ${D}${bindir}`
194 do
195 p=${TARGET_ARCH}$v-$i-`echo $j | sed -e s,${TARGET_PREFIX},,`
196 ln -s ../${TARGET_SYS}/$j $d/$p
197 done
198 done
199 done
200}