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