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