xref: /OK3568_Linux_fs/yocto/poky/meta/classes/waf.bbclass (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# avoids build breaks when using no-static-libs.inc
2*4882a593SmuzhiyunDISABLE_STATIC = ""
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun# What Python interpretter to use.  Defaults to Python 3 but can be
5*4882a593Smuzhiyun# overridden if required.
6*4882a593SmuzhiyunWAF_PYTHON ?= "python3"
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunB = "${WORKDIR}/build"
9*4882a593Smuzhiyundo_configure[cleandirs] += "${B}"
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunEXTRA_OECONF:append = " ${PACKAGECONFIG_CONFARGS}"
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunEXTRA_OEWAF_BUILD ??= ""
14*4882a593Smuzhiyun# In most cases, you want to pass the same arguments to `waf build` and `waf
15*4882a593Smuzhiyun# install`, but you can override it if necessary
16*4882a593SmuzhiyunEXTRA_OEWAF_INSTALL ??= "${EXTRA_OEWAF_BUILD}"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyundef waflock_hash(d):
19*4882a593Smuzhiyun    # Calculates the hash used for the waf lock file. This should include
20*4882a593Smuzhiyun    # all of the user controllable inputs passed to waf configure. Note
21*4882a593Smuzhiyun    # that the full paths for ${B} and ${S} are used; this is OK and desired
22*4882a593Smuzhiyun    # because a change to either of these should create a unique lock file
23*4882a593Smuzhiyun    # to prevent collisions.
24*4882a593Smuzhiyun    import hashlib
25*4882a593Smuzhiyun    h = hashlib.sha512()
26*4882a593Smuzhiyun    def update(name):
27*4882a593Smuzhiyun        val = d.getVar(name)
28*4882a593Smuzhiyun        if val is not None:
29*4882a593Smuzhiyun            h.update(val.encode('utf-8'))
30*4882a593Smuzhiyun    update('S')
31*4882a593Smuzhiyun    update('B')
32*4882a593Smuzhiyun    update('prefix')
33*4882a593Smuzhiyun    update('EXTRA_OECONF')
34*4882a593Smuzhiyun    return h.hexdigest()
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun# Use WAFLOCK to specify a separate lock file. The build is already
37*4882a593Smuzhiyun# sufficiently isolated by setting the output directory, this ensures that
38*4882a593Smuzhiyun# bitbake won't step on toes of any other configured context in the source
39*4882a593Smuzhiyun# directory (e.g. if the source is coming from externalsrc and was previously
40*4882a593Smuzhiyun# configured elsewhere).
41*4882a593Smuzhiyunexport WAFLOCK = ".lock-waf_oe_${@waflock_hash(d)}_build"
42*4882a593SmuzhiyunBB_BASEHASH_IGNORE_VARS += "WAFLOCK"
43*4882a593Smuzhiyun
44*4882a593Smuzhiyunpython waf_preconfigure() {
45*4882a593Smuzhiyun    import subprocess
46*4882a593Smuzhiyun    subsrcdir = d.getVar('S')
47*4882a593Smuzhiyun    python = d.getVar('WAF_PYTHON')
48*4882a593Smuzhiyun    wafbin = os.path.join(subsrcdir, 'waf')
49*4882a593Smuzhiyun    try:
50*4882a593Smuzhiyun        result = subprocess.check_output([python, wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
51*4882a593Smuzhiyun        version = result.decode('utf-8').split()[1]
52*4882a593Smuzhiyun        if bb.utils.vercmp_string_op(version, "1.8.7", ">="):
53*4882a593Smuzhiyun            d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir} --libdir=${libdir}")
54*4882a593Smuzhiyun    except subprocess.CalledProcessError as e:
55*4882a593Smuzhiyun        bb.warn("Unable to execute waf --version, exit code %d. Assuming waf version without bindir/libdir support." % e.returncode)
56*4882a593Smuzhiyun    except FileNotFoundError:
57*4882a593Smuzhiyun        bb.fatal("waf does not exist in %s" % subsrcdir)
58*4882a593Smuzhiyun}
59*4882a593Smuzhiyun
60*4882a593Smuzhiyundo_configure[prefuncs] += "waf_preconfigure"
61*4882a593Smuzhiyun
62*4882a593Smuzhiyunwaf_do_configure() {
63*4882a593Smuzhiyun	(cd ${S} && ${WAF_PYTHON} ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
64*4882a593Smuzhiyun}
65*4882a593Smuzhiyun
66*4882a593Smuzhiyundo_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+"
67*4882a593Smuzhiyunwaf_do_compile()  {
68*4882a593Smuzhiyun	(cd ${S} && ${WAF_PYTHON} ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
69*4882a593Smuzhiyun}
70*4882a593Smuzhiyun
71*4882a593Smuzhiyunwaf_do_install() {
72*4882a593Smuzhiyun	(cd ${S} && ${WAF_PYTHON} ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
73*4882a593Smuzhiyun}
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunEXPORT_FUNCTIONS do_configure do_compile do_install
76