blob: 61ad053def65af1d1a8516273a56ad84049cdf28 [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
142 def map_dependencies(varname, d, suffix = "", selfref=True):
143 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:
151 if dep == pn:
152 if not selfref:
153 continue
154 newdeps.append(dep)
155 elif "-cross-" in dep:
156 newdeps.append(dep.replace("-cross", "-native"))
157 elif not dep.endswith("-native"):
158 # Replace ${PN} with ${BPN} in the dependency to make sure
159 # dependencies on, e.g., ${PN}-foo become ${BPN}-foo-native
160 # rather than ${BPN}-native-foo-native.
161 newdeps.append(dep.replace(pn, bpn) + "-native")
162 else:
163 newdeps.append(dep)
164 d.setVar(varname, " ".join(newdeps), parsing=True)
165
166 map_dependencies("DEPENDS", e.data, selfref=False)
167 for pkg in e.data.getVar("PACKAGES", False).split():
168 map_dependencies("RDEPENDS", e.data, pkg)
169 map_dependencies("RRECOMMENDS", e.data, pkg)
170 map_dependencies("RSUGGESTS", e.data, pkg)
171 map_dependencies("RPROVIDES", e.data, pkg)
172 map_dependencies("RREPLACES", e.data, pkg)
173 map_dependencies("PACKAGES", e.data)
174
175 provides = e.data.getVar("PROVIDES")
176 nprovides = []
177 for prov in provides.split():
178 if prov.find(pn) != -1:
179 nprovides.append(prov)
180 elif not prov.endswith("-native"):
181 nprovides.append(prov + "-native")
182 else:
183 nprovides.append(prov)
184 e.data.setVar("PROVIDES", ' '.join(nprovides))
185
186
187}
188
189addhandler native_virtclass_handler
190native_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
191
192python do_addto_recipe_sysroot () {
193 bb.build.exec_func("extend_recipe_sysroot", d)
194}
195addtask addto_recipe_sysroot after do_populate_sysroot
196do_addto_recipe_sysroot[deptask] = "do_populate_sysroot"
197
198inherit nopackages
199
200do_packagedata[stamp-extra-info] = ""
201
202USE_NLS = "no"
203
204RECIPERDEPTASK = "do_populate_sysroot"
205do_populate_sysroot[rdeptask] = "${RECIPERDEPTASK}"
206
207#
208# Native task outputs are directly run on the target (host) system after being
209# built. Even if the output of this recipe doesn't change, a change in one of
210# its dependencies may cause a change in the output it generates (e.g. rpm
211# output depends on the output of its dependent zstd library).
212#
213# This can cause poor interactions with hash equivalence, since this recipes
214# output-changing dependency is "hidden" and downstream task only see that this
215# recipe has the same outhash and therefore is equivalent. This can result in
216# different output in different cases.
217#
218# To resolve this, unhide the output-changing dependency by adding its unihash
219# to this tasks outhash calculation. Unfortunately, don't know specifically
220# know which dependencies are output-changing, so we have to add all of them.
221#
222python native_add_do_populate_sysroot_deps () {
223 current_task = "do_" + d.getVar("BB_CURRENTTASK")
224 if current_task != "do_populate_sysroot":
225 return
226
227 taskdepdata = d.getVar("BB_TASKDEPDATA", False)
228 pn = d.getVar("PN")
229 deps = {
230 dep[0]:dep[6] for dep in taskdepdata.values() if
231 dep[1] == current_task and dep[0] != pn
232 }
233
234 d.setVar("HASHEQUIV_EXTRA_SIGDATA", "\n".join("%s: %s" % (k, deps[k]) for k in sorted(deps.keys())))
235}
236SSTATECREATEFUNCS += "native_add_do_populate_sysroot_deps"