Skip to content

Commit 3122c84

Browse files
committed
kconfig: refactor Makefile to reduce process forks
Refactor Makefile and use read-file macro. For Make >= 4.2, it can read out a file by using the built-in function. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent 6768fa4 commit 3122c84

File tree

7 files changed

+68
-48
lines changed

7 files changed

+68
-48
lines changed

scripts/kconfig/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
/conf
33
/[gmnq]conf
4-
/[gmnq]conf-cfg
4+
/[gmnq]conf-cflags
5+
/[gmnq]conf-libs
6+
/qconf-bin
57
/qconf-moc.cc

scripts/kconfig/Makefile

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,39 +159,41 @@ conf-objs := conf.o $(common-objs)
159159
hostprogs += nconf
160160
nconf-objs := nconf.o nconf.gui.o $(common-objs)
161161

162-
HOSTLDLIBS_nconf = $(shell . $(obj)/nconf-cfg && echo $$libs)
163-
HOSTCFLAGS_nconf.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
164-
HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
162+
HOSTLDLIBS_nconf = $(call read-file, $(obj)/nconf-libs)
163+
HOSTCFLAGS_nconf.o = $(call read-file, $(obj)/nconf-cflags)
164+
HOSTCFLAGS_nconf.gui.o = $(call read-file, $(obj)/nconf-cflags)
165165

166-
$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
166+
$(obj)/nconf: | $(obj)/nconf-libs
167+
$(obj)/nconf.o $(obj)/nconf.gui.o: | $(obj)/nconf-cflags
167168

168169
# mconf: Used for the menuconfig target based on lxdialog
169170
hostprogs += mconf
170171
lxdialog := $(addprefix lxdialog/, \
171172
checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
172173
mconf-objs := mconf.o $(lxdialog) $(common-objs)
173174

174-
HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
175+
HOSTLDLIBS_mconf = $(call read-file, $(obj)/mconf-libs)
175176
$(foreach f, mconf.o $(lxdialog), \
176-
$(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
177+
$(eval HOSTCFLAGS_$f = $$(call read-file, $(obj)/mconf-cflags)))
177178

178-
$(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
179+
$(obj)/mconf: | $(obj)/mconf-libs
180+
$(addprefix $(obj)/, mconf.o $(lxdialog)): | $(obj)/mconf-cflags
179181

180182
# qconf: Used for the xconfig target based on Qt
181183
hostprogs += qconf
182184
qconf-cxxobjs := qconf.o qconf-moc.o
183185
qconf-objs := images.o $(common-objs)
184186

185-
HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs)
186-
HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
187-
HOSTCXXFLAGS_qconf-moc.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
188-
189-
$(obj)/qconf.o: $(obj)/qconf-cfg
187+
HOSTLDLIBS_qconf = $(call read-file, $(obj)/qconf-libs)
188+
HOSTCXXFLAGS_qconf.o = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags)
189+
HOSTCXXFLAGS_qconf-moc.o = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags)
190+
$(obj)/qconf: | $(obj)/qconf-libs
191+
$(obj)/qconf.o $(obj)/qconf-moc.o: | $(obj)/qconf-cflags
190192

191193
quiet_cmd_moc = MOC $@
192-
cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) $< -o $@
194+
cmd_moc = $(call read-file, $(obj)/qconf-bin)/moc $< -o $@
193195

194-
$(obj)/qconf-moc.cc: $(src)/qconf.h $(obj)/qconf-cfg FORCE
196+
$(obj)/qconf-moc.cc: $(src)/qconf.h FORCE | $(obj)/qconf-bin
195197
$(call if_changed,moc)
196198

197199
targets += qconf-moc.cc
@@ -200,15 +202,16 @@ targets += qconf-moc.cc
200202
hostprogs += gconf
201203
gconf-objs := gconf.o images.o $(common-objs)
202204

203-
HOSTLDLIBS_gconf = $(shell . $(obj)/gconf-cfg && echo $$libs)
204-
HOSTCFLAGS_gconf.o = $(shell . $(obj)/gconf-cfg && echo $$cflags)
205+
HOSTLDLIBS_gconf = $(call read-file, $(obj)/gconf-libs)
206+
HOSTCFLAGS_gconf.o = $(call read-file, $(obj)/gconf-cflags)
205207

206-
$(obj)/gconf.o: $(obj)/gconf-cfg
208+
$(obj)/gconf: | $(obj)/gconf-libs
209+
$(obj)/gconf.o: | $(obj)/gconf-cflags
207210

208211
# check if necessary packages are available, and configure build flags
209-
filechk_conf_cfg = $(CONFIG_SHELL) $<
212+
cmd_conf_cfg = $< $(addprefix $(obj)/$*conf-, cflags libs bin)
210213

