diff options
Diffstat (limited to 'meta/classes-recipe/cross-canadian.bbclass')
-rw-r--r-- | meta/classes-recipe/cross-canadian.bbclass | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/meta/classes-recipe/cross-canadian.bbclass b/meta/classes-recipe/cross-canadian.bbclass new file mode 100644 index 0000000000..1670217d69 --- /dev/null +++ b/meta/classes-recipe/cross-canadian.bbclass | |||
@@ -0,0 +1,200 @@ | |||
1 | # | ||
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'. | ||
14 | EXCLUDE_FROM_WORLD = "1" | ||
15 | NATIVESDKLIBC ?= "libc-glibc" | ||
16 | LIBCOVERRIDE = ":${NATIVESDKLIBC}" | ||
17 | CLASSOVERRIDE = "class-cross-canadian" | ||
18 | STAGING_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 | # | ||
23 | PACKAGE_ARCH = "${SDK_ARCH}-${SDKPKGSUFFIX}" | ||
24 | BASECANADIANEXTRAOS ?= "linux-musl" | ||
25 | CANADIANEXTRAOS = "${BASECANADIANEXTRAOS}" | ||
26 | CANADIANEXTRAVENDOR = "" | ||
27 | MODIFYTOS ??= "1" | ||
28 | python () { | ||
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 | } | ||
105 | MULTIMACH_TARGET_SYS = "${PACKAGE_ARCH}${HOST_VENDOR}-${HOST_OS}" | ||
106 | |||
107 | INHIBIT_DEFAULT_DEPS = "1" | ||
108 | |||
109 | STAGING_DIR_HOST = "${RECIPE_SYSROOT}" | ||
110 | |||
111 | TOOLCHAIN_OPTIONS = " --sysroot=${RECIPE_SYSROOT}" | ||
112 | |||
113 | PATH:append = ":${TMPDIR}/sysroots/${HOST_ARCH}/${bindir_cross}" | ||
114 | PKGHIST_DIR = "${TMPDIR}/pkghistory/${HOST_ARCH}-${SDKPKGSUFFIX}${HOST_VENDOR}-${HOST_OS}/" | ||
115 | |||
116 | HOST_ARCH = "${SDK_ARCH}" | ||
117 | HOST_VENDOR = "${SDK_VENDOR}" | ||
118 | HOST_OS = "${SDK_OS}" | ||
119 | HOST_PREFIX = "${SDK_PREFIX}" | ||
120 | HOST_CC_ARCH = "${SDK_CC_ARCH}" | ||
121 | HOST_LD_ARCH = "${SDK_LD_ARCH}" | ||
122 | HOST_AS_ARCH = "${SDK_AS_ARCH}" | ||
123 | |||
124 | #assign DPKG_ARCH | ||
125 | DPKG_ARCH = "${@debian_arch_map(d.getVar('SDK_ARCH'), '')}" | ||
126 | |||
127 | CPPFLAGS = "${BUILDSDK_CPPFLAGS}" | ||
128 | CFLAGS = "${BUILDSDK_CFLAGS}" | ||
129 | CXXFLAGS = "${BUILDSDK_CFLAGS}" | ||
130 | LDFLAGS = "${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 | # | ||
138 | DEPENDS:append = " chrpath-replacement-native" | ||
139 | EXTRANATIVEPATH += "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. | ||
144 | target_base_prefix := "${base_prefix}" | ||
145 | target_prefix := "${prefix}" | ||
146 | target_exec_prefix := "${exec_prefix}" | ||
147 | target_base_libdir = "${target_base_prefix}/${baselib}" | ||
148 | target_libdir = "${target_exec_prefix}/${baselib}" | ||
149 | target_includedir := "${includedir}" | ||
150 | |||
151 | # Change to place files in SDKPATH | ||
152 | base_prefix = "${SDKPATHNATIVE}" | ||
153 | prefix = "${SDKPATHNATIVE}${prefix_nativesdk}" | ||
154 | exec_prefix = "${SDKPATHNATIVE}${prefix_nativesdk}" | ||
155 | bindir = "${exec_prefix}/bin/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}" | ||
156 | sbindir = "${bindir}" | ||
157 | base_bindir = "${bindir}" | ||
158 | base_sbindir = "${bindir}" | ||
159 | libdir = "${exec_prefix}/lib/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}" | ||
160 | libexecdir = "${exec_prefix}/libexec/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}" | ||
161 | |||
162 | FILES:${PN} = "${prefix}" | ||
163 | |||
164 | export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${exec_prefix}/lib/pkgconfig" | ||
165 | export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}" | ||
166 | |||
167 | do_populate_sysroot[stamp-extra-info] = "" | ||
168 | do_packagedata[stamp-extra-info] = "" | ||
169 | |||
170 | USE_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. | ||
174 | TARGET_ARCH[vardepsexclude] = "TUNE_ARCH" | ||
175 | |||
176 | PKGDATA_DIR = "${PKGDATA_DIR_SDK}" | ||
177 | # If MLPREFIX is set by multilib code, shlibs | ||
178 | # points to the wrong place so force it | ||
179 | SHLIBSDIRS = "${PKGDATA_DIR}/nativesdk-shlibs2" | ||
180 | SHLIBSWORKDIR = "${PKGDATA_DIR}/nativesdk-shlibs2" | ||
181 | |||
182 | cross_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 | } | ||