blob: 486c96cf1d1d7b8f3afd47af765eda0478b4521f [file] [log] [blame]
Jordan Crouse7249f792008-03-20 00:11:05 +00001##
2## This file is part of the coreinfo project.
3##
4## Copyright (C) 2008 Advanced Micro Devices, Inc.
Uwe Hermann2216d1b2008-03-24 15:47:49 +00005## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
Jordan Crouse7249f792008-03-20 00:11:05 +00006##
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 Crouse7249f792008-03-20 00:11:05 +000016
Martin Roth6116f362016-03-08 12:32:40 -070017src := $(CURDIR)
Marc Jones5d01b762012-11-30 17:04:58 -070018srctree := $(src)
Stefan Reinauer0ab2b252015-06-29 16:10:16 -070019srck := $(src)/../../util/kconfig
Martin Roth9c3ff1b2016-03-07 16:26:51 -070020coreinfo_obj := $(src)/build
Marc Jones5d01b762012-11-30 17:04:58 -070021objk := $(src)/build/util/kconfig
Uwe Hermann2216d1b2008-03-24 15:47:49 +000022
23export KERNELVERSION := 0.1.0
Martin Roth9c3ff1b2016-03-07 16:26:51 -070024export KCONFIG_AUTOHEADER := $(coreinfo_obj)/config.h
25export KCONFIG_AUTOCONFIG := $(coreinfo_obj)/auto.conf
26export KCONFIG_DEPENDENCIES := $(coreinfo_obj)/auto.conf.cmd
27export KCONFIG_SPLITCONFIG := $(coreinfo_obj)/config
28export KCONFIG_TRISTATE := $(coreinfo_obj)/tristate.conf
Martin Roth47ca65a2016-08-01 19:25:33 -060029export KCONFIG_CONFIG := $(CURDIR)/.config
Stefan Reinauer0ab2b252015-06-29 16:10:16 -070030export KCONFIG_NEGATIVES := 1
31export Kconfig := Kconfig
32
Marc Jones5d01b762012-11-30 17:04:58 -070033export V := $(V)
Uwe Hermann2216d1b2008-03-24 15:47:49 +000034
35CONFIG_SHELL := sh
36KBUILD_DEFCONFIG := configs/defconfig
37UNAME_RELEASE := $(shell uname -r)
38HAVE_DOTCONFIG := $(wildcard .config)
39MAKEFLAGS += -rR --no-print-directory
40
41# Make is silent per default, but 'make V=1' will show all compiler calls.
42ifneq ($(V),1)
Stefan Reinauer739a6adb2015-06-30 15:22:12 -070043.SILENT:
Uwe Hermann2216d1b2008-03-24 15:47:49 +000044endif
45
Marc Jones5d01b762012-11-30 17:04:58 -070046HOSTCC ?= gcc
47HOSTCXX ?= g++
Uwe Hermann2216d1b2008-03-24 15:47:49 +000048HOSTCFLAGS := -I$(srck) -I$(objk)
49HOSTCXXFLAGS := -I$(srck) -I$(objk)
50
Martin Roth69836662016-04-23 17:33:18 -060051LIBPAYLOAD_PATH := $(realpath ../libpayload)
Stefan Reinauer62af53f2016-03-15 13:29:35 -070052LIBPAYLOAD_OBJ := $(coreinfo_obj)/libpayload
53HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_OBJ)/lib/libpayload.a)
Stefan Reinauer80547362016-03-12 11:47:00 -080054LIBPAYLOAD_CONFIG ?= configs/defconfig-tinycurses
Marc Jones5d01b762012-11-30 17:04:58 -070055OBJCOPY ?= objcopy
Jordan Crouse1cb92bc2008-04-10 00:05:41 +000056
Antonello Dettori4b1668f2016-07-08 11:14:40 +020057INCLUDES = -I$(coreinfo_obj) -include $(LIBPAYLOAD_OBJ)/include/kconfig.h -I$(src)/../../src/commonlib/include
Uwe Hermannab5b3e02008-03-31 20:30:18 +000058OBJECTS = cpuinfo_module.o cpuid.S.o pci_module.o coreboot_module.o \
Jonathan Neuschäferd4318642016-03-11 17:30:14 +010059 nvram_module.o bootlog_module.o ramdump_module.o \
Antonello Dettori4b1668f2016-07-08 11:14:40 +020060 multiboot_module.o cbfs_module.o timestamps_module.o coreinfo.o
Martin Roth9c3ff1b2016-03-07 16:26:51 -070061OBJS = $(patsubst %,$(coreinfo_obj)/%,$(OBJECTS))
62TARGET = $(coreinfo_obj)/coreinfo.elf
Uwe Hermann2216d1b2008-03-24 15:47:49 +000063
Martin Rothcacbcf42015-11-16 22:33:48 -070064all: 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
73CONFIG_COMPILER_GCC := y
74ARCH-y := x86_32
75
76include .xcompile
77
78CC := $(CC_$(ARCH-y))
79AS := $(AS_$(ARCH-y))
80OBJCOPY := $(OBJCOPY_$(ARCH-y))
81
Stefan Reinauer62af53f2016-03-15 13:29:35 -070082LPCC := CC="$(CC)" $(LIBPAYLOAD_OBJ)/bin/lpgcc
83LPAS := AS="$(AS)" $(LIBPAYLOAD_OBJ)/bin/lpas
Martin Rothcacbcf42015-11-16 22:33:48 -070084
85CFLAGS += -Wall -Werror -Os -fno-builtin $(CFLAGS_$(ARCH-y)) $(INCLUDES)
86
Marc Jones5d01b762012-11-30 17:04:58 -070087ifneq ($(strip $(HAVE_DOTCONFIG)),)
Uwe Hermann2216d1b2008-03-24 15:47:49 +000088include $(src)/.config
Martin Rothcacbcf42015-11-16 22:33:48 -070089real-all: $(TARGET)
Jordan Crouse7249f792008-03-20 00:11:05 +000090
Martin Roth9c3ff1b2016-03-07 16:26:51 -070091$(TARGET): $(src)/.config $(coreinfo_obj)/config.h $(OBJS) libpayload
Martin Roth6116f362016-03-08 12:32:40 -070092 printf " LPCC $(subst $(CURDIR)/,,$(@)) (LINK)\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -070093 $(LPCC) -o $@ $(OBJS)
94 $(OBJCOPY) --only-keep-debug $@ $(TARGET).debug
95 $(OBJCOPY) --strip-debug $@
96 $(OBJCOPY) --add-gnu-debuglink=$(TARGET).debug $@
Uwe Hermann2216d1b2008-03-24 15:47:49 +000097
Martin Roth9c3ff1b2016-03-07 16:26:51 -070098$(coreinfo_obj)/%.S.o: $(src)/%.S libpayload
Martin Roth6116f362016-03-08 12:32:40 -070099 printf " LPAS $(subst $(CURDIR)/,,$(@))\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -0700100 $(LPAS) -o $@ $<
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000101
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700102$(coreinfo_obj)/%.o: $(src)/%.c libpayload
Martin Roth6116f362016-03-08 12:32:40 -0700103 printf " LPCC $(subst $(CURDIR)/,,$(@))\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -0700104 $(LPCC) $(CFLAGS) -c -o $@ $<
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000105
Marc Jones5d01b762012-11-30 17:04:58 -0700106else
Martin Rothcacbcf42015-11-16 22:33:48 -0700107real-all: config
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000108endif
109
Martin Roth50943b12016-01-25 14:01:55 -0700110defaultbuild:
111 $(MAKE) olddefconfig
112 $(MAKE) all
113
Marc Jones9915b372012-11-30 17:15:36 -0700114ifneq ($(strip $(HAVE_LIBPAYLOAD)),)
115libpayload:
Stefan Reinauer62af53f2016-03-15 13:29:35 -0700116 printf "Found Libpayload $(LIBPAYLOAD_OBJ).\n"
Marc Jones9915b372012-11-30 17:15:36 -0700117else
Iru Cai12b641d2016-04-16 00:54:23 +0800118LPOPTS=obj="$(CURDIR)/lpbuild" DOTCONFIG="$(CURDIR)/lp.config"
Marc Jones9915b372012-11-30 17:15:36 -0700119libpayload:
Stefan Reinauer62af53f2016-03-15 13:29:35 -0700120 printf "Building libpayload @ $(LIBPAYLOAD_PATH).\n"
Iru Cai12b641d2016-04-16 00:54:23 +0800121 $(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 Jones9915b372012-11-30 17:15:36 -0700124endif
Marc Jones5d01b762012-11-30 17:04:58 -0700125
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700126$(coreinfo_obj)/config.h:
Stefan Reinauerccc55fd2015-06-29 16:44:12 -0700127 $(MAKE) oldconfig
128
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700129$(shell mkdir -p $(coreinfo_obj) $(objk)/lxdialog $(KCONFIG_SPLITCONFIG))
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000130
Jordan Crouse7249f792008-03-20 00:11:05 +0000131clean:
Martin Roth143a78c92016-03-08 12:29:33 -0700132 rm -rf build/*.elf build/*.o .xcompile
Jordan Crouse7249f792008-03-20 00:11:05 +0000133
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000134distclean: clean
Iru Cai12b641d2016-04-16 00:54:23 +0800135 rm -rf build lpbuild
Martin Roth69836662016-04-23 17:33:18 -0600136 rm -f .config* lp.config*
Jordan Crouse7249f792008-03-20 00:11:05 +0000137
Stefan Reinauer0ab2b252015-06-29 16:10:16 -0700138include $(srck)/Makefile
Jordan Crouse7249f792008-03-20 00:11:05 +0000139
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000140.PHONY: $(PHONY) prepare clean distclean