blob: 3ac541f9b31cb2c54b5102ef1adcd62f5078c784 [file] [log] [blame]
Stefan Reinauercc5b3442013-01-15 17:02:58 -08001##
2## This file is part of the TianoCoreBoot project.
3##
4## Copyright (C) 2013 Google Inc.
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; version 2 of the License.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauercc5b3442013-01-15 17:02:58 -080018##
19
20src := $(shell pwd)
21srctree := $(src)
22obj ?= $(src)/build
23
24export V := $(V)
25
26CONFIG_SHELL := sh
27UNAME_RELEASE := $(shell uname -r)
28HAVE_DOTCONFIG := $(wildcard .config)
29MAKEFLAGS += -rR --no-print-directory
30
31# Make is silent per default, but 'make V=1' will show all compiler calls.
32ifneq ($(V),1)
33Q := @
34endif
35
36LIBCONFIG_PATH := ../libpayload
37LIBPAYLOAD_DIR := $(obj)/libpayload
38LPCC := $(LIBPAYLOAD_DIR)/libpayload/bin/lpgcc
39LPAS := $(LIBPAYLOAD_DIR)/libpayload/bin/lpas
40HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_DIR)/libpayload/lib/libpayload.a)
41OBJCOPY ?= objcopy
42
43INCLUDES = -Iinclude
44CFLAGS := -Wall -Werror -Os $(INCLUDES)
45OBJECTS = tianocoreboot.o
46OBJS = $(patsubst %,$(obj)/%,$(OBJECTS))
47TARGET = $(obj)/tianocoreboot.elf
48
49all: $(TARGET)
50
51$(TARGET): prepare $(OBJS) libpayload
52 $(Q)printf " LINK $(subst $(shell pwd)/,,$(@))\n"
53 $(Q)CC="$(CC)" $(LPCC) -o $@ $(OBJS)
54 $(Q)$(OBJCOPY) --only-keep-debug $@ $(TARGET).debug
55 $(Q)$(OBJCOPY) --strip-debug $@
56 $(Q)$(OBJCOPY) --add-gnu-debuglink=$(TARGET).debug $@
57
58$(obj)/%.o: $(src)/%.c libpayload
59 $(Q)printf " CC $(subst $(shell pwd)/,,$(@))\n"
60 $(Q)CC="$(CC)" $(LPCC) $(CFLAGS) -c -o $@ $<
61
62ifneq ($(strip $(HAVE_LIBPAYLOAD)),)
63libpayload:
64 $(Q)printf "Found Libpayload $(LIBPAYLOAD_DIR).\n"
65else
66libpayload:
67 $(Q)printf "Building libpayload @ $(LIBCONFIG_PATH).\n"
68 $(Q)cp libpayload.config .config
69 $(Q)make -C $(LIBCONFIG_PATH) distclean
70 $(Q)make -C $(LIBCONFIG_PATH) DESTDIR=$(LIBPAYLOAD_DIR) install DOTCONFIG=$(shell pwd)/.config
71endif
72
73prepare:
74 $(Q)mkdir -p $(obj)
75
76clean:
77 $(Q)rm -rf $(obj) $(LIBPAYLOAD_DIR) .xcompile .config .config.old
78
79.PHONY: $(PHONY) clean
80