blob: dc39b956dc27f87967dab210bf465d1d2f451443 [file] [log] [blame]
Don Garrett0fc95942012-01-24 18:36:03 -08001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +08005export FIRMWARE_ARCH
Che-Liang Chiou8511f782011-04-22 16:01:38 +08006export MOCK_TPM
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +08007
Simon Glass6d696e52011-11-14 13:46:33 -08008# This Makefile normally builds in a 'build' subdir, but use
9#
10# make BUILD=<dir>
11#
12# to put the output somewhere else
13
Simon Glassb265c342011-11-16 15:09:51 -080014#
15# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
16# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -070017#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +080018# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
19# temporarily. As we are still investigating which flags are necessary for
20# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070021#
Simon Glassb265c342011-11-16 15:09:51 -080022# As a first step, this makes the setting of CC and CFLAGS here optional, to
23# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070024#
Simon Glassb265c342011-11-16 15:09:51 -080025# Flag ordering: arch, then -f, then -m, then -W
26DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
27COMMON_FLAGS := -nostdinc -pipe \
28 -ffreestanding -fno-builtin -fno-stack-protector \
29 -Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS)
30
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070031ifeq ($(FIRMWARE_ARCH), arm)
Simon Glassb265c342011-11-16 15:09:51 -080032CC ?= armv7a-cros-linux-gnueabi-gcc
33CFLAGS ?= -march=armv5 \
34 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -070035 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Simon Glassb265c342011-11-16 15:09:51 -080036 $(COMMON_FLAGS)
Che-Liang Chiou74359b72011-06-21 15:25:51 -070037endif
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070038ifeq ($(FIRMWARE_ARCH), i386)
Simon Glassb265c342011-11-16 15:09:51 -080039CC ?= i686-pc-linux-gnu-gcc
40# Drop -march=i386 to permit use of SSE instructions
41CFLAGS ?= \
42 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
43 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
44 -mpreferred-stack-boundary=2 -mregparm=3 \
45 $(COMMON_FLAGS)
Che-Liang Chiou34be8272011-01-27 16:44:36 +080046endif
Simon Glass8e85e982011-11-22 13:54:50 -080047ifeq ($(FIRMWARE_ARCH), x86_64)
48CFLAGS ?= $(COMMON_FLAGS) \
49 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
50endif
Che-Liang Chiou34be8272011-01-27 16:44:36 +080051
Simon Glassb265c342011-11-16 15:09:51 -080052CC ?= gcc
53CXX ?= g++
54
Randall Spangler287beae2011-04-11 12:46:40 -070055# Fix compiling directly on host (outside of emake)
56ifeq ($(ARCH),)
57export ARCH=amd64
58endif
59
Che-Liang Chiou34be8272011-01-27 16:44:36 +080060ifeq ($(FIRMWARE_ARCH),)
Bill Richardsonf4729192012-05-02 23:30:16 -070061CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror
Che-Liang Chiou34be8272011-01-27 16:44:36 +080062endif
63
64ifneq (${DEBUG},)
65CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -070066endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080067
vbendebb2b0fcc2010-07-15 15:09:47 -070068ifeq (${DISABLE_NDEBUG},)
69CFLAGS += -DNDEBUG
70endif
71
Simon Glassb265c342011-11-16 15:09:51 -080072export CC CXX CFLAGS
73
Gaurav Shah7ca31f32010-02-16 19:04:11 -080074export TOP = $(shell pwd)
Randall Spangler620c38c2010-06-17 14:45:22 -070075export FWDIR=$(TOP)/firmware
Randall Spanglerd1836442010-06-10 09:59:04 -070076export HOSTDIR=$(TOP)/host
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080077ifeq ($(FIRMWARE_ARCH),)
Randall Spanglerd0dae7a2010-06-21 18:25:31 -070078export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080079else
80export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/arch/$(FIRMWARE_ARCH)/include
81endif
Gaurav Shah322536d2010-01-28 15:01:23 -080082
Simon Glass6d696e52011-11-14 13:46:33 -080083export BUILD ?= ${TOP}/build
vbendeb70e95092010-06-14 15:41:27 -070084export FWLIB = ${BUILD}/vboot_fw.a
Che-Liang Chiou89678602010-11-09 08:33:36 +080085export HOSTLIB = ${BUILD}/vboot_host.a
Don Garretted5fcc02012-02-14 12:47:57 -080086export DUMPKERNELCONFIGLIB = ${BUILD}/libdump_kernel_config.a
Bill Richardson0b8f35c2010-05-26 09:18:38 -070087
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080088ifeq ($(FIRMWARE_ARCH),)
Randall Spangler39f66112010-07-14 09:10:23 -070089SUBDIRS = firmware host utility cgpt tests tests/tpm_lite
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080090else
91SUBDIRS = firmware
92endif
Gaurav Shah322536d2010-01-28 15:01:23 -080093
94all:
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +080095 set -e; \
vbendeb70e95092010-06-14 15:41:27 -070096 for d in $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; |\
97 sort -u); do \
98 newdir=${BUILD}/$$d; \
99 if [ ! -d $$newdir ]; then \
100 mkdir -p $$newdir; \
101 fi; \
Luigi Semenzato5896b962010-08-25 07:16:03 -0700102 done; \
Simon Glass6d696e52011-11-14 13:46:33 -0800103 [ -z "$(FIRMWARE_ARCH)" ] && $(MAKE) -C utility update_tlcl_structures; \
Gaurav Shah322536d2010-01-28 15:01:23 -0800104 for i in $(SUBDIRS); do \
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +0800105 make -C $$i; \
Gaurav Shah322536d2010-01-28 15:01:23 -0800106 done
107
Jay Srinivasan5fac7572012-02-23 10:59:01 -0800108libcgpt_cc:
Bill Richardsonf4729192012-05-02 23:30:16 -0700109 mkdir -p ${BUILD}/cgpt ${BUILD}/firmware/lib/cgptlib ${BUILD}/firmware/stub
Jay Srinivasan250549d2012-02-16 17:40:45 -0800110 $(MAKE) -C cgpt libcgpt_cc
Jay Srinivasan5fac7572012-02-23 10:59:01 -0800111
112cgptmanager_tests: libcgpt_cc
113 mkdir -p ${BUILD}/tests
114 $(MAKE) -C tests cgptmanager_tests
115
116libdump_kernel_config:
117 mkdir -p ${BUILD}/utility
118 $(MAKE) -C utility $(DUMPKERNELCONFIGLIB)
Jay Srinivasan250549d2012-02-16 17:40:45 -0800119
Gaurav Shah322536d2010-01-28 15:01:23 -0800120clean:
vbendeb70e95092010-06-14 15:41:27 -0700121 /bin/rm -rf ${BUILD}
Bill Richardson371df8b2010-05-27 14:19:47 -0700122
123install:
124 $(MAKE) -C utility install
Bill Richardsonf1372d92010-06-11 09:15:55 -0700125 $(MAKE) -C cgpt install
Gaurav Shahe6421982010-06-03 07:49:32 -0700126
127runtests:
128 $(MAKE) -C tests runtests
Luigi Semenzato18b814d2010-07-08 17:17:02 -0700129
Jay Srinivasan250549d2012-02-16 17:40:45 -0800130runcgptmanagertests:
131 $(MAKE) -C tests runcgptmanagertests
132
Luigi Semenzato18b814d2010-07-08 17:17:02 -0700133rbtest:
134 $(MAKE) -C tests rbtest
Bill Richardson856e0722011-02-07 15:39:45 -0800135
136runbmptests:
137 $(MAKE) -C tests runbmptests