build: scripts/config - update to kconfig-v5.14
[openwrt/staging/jow.git] / scripts / config / Makefile
1 # SPDX-License-Identifier: GPL-2.0-only
2 # ===========================================================================
3 # OpenWrt configuration targets
4
5 .PHONY: clean all
6 all: conf mconf
7 clean:
8 rm -f *.o lxdialog/*.o *.moc .*.cmd $(clean-files)
9
10 # This clean-files definition is here to ensure that temporary files from the
11 # previous version are removed by make config-clean.
12 # It should be emptied after the end of support for OpenWrt 19.07.
13 clean-files := zconf.tab.c zconf.lex.c zconf.hash.c .tmp_qtcheck
14
15 # ===========================================================================
16 # Variables needed by the upstream Makefile
17
18 # Avoids displaying 'UPD mconf-cfg' in an otherwise quiet make menuconfig
19 kecho:=true
20
21 CONFIG_SHELL:=$(SHELL)
22 srctree:=.
23 src:=.
24 obj:=.
25 Q:=$(if $V,,@)
26 cmd = $(cmd_$(1))
27
28 # some definitions taken from ../Kbuild.include
29 dot-target = $(dir $@).$(notdir $@)
30 squote := '
31 escsq = $(subst $(squote),'\$(squote)',$1)
32 define filechk
33 $(Q)set -e; \
34 mkdir -p $(dir $@); \
35 trap "rm -f $(dot-target).tmp" EXIT; \
36 { $(filechk_$(1)); } > $(dot-target).tmp; \
37 if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \
38 $(kecho) ' UPD $@'; \
39 mv -f $(dot-target).tmp $@; \
40 fi
41 endef
42 cmd-check = $(if $(strip $(cmd_$@)),,1)
43 make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
44 newer-prereqs = $(filter-out $(PHONY),$?)
45 if_changed = $(if $(newer-prereqs)$(cmd-check), \
46 $(cmd); \
47 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
48
49 ### Stripped down upstream Makefile follows:
50 # ===========================================================================
51 # object files used by all kconfig flavours
52 common-objs := confdata.o expr.o lexer.lex.o menu.o parser.tab.o \
53 preprocess.o symbol.o util.o
54
55 $(obj)/lexer.lex.o: $(obj)/parser.tab.h
56 HOSTCFLAGS_lexer.lex.o := -I $(srctree)/$(src)
57 HOSTCFLAGS_parser.tab.o := -I $(srctree)/$(src)
58
59 # conf: Used for defconfig, oldconfig and related targets
60 hostprogs += conf
61 conf-objs := conf.o $(common-objs)
62
63 # nconf: Used for the nconfig target based on ncurses
64 hostprogs += nconf
65 nconf-objs := nconf.o nconf.gui.o $(common-objs)
66
67 HOSTLDLIBS_nconf = $(shell . $(obj)/nconf-cfg && echo $$libs)
68 HOSTCFLAGS_nconf.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
69 HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
70
71 $(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
72
73 # mconf: Used for the menuconfig target based on lxdialog
74 hostprogs += mconf
75 lxdialog := $(addprefix lxdialog/, \
76 checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
77 mconf-objs := mconf.o $(lxdialog) $(common-objs)
78
79 HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
80 $(foreach f, mconf.o $(lxdialog), \
81 $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
82
83 $(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
84
85 # qconf: Used for the xconfig target based on Qt
86 hostprogs += qconf
87 qconf-cxxobjs := qconf.o qconf-moc.o
88 qconf-objs := images.o $(common-objs)
89
90 HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs)
91 HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
92 HOSTCXXFLAGS_qconf-moc.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
93
94 $(obj)/qconf.o: $(obj)/qconf-cfg
95
96 quiet_cmd_moc = MOC $@
97 cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) $< -o $@
98
99 $(obj)/qconf-moc.cc: $(src)/qconf.h $(obj)/qconf-cfg FORCE
100 $(call if_changed,moc)
101
102 targets += qconf-moc.cc
103
104 # check if necessary packages are available, and configure build flags
105 filechk_conf_cfg = $(CONFIG_SHELL) $<
106
107 $(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
108 $(call filechk,conf_cfg)
109
110 clean-files += *conf-cfg
111
112 # ===========================================================================
113 # OpenWrt rules and final adjustments that need to be made after reading the
114 # full upstream Makefile
115
116 clean-files += $(targets) $(hostprogs)
117
118 FORCE:
119
120 ifdef BUILD_SHIPPED_FILES
121 shipped-files := lexer.lex.c parser.tab.c parser.tab.h
122 clean-files += $(shipped-files)
123
124 .SECONDARY: $(shipped-files)
125
126 %.tab.c %.tab.h: %.y
127 bison -l -d -b $* $<
128
129 %.lex.c: %.l
130 flex -L -o$@ $<
131 endif
132
133 $(foreach f,$(conf-objs) $(filter-out $(common-objs),$(mconf-objs) \
134 $(qconf-objs) \
135 $(nconf-objs)), \
136 $(eval $(obj)/$f: CFLAGS+=$$(HOSTCFLAGS_$f)))
137
138 $(foreach f,$(qconf-cxxobjs), \
139 $(eval $(obj)/$f: CXXFLAGS+=$$(HOSTCXXFLAGS_$f)))
140
141 $(obj)/conf: $(addprefix $(obj)/,$(conf-objs))
142
143 # The *conf-cfg file is used (then filtered out) as the first prerequisite to
144 # avoid sourcing it before the script is built, when trying to compute CFLAGS
145 # for the actual first prerequisite. This avoids errors like:
146 # '/bin/sh: ./mconf-cfg: No such file or directory'
147 $(obj)/mconf: mconf-cfg $(addprefix $(obj)/,$(mconf-objs))
148 $(CC) -o $@ $(filter-out mconf-cfg,$^) $(HOSTLDLIBS_mconf)
149
150 $(obj)/nconf: nconf-cfg $(addprefix $(obj)/,$(nconf-objs))
151 $(CC) -o $@ $(filter-out nconf-cfg,$^) $(HOSTLDLIBS_nconf)
152
153 $(obj)/qconf: qconf-cfg $(addprefix $(obj)/,$(qconf-cxxobjs) $(qconf-objs))
154 $(CXX) -o $@ $(filter-out qconf-cfg,$^) $(HOSTLDLIBS_qconf)