3082a65ceb96d4fae5d20d7f5b8150dc13691edc
[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 nconf
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 # nconf: Used for the nconfig target based on ncurses
56 hostprogs-y += nconf
57 nconf-objs := nconf.o nconf.gui.o $(common-objs)
58
59 HOSTLDLIBS_nconf = $(shell . $(obj)/nconf-cfg && echo $$libs)
60 HOSTCFLAGS_nconf.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
61 HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
62
63 $(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
64
65 # mconf: Used for the menuconfig target based on lxdialog
66 hostprogs-y += mconf
67 lxdialog := $(addprefix lxdialog/, \
68 checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
69 mconf-objs := mconf.o $(lxdialog) $(common-objs)
70
71 HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
72 $(foreach f, mconf.o $(lxdialog), \
73 $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
74
75 $(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
76
77 # qconf: Used for the xconfig target based on Qt
78 hostprogs-y += qconf
79 qconf-cxxobjs := qconf.o
80 qconf-objs := images.o $(common-objs)
81
82 HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs)
83 HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
84
85 $(obj)/qconf.o: $(obj)/qconf-cfg $(obj)/qconf.moc
86
87 quiet_cmd_moc = MOC $@
88 cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) -i $< -o $@
89
90 $(obj)/%.moc: $(src)/%.h $(obj)/qconf-cfg
91 $(call cmd,moc)
92
93 # check if necessary packages are available, and configure build flags
94 filechk_conf_cfg = $(CONFIG_SHELL) $<
95
96 $(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
97 $(call filechk,conf_cfg)
98
99 clean-files += *conf-cfg
100
101 # ===========================================================================
102 # OpenWrt rules and final adjustments that need to be made after reading the
103 # full upstream Makefile
104
105 FORCE:
106
107 ifdef BUILD_SHIPPED_FILES
108 shipped-files := lexer.lex.c parser.tab.c parser.tab.h
109 clean-files += $(shipped-files)
110
111 .SECONDARY: $(shipped-files)
112
113 %.tab.c %.tab.h: %.y
114 bison -l -d -b $* $<
115
116 %.lex.c: %.l
117 flex -L -o$@ $<
118 endif
119
120 $(foreach f, mconf.o $(lxdialog), \
121 $(eval $f: CFLAGS+=$$(HOSTCFLAGS_$f)))
122
123 $(obj)/lexer.lex.o: CFLAGS += $(HOSTCFLAGS_lexer.lex.o)
124 $(obj)/parser.tab.o: CFLAGS += $(HOSTCFLAGS_parser.tab.o)
125 $(obj)/qconf.o: CXXFLAGS+=$(HOSTCXXFLAGS_qconf.o)
126
127 conf: $(conf-objs)
128
129 # The *conf-cfg file is used (then filtered out) as the first prerequisite to
130 # avoid sourcing it before the script is built, when trying to compute CFLAGS
131 # for the actual first prerequisite. This avoids errors like:
132 # '/bin/sh: ./mconf-cfg: No such file or directory'
133 mconf: mconf-cfg $(mconf-objs)
134 $(CC) -o $@ $(filter-out mconf-cfg,$^) $(HOSTLDLIBS_mconf)
135
136 nconf: nconf-cfg $(nconf-objs)
137 $(CC) -o $@ $(filter-out nconf-cfg,$^) $(HOSTLDLIBS_nconf)
138
139 qconf: qconf-cfg $(qconf-cxxobjs) $(qconf-objs)
140 $(CXX) -o $@ $(filter-out qconf-cfg,$^) $(HOSTLDLIBS_qconf)