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