blob: 50659d3c0b3c1a7e5dd1de393aeb2fe486974b20 [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
86CFLAGS += -Wall -Werror -Os -fno-builtin $(CFLAGS_$(ARCH-y)) $(INCLUDES)
87
Marc Jones5d01b762012-11-30 17:04:58 -070088ifneq ($(strip $(HAVE_DOTCONFIG)),)
Uwe Hermann2216d1b2008-03-24 15:47:49 +000089include $(src)/.config
Martin Rothcacbcf42015-11-16 22:33:48 -070090real-all: $(TARGET)
Jordan Crouse7249f792008-03-20 00:11:05 +000091
Martin Roth9c3ff1b2016-03-07 16:26:51 -070092$(TARGET): $(src)/.config $(coreinfo_obj)/config.h $(OBJS) libpayload
Martin Roth6116f362016-03-08 12:32:40 -070093 printf " LPCC $(subst $(CURDIR)/,,$(@)) (LINK)\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -070094 $(LPCC) -o $@ $(OBJS)
95 $(OBJCOPY) --only-keep-debug $@ $(TARGET).debug
96 $(OBJCOPY) --strip-debug $@
97 $(OBJCOPY) --add-gnu-debuglink=$(TARGET).debug $@
Uwe Hermann2216d1b2008-03-24 15:47:49 +000098
Martin Roth9c3ff1b2016-03-07 16:26:51 -070099$(coreinfo_obj)/%.S.o: $(src)/%.S libpayload
Martin Roth6116f362016-03-08 12:32:40 -0700100 printf " LPAS $(subst $(CURDIR)/,,$(@))\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -0700101 $(LPAS) -o $@ $<
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000102
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700103$(coreinfo_obj)/%.o: $(src)/%.c libpayload
Martin Roth6116f362016-03-08 12:32:40 -0700104 printf " LPCC $(subst $(CURDIR)/,,$(@))\n"
Stefan Reinauer739a6adb2015-06-30 15:22:12 -0700105 $(LPCC) $(CFLAGS) -c -o $@ $<
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000106
Marc Jones5d01b762012-11-30 17:04:58 -0700107else
Martin Rothcacbcf42015-11-16 22:33:48 -0700108real-all: config
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000109endif
110
Martin Roth50943b12016-01-25 14:01:55 -0700111defaultbuild:
112 $(MAKE) olddefconfig
113 $(MAKE) all
114
Marc Jones9915b372012-11-30 17:15:36 -0700115ifneq ($(strip $(HAVE_LIBPAYLOAD)),)
116libpayload:
Stefan Reinauer62af53f2016-03-15 13:29:35 -0700117 printf "Found Libpayload $(LIBPAYLOAD_OBJ).\n"
Marc Jones9915b372012-11-30 17:15:36 -0700118else
Iru Cai12b641d2016-04-16 00:54:23 +0800119LPOPTS=obj="$(CURDIR)/lpbuild" DOTCONFIG="$(CURDIR)/lp.config"
Marc Jones9915b372012-11-30 17:15:36 -0700120libpayload:
Stefan Reinauer62af53f2016-03-15 13:29:35 -0700121 printf "Building libpayload @ $(LIBPAYLOAD_PATH).\n"
Iru Cai12b641d2016-04-16 00:54:23 +0800122 $(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 Jones9915b372012-11-30 17:15:36 -0700125endif
Marc Jones5d01b762012-11-30 17:04:58 -0700126
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700127$(coreinfo_obj)/config.h:
Stefan Reinauerccc55fd2015-06-29 16:44:12 -0700128 $(MAKE) oldconfig
129
Martin Roth9c3ff1b2016-03-07 16:26:51 -0700130$(shell mkdir -p $(coreinfo_obj) $(objk)/lxdialog $(KCONFIG_SPLITCONFIG))
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000131
Patrick Georgi0ffef882017-01-19 23:20:14 +0100132include $(srck)/Makefile
133
134.PHONY: $(PHONY) prepare
135
136else
137
Jordan Crouse7249f792008-03-20 00:11:05 +0000138clean:
Martin Roth143a78c92016-03-08 12:29:33 -0700139 rm -rf build/*.elf build/*.o .xcompile
Jordan Crouse7249f792008-03-20 00:11:05 +0000140
Uwe Hermann2216d1b2008-03-24 15:47:49 +0000141distclean: clean
Iru Cai12b641d2016-04-16 00:54:23 +0800142 rm -rf build lpbuild
Martin Roth69836662016-04-23 17:33:18 -0600143 rm -f .config* lp.config*
Jordan Crouse7249f792008-03-20 00:11:05 +0000144
Patrick Georgi0ffef882017-01-19 23:20:14 +0100145.PHONY: clean distclean
146endif