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