211-
$(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
212-
$(call filechk,conf_cfg)
214+
$(obj)/%conf-cflags $(obj)/%conf-libs $(obj)/%conf-bin: $(src)/%conf-cfg.sh
215+
$(call cmd,conf_cfg)
213216

214-
clean-files += *conf-cfg
217+
clean-files += *conf-cflags *conf-libs *conf-bin

scripts/kconfig/gconf-cfg.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0
33

4+
cflags=$1
5+
libs=$2
6+
47
PKG="gtk+-2.0 gmodule-2.0 libglade-2.0"
58

69
if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then
@@ -26,5 +29,5 @@ if ! ${HOSTPKG_CONFIG} --atleast-version=2.0.0 gtk+-2.0; then
2629
exit 1
2730
fi
2831

29-
echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\"
30-
echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\"
32+
${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags}
33+
${HOSTPKG_CONFIG} --libs ${PKG} > ${libs}

scripts/kconfig/mconf-cfg.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0
33

4+
cflags=$1
5+
libs=$2
6+
47
PKG="ncursesw"
58
PKG2="ncurses"
69

710
if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then
811
if ${HOSTPKG_CONFIG} --exists $PKG; then
9-
echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\"
10-
echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\"
12+
${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags}
13+
${HOSTPKG_CONFIG} --libs ${PKG} > ${libs}
1114
exit 0
1215
fi
1316

14-
if ${HOSTPKG_CONFIG} --exists $PKG2; then
15-
echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\"
16-
echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\"
17+
if ${HOSTPKG_CONFIG} --exists ${PKG2}; then
18+
${HOSTPKG_CONFIG} --cflags ${PKG2} > ${cflags}
19+
${HOSTPKG_CONFIG} --libs ${PKG2} > ${libs}
1720
exit 0
1821
fi
1922
fi
@@ -22,22 +25,22 @@ fi
2225
# (Even if it is installed, some distributions such as openSUSE cannot
2326
# find ncurses by pkg-config.)
2427
if [ -f /usr/include/ncursesw/ncurses.h ]; then
25-
echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\"
26-
echo libs=\"-lncursesw\"
28+
echo -D_GNU_SOURCE -I/usr/include/ncursesw > ${cflags}
29+
echo -lncursesw > ${libs}
2730
exit 0
2831
fi
2932

3033
if [ -f /usr/include/ncurses/ncurses.h ]; then
31-
echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\"
32-
echo libs=\"-lncurses\"
34+
echo -D_GNU_SOURCE -I/usr/include/ncurses > ${cflags}
35+
echo -lncurses > ${libs}
3336
exit 0
3437
fi
3538

3639
# As a final fallback before giving up, check if $HOSTCC knows of a default
3740
# ncurses installation (e.g. from a vendor-specific sysroot).
3841
if echo '#include <ncurses.h>' | ${HOSTCC} -E - >/dev/null 2>&1; then
39-
echo cflags=\"-D_GNU_SOURCE\"
40-
echo libs=\"-lncurses\"
42+
echo -D_GNU_SOURCE > ${cflags}
43+
echo -lncurses > ${libs}
4144
exit 0
4245
fi
4346

scripts/kconfig/nconf-cfg.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0
33

4+
cflags=$1
5+
libs=$2
6+
47
PKG="ncursesw menuw panelw"
58
PKG2="ncurses menu panel"
69

710
if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then
811
if ${HOSTPKG_CONFIG} --exists $PKG; then
9-
echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG)\"
10-
echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\"
12+
${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags}
13+
${HOSTPKG_CONFIG} --libs ${PKG} > ${libs}
1114
exit 0
1215
fi
1316

1417
if ${HOSTPKG_CONFIG} --exists $PKG2; then
15-
echo cflags=\"$(${HOSTPKG_CONFIG} --cflags $PKG2)\"
16-
echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG2)\"
18+
${HOSTPKG_CONFIG} --cflags ${PKG2} > ${cflags}
19+
${HOSTPKG_CONFIG} --libs ${PKG2} > ${libs}
1720
exit 0
1821
fi
1922
fi
@@ -22,20 +25,20 @@ fi
2225
# (Even if it is installed, some distributions such as openSUSE cannot
2326
# find ncurses by pkg-config.)
2427
if [ -f /usr/include/ncursesw/ncurses.h ]; then
25-
echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncursesw\"
26-
echo libs=\"-lncursesw -lmenuw -lpanelw\"
28+
echo -D_GNU_SOURCE -I/usr/include/ncursesw > ${cflags}
29+
echo -lncursesw -lmenuw -lpanelw > ${libs}
2730
exit 0
2831
fi
2932

3033
if [ -f /usr/include/ncurses/ncurses.h ]; then
31-
echo cflags=\"-D_GNU_SOURCE -I/usr/include/ncurses\"
32-
echo libs=\"-lncurses -lmenu -lpanel\"
34+
echo -D_GNU_SOURCE -I/usr/include/ncurses > ${cflags}
35+
echo -lncurses -lmenu -lpanel > ${libs}
3336
exit 0
3437
fi
3538

3639
if [ -f /usr/include/ncurses.h ]; then
37-
echo cflags=\"-D_GNU_SOURCE\"
38-
echo libs=\"-lncurses -lmenu -lpanel\"
40+
echo -D_GNU_SOURCE > ${cflags}
41+
echo -lncurses -lmenu -lpanel > ${libs}
3942
exit 0
4043
fi
4144

scripts/kconfig/qconf-cfg.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0
33

4+
cflags=$1
5+
libs=$2
6+
bin=$3
7+
48
PKG="Qt5Core Qt5Gui Qt5Widgets"
59

610
if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then
@@ -11,9 +15,9 @@ if [ -z "$(command -v ${HOSTPKG_CONFIG})" ]; then
1115
fi
1216

1317
if ${HOSTPKG_CONFIG} --exists $PKG; then
14-
echo cflags=\"-std=c++11 -fPIC $(${HOSTPKG_CONFIG} --cflags $PKG)\"
15-
echo libs=\"$(${HOSTPKG_CONFIG} --libs $PKG)\"
16-
echo moc=\"$(${HOSTPKG_CONFIG} --variable=host_bins Qt5Core)/moc\"
18+
${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags}
19+
${HOSTPKG_CONFIG} --libs ${PKG} > ${libs}
20+
${HOSTPKG_CONFIG} --variable=host_bins Qt5Core > ${bin}
1721
exit 0
1822
fi
1923

scripts/remove-stale-files

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ rm -f arch/riscv/purgatory/kexec-purgatory.c
4747
rm -f scripts/extract-cert
4848

4949
rm -f arch/x86/purgatory/kexec-purgatory.c
50+
51+
rm -f scripts/kconfig/[gmnq]conf-cfg

0 commit comments

Comments
 (0)