Stefan Reinauer | cc5b344 | 2013-01-15 17:02:58 -0800 | [diff] [blame] | 1 | ## |
| 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 Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | cc5b344 | 2013-01-15 17:02:58 -0800 | [diff] [blame] | 18 | ## |
| 19 | |
| 20 | src := $(shell pwd) |
| 21 | srctree := $(src) |
| 22 | obj ?= $(src)/build |
| 23 | |
| 24 | export V := $(V) |
| 25 | |
| 26 | CONFIG_SHELL := sh |
| 27 | UNAME_RELEASE := $(shell uname -r) |
| 28 | HAVE_DOTCONFIG := $(wildcard .config) |
| 29 | MAKEFLAGS += -rR --no-print-directory |
| 30 | |
| 31 | # Make is silent per default, but 'make V=1' will show all compiler calls. |
| 32 | ifneq ($(V),1) |
| 33 | Q := @ |
| 34 | endif |
| 35 | |
| 36 | LIBCONFIG_PATH := ../libpayload |
| 37 | LIBPAYLOAD_DIR := $(obj)/libpayload |
| 38 | LPCC := $(LIBPAYLOAD_DIR)/libpayload/bin/lpgcc |
| 39 | LPAS := $(LIBPAYLOAD_DIR)/libpayload/bin/lpas |
| 40 | HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_DIR)/libpayload/lib/libpayload.a) |
| 41 | OBJCOPY ?= objcopy |
| 42 | |
| 43 | INCLUDES = -Iinclude |
| 44 | CFLAGS := -Wall -Werror -Os $(INCLUDES) |
| 45 | OBJECTS = tianocoreboot.o |
| 46 | OBJS = $(patsubst %,$(obj)/%,$(OBJECTS)) |
| 47 | TARGET = $(obj)/tianocoreboot.elf |
| 48 | |
| 49 | all: $(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 | |
| 62 | ifneq ($(strip $(HAVE_LIBPAYLOAD)),) |
| 63 | libpayload: |
| 64 | $(Q)printf "Found Libpayload $(LIBPAYLOAD_DIR).\n" |
| 65 | else |
| 66 | libpayload: |
| 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 |
| 71 | endif |
| 72 | |
| 73 | prepare: |
| 74 | $(Q)mkdir -p $(obj) |
| 75 | |
| 76 | clean: |
| 77 | $(Q)rm -rf $(obj) $(LIBPAYLOAD_DIR) .xcompile .config .config.old |
| 78 | |
| 79 | .PHONY: $(PHONY) clean |
| 80 | |