blob: cfd299d0c8c584af280486021256299f158ad7fd [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# We want native packages to be relocatable
8inherit relocatable
9
10# Native packages are built indirectly via dependency,
11# no need for them to be a direct target of 'world'
12EXCLUDE_FROM_WORLD = "1"
13
14PACKAGE_ARCH = "${BUILD_ARCH}"
15
16# used by cmake class
17OECMAKE_RPATH = "${libdir}"
18OECMAKE_RPATH:class-native = "${libdir}"
19
20TARGET_ARCH = "${BUILD_ARCH}"
21TARGET_OS = "${BUILD_OS}"
22TARGET_VENDOR = "${BUILD_VENDOR}"
23TARGET_PREFIX = "${BUILD_PREFIX}"
24TARGET_CC_ARCH = "${BUILD_CC_ARCH}"
25TARGET_LD_ARCH = "${BUILD_LD_ARCH}"
26TARGET_AS_ARCH = "${BUILD_AS_ARCH}"
27TARGET_CPPFLAGS = "${BUILD_CPPFLAGS}"
28TARGET_CFLAGS = "${BUILD_CFLAGS}"
29TARGET_CXXFLAGS = "${BUILD_CXXFLAGS}"
30TARGET_LDFLAGS = "${BUILD_LDFLAGS}"
31TARGET_FPU = ""
32TUNE_FEATURES = ""
33ABIEXTENSION = ""
34
35HOST_ARCH = "${BUILD_ARCH}"
36HOST_OS = "${BUILD_OS}"
37HOST_VENDOR = "${BUILD_VENDOR}"
38HOST_PREFIX = "${BUILD_PREFIX}"
39HOST_CC_ARCH = "${BUILD_CC_ARCH}"
40HOST_LD_ARCH = "${BUILD_LD_ARCH}"
41HOST_AS_ARCH = "${BUILD_AS_ARCH}"
42
43CPPFLAGS = "${BUILD_CPPFLAGS}"
44CFLAGS = "${BUILD_CFLAGS}"
45CXXFLAGS = "${BUILD_CXXFLAGS}"
46LDFLAGS = "${BUILD_LDFLAGS}"
47
48STAGING_BINDIR = "${STAGING_BINDIR_NATIVE}"
49STAGING_BINDIR_CROSS = "${STAGING_BINDIR_NATIVE}"
50
51# native pkg doesn't need the TOOLCHAIN_OPTIONS.
52TOOLCHAIN_OPTIONS = ""
53
54# Don't build ptest natively
55PTEST_ENABLED = "0"
56
57# Don't use site files for native builds
58export CONFIG_SITE = "${COREBASE}/meta/site/native"
59
60# set the compiler as well. It could have been set to something else
61export CC = "${BUILD_CC}"
62export CXX = "${BUILD_CXX}"
63export FC = "${BUILD_FC}"
64export CPP = "${BUILD_CPP}"
65export LD = "${BUILD_LD}"
66export CCLD = "${BUILD_CCLD}"
67export AR = "${BUILD_AR}"
68export AS = "${BUILD_AS}"
69export RANLIB = "${BUILD_RANLIB}"
70export STRIP = "${BUILD_STRIP}"
71export NM = "${BUILD_NM}"
72
73# Path prefixes
74base_prefix = "${STAGING_DIR_NATIVE}"
75prefix = "${STAGING_DIR_NATIVE}${prefix_native}"
76exec_prefix = "${STAGING_DIR_NATIVE}${prefix_native}"
77
78bindir = "${STAGING_BINDIR_NATIVE}"
79sbindir = "${STAGING_SBINDIR_NATIVE}"
80base_libdir = "${STAGING_LIBDIR_NATIVE}"
81libdir = "${STAGING_LIBDIR_NATIVE}"
82includedir = "${STAGING_INCDIR_NATIVE}"
83sysconfdir = "${STAGING_ETCDIR_NATIVE}"
84datadir = "${STAGING_DATADIR_NATIVE}"
85
86baselib = "lib"
87
88export lt_cv_sys_lib_dlsearch_path_spec = "${libdir} ${base_libdir} /lib /lib64 /usr/lib /usr/lib64"
89
90NATIVE_PACKAGE_PATH_SUFFIX ?= ""
91bindir .= "${NATIVE_PACKAGE_PATH_SUFFIX}"
92sbindir .= "${NATIVE_PACKAGE_PATH_SUFFIX}"
93base_libdir .= "${NATIVE_PACKAGE_PATH_SUFFIX}"
94libdir .= "${NATIVE_PACKAGE_PATH_SUFFIX}"
95libexecdir .= "${NATIVE_PACKAGE_PATH_SUFFIX}"
96
97do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE}/"
98do_populate_sysroot[sstate-outputdirs] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}"
99
100# Since we actually install these into situ there is no staging prefix
101STAGING_DIR_HOST = ""
102STAGING_DIR_TARGET = ""
103PKG_CONFIG_DIR = "${libdir}/pkgconfig"
104
105EXTRA_NATIVE_PKGCONFIG_PATH ?= ""
106PKG_CONFIG_PATH .= "${EXTRA_NATIVE_PKGCONFIG_PATH}"
107PKG_CONFIG_SYSROOT_DIR = ""
108PKG_CONFIG_SYSTEM_LIBRARY_PATH[unexport] = "1"
109PKG_CONFIG_SYSTEM_INCLUDE_PATH[unexport] = "1"
110
111# we dont want libc-*libc to kick in for native recipes
112LIBCOVERRIDE = ""
113CLASSOVERRIDE = "class-native"
114MACHINEOVERRIDES = ""
115MACHINE_FEATURES = ""
116
117PATH:prepend = "${COREBASE}/scripts/native-intercept:"
118
119# This class encodes staging paths into its scripts data so can only be
120# reused if we manipulate the paths.
121SSTATE_SCAN_CMD ?= "${SSTATE_SCAN_CMD_NATIVE}"
122
123# No strip sysroot when DEBUG_BUILD is enabled
124INHIBIT_SYSROOT_STRIP ?= "${@oe.utils.vartrue('DEBUG_BUILD', '1', '', d)}"
125
126python native_virtclass_handler () {
127 pn = e.data.getVar("PN")
128 if not pn.endswith("-native"):
129 return
130 bpn = e.data.getVar("BPN")
131
132 # Set features here to prevent appends and distro features backfill
133 # from modifying native distro features
134 features = set(d.getVar("DISTRO_FEATURES_NATIVE").split())
135 filtered = set(bb.utils.filter("DISTRO_FEATURES", d.getVar("DISTRO_FEATURES_FILTER_NATIVE"), d).split())
136 d.setVar("DISTRO_FEATURES", " ".join(sorted(features | filtered)))
137
138 classextend = e.data.getVar('BBCLASSEXTEND') or ""
139 if "native" not in classextend:
140 return
141
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600142 def map_dependencies(varname, d, suffix = "", selfref=True, regex=False):
Patrick Williams92b42cb2022-09-03 06:53:57 -0500143 if suffix:
144 varname = varname + ":" + suffix
145 deps = d.getVar(varname)
146 if not deps:
147 return
148 deps = bb.utils.explode_deps(deps)
149 newdeps = []
150 for dep in deps:
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600151 if regex and dep.startswith("^") and dep.endswith("$"):
152 newdeps.append(dep[:-1].replace(pn, bpn) + "-native$")
153 elif dep == pn:
Patrick Williams92b42cb2022-09-03 06:53:57 -0500154 if not selfref:
155 continue
156 newdeps.append(dep)
157 elif "-cross-" in dep:
158 newdeps.append(dep.replace("-cross", "-native"))
159 elif not dep.endswith("-native"):
160 # Replace ${PN} with ${BPN} in the dependency to make sure
161 # dependencies on, e.g., ${PN}-foo become ${BPN}-foo-native
162 # rather than ${BPN}-native-foo-native.
163 newdeps.append(dep.replace(pn, bpn) + "-native")
164 else:
165 newdeps.append(dep)
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600166 d.setVar(varname, " ".join(newdeps))
Patrick Williams92b42cb2022-09-03 06:53:57 -0500167
168 map_dependencies("DEPENDS", e.data, selfref=False)
169 for pkg in e.data.getVar("PACKAGES", False).split():
170 map_dependencies("RDEPENDS", e.data, pkg)
171 map_dependencies("RRECOMMENDS", e.data, pkg)
172 map_dependencies("RSUGGESTS", e.data, pkg)
173 map_dependencies("RPROVIDES", e.data, pkg)
174 map_dependencies("RREPLACES", e.data, pkg)
175 map_dependencies("PACKAGES", e.data)
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600176 map_dependencies("PACKAGES_DYNAMIC", e.data, regex=True)
Patrick Williams92b42cb2022-09-03 06:53:57 -0500177
178 provides = e.data.getVar("PROVIDES")
179 nprovides = []
180 for prov in provides.split():
181 if prov.find(pn) != -1:
182 nprovides.append(prov)
183 elif not prov.endswith("-native"):
184 nprovides.append(prov + "-native")
185 else:
186 nprovides.append(prov)
187 e.data.setVar("PROVIDES", ' '.join(nprovides))
188
189
190}
191
192addhandler native_virtclass_handler
193native_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
194
195python do_addto_recipe_sysroot () {
196 bb.build.exec_func("extend_recipe_sysroot", d)
197}
198addtask addto_recipe_sysroot after do_populate_sysroot
199do_addto_recipe_sysroot[deptask] = "do_populate_sysroot"
200
201inherit nopackages
202
203do_packagedata[stamp-extra-info] = ""
204
205USE_NLS = "no"
206
207RECIPERDEPTASK = "do_populate_sysroot"
208do_populate_sysroot[rdeptask] = "${RECIPERDEPTASK}"
209
210#
211# Native task outputs are directly run on the target (host) system after being
212# built. Even if the output of this recipe doesn't change, a change in one of
213# its dependencies may cause a change in the output it generates (e.g. rpm
214# output depends on the output of its dependent zstd library).
215#
216# This can cause poor interactions with hash equivalence, since this recipes
217# output-changing dependency is "hidden" and downstream task only see that this
218# recipe has the same outhash and therefore is equivalent. This can result in
219# different output in different cases.
220#
221# To resolve this, unhide the output-changing dependency by adding its unihash
222# to this tasks outhash calculation. Unfortunately, don't know specifically
223# know which dependencies are output-changing, so we have to add all of them.
224#
225python native_add_do_populate_sysroot_deps () {
226 current_task = "do_" + d.getVar("BB_CURRENTTASK")
227 if current_task != "do_populate_sysroot":
228 return
229
230 taskdepdata = d.getVar("BB_TASKDEPDATA", False)
231 pn = d.getVar("PN")
232 deps = {
233 dep[0]:dep[6] for dep in taskdepdata.values() if
234 dep[1] == current_task and dep[0] != pn
235 }
236
237 d.setVar("HASHEQUIV_EXTRA_SIGDATA", "\n".join("%s: %s" % (k, deps[k]) for k in sorted(deps.keys())))
238}
239SSTATECREATEFUNCS += "native_add_do_populate_sysroot_deps"