blob: 83fad884b71c2a9f6be5f72531daed311d2a34a3 [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
Patrick Georgi53ea1d42019-11-22 16:55:58 +010050savedefconfig: $(objk)/conf
51 cp $(DOTCONFIG) $(DEFCONFIG)
Richard Markocec3a7b2023-10-16 15:26:33 +020052 chmod +w $(DEFCONFIG)
Patrick Georgi53ea1d42019-11-22 16:55:58 +010053 $< --savedefconfig=$(DEFCONFIG) $(KBUILD_KCONFIG)
54
55FORCE:
56
57filechk=$< > $@
58
59$(objk)/%.o: $(srck)/%.c
60 $(HOSTCC) -I $(srck) -I $(objk) -c $(HOSTCFLAGS_$(notdir $@)) -o $@ $<
61
62$(objk)/%.o: $(srck)/%.cc
63 $(HOSTCXX) -I $(srck) -I $(objk) -c $(HOSTCXXFLAGS_$(notdir $@)) -o $@ $<
64
65$(objk)/%.o: $(objk)/%.c
66 $(HOSTCC) -I $(srck) -I $(objk) -c -o $@ $<
67
68$(objk)/%.moc: $(srck)/%.h | $(objk)/qconf-cfg
69 $(call cmd_moc)
70
71define hostprogs_template
72# $1 entry in hostprogs
73$(objk)/$(1): $$(foreach _o,$$($(1)-objs) $$($(1)-cxxobjs),$(objk)/$$(_o)) | $(wildcard $(objk)/$(1)-cfg)
74 $$(HOSTCXX) -o $$@ $$^ $$(HOSTLDLIBS_$(1))
75endef
76
77$(foreach prog,$(hostprogs),$(eval $(call hostprogs_template,$(prog))))
78
Patrick Georgi615cdfc2021-09-06 16:59:56 +020079# This might be a bit of a chicken & egg problem, using a kconfig flag when
80# building kconfig, but if you're messing with the parser you probably know
81# what you're doing: make CONFIG_UTIL_GENPARSER=y
82ifeq ($(CONFIG_UTIL_GENPARSER),y)
Patrick Georgi116b1442021-09-09 00:44:06 +020083$(objk)/%.tab.c $(objk)/%.tab.h: $(srck)/%.y
84 bison -t -l --defines -b $(objk)/$* $<
Patrick Georgi53ea1d42019-11-22 16:55:58 +010085
86$(objk)/%.lex.c: $(srck)/%.l
87 flex -L -o$@ $<
Patrick Georgi3e8ef102019-11-22 16:54:17 +010088
Patrick Georgi615cdfc2021-09-06 16:59:56 +020089else # !CONFIG_UTIL_GENPARSER
90
91$(objk)/parser.tab.c: | $(objk)/parser.tab.h
92
93$(objk)/%: $(srck)/%_shipped
94 cp $< $@
95
96endif
97
Patrick Georgi3e8ef102019-11-22 16:54:17 +010098# Support mingw by shipping our own regex implementation
99_OS=$(shell uname -s |cut -c-7)
100regex-objs=
101ifeq ($(_OS),MINGW32)
102 regex-objs=regex.o
103endif
104$(objk)/regex.o: $(srck)/regex.c
105 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -DHAVE_STRING_H -c -o $@ $<
106
107conf-objs += $(regex-objs)
108mconf-objs += $(regex-objs)
109
110# Provide tool to convert kconfig output into Ada format
111$(objk)/toada: $(objk)/toada.o
112 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -o $@ $^
113$(objk)/toada.o: $(srck)/toada.c
114 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<