Patrick Georgi | 3e8ef10 | 2019-11-22 16:54:17 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 3 | # Early coreboot specific configuration |
| 4 | KBUILD_KCONFIG ?= src/Kconfig |
Patrick Georgi | 3e8ef10 | 2019-11-22 16:54:17 +0100 | [diff] [blame] | 5 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 6 | export LC_ALL=C |
| 7 | export LANG=C |
Patrick Georgi | 3e8ef10 | 2019-11-22 16:54:17 +0100 | [diff] [blame] | 8 | |
Patrick Georgi | 4b8b2a0 | 2021-07-30 09:07:50 -0400 | [diff] [blame] | 9 | DEFCONFIG ?= defconfig |
| 10 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 11 | # 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 | |
| 26 | kecho := echo |
| 27 | |
Patrick Georgi | 41419d9c | 2023-11-26 19:17:39 +0100 | [diff] [blame] | 28 | cmd = $(cmd_$(1)) |
| 29 | cmd_conf_cfg = $< $(addprefix $(obj)/$*conf-, cflags libs bin); touch $(obj)/$*conf-bin |
| 30 | |
Patrick Georgi | 7eab8ef | 2023-11-20 18:03:34 +0100 | [diff] [blame] | 31 | ### |
| 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> |
| 39 | ifneq ($(filter-out 3.% 4.0 4.1, $(MAKE_VERSION)),) |
| 40 | read-file = $(subst $(newline),$(space),$(file < $1)) |
| 41 | else |
| 42 | read-file = $(shell cat $1 2>/dev/null) |
| 43 | endif |
| 44 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 45 | -include $(objk)/Makefile.real |
Patrick Georgi | 870cbb9 | 2021-07-16 09:34:25 +0200 | [diff] [blame] | 46 | unexport KCONFIG_DEFCONFIG_LIST |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 47 | |
| 48 | # Fill in Linux kconfig build rules to work |
| 49 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 50 | savedefconfig: $(objk)/conf |
| 51 | cp $(DOTCONFIG) $(DEFCONFIG) |
Richard Marko | cec3a7b | 2023-10-16 15:26:33 +0200 | [diff] [blame] | 52 | chmod +w $(DEFCONFIG) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 53 | $< --savedefconfig=$(DEFCONFIG) $(KBUILD_KCONFIG) |
| 54 | |
| 55 | FORCE: |
| 56 | |
| 57 | filechk=$< > $@ |
| 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 | |
| 71 | define 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)) |
| 75 | endef |
| 76 | |
| 77 | $(foreach prog,$(hostprogs),$(eval $(call hostprogs_template,$(prog)))) |
| 78 | |
Patrick Georgi | 615cdfc | 2021-09-06 16:59:56 +0200 | [diff] [blame] | 79 | # 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 |
| 82 | ifeq ($(CONFIG_UTIL_GENPARSER),y) |
Patrick Georgi | 116b144 | 2021-09-09 00:44:06 +0200 | [diff] [blame] | 83 | $(objk)/%.tab.c $(objk)/%.tab.h: $(srck)/%.y |
| 84 | bison -t -l --defines -b $(objk)/$* $< |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 85 | |
| 86 | $(objk)/%.lex.c: $(srck)/%.l |
| 87 | flex -L -o$@ $< |
Patrick Georgi | 3e8ef10 | 2019-11-22 16:54:17 +0100 | [diff] [blame] | 88 | |
Patrick Georgi | 615cdfc | 2021-09-06 16:59:56 +0200 | [diff] [blame] | 89 | else # !CONFIG_UTIL_GENPARSER |
| 90 | |
| 91 | $(objk)/parser.tab.c: | $(objk)/parser.tab.h |
| 92 | |
| 93 | $(objk)/%: $(srck)/%_shipped |
| 94 | cp $< $@ |
| 95 | |
| 96 | endif |
| 97 | |
Patrick Georgi | 3e8ef10 | 2019-11-22 16:54:17 +0100 | [diff] [blame] | 98 | # Support mingw by shipping our own regex implementation |
| 99 | _OS=$(shell uname -s |cut -c-7) |
| 100 | regex-objs= |
| 101 | ifeq ($(_OS),MINGW32) |
| 102 | regex-objs=regex.o |
| 103 | endif |
| 104 | $(objk)/regex.o: $(srck)/regex.c |
| 105 | $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -DHAVE_STRING_H -c -o $@ $< |
| 106 | |
| 107 | conf-objs += $(regex-objs) |
| 108 | mconf-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 $@ $< |