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}" |
| 80 | base_libdir = "${STAGING_LIBDIR_NATIVE}" |
| 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 | |
| 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 | |
| 189 | addhandler native_virtclass_handler |
| 190 | native_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise" |
| 191 | |
| 192 | python do_addto_recipe_sysroot () { |
| 193 | bb.build.exec_func("extend_recipe_sysroot", d) |
| 194 | } |
| 195 | addtask addto_recipe_sysroot after do_populate_sysroot |
| 196 | do_addto_recipe_sysroot[deptask] = "do_populate_sysroot" |
| 197 | |
| 198 | inherit nopackages |
| 199 | |
| 200 | do_packagedata[stamp-extra-info] = "" |
| 201 | |
| 202 | USE_NLS = "no" |
| 203 | |
| 204 | RECIPERDEPTASK = "do_populate_sysroot" |
| 205 | do_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 | # |
| 222 | python 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 | } |
| 236 | SSTATECREATEFUNCS += "native_add_do_populate_sysroot_deps" |