xref: /OK3568_Linux_fs/yocto/poky/meta/classes/cml1.bbclass (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# returns all the elements from the src uri that are .cfg files
2*4882a593Smuzhiyundef find_cfgs(d):
3*4882a593Smuzhiyun    sources=src_patches(d, True)
4*4882a593Smuzhiyun    sources_list=[]
5*4882a593Smuzhiyun    for s in sources:
6*4882a593Smuzhiyun        if s.endswith('.cfg'):
7*4882a593Smuzhiyun            sources_list.append(s)
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun    return sources_list
10*4882a593Smuzhiyun
11*4882a593Smuzhiyuncml1_do_configure() {
12*4882a593Smuzhiyun	set -e
13*4882a593Smuzhiyun	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
14*4882a593Smuzhiyun	yes '' | oe_runmake oldconfig
15*4882a593Smuzhiyun}
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunEXPORT_FUNCTIONS do_configure
18*4882a593Smuzhiyunaddtask configure after do_unpack do_patch before do_compile
19*4882a593Smuzhiyun
20*4882a593Smuzhiyuninherit terminal
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunOE_TERMINAL_EXPORTS += "HOST_EXTRACFLAGS HOSTLDFLAGS TERMINFO CROSS_CURSES_LIB CROSS_CURSES_INC"
23*4882a593SmuzhiyunHOST_EXTRACFLAGS = "${BUILD_CFLAGS} ${BUILD_LDFLAGS}"
24*4882a593SmuzhiyunHOSTLDFLAGS = "${BUILD_LDFLAGS}"
25*4882a593SmuzhiyunCROSS_CURSES_LIB = "-lncurses -ltinfo"
26*4882a593SmuzhiyunCROSS_CURSES_INC = '-DCURSES_LOC="<curses.h>"'
27*4882a593SmuzhiyunTERMINFO = "${STAGING_DATADIR_NATIVE}/terminfo"
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunKCONFIG_CONFIG_COMMAND ??= "menuconfig"
30*4882a593SmuzhiyunKCONFIG_CONFIG_ROOTDIR ??= "${B}"
31*4882a593Smuzhiyunpython do_menuconfig() {
32*4882a593Smuzhiyun    import shutil
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun    config = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config")
35*4882a593Smuzhiyun    configorig = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config.orig")
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun    try:
38*4882a593Smuzhiyun        mtime = os.path.getmtime(config)
39*4882a593Smuzhiyun        shutil.copy(config, configorig)
40*4882a593Smuzhiyun    except OSError:
41*4882a593Smuzhiyun        mtime = 0
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun    # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
44*4882a593Smuzhiyun    d.setVar("PKG_CONFIG_DIR", "${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig")
45*4882a593Smuzhiyun    d.setVar("PKG_CONFIG_PATH", "${PKG_CONFIG_DIR}:${STAGING_DATADIR_NATIVE}/pkgconfig")
46*4882a593Smuzhiyun    d.setVar("PKG_CONFIG_LIBDIR", "${PKG_CONFIG_DIR}")
47*4882a593Smuzhiyun    d.setVarFlag("PKG_CONFIG_SYSROOT_DIR", "unexport", "1")
48*4882a593Smuzhiyun    # ensure that environment variables are overwritten with this tasks 'd' values
49*4882a593Smuzhiyun    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_DIR PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun    oe_terminal("sh -c \"make %s; if [ \\$? -ne 0 ]; then echo 'Command failed.'; printf 'Press any key to continue... '; read r; fi\"" % d.getVar('KCONFIG_CONFIG_COMMAND'),
52*4882a593Smuzhiyun                d.getVar('PN') + ' Configuration', d)
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun    # FIXME this check can be removed when the minimum bitbake version has been bumped
55*4882a593Smuzhiyun    if hasattr(bb.build, 'write_taint'):
56*4882a593Smuzhiyun        try:
57*4882a593Smuzhiyun            newmtime = os.path.getmtime(config)
58*4882a593Smuzhiyun        except OSError:
59*4882a593Smuzhiyun            newmtime = 0
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun        if newmtime > mtime:
62*4882a593Smuzhiyun            bb.note("Configuration changed, recompile will be forced")
63*4882a593Smuzhiyun            bb.build.write_taint('do_compile', d)
64*4882a593Smuzhiyun}
65*4882a593Smuzhiyundo_menuconfig[depends] += "ncurses-native:do_populate_sysroot"
66*4882a593Smuzhiyundo_menuconfig[nostamp] = "1"
67*4882a593Smuzhiyundo_menuconfig[dirs] = "${KCONFIG_CONFIG_ROOTDIR}"
68*4882a593Smuzhiyunaddtask menuconfig after do_configure
69*4882a593Smuzhiyun
70*4882a593Smuzhiyunpython do_diffconfig() {
71*4882a593Smuzhiyun    import shutil
72*4882a593Smuzhiyun    import subprocess
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun    workdir = d.getVar('WORKDIR')
75*4882a593Smuzhiyun    fragment = workdir + '/fragment.cfg'
76*4882a593Smuzhiyun    configorig = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config.orig")
77*4882a593Smuzhiyun    config = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config")
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun    try:
80*4882a593Smuzhiyun        md5newconfig = bb.utils.md5_file(configorig)
81*4882a593Smuzhiyun        md5config = bb.utils.md5_file(config)
82*4882a593Smuzhiyun        isdiff = md5newconfig != md5config
83*4882a593Smuzhiyun    except IOError as e:
84*4882a593Smuzhiyun        bb.fatal("No config files found. Did you do menuconfig ?\n%s" % e)
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun    if isdiff:
87*4882a593Smuzhiyun        statement = 'diff --unchanged-line-format= --old-line-format= --new-line-format="%L" ' + configorig + ' ' + config + '>' + fragment
88*4882a593Smuzhiyun        subprocess.call(statement, shell=True)
89*4882a593Smuzhiyun        # No need to check the exit code as we know it's going to be
90*4882a593Smuzhiyun        # non-zero, but that's what we expect.
91*4882a593Smuzhiyun        shutil.copy(configorig, config)
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun        bb.plain("Config fragment has been dumped into:\n %s" % fragment)
94*4882a593Smuzhiyun    else:
95*4882a593Smuzhiyun        if os.path.exists(fragment):
96*4882a593Smuzhiyun            os.unlink(fragment)
97*4882a593Smuzhiyun}
98*4882a593Smuzhiyun
99*4882a593Smuzhiyundo_diffconfig[nostamp] = "1"
100*4882a593Smuzhiyundo_diffconfig[dirs] = "${KCONFIG_CONFIG_ROOTDIR}"
101*4882a593Smuzhiyunaddtask diffconfig
102