blob: 34c45d98559c063f376bd3a6dd476c4e87c9d2cf [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
Patrick Georgi0ffef882017-01-19 23:20:14 +010023ifeq ($(filter %clean,$(MAKECMDGOALS)),)
Uwe Hermann2216d1b2008-03-24 15:47:49 +000024export KERNELVERSION := 0.1.0
Martin Roth9c3ff1b2016-03-07 16:26:51 -070025export KCONFIG_AUTOHEADER := $(coreinfo_obj)/config.h
26export KCONFIG_AUTOCONFIG := $(coreinfo_obj)/auto.conf
27export KCONFIG_DEPENDENCIES := $(coreinfo_obj)/auto.conf.cmd
28export KCONFIG_SPLITCONFIG := $(coreinfo_obj)/config
29export KCONFIG_TRISTATE := $(coreinfo_obj)/tristate.conf
Martin Roth47ca65a2016-08-01 19:25:33 -060030export KCONFIG_CONFIG := $(CURDIR)/.config
Stefan Reinauer0ab2b252015-06-29 16:10:16 -070031export KCONFIG_NEGATIVES := 1
32export Kconfig := Kconfig
33
Marc Jones5d01b762012-11-30 17:04:58 -070034export V := $(V)
Uwe Hermann2216d1b2008-03-24 15:47:49 +000035
36CONFIG_SHELL := sh
37KBUILD_DEFCONFIG := configs/defconfig
38UNAME_RELEASE := $(shell uname -r)
39HAVE_DOTCONFIG := $(wildcard .config)
40MAKEFLAGS += -rR --no-print-directory
41
42# Make is silent per default, but 'make V=1' will show all compiler calls.
43ifneq ($(V),1)
Stefan Reinauer739a6adb2015-06-30 15:22:12 -070044.SILENT:
Uwe Hermann2216d1b2008-03-24 15:47:49 +000045endif
46
Marc Jones5d01b762012-11-30 17:04:58 -070047HOSTCC ?= gcc
48HOSTCXX ?= g++
Uwe Hermann2216d1b2008-03-24 15:47:49 +000049HOSTCFLAGS := -I$(srck) -I$(objk)
50HOSTCXXFLAGS := -I$(srck) -I$(objk)
51
Martin Roth69836662016-04-23 17:33:18 -060052LIBPAYLOAD_PATH := $(realpath ../libpayload)
Stefan Reinauer62af53f2016-03-15 13:29:35 -070053LIBPAYLOAD_OBJ := $(coreinfo_obj)/libpayload
54HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_OBJ)/lib/libpayload.a)
Stefan Reinauer80547362016-03-12 11:47:00 -080055LIBPAYLOAD_CONFIG ?= configs/defconfig-tinycurses
Marc Jones5d01b762012-11-30 17:04:58 -070056OBJCOPY ?= objcopy
Jordan Crouse1cb92bc2008-04-10 00:05:41 +000057
Antonello Dettori4b1668f2016-07-08 11:14:40 +020058INCLUDES = -I$(coreinfo_obj) -include $(LIBPAYLOAD_OBJ)/include/kconfig.h -I$(src)/../../src/commonlib/include
Uwe Hermannab5b3e02008-03-31 20:30:18 +000059OBJECTS = cpuinfo_module.o cpuid.S.o pci_module.o coreboot_module.o \
Jonathan Neuschäferd4318642016-03-11 17:30:14 +010060 nvram_module.o bootlog_module.o ramdump_module.o \
Antonello Dettori4b1668f2016-07-08 11:14:40 +020061 multiboot_module.o cbfs_module.o timestamps_module.o coreinfo.o
Martin Roth9c3ff1b2016-03-07 16:26:51 -070062OBJS = $(patsubst %,$(coreinfo_obj)/%,$(OBJECTS))
63TARGET = $(coreinfo_obj)/coreinfo.elf
Uwe Hermann2216d1b2008-03-24 15:47:49 +000064
Martin Rothcacbcf42015-11-16 22:33:48 -070065all: 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
74CONFIG_COMPILER_GCC := y
75ARCH-y := x86_32
76
77include .xcompile
78
79CC := $(CC_$(ARCH-y))
80AS := $(AS_$(ARCH-y))
81OBJCOPY := $(OBJCOPY_$(ARCH-y))
82
Stefan Reinauer62af53f2016-03-15 13:29:35 -070083LPCC := CC="$(CC)" $(LIBPAYLOAD_OBJ)/bin/lpgcc
84LPAS := AS="$(AS)" $(LIBPAYLOAD_OBJ)/bin/lpas
Martin Rothcacbcf42015-11-16 22:33:48 -070085
Jacob Garber9cd53c52019-06-27 13:23:38 -060086CFLAGS += -Wall -Wextra -Wmissing-prototypes -Wvla -Werror
Jacob Garbere2e8cce2019-06-29 11:04:42 -060087CFLAGS += -Os -fno-builtin $(CFLAGS_$(ARCH-y)) $(INCLUDES)
Martin Rothcacbcf42015-11-16 22:33:48 -070088
Marc Jones5d01b762012-11-30 17:04:58 -070089ifneq ($(strip $(HAVE_DOTCONFIG)),)
Uwe Hermann2216d1b2008-03-24 15:47:49 +000090include $(src)/.config
Martin Rothcacbcf42015-11-16 22:33:48 -070091real-all: $(TARGET)
Jordan Crouse7249f792008-03-20 00:11:05 +000092
Martin Roth9c3ff1b2016-03-07 16:26:51 -070093$(TARGET): $(src)/.config $(coreinfo_obj)/config.h $(OBJS) libpayload
Martin Roth6116f362016-03-08 12:32:40 -070094 printf " LPCC $(subst $(CURDIR)/,,$(@)) (LINK)\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -070095 $(LPCC) -o $@ $(OBJS)
96 $(OBJCOPY) --only-keep-debug $@ $(TARGET).debug
97 $(OBJCOPY) --strip-debug $@
98 $(OBJCOPY) --add-gnu-debuglink=$(TARGET).debug $@
Uwe Hermann2216d1b2008-03-24 15:47:49 +000099
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700100$(coreinfo_obj)/%.S.o: $(src)/%.S libpayload
Martin Roth6116f362016-03-08 12:32:40 -0700101 printf " LPAS $(subst $(CURDIR)/,,$(@))\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -0700102 $(LPAS) -o $@ $<
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000103
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700104$(coreinfo_obj)/%.o: $(src)/%.c libpayload
Martin Roth6116f362016-03-08 12:32:40 -0700105 printf " LPCC $(subst $(CURDIR)/,,$(@))\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -0700106 $(LPCC) $(CFLAGS) -c -o $@ $<
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000107
Marc Jones5d01b762012-11-30 17:04:58 -0700108else
Martin Rothcacbcf42015-11-16 22:33:48 -0700109real-all: config
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000110endif
111
Martin Roth50943b12016-01-25 14:01:55 -0700112defaultbuild:
113 $(MAKE) olddefconfig
114 $(MAKE) all
115
Marc Jones9915b372012-11-30 17:15:36 -0700116ifneq ($(strip $(HAVE_LIBPAYLOAD)),)
117libpayload:
Stefan Reinauer62af53f2016-03-15 13:29:35 -0700118 printf "Found Libpayload $(LIBPAYLOAD_OBJ).\n"
Marc Jones9915b372012-11-30 17:15:36 -0700119else
Iru Cai12b641d2016-04-16 00:54:23 +0800120LPOPTS=obj="$(CURDIR)/lpbuild" DOTCONFIG="$(CURDIR)/lp.config"
Marc Jones9915b372012-11-30 17:15:36 -0700121libpayload:
Stefan Reinauer62af53f2016-03-15 13:29:35 -0700122 printf "Building libpayload @ $(LIBPAYLOAD_PATH).\n"
Iru Cai12b641d2016-04-16 00:54:23 +0800123 $(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 Jones9915b372012-11-30 17:15:36 -0700126endif
Marc Jones5d01b762012-11-30 17:04:58 -0700127
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700128$(coreinfo_obj)/config.h:
Stefan Reinauerccc55fd2015-06-29 16:44:12 -0700129 $(MAKE) oldconfig
130
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700131$(shell mkdir -p $(coreinfo_obj) $(objk)/lxdialog $(KCONFIG_SPLITCONFIG))
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000132
Patrick Georgi0ffef882017-01-19 23:20:14 +0100133include $(srck)/Makefile
134
135.PHONY: $(PHONY) prepare
136
137else
138
Jordan Crouse7249f792008-03-20 00:11:05 +0000139clean:
Martin Roth143a78c92016-03-08 12:29:33 -0700140 rm -rf build/*.elf build/*.o .xcompile
Jordan Crouse7249f792008-03-20 00:11:05 +0000141
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000142distclean: clean
Iru Cai12b641d2016-04-16 00:54:23 +0800143 rm -rf build lpbuild
Martin Roth69836662016-04-23 17:33:18 -0600144 rm -f .config* lp.config*
Jordan Crouse7249f792008-03-20 00:11:05 +0000145
Patrick Georgi0ffef882017-01-19 23:20:14 +0100146.PHONY: clean distclean
147endif