blob: d87d8204e44fec405c58a7485660d58c314c54d3 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# returns all the elements from the src uri that are .cfg files
8def find_cfgs(d):
9 sources=src_patches(d, True)
10 sources_list=[]
11 for s in sources:
12 if s.endswith('.cfg'):
13 sources_list.append(s)
14
15 return sources_list
16
17cml1_do_configure() {
18 set -e
19 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
20 yes '' | oe_runmake oldconfig
21}
22
23EXPORT_FUNCTIONS do_configure
Patrick Williams92b42cb2022-09-03 06:53:57 -050024
25inherit terminal
26
27OE_TERMINAL_EXPORTS += "HOST_EXTRACFLAGS HOSTLDFLAGS TERMINFO CROSS_CURSES_LIB CROSS_CURSES_INC"
28HOST_EXTRACFLAGS = "${BUILD_CFLAGS} ${BUILD_LDFLAGS}"
29HOSTLDFLAGS = "${BUILD_LDFLAGS}"
30CROSS_CURSES_LIB = "-lncurses -ltinfo"
31CROSS_CURSES_INC = '-DCURSES_LOC="<curses.h>"'
32TERMINFO = "${STAGING_DATADIR_NATIVE}/terminfo"
33
34KCONFIG_CONFIG_COMMAND ??= "menuconfig"
Patrick Williams520786c2023-06-25 16:20:36 -050035KCONFIG_CONFIG_ENABLE_MENUCONFIG ??= "true"
Patrick Williams92b42cb2022-09-03 06:53:57 -050036KCONFIG_CONFIG_ROOTDIR ??= "${B}"
37python do_menuconfig() {
38 import shutil
39
Patrick Williams520786c2023-06-25 16:20:36 -050040 if not bb.utils.to_boolean(d.getVar("KCONFIG_CONFIG_ENABLE_MENUCONFIG")):
41 bb.fatal("do_menuconfig is disabled, please check KCONFIG_CONFIG_ENABLE_MENUCONFIG variable.")
42 return
43
Patrick Williams92b42cb2022-09-03 06:53:57 -050044 config = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config")
45 configorig = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config.orig")
46
47 try:
48 mtime = os.path.getmtime(config)
49 shutil.copy(config, configorig)
50 except OSError:
51 mtime = 0
52
53 # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
54 d.setVar("PKG_CONFIG_DIR", "${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig")
55 d.setVar("PKG_CONFIG_PATH", "${PKG_CONFIG_DIR}:${STAGING_DATADIR_NATIVE}/pkgconfig")
56 d.setVar("PKG_CONFIG_LIBDIR", "${PKG_CONFIG_DIR}")
57 d.setVarFlag("PKG_CONFIG_SYSROOT_DIR", "unexport", "1")
58 # ensure that environment variables are overwritten with this tasks 'd' values
59 d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_DIR PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
60
61 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'),
62 d.getVar('PN') + ' Configuration', d)
63
64 # FIXME this check can be removed when the minimum bitbake version has been bumped
65 if hasattr(bb.build, 'write_taint'):
66 try:
67 newmtime = os.path.getmtime(config)
68 except OSError:
69 newmtime = 0
70
71 if newmtime > mtime:
72 bb.note("Configuration changed, recompile will be forced")
73 bb.build.write_taint('do_compile', d)
74}
75do_menuconfig[depends] += "ncurses-native:do_populate_sysroot"
76do_menuconfig[nostamp] = "1"
77do_menuconfig[dirs] = "${KCONFIG_CONFIG_ROOTDIR}"
78addtask menuconfig after do_configure
79
80python do_diffconfig() {
81 import shutil
82 import subprocess
83
84 workdir = d.getVar('WORKDIR')
85 fragment = workdir + '/fragment.cfg'
86 configorig = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config.orig")
87 config = os.path.join(d.getVar('KCONFIG_CONFIG_ROOTDIR'), ".config")
88
89 try:
90 md5newconfig = bb.utils.md5_file(configorig)
91 md5config = bb.utils.md5_file(config)
92 isdiff = md5newconfig != md5config
93 except IOError as e:
94 bb.fatal("No config files found. Did you do menuconfig ?\n%s" % e)
95
96 if isdiff:
97 statement = 'diff --unchanged-line-format= --old-line-format= --new-line-format="%L" ' + configorig + ' ' + config + '>' + fragment
98 subprocess.call(statement, shell=True)
99 # No need to check the exit code as we know it's going to be
100 # non-zero, but that's what we expect.
101 shutil.copy(configorig, config)
102
103 bb.plain("Config fragment has been dumped into:\n %s" % fragment)
104 else:
105 if os.path.exists(fragment):
106 os.unlink(fragment)
107}
108
109do_diffconfig[nostamp] = "1"
110do_diffconfig[dirs] = "${KCONFIG_CONFIG_ROOTDIR}"
111addtask diffconfig