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 | |
| 86 | CFLAGS += -Wall -Werror -Os -fno-builtin $(CFLAGS_$(ARCH-y)) $(INCLUDES) |
| 87 | |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 88 | ifneq ($(strip $(HAVE_DOTCONFIG)),) |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 89 | include $(src)/.config |
Martin Roth | cacbcf4 | 2015-11-16 22:33:48 -0700 | [diff] [blame] | 90 | real-all: $(TARGET) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 91 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 92 | $(TARGET): $(src)/.config $(coreinfo_obj)/config.h $(OBJS) libpayload |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 93 | printf " LPCC $(subst $(CURDIR)/,,$(@)) (LINK)\n" |
Stefan Reinauer | 739a6adb | 2015-06-30 15:22:12 -0700 | [diff] [blame] | 94 | $(LPCC) -o $@ $(OBJS) |
| 95 | $(OBJCOPY) --only-keep-debug $@ $(TARGET).debug |
| 96 | $(OBJCOPY) --strip-debug $@ |
| 97 | $(OBJCOPY) --add-gnu-debuglink=$(TARGET).debug $@ |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 98 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 99 | $(coreinfo_obj)/%.S.o: $(src)/%.S libpayload |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 100 | printf " LPAS $(subst $(CURDIR)/,,$(@))\n" |
Stefan Reinauer | 739a6adb | 2015-06-30 15:22:12 -0700 | [diff] [blame] | 101 | $(LPAS) -o $@ $< |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 102 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 103 | $(coreinfo_obj)/%.o: $(src)/%.c libpayload |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 104 | printf " LPCC $(subst $(CURDIR)/,,$(@))\n" |
Stefan Reinauer | 739a6adb | 2015-06-30 15:22:12 -0700 | [diff] [blame] | 105 | $(LPCC) $(CFLAGS) -c -o $@ $< |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 106 | |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 107 | else |
Martin Roth | cacbcf4 | 2015-11-16 22:33:48 -0700 | [diff] [blame] | 108 | real-all: config |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 109 | endif |
| 110 | |
Martin Roth | 50943b1 | 2016-01-25 14:01:55 -0700 | [diff] [blame] | 111 | defaultbuild: |
| 112 | $(MAKE) olddefconfig |
| 113 | $(MAKE) all |
| 114 | |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 115 | ifneq ($(strip $(HAVE_LIBPAYLOAD)),) |
| 116 | libpayload: |
Stefan Reinauer | 62af53f | 2016-03-15 13:29:35 -0700 | [diff] [blame] | 117 | printf "Found Libpayload $(LIBPAYLOAD_OBJ).\n" |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 118 | else |
Iru Cai | 12b641d | 2016-04-16 00:54:23 +0800 | [diff] [blame] | 119 | LPOPTS=obj="$(CURDIR)/lpbuild" DOTCONFIG="$(CURDIR)/lp.config" |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 120 | libpayload: |
Stefan Reinauer | 62af53f | 2016-03-15 13:29:35 -0700 | [diff] [blame] | 121 | printf "Building libpayload @ $(LIBPAYLOAD_PATH).\n" |
Iru Cai | 12b641d | 2016-04-16 00:54:23 +0800 | [diff] [blame] | 122 | $(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) distclean coreinfo_obj=$(coreinfo_obj)/libptmp |
| 123 | $(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) defconfig KBUILD_DEFCONFIG=$(LIBPAYLOAD_CONFIG) |
| 124 | $(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) install DESTDIR=$(coreinfo_obj) |
Marc Jones | 9915b37 | 2012-11-30 17:15:36 -0700 | [diff] [blame] | 125 | endif |
Marc Jones | 5d01b76 | 2012-11-30 17:04:58 -0700 | [diff] [blame] | 126 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 127 | $(coreinfo_obj)/config.h: |
Stefan Reinauer | ccc55fd | 2015-06-29 16:44:12 -0700 | [diff] [blame] | 128 | $(MAKE) oldconfig |
| 129 | |
Martin Roth | 9c3ff1b | 2016-03-07 16:26:51 -0700 | [diff] [blame] | 130 | $(shell mkdir -p $(coreinfo_obj) $(objk)/lxdialog $(KCONFIG_SPLITCONFIG)) |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 131 | |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 132 | include $(srck)/Makefile |
| 133 | |
| 134 | .PHONY: $(PHONY) prepare |
| 135 | |
| 136 | else |
| 137 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 138 | clean: |
Martin Roth | 143a78c9 | 2016-03-08 12:29:33 -0700 | [diff] [blame] | 139 | rm -rf build/*.elf build/*.o .xcompile |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 140 | |
Uwe Hermann | 2216d1b | 2008-03-24 15:47:49 +0000 | [diff] [blame] | 141 | distclean: clean |
Iru Cai | 12b641d | 2016-04-16 00:54:23 +0800 | [diff] [blame] | 142 | rm -rf build lpbuild |
Martin Roth | 6983666 | 2016-04-23 17:33:18 -0600 | [diff] [blame] | 143 | rm -f .config* lp.config* |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 144 | |
Patrick Georgi | 0ffef88 | 2017-01-19 23:20:14 +0100 | [diff] [blame] | 145 | .PHONY: clean distclean |
| 146 | endif |