Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 1 | ## |
| 2 | ## This file is part of the coreinfo project. |
| 3 | ## |
| 4 | ## Copyright (C) 2008 Advanced Micro Devices, Inc. |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 5 | ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de> |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 6 | ## |
| 7 | ## This program is free software; you can redistribute it and/or modify |
| 8 | ## it under the terms of the GNU General Public License as published by |
| 9 | ## the Free Software Foundation; version 2 of the License. |
| 10 | ## |
| 11 | ## This program is distributed in the hope that it will be useful, |
| 12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | ## GNU General Public License for more details. |
| 15 | ## |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 16 | |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 17 | src := $(CURDIR) |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 18 | srctree := $(src) |
Stefan Reinauer | 0ab2b25 | 2015-06-29 16:10:16 -0700 | [diff] [blame] | 19 | srck := $(src)/../../util/kconfig |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 20 | coreinfo_obj := $(src)/build |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 21 | objk := $(src)/build/util/kconfig |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 22 | |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 23 | ifeq ($(filter %clean,$(MAKECMDGOALS)),) |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 24 | export KERNELVERSION := 0.1.0 |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 25 | export KCONFIG_AUTOHEADER := $(coreinfo_obj)/config.h |
| 26 | export KCONFIG_AUTOCONFIG := $(coreinfo_obj)/auto.conf |
| 27 | export KCONFIG_DEPENDENCIES := $(coreinfo_obj)/auto.conf.cmd |
| 28 | export KCONFIG_SPLITCONFIG := $(coreinfo_obj)/config |
| 29 | export KCONFIG_TRISTATE := $(coreinfo_obj)/tristate.conf |
Martin Roth | 47ca65a | 2016-08-01 19:25:33 -0600 | [diff] [blame] | 30 | export KCONFIG_CONFIG := $(CURDIR)/.config |
Stefan Reinauer | 0ab2b25 | 2015-06-29 16:10:16 -0700 | [diff] [blame] | 31 | export KCONFIG_NEGATIVES := 1 |
| 32 | export Kconfig := Kconfig |
| 33 | |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 34 | export V := $(V) |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 35 | |
| 36 | CONFIG_SHELL := sh |
| 37 | KBUILD_DEFCONFIG := configs/defconfig |
| 38 | UNAME_RELEASE := $(shell uname -r) |
| 39 | HAVE_DOTCONFIG := $(wildcard .config) |
| 40 | MAKEFLAGS += -rR --no-print-directory |
| 41 | |
| 42 | # Make is silent per default, but 'make V=1' will show all compiler calls. |
| 43 | ifneq ($(V),1) |
Stefan Reinauer | 739a6adb | 2015-06-30 15:22:12 -0700 | [diff] [blame] | 44 | .SILENT: |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 45 | endif |
| 46 | |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 47 | HOSTCC ?= gcc |
| 48 | HOSTCXX ?= g++ |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 49 | HOSTCFLAGS := -I$(srck) -I$(objk) |
| 50 | HOSTCXXFLAGS := -I$(srck) -I$(objk) |
| 51 | |
Martin Roth | 6983666 | 2016-04-23 17:33:18 -0600 | [diff] [blame] | 52 | LIBPAYLOAD_PATH := $(realpath ../libpayload) |
Stefan Reinauer | 62af53f | 2016-03-15 13:29:35 -0700 | [diff] [blame] | 53 | LIBPAYLOAD_OBJ := $(coreinfo_obj)/libpayload |
| 54 | HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_OBJ)/lib/libpayload.a) |
Stefan Reinauer | 8054736 | 2016-03-12 11:47:00 -0800 | [diff] [blame] | 55 | LIBPAYLOAD_CONFIG ?= configs/defconfig-tinycurses |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 56 | OBJCOPY ?= objcopy |
Jordan Crouse | 1cb92bc | 2008-04-10 00:05:41 +0000 | [diff] [blame] | 57 | |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 58 | INCLUDES = -I$(coreinfo_obj) -include $(LIBPAYLOAD_OBJ)/include/kconfig.h -I$(src)/../../src/commonlib/include |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 59 | OBJECTS = cpuinfo_module.o cpuid.S.o pci_module.o coreboot_module.o \ |
Jonathan Neuschäfer | d431864 | 2016-03-11 17:30:14 +0100 | [diff] [blame] | 60 | nvram_module.o bootlog_module.o ramdump_module.o \ |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 61 | multiboot_module.o cbfs_module.o timestamps_module.o coreinfo.o |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 62 | OBJS = $(patsubst %,$(coreinfo_obj)/%,$(OBJECTS)) |
| 63 | TARGET = $(coreinfo_obj)/coreinfo.elf |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 64 | |
Martin Roth | cacbcf4 | 2015-11-16 22:33:48 -0700 | [diff] [blame] | 65 | all: real-all |
| 66 | |
| 67 | # in addition to the dependency below, create the file if it doesn't exist |
| 68 | # to silence warnings about a file that would be generated anyway. |
| 69 | $(if $(wildcard .xcompile),,$(eval $(shell ../../util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile))) |
| 70 | .xcompile: ../../util/xcompile/xcompile |
| 71 | $< $(XGCCPATH) > $@.tmp |
| 72 | \mv -f $@.tmp $@ 2> /dev/null || rm -f $@.tmp $@ |
| 73 | |
| 74 | CONFIG_COMPILER_GCC := y |
| 75 | ARCH-y := x86_32 |
| 76 | |
| 77 | include .xcompile |
| 78 | |
| 79 | CC := $(CC_$(ARCH-y)) |
| 80 | AS := $(AS_$(ARCH-y)) |
| 81 | OBJCOPY := $(OBJCOPY_$(ARCH-y)) |
| 82 | |
Stefan Reinauer | 62af53f | 2016-03-15 13:29:35 -0700 | [diff] [blame] | 83 | LPCC := CC="$(CC)" $(LIBPAYLOAD_OBJ)/bin/lpgcc |
| 84 | LPAS := AS="$(AS)" $(LIBPAYLOAD_OBJ)/bin/lpas |
Martin Roth | cacbcf4 | 2015-11-16 22:33:48 -0700 | [diff] [blame] | 85 | |
Jacob Garber | 9cd53c5 | 2019-06-27 13:23:38 -0600 | [diff] [blame] | 86 | CFLAGS += -Wall -Wextra -Wmissing-prototypes -Wvla -Werror |
Jacob Garber | e2e8cce | 2019-06-29 11:04:42 -0600 | [diff] [blame] | 87 | CFLAGS += -Os -fno-builtin $(CFLAGS_$(ARCH-y)) $(INCLUDES) |
Martin Roth | cacbcf4 | 2015-11-16 22:33:48 -0700 | [diff] [blame] | 88 | |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 89 | ifneq ($(strip $(HAVE_DOTCONFIG)),) |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 90 | include $(src)/.config |
Martin Roth | cacbcf4 | 2015-11-16 22:33:48 -0700 | [diff] [blame] | 91 | real-all: $(TARGET) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 92 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 93 | $(TARGET): $(src)/.config $(coreinfo_obj)/config.h $(OBJS) libpayload |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 94 | printf " LPCC $(subst $(CURDIR)/,,$(@)) (LINK)\n" |
Stefan Reinauer | 739a6adb | 2015-06-30 15:22:12 -0700 | [diff] [blame] | 95 | $(LPCC) -o $@ $(OBJS) |
| 96 | $(OBJCOPY) --only-keep-debug $@ $(TARGET).debug |
| 97 | $(OBJCOPY) --strip-debug $@ |
| 98 | $(OBJCOPY) --add-gnu-debuglink=$(TARGET).debug $@ |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 99 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 100 | $(coreinfo_obj)/%.S.o: $(src)/%.S libpayload |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 101 | printf " LPAS $(subst $(CURDIR)/,,$(@))\n" |
Stefan Reinauer | 739a6adb | 2015-06-30 15:22:12 -0700 | [diff] [blame] | 102 | $(LPAS) -o $@ $< |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 103 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 104 | $(coreinfo_obj)/%.o: $(src)/%.c libpayload |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 105 | printf " LPCC $(subst $(CURDIR)/,,$(@))\n" |
Stefan Reinauer | 739a6adb | 2015-06-30 15:22:12 -0700 | [diff] [blame] | 106 | $(LPCC) $(CFLAGS) -c -o $@ $< |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 107 | |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 108 | else |
Martin Roth | cacbcf4 | 2015-11-16 22:33:48 -0700 | [diff] [blame] | 109 | real-all: config |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 110 | endif |
| 111 | |
Martin Roth | 50943b1 | 2016-01-25 14:01:55 -0700 | [diff] [blame] | 112 | defaultbuild: |
| 113 | $(MAKE) olddefconfig |
| 114 | $(MAKE) all |
| 115 | |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 116 | ifneq ($(strip $(HAVE_LIBPAYLOAD)),) |
| 117 | libpayload: |
Stefan Reinauer | 62af53f | 2016-03-15 13:29:35 -0700 | [diff] [blame] | 118 | printf "Found Libpayload $(LIBPAYLOAD_OBJ).\n" |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 119 | else |
Iru Cai | 12b641d | 2016-04-16 00:54:23 +0800 | [diff] [blame] | 120 | LPOPTS=obj="$(CURDIR)/lpbuild" DOTCONFIG="$(CURDIR)/lp.config" |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 121 | libpayload: |
Stefan Reinauer | 62af53f | 2016-03-15 13:29:35 -0700 | [diff] [blame] | 122 | printf "Building libpayload @ $(LIBPAYLOAD_PATH).\n" |
Iru Cai | 12b641d | 2016-04-16 00:54:23 +0800 | [diff] [blame] | 123 | $(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) distclean coreinfo_obj=$(coreinfo_obj)/libptmp |
| 124 | $(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) defconfig KBUILD_DEFCONFIG=$(LIBPAYLOAD_CONFIG) |
| 125 | $(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) install DESTDIR=$(coreinfo_obj) |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 126 | endif |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 127 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 128 | $(coreinfo_obj)/config.h: |
Stefan Reinauer | ccc55fd | 2015-06-29 16:44:12 -0700 | [diff] [blame] | 129 | $(MAKE) oldconfig |
| 130 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 131 | $(shell mkdir -p $(coreinfo_obj) $(objk)/lxdialog $(KCONFIG_SPLITCONFIG)) |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 132 | |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 133 | include $(srck)/Makefile |
| 134 | |
| 135 | .PHONY: $(PHONY) prepare |
| 136 | |
| 137 | else |
| 138 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 139 | clean: |
Martin Roth | 143a78c9 | 2016-03-08 12:29:33 -0700 | [diff] [blame] | 140 | rm -rf build/*.elf build/*.o .xcompile |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 141 | |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 142 | distclean: clean |
Iru Cai | 12b641d | 2016-04-16 00:54:23 +0800 | [diff] [blame] | 143 | rm -rf build lpbuild |
Martin Roth | 6983666 | 2016-04-23 17:33:18 -0600 | [diff] [blame] | 144 | rm -f .config* lp.config* |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 145 | |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 146 | .PHONY: clean distclean |
| 147 | endif |