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