blob: 5f75ba3c62718bceaa6c1c7097cc576233e5159e [file] [log] [blame]
Patrick Georgi3e8ef102019-11-22 16:54:17 +01001# SPDX-License-Identifier: GPL-2.0-or-later
2
Patrick Georgi53ea1d42019-11-22 16:55:58 +01003# Early coreboot specific configuration
4KBUILD_KCONFIG ?= src/Kconfig
Patrick Georgi3e8ef102019-11-22 16:54:17 +01005
Patrick Georgi53ea1d42019-11-22 16:55:58 +01006export LC_ALL=C
7export LANG=C
Patrick Georgi3e8ef102019-11-22 16:54:17 +01008
Patrick Georgi4b8b2a02021-07-30 09:07:50 -04009DEFCONFIG ?= defconfig
10
Patrick Georgi53ea1d42019-11-22 16:55:58 +010011# Include original Makefile, with just enough edits to work for us
12$(objk)/Makefile.real: $(dir $(lastword $(MAKEFILE_LIST)))Makefile
13 mkdir -p $(objk)
14 sed \
15 -e "s,\$$(obj),\$$(objk),g" \
16 -e "s,\$$(src),\$$(srck),g" \
17 -e "s,^help:,help_kconfig help::," \
18 -e "s,^%.config:,__disable__&," \
19 -e "s,^savedefconfig:,__disable__&," \
20 -e "s,\$$(srctree)/arch/\$$(SRCARCH)/configs/\$$(KBUILD_DEFCONFIG),\$$(KBUILD_DEFCONFIG)," \
21 -e "s,--defconfig=arch/\$$(SRCARCH)/configs/\$$(KBUILD_DEFCONFIG),--defconfig=\$$(KBUILD_DEFCONFIG)," \
22 -e "/^unexport CONFIG_$$/d" \
23 $< > $@.tmp
24 mv $@.tmp $@
25
26kecho := echo
27
28-include $(objk)/Makefile.real
Patrick Georgi870cbb92021-07-16 09:34:25 +020029unexport KCONFIG_DEFCONFIG_LIST
Patrick Georgi53ea1d42019-11-22 16:55:58 +010030
31# Fill in Linux kconfig build rules to work
32
33oldconfig: KCONFIG_STRICT=
34
35savedefconfig: $(objk)/conf
36 cp $(DOTCONFIG) $(DEFCONFIG)
Richard Markocec3a7b2023-10-16 15:26:33 +020037 chmod +w $(DEFCONFIG)
Patrick Georgi53ea1d42019-11-22 16:55:58 +010038 $< --savedefconfig=$(DEFCONFIG) $(KBUILD_KCONFIG)
39
40FORCE:
41
42filechk=$< > $@
43
44$(objk)/%.o: $(srck)/%.c
45 $(HOSTCC) -I $(srck) -I $(objk) -c $(HOSTCFLAGS_$(notdir $@)) -o $@ $<
46
47$(objk)/%.o: $(srck)/%.cc
48 $(HOSTCXX) -I $(srck) -I $(objk) -c $(HOSTCXXFLAGS_$(notdir $@)) -o $@ $<
49
50$(objk)/%.o: $(objk)/%.c
51 $(HOSTCC) -I $(srck) -I $(objk) -c -o $@ $<
52
53$(objk)/%.moc: $(srck)/%.h | $(objk)/qconf-cfg
54 $(call cmd_moc)
55
56define hostprogs_template
57# $1 entry in hostprogs
58$(objk)/$(1): $$(foreach _o,$$($(1)-objs) $$($(1)-cxxobjs),$(objk)/$$(_o)) | $(wildcard $(objk)/$(1)-cfg)
59 $$(HOSTCXX) -o $$@ $$^ $$(HOSTLDLIBS_$(1))
60endef
61
62$(foreach prog,$(hostprogs),$(eval $(call hostprogs_template,$(prog))))
63
Patrick Georgi615cdfc2021-09-06 16:59:56 +020064# This might be a bit of a chicken & egg problem, using a kconfig flag when
65# building kconfig, but if you're messing with the parser you probably know
66# what you're doing: make CONFIG_UTIL_GENPARSER=y
67ifeq ($(CONFIG_UTIL_GENPARSER),y)
Patrick Georgi116b1442021-09-09 00:44:06 +020068$(objk)/%.tab.c $(objk)/%.tab.h: $(srck)/%.y
69 bison -t -l --defines -b $(objk)/$* $<
Patrick Georgi53ea1d42019-11-22 16:55:58 +010070
71$(objk)/%.lex.c: $(srck)/%.l
72 flex -L -o$@ $<
Patrick Georgi3e8ef102019-11-22 16:54:17 +010073
Patrick Georgi615cdfc2021-09-06 16:59:56 +020074else # !CONFIG_UTIL_GENPARSER
75
76$(objk)/parser.tab.c: | $(objk)/parser.tab.h
77
78$(objk)/%: $(srck)/%_shipped
79 cp $< $@
80
81endif
82
Patrick Georgi3e8ef102019-11-22 16:54:17 +010083# Support mingw by shipping our own regex implementation
84_OS=$(shell uname -s |cut -c-7)
85regex-objs=
86ifeq ($(_OS),MINGW32)
87 regex-objs=regex.o
88endif
89$(objk)/regex.o: $(srck)/regex.c
90 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -DHAVE_STRING_H -c -o $@ $<
91
92conf-objs += $(regex-objs)
93mconf-objs += $(regex-objs)
94
95# Provide tool to convert kconfig output into Ada format
96$(objk)/toada: $(objk)/toada.o
97 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -o $@ $^
98$(objk)/toada.o: $(srck)/toada.c
99 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<