blob: 3a9f3530c0649736e162d51d0b6c30a2da89cd82 [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
Patrick Georgi41419d9c2023-11-26 19:17:39 +010028cmd = $(cmd_$(1))
29cmd_conf_cfg = $< $(addprefix $(obj)/$*conf-, cflags libs bin); touch $(obj)/$*conf-bin
30
Patrick Georgi7eab8ef2023-11-20 18:03:34 +010031###
32# Read a file, replacing newlines with spaces
33#
34# Make 4.2 or later can read a file by using its builtin function.
35#
36# Imported from Linux upstream:
37# commit 6768fa4bcb6c1618248f135d04b9287ba2724ae0
38# Author: Masahiro Yamada <masahiroy@kernel.org>
39ifneq ($(filter-out 3.% 4.0 4.1, $(MAKE_VERSION)),)
40read-file = $(subst $(newline),$(space),$(file < $1))
41else
42read-file = $(shell cat $1 2>/dev/null)
43endif
44
Patrick Georgi53ea1d42019-11-22 16:55:58 +010045-include $(objk)/Makefile.real
Patrick Georgi870cbb92021-07-16 09:34:25 +020046unexport KCONFIG_DEFCONFIG_LIST
Patrick Georgi53ea1d42019-11-22 16:55:58 +010047
48# Fill in Linux kconfig build rules to work
49
50oldconfig: KCONFIG_STRICT=
51
52savedefconfig: $(objk)/conf
53 cp $(DOTCONFIG) $(DEFCONFIG)
Richard Markocec3a7b2023-10-16 15:26:33 +020054 chmod +w $(DEFCONFIG)
Patrick Georgi53ea1d42019-11-22 16:55:58 +010055 $< --savedefconfig=$(DEFCONFIG) $(KBUILD_KCONFIG)
56
57FORCE:
58
59filechk=$< > $@
60
61$(objk)/%.o: $(srck)/%.c
62 $(HOSTCC) -I $(srck) -I $(objk) -c $(HOSTCFLAGS_$(notdir $@)) -o $@ $<
63
64$(objk)/%.o: $(srck)/%.cc
65 $(HOSTCXX) -I $(srck) -I $(objk) -c $(HOSTCXXFLAGS_$(notdir $@)) -o $@ $<
66
67$(objk)/%.o: $(objk)/%.c
68 $(HOSTCC) -I $(srck) -I $(objk) -c -o $@ $<
69
70$(objk)/%.moc: $(srck)/%.h | $(objk)/qconf-cfg
71 $(call cmd_moc)
72
73define hostprogs_template
74# $1 entry in hostprogs
75$(objk)/$(1): $$(foreach _o,$$($(1)-objs) $$($(1)-cxxobjs),$(objk)/$$(_o)) | $(wildcard $(objk)/$(1)-cfg)
76 $$(HOSTCXX) -o $$@ $$^ $$(HOSTLDLIBS_$(1))
77endef
78
79$(foreach prog,$(hostprogs),$(eval $(call hostprogs_template,$(prog))))
80
Patrick Georgi615cdfc2021-09-06 16:59:56 +020081# This might be a bit of a chicken & egg problem, using a kconfig flag when
82# building kconfig, but if you're messing with the parser you probably know
83# what you're doing: make CONFIG_UTIL_GENPARSER=y
84ifeq ($(CONFIG_UTIL_GENPARSER),y)
Patrick Georgi116b1442021-09-09 00:44:06 +020085$(objk)/%.tab.c $(objk)/%.tab.h: $(srck)/%.y
86 bison -t -l --defines -b $(objk)/$* $<
Patrick Georgi53ea1d42019-11-22 16:55:58 +010087
88$(objk)/%.lex.c: $(srck)/%.l
89 flex -L -o$@ $<
Patrick Georgi3e8ef102019-11-22 16:54:17 +010090
Patrick Georgi615cdfc2021-09-06 16:59:56 +020091else # !CONFIG_UTIL_GENPARSER
92
93$(objk)/parser.tab.c: | $(objk)/parser.tab.h
94
95$(objk)/%: $(srck)/%_shipped
96 cp $< $@
97
98endif
99
Patrick Georgi3e8ef102019-11-22 16:54:17 +0100100# Support mingw by shipping our own regex implementation
101_OS=$(shell uname -s |cut -c-7)
102regex-objs=
103ifeq ($(_OS),MINGW32)
104 regex-objs=regex.o
105endif
106$(objk)/regex.o: $(srck)/regex.c
107 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -DHAVE_STRING_H -c -o $@ $<
108
109conf-objs += $(regex-objs)
110mconf-objs += $(regex-objs)
111
112# Provide tool to convert kconfig output into Ada format
113$(objk)/toada: $(objk)/toada.o
114 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -o $@ $^
115$(objk)/toada.o: $(srck)/toada.c
116 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<