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 | # This class exists to provide information about the targets that |
| 8 | # may be needed by other classes and/or recipes. If you add a new |
| 9 | # target this will probably need to be updated. |
| 10 | |
| 11 | # |
| 12 | # Returns information about 'what' for the named target 'target' |
| 13 | # where 'target' == "<arch>-<os>" |
| 14 | # |
| 15 | # 'what' can be one of |
| 16 | # * target: Returns the target name ("<arch>-<os>") |
| 17 | # * endianness: Return "be" for big endian targets, "le" for little endian |
| 18 | # * bits: Returns the bit size of the target, either "32" or "64" |
| 19 | # * libc: Returns the name of the c library used by the target |
| 20 | # |
| 21 | # It is an error for the target not to exist. |
| 22 | # If 'what' doesn't exist then an empty value is returned |
| 23 | # |
| 24 | def siteinfo_data_for_machine(arch, os, d): |
| 25 | archinfo = { |
| 26 | "allarch": "endian-little bit-32", # bogus, but better than special-casing the checks below for allarch |
| 27 | "aarch64": "endian-little bit-64 arm-common arm-64", |
| 28 | "aarch64_be": "endian-big bit-64 arm-common arm-64", |
| 29 | "arc": "endian-little bit-32 arc-common", |
| 30 | "arceb": "endian-big bit-32 arc-common", |
| 31 | "arm": "endian-little bit-32 arm-common arm-32", |
| 32 | "armeb": "endian-big bit-32 arm-common arm-32", |
| 33 | "avr32": "endian-big bit-32 avr32-common", |
| 34 | "bfin": "endian-little bit-32 bfin-common", |
| 35 | "epiphany": "endian-little bit-32", |
| 36 | "i386": "endian-little bit-32 ix86-common", |
| 37 | "i486": "endian-little bit-32 ix86-common", |
| 38 | "i586": "endian-little bit-32 ix86-common", |
| 39 | "i686": "endian-little bit-32 ix86-common", |
| 40 | "ia64": "endian-little bit-64", |
| 41 | "lm32": "endian-big bit-32", |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame] | 42 | "loongarch32": "endian-little bit-32 loongarch", |
| 43 | "loongarch64": "endian-little bit-64 loongarch", |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 44 | "m68k": "endian-big bit-32", |
| 45 | "microblaze": "endian-big bit-32 microblaze-common", |
| 46 | "microblazeel": "endian-little bit-32 microblaze-common", |
| 47 | "mips": "endian-big bit-32 mips-common", |
| 48 | "mips64": "endian-big bit-64 mips-common", |
| 49 | "mips64el": "endian-little bit-64 mips-common", |
| 50 | "mipsisa64r6": "endian-big bit-64 mips-common", |
| 51 | "mipsisa64r6el": "endian-little bit-64 mips-common", |
| 52 | "mipsel": "endian-little bit-32 mips-common", |
| 53 | "mipsisa32r6": "endian-big bit-32 mips-common", |
| 54 | "mipsisa32r6el": "endian-little bit-32 mips-common", |
| 55 | "powerpc": "endian-big bit-32 powerpc-common", |
| 56 | "powerpcle": "endian-little bit-32 powerpc-common", |
| 57 | "nios2": "endian-little bit-32 nios2-common", |
| 58 | "powerpc64": "endian-big bit-64 powerpc-common", |
| 59 | "powerpc64le": "endian-little bit-64 powerpc-common", |
| 60 | "ppc": "endian-big bit-32 powerpc-common", |
| 61 | "ppc64": "endian-big bit-64 powerpc-common", |
| 62 | "ppc64le" : "endian-little bit-64 powerpc-common", |
| 63 | "riscv32": "endian-little bit-32 riscv-common", |
| 64 | "riscv64": "endian-little bit-64 riscv-common", |
| 65 | "sh3": "endian-little bit-32 sh-common", |
| 66 | "sh3eb": "endian-big bit-32 sh-common", |
| 67 | "sh4": "endian-little bit-32 sh-common", |
| 68 | "sh4eb": "endian-big bit-32 sh-common", |
| 69 | "sparc": "endian-big bit-32", |
| 70 | "viac3": "endian-little bit-32 ix86-common", |
| 71 | "x86_64": "endian-little", # bitinfo specified in targetinfo |
| 72 | } |
| 73 | osinfo = { |
| 74 | "darwin": "common-darwin", |
| 75 | "darwin9": "common-darwin", |
Patrick Williams | 56b44a9 | 2024-01-19 08:49:29 -0600 | [diff] [blame] | 76 | "darwin19": "common-darwin", |
| 77 | "darwin21": "common-darwin", |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 78 | "linux": "common-linux common-glibc", |
| 79 | "linux-gnu": "common-linux common-glibc", |
| 80 | "linux-gnu_ilp32": "common-linux common-glibc", |
| 81 | "linux-gnux32": "common-linux common-glibc", |
| 82 | "linux-gnun32": "common-linux common-glibc", |
| 83 | "linux-gnueabi": "common-linux common-glibc", |
| 84 | "linux-gnuspe": "common-linux common-glibc", |
| 85 | "linux-musl": "common-linux common-musl", |
| 86 | "linux-muslx32": "common-linux common-musl", |
| 87 | "linux-musleabi": "common-linux common-musl", |
| 88 | "linux-muslspe": "common-linux common-musl", |
| 89 | "uclinux-uclibc": "common-uclibc", |
| 90 | "cygwin": "common-cygwin", |
| 91 | "mingw32": "common-mingw", |
| 92 | } |
| 93 | targetinfo = { |
| 94 | "aarch64-linux-gnu": "aarch64-linux", |
| 95 | "aarch64_be-linux-gnu": "aarch64_be-linux", |
| 96 | "aarch64-linux-gnu_ilp32": "bit-32 aarch64_be-linux arm-32", |
| 97 | "aarch64_be-linux-gnu_ilp32": "bit-32 aarch64_be-linux arm-32", |
| 98 | "aarch64-linux-musl": "aarch64-linux", |
| 99 | "aarch64_be-linux-musl": "aarch64_be-linux", |
| 100 | "arm-linux-gnueabi": "arm-linux", |
| 101 | "arm-linux-musleabi": "arm-linux", |
| 102 | "armeb-linux-gnueabi": "armeb-linux", |
| 103 | "armeb-linux-musleabi": "armeb-linux", |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame] | 104 | "loongarch32-linux": "loongarch32-linux", |
| 105 | "loongarch64-linux": "loongarch64-linux", |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 106 | "microblazeel-linux" : "microblaze-linux", |
| 107 | "microblazeel-linux-musl" : "microblaze-linux", |
| 108 | "mips-linux-musl": "mips-linux", |
| 109 | "mipsel-linux-musl": "mipsel-linux", |
| 110 | "mips64-linux-musl": "mips64-linux", |
| 111 | "mips64el-linux-musl": "mips64el-linux", |
| 112 | "mips64-linux-gnun32": "mips-linux bit-32", |
| 113 | "mips64el-linux-gnun32": "mipsel-linux bit-32", |
| 114 | "mipsisa64r6-linux-gnun32": "mipsisa32r6-linux bit-32", |
| 115 | "mipsisa64r6el-linux-gnun32": "mipsisa32r6el-linux bit-32", |
| 116 | "powerpc-linux": "powerpc32-linux powerpc32-linux-glibc", |
| 117 | "powerpc-linux-musl": "powerpc-linux powerpc32-linux powerpc32-linux-musl", |
| 118 | "powerpcle-linux": "powerpc32-linux powerpc32-linux-glibc", |
| 119 | "powerpcle-linux-musl": "powerpc-linux powerpc32-linux powerpc32-linux-musl", |
| 120 | "powerpc-linux-gnuspe": "powerpc-linux powerpc32-linux powerpc32-linux-glibc", |
| 121 | "powerpc-linux-muslspe": "powerpc-linux powerpc32-linux powerpc32-linux-musl", |
| 122 | "powerpc64-linux-gnuspe": "powerpc-linux powerpc64-linux powerpc64-linux-glibc", |
| 123 | "powerpc64-linux-muslspe": "powerpc-linux powerpc64-linux powerpc64-linux-musl", |
| 124 | "powerpc64-linux": "powerpc-linux powerpc64-linux powerpc64-linux-glibc", |
| 125 | "powerpc64-linux-musl": "powerpc-linux powerpc64-linux powerpc64-linux-musl", |
| 126 | "powerpc64le-linux": "powerpc-linux powerpc64-linux powerpc64-linux-glibc", |
| 127 | "powerpc64le-linux-musl": "powerpc-linux powerpc64-linux powerpc64-linux-musl", |
| 128 | "riscv32-linux": "riscv32-linux", |
| 129 | "riscv32-linux-musl": "riscv32-linux", |
| 130 | "riscv64-linux": "riscv64-linux", |
| 131 | "riscv64-linux-musl": "riscv64-linux", |
| 132 | "x86_64-cygwin": "bit-64", |
| 133 | "x86_64-darwin": "bit-64", |
| 134 | "x86_64-darwin9": "bit-64", |
Patrick Williams | 56b44a9 | 2024-01-19 08:49:29 -0600 | [diff] [blame] | 135 | "x86_64-darwin19": "bit-64", |
| 136 | "x86_64-darwin21": "bit-64", |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 137 | "x86_64-linux": "bit-64", |
| 138 | "x86_64-linux-musl": "x86_64-linux bit-64", |
| 139 | "x86_64-linux-muslx32": "bit-32 ix86-common x32-linux", |
| 140 | "x86_64-elf": "bit-64", |
| 141 | "x86_64-linux-gnu": "bit-64 x86_64-linux", |
| 142 | "x86_64-linux-gnux32": "bit-32 ix86-common x32-linux", |
| 143 | "x86_64-mingw32": "bit-64", |
| 144 | } |
| 145 | |
| 146 | # Add in any extra user supplied data which may come from a BSP layer, removing the |
| 147 | # need to always change this class directly |
| 148 | extra_siteinfo = (d.getVar("SITEINFO_EXTRA_DATAFUNCS") or "").split() |
| 149 | for m in extra_siteinfo: |
| 150 | call = m + "(archinfo, osinfo, targetinfo, d)" |
| 151 | locs = { "archinfo" : archinfo, "osinfo" : osinfo, "targetinfo" : targetinfo, "d" : d} |
| 152 | archinfo, osinfo, targetinfo = bb.utils.better_eval(call, locs) |
| 153 | |
| 154 | target = "%s-%s" % (arch, os) |
| 155 | |
| 156 | sitedata = [] |
| 157 | if arch in archinfo: |
| 158 | sitedata.extend(archinfo[arch].split()) |
| 159 | if os in osinfo: |
| 160 | sitedata.extend(osinfo[os].split()) |
| 161 | if target in targetinfo: |
| 162 | sitedata.extend(targetinfo[target].split()) |
| 163 | sitedata.append(target) |
| 164 | sitedata.append("common") |
| 165 | |
| 166 | bb.debug(1, "SITE files %s" % sitedata); |
| 167 | return sitedata |
| 168 | |
| 169 | def siteinfo_data(d): |
| 170 | return siteinfo_data_for_machine(d.getVar("HOST_ARCH"), d.getVar("HOST_OS"), d) |
| 171 | |
| 172 | python () { |
| 173 | sitedata = set(siteinfo_data(d)) |
| 174 | if "endian-little" in sitedata: |
| 175 | d.setVar("SITEINFO_ENDIANNESS", "le") |
| 176 | elif "endian-big" in sitedata: |
| 177 | d.setVar("SITEINFO_ENDIANNESS", "be") |
| 178 | else: |
| 179 | bb.error("Unable to determine endianness for architecture '%s'" % |
| 180 | d.getVar("HOST_ARCH")) |
| 181 | bb.fatal("Please add your architecture to siteinfo.bbclass") |
| 182 | |
| 183 | if "bit-32" in sitedata: |
| 184 | d.setVar("SITEINFO_BITS", "32") |
| 185 | elif "bit-64" in sitedata: |
| 186 | d.setVar("SITEINFO_BITS", "64") |
| 187 | else: |
| 188 | bb.error("Unable to determine bit size for architecture '%s'" % |
| 189 | d.getVar("HOST_ARCH")) |
| 190 | bb.fatal("Please add your architecture to siteinfo.bbclass") |
| 191 | } |
| 192 | |
| 193 | # Layers with siteconfig need to add a replacement path to this variable so the |
| 194 | # sstate isn't path specific |
| 195 | SITEINFO_PATHVARS = "COREBASE" |
| 196 | |
| 197 | def siteinfo_get_files(d, sysrootcache=False): |
| 198 | sitedata = siteinfo_data(d) |
| 199 | sitefiles = [] |
| 200 | searched = [] |
| 201 | for path in d.getVar("BBPATH").split(":"): |
| 202 | for element in sitedata: |
| 203 | filename = os.path.join(path, "site", element) |
| 204 | if os.path.exists(filename): |
| 205 | searched.append(filename + ":True") |
| 206 | sitefiles.append(filename) |
| 207 | else: |
| 208 | searched.append(filename + ":False") |
| 209 | |
| 210 | # Have to parameterise out hardcoded paths such as COREBASE for the main site files |
| 211 | for var in d.getVar("SITEINFO_PATHVARS").split(): |
| 212 | searched2 = [] |
| 213 | replace = os.path.normpath(d.getVar(var)) |
| 214 | for s in searched: |
| 215 | searched2.append(s.replace(replace, "${" + var + "}")) |
| 216 | searched = searched2 |
| 217 | |
| 218 | if bb.data.inherits_class('native', d) or bb.data.inherits_class('cross', d) or bb.data.inherits_class('crosssdk', d): |
| 219 | # We need sstate sigs for native/cross not to vary upon arch so we can't depend on the site files. |
| 220 | # In future we may want to depend upon all site files? |
| 221 | # This would show up as breaking sstatetests.SStateTests.test_sstate_32_64_same_hash for example |
| 222 | searched = [] |
| 223 | |
| 224 | if not sysrootcache: |
| 225 | return sitefiles, searched |
| 226 | |
| 227 | # Now check for siteconfig cache files in sysroots |
| 228 | path_siteconfig = d.getVar('SITECONFIG_SYSROOTCACHE') |
| 229 | if path_siteconfig and os.path.isdir(path_siteconfig): |
| 230 | for i in os.listdir(path_siteconfig): |
| 231 | if not i.endswith("_config"): |
| 232 | continue |
| 233 | filename = os.path.join(path_siteconfig, i) |
| 234 | sitefiles.append(filename) |
| 235 | return sitefiles, searched |
| 236 | |
| 237 | # |
| 238 | # Make some information available via variables |
| 239 | # |
| 240 | SITECONFIG_SYSROOTCACHE = "${STAGING_DATADIR}/${TARGET_SYS}_config_site.d" |