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