Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # We want native packages to be relocatable |
| 8 | inherit relocatable |
| 9 | |
| 10 | # Native packages are built indirectly via dependency, |
| 11 | # no need for them to be a direct target of 'world' |
| 12 | EXCLUDE_FROM_WORLD = "1" |
| 13 | |
| 14 | PACKAGE_ARCH = "${BUILD_ARCH}" |
| 15 | |
| 16 | # used by cmake class |
| 17 | OECMAKE_RPATH = "${libdir}" |
| 18 | OECMAKE_RPATH:class-native = "${libdir}" |
| 19 | |
| 20 | TARGET_ARCH = "${BUILD_ARCH}" |
| 21 | TARGET_OS = "${BUILD_OS}" |
| 22 | TARGET_VENDOR = "${BUILD_VENDOR}" |
| 23 | TARGET_PREFIX = "${BUILD_PREFIX}" |
| 24 | TARGET_CC_ARCH = "${BUILD_CC_ARCH}" |
| 25 | TARGET_LD_ARCH = "${BUILD_LD_ARCH}" |
| 26 | TARGET_AS_ARCH = "${BUILD_AS_ARCH}" |
| 27 | TARGET_CPPFLAGS = "${BUILD_CPPFLAGS}" |
| 28 | TARGET_CFLAGS = "${BUILD_CFLAGS}" |
| 29 | TARGET_CXXFLAGS = "${BUILD_CXXFLAGS}" |
| 30 | TARGET_LDFLAGS = "${BUILD_LDFLAGS}" |
| 31 | TARGET_FPU = "" |
| 32 | TUNE_FEATURES = "" |
| 33 | ABIEXTENSION = "" |
| 34 | |
| 35 | HOST_ARCH = "${BUILD_ARCH}" |
| 36 | HOST_OS = "${BUILD_OS}" |
| 37 | HOST_VENDOR = "${BUILD_VENDOR}" |
| 38 | HOST_PREFIX = "${BUILD_PREFIX}" |
| 39 | HOST_CC_ARCH = "${BUILD_CC_ARCH}" |
| 40 | HOST_LD_ARCH = "${BUILD_LD_ARCH}" |
| 41 | HOST_AS_ARCH = "${BUILD_AS_ARCH}" |
| 42 | |
| 43 | CPPFLAGS = "${BUILD_CPPFLAGS}" |
| 44 | CFLAGS = "${BUILD_CFLAGS}" |
| 45 | CXXFLAGS = "${BUILD_CXXFLAGS}" |
| 46 | LDFLAGS = "${BUILD_LDFLAGS}" |
| 47 | |
| 48 | STAGING_BINDIR = "${STAGING_BINDIR_NATIVE}" |
| 49 | STAGING_BINDIR_CROSS = "${STAGING_BINDIR_NATIVE}" |
| 50 | |
| 51 | # native pkg doesn't need the TOOLCHAIN_OPTIONS. |
| 52 | TOOLCHAIN_OPTIONS = "" |
| 53 | |
| 54 | # Don't build ptest natively |
| 55 | PTEST_ENABLED = "0" |
| 56 | |
| 57 | # Don't use site files for native builds |
| 58 | export CONFIG_SITE = "${COREBASE}/meta/site/native" |
| 59 | |
| 60 | # set the compiler as well. It could have been set to something else |
| 61 | export CC = "${BUILD_CC}" |
| 62 | export CXX = "${BUILD_CXX}" |
| 63 | export FC = "${BUILD_FC}" |
| 64 | export CPP = "${BUILD_CPP}" |
| 65 | export LD = "${BUILD_LD}" |
| 66 | export CCLD = "${BUILD_CCLD}" |
| 67 | export AR = "${BUILD_AR}" |
| 68 | export AS = "${BUILD_AS}" |
| 69 | export RANLIB = "${BUILD_RANLIB}" |
| 70 | export STRIP = "${BUILD_STRIP}" |
| 71 | export NM = "${BUILD_NM}" |
| 72 | |
| 73 | # Path prefixes |
| 74 | base_prefix = "${STAGING_DIR_NATIVE}" |
| 75 | prefix = "${STAGING_DIR_NATIVE}${prefix_native}" |
| 76 | exec_prefix = "${STAGING_DIR_NATIVE}${prefix_native}" |
| 77 | |
| 78 | bindir = "${STAGING_BINDIR_NATIVE}" |
| 79 | sbindir = "${STAGING_SBINDIR_NATIVE}" |
Patrick Williams | f52e3dd | 2024-01-26 13:04:43 -0600 | [diff] [blame] | 80 | base_libdir = "${STAGING_BASE_LIBDIR_NATIVE}" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 81 | libdir = "${STAGING_LIBDIR_NATIVE}" |
| 82 | includedir = "${STAGING_INCDIR_NATIVE}" |
| 83 | sysconfdir = "${STAGING_ETCDIR_NATIVE}" |
| 84 | datadir = "${STAGING_DATADIR_NATIVE}" |
| 85 | |
| 86 | baselib = "lib" |
| 87 | |
| 88 | export lt_cv_sys_lib_dlsearch_path_spec = "${libdir} ${base_libdir} /lib /lib64 /usr/lib /usr/lib64" |
| 89 | |
| 90 | NATIVE_PACKAGE_PATH_SUFFIX ?= "" |
| 91 | bindir .= "${NATIVE_PACKAGE_PATH_SUFFIX}" |
| 92 | sbindir .= "${NATIVE_PACKAGE_PATH_SUFFIX}" |
| 93 | base_libdir .= "${NATIVE_PACKAGE_PATH_SUFFIX}" |
| 94 | libdir .= "${NATIVE_PACKAGE_PATH_SUFFIX}" |
| 95 | libexecdir .= "${NATIVE_PACKAGE_PATH_SUFFIX}" |
| 96 | |
| 97 | do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE}/" |
| 98 | do_populate_sysroot[sstate-outputdirs] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}" |
| 99 | |
| 100 | # Since we actually install these into situ there is no staging prefix |
| 101 | STAGING_DIR_HOST = "" |
| 102 | STAGING_DIR_TARGET = "" |
| 103 | PKG_CONFIG_DIR = "${libdir}/pkgconfig" |
| 104 | |
| 105 | EXTRA_NATIVE_PKGCONFIG_PATH ?= "" |
| 106 | PKG_CONFIG_PATH .= "${EXTRA_NATIVE_PKGCONFIG_PATH}" |
| 107 | PKG_CONFIG_SYSROOT_DIR = "" |
| 108 | PKG_CONFIG_SYSTEM_LIBRARY_PATH[unexport] = "1" |
| 109 | PKG_CONFIG_SYSTEM_INCLUDE_PATH[unexport] = "1" |
| 110 | |
| 111 | # we dont want libc-*libc to kick in for native recipes |
| 112 | LIBCOVERRIDE = "" |
| 113 | CLASSOVERRIDE = "class-native" |
| 114 | MACHINEOVERRIDES = "" |
| 115 | MACHINE_FEATURES = "" |
| 116 | |
| 117 | PATH: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. |
| 121 | SSTATE_SCAN_CMD ?= "${SSTATE_SCAN_CMD_NATIVE}" |
| 122 | |
| 123 | # No strip sysroot when DEBUG_BUILD is enabled |
| 124 | INHIBIT_SYSROOT_STRIP ?= "${@oe.utils.vartrue('DEBUG_BUILD', '1', '', d)}" |
| 125 | |
| 126 | python 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 Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 142 | def map_dependencies(varname, d, suffix = "", selfref=True, regex=False): |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 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: |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 151 | if regex and dep.startswith("^") and dep.endswith("$"): |
| 152 | newdeps.append(dep[:-1].replace(pn, bpn) + "-native$") |
| 153 | elif dep == pn: |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 154 | 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 Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 166 | d.setVar(varname, " ".join(newdeps)) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 167 | |
| 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 Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 176 | map_dependencies("PACKAGES_DYNAMIC", e.data, regex=True) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 177 | |
| 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 | |
| 192 | addhandler native_virtclass_handler |
| 193 | native_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise" |
| 194 | |
| 195 | python do_addto_recipe_sysroot () { |
| 196 | bb.build.exec_func("extend_recipe_sysroot", d) |
| 197 | } |
| 198 | addtask addto_recipe_sysroot after do_populate_sysroot |
| 199 | do_addto_recipe_sysroot[deptask] = "do_populate_sysroot" |
| 200 | |
| 201 | inherit nopackages |
| 202 | |
| 203 | do_packagedata[stamp-extra-info] = "" |
| 204 | |
| 205 | USE_NLS = "no" |
| 206 | |
| 207 | RECIPERDEPTASK = "do_populate_sysroot" |
| 208 | do_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 | # |
| 225 | python 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 | } |
| 239 | SSTATECREATEFUNCS += "native_add_do_populate_sysroot_deps" |