blob: 7652bde84d45ba5d04820d0fc4e03592eb40e48f [file] [log] [blame]
Gaurav Shah322536d2010-01-28 15:01:23 -08001# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2# 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 Glassb265c342011-11-16 15:09:51 -08008#
9# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
10# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -070011#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +080012# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
13# temporarily. As we are still investigating which flags are necessary for
14# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070015#
Simon Glassb265c342011-11-16 15:09:51 -080016# As a first step, this makes the setting of CC and CFLAGS here optional, to
17# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -070018#
Simon Glassb265c342011-11-16 15:09:51 -080019# Flag ordering: arch, then -f, then -m, then -W
20DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
21COMMON_FLAGS := -nostdinc -pipe \
22 -ffreestanding -fno-builtin -fno-stack-protector \
23 -Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS)
24
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070025ifeq ($(FIRMWARE_ARCH), arm)
Simon Glassb265c342011-11-16 15:09:51 -080026CC ?= armv7a-cros-linux-gnueabi-gcc
27CFLAGS ?= -march=armv5 \
28 -fno-common -ffixed-r8 \
29 -msoft-float -marm -mabi=aapcs-linux -mno-thumb-interwork \
30 $(COMMON_FLAGS)
Che-Liang Chiou74359b72011-06-21 15:25:51 -070031endif
Che-Liang Chiou7604a7d2011-06-21 17:40:34 -070032ifeq ($(FIRMWARE_ARCH), i386)
Simon Glassb265c342011-11-16 15:09:51 -080033CC ?= i686-pc-linux-gnu-gcc
34# Drop -march=i386 to permit use of SSE instructions
35CFLAGS ?= \
36 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
37 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
38 -mpreferred-stack-boundary=2 -mregparm=3 \
39 $(COMMON_FLAGS)
Che-Liang Chiou34be8272011-01-27 16:44:36 +080040endif
41
Simon Glassb265c342011-11-16 15:09:51 -080042CC ?= gcc
43CXX ?= g++
44
Randall Spangler287beae2011-04-11 12:46:40 -070045# Fix compiling directly on host (outside of emake)
46ifeq ($(ARCH),)
47export ARCH=amd64
48endif
49
Che-Liang Chiou34be8272011-01-27 16:44:36 +080050ifeq ($(FIRMWARE_ARCH),)
51CFLAGS += -DCHROMEOS_ENVIRONMENT
52endif
53
54ifneq (${DEBUG},)
55CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -070056endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080057
vbendebb2b0fcc2010-07-15 15:09:47 -070058ifeq (${DISABLE_NDEBUG},)
59CFLAGS += -DNDEBUG
60endif
61
Simon Glassb265c342011-11-16 15:09:51 -080062export CC CXX CFLAGS
63
Gaurav Shah7ca31f32010-02-16 19:04:11 -080064export TOP = $(shell pwd)
Randall Spangler620c38c2010-06-17 14:45:22 -070065export FWDIR=$(TOP)/firmware
Randall Spanglerd1836442010-06-10 09:59:04 -070066export HOSTDIR=$(TOP)/host
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080067ifeq ($(FIRMWARE_ARCH),)
Randall Spanglerd0dae7a2010-06-21 18:25:31 -070068export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080069else
70export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/arch/$(FIRMWARE_ARCH)/include
71endif
Gaurav Shah322536d2010-01-28 15:01:23 -080072
vbendeb70e95092010-06-14 15:41:27 -070073export BUILD = ${TOP}/build
74export FWLIB = ${BUILD}/vboot_fw.a
Che-Liang Chiou89678602010-11-09 08:33:36 +080075export HOSTLIB = ${BUILD}/vboot_host.a
Bill Richardson0b8f35c2010-05-26 09:18:38 -070076
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080077ifeq ($(FIRMWARE_ARCH),)
Randall Spangler39f66112010-07-14 09:10:23 -070078SUBDIRS = firmware host utility cgpt tests tests/tpm_lite
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080079else
80SUBDIRS = firmware
81endif
Gaurav Shah322536d2010-01-28 15:01:23 -080082
83all:
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +080084 set -e; \
vbendeb70e95092010-06-14 15:41:27 -070085 for d in $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; |\
86 sort -u); do \
87 newdir=${BUILD}/$$d; \
88 if [ ! -d $$newdir ]; then \
89 mkdir -p $$newdir; \
90 fi; \
Luigi Semenzato5896b962010-08-25 07:16:03 -070091 done; \
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080092 [ -z "$(FIRMWARE_ARCH)" ] && make -C utility update_tlcl_structures; \
Gaurav Shah322536d2010-01-28 15:01:23 -080093 for i in $(SUBDIRS); do \
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +080094 make -C $$i; \
Gaurav Shah322536d2010-01-28 15:01:23 -080095 done
96
97clean:
vbendeb70e95092010-06-14 15:41:27 -070098 /bin/rm -rf ${BUILD}
Bill Richardson371df8b2010-05-27 14:19:47 -070099
100install:
101 $(MAKE) -C utility install
Bill Richardsonf1372d92010-06-11 09:15:55 -0700102 $(MAKE) -C cgpt install
Gaurav Shahe6421982010-06-03 07:49:32 -0700103
104runtests:
105 $(MAKE) -C tests runtests
Luigi Semenzato18b814d2010-07-08 17:17:02 -0700106
107rbtest:
108 $(MAKE) -C tests rbtest
Bill Richardson856e0722011-02-07 15:39:45 -0800109
110runbmptests:
111 $(MAKE) -C tests runbmptests