blob: 19b91d5234877a6b24842ad9c4407db5040aec2d [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
Simon Glass8e85e982011-11-22 13:54:50 -080041ifeq ($(FIRMWARE_ARCH), x86_64)
42CFLAGS ?= $(COMMON_FLAGS) \
43 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
44endif
Che-Liang Chiou34be8272011-01-27 16:44:36 +080045
Simon Glassb265c342011-11-16 15:09:51 -080046CC ?= gcc
47CXX ?= g++
48
Randall Spangler287beae2011-04-11 12:46:40 -070049# Fix compiling directly on host (outside of emake)
50ifeq ($(ARCH),)
51export ARCH=amd64
52endif
53
Che-Liang Chiou34be8272011-01-27 16:44:36 +080054ifeq ($(FIRMWARE_ARCH),)
55CFLAGS += -DCHROMEOS_ENVIRONMENT
56endif
57
58ifneq (${DEBUG},)
59CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -070060endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080061
vbendebb2b0fcc2010-07-15 15:09:47 -070062ifeq (${DISABLE_NDEBUG},)
63CFLAGS += -DNDEBUG
64endif
65
Simon Glassb265c342011-11-16 15:09:51 -080066export CC CXX CFLAGS
67
Gaurav Shah7ca31f32010-02-16 19:04:11 -080068export TOP = $(shell pwd)
Randall Spangler620c38c2010-06-17 14:45:22 -070069export FWDIR=$(TOP)/firmware
Randall Spanglerd1836442010-06-10 09:59:04 -070070export HOSTDIR=$(TOP)/host
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080071ifeq ($(FIRMWARE_ARCH),)
Randall Spanglerd0dae7a2010-06-21 18:25:31 -070072export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/stub/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080073else
74export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/arch/$(FIRMWARE_ARCH)/include
75endif
Gaurav Shah322536d2010-01-28 15:01:23 -080076
vbendeb70e95092010-06-14 15:41:27 -070077export BUILD = ${TOP}/build
78export FWLIB = ${BUILD}/vboot_fw.a
Che-Liang Chiou89678602010-11-09 08:33:36 +080079export HOSTLIB = ${BUILD}/vboot_host.a
Bill Richardson0b8f35c2010-05-26 09:18:38 -070080
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080081ifeq ($(FIRMWARE_ARCH),)
Randall Spangler39f66112010-07-14 09:10:23 -070082SUBDIRS = firmware host utility cgpt tests tests/tpm_lite
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080083else
84SUBDIRS = firmware
85endif
Gaurav Shah322536d2010-01-28 15:01:23 -080086
87all:
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +080088 set -e; \
vbendeb70e95092010-06-14 15:41:27 -070089 for d in $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; |\
90 sort -u); do \
91 newdir=${BUILD}/$$d; \
92 if [ ! -d $$newdir ]; then \
93 mkdir -p $$newdir; \
94 fi; \
Luigi Semenzato5896b962010-08-25 07:16:03 -070095 done; \
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +080096 [ -z "$(FIRMWARE_ARCH)" ] && make -C utility update_tlcl_structures; \
Gaurav Shah322536d2010-01-28 15:01:23 -080097 for i in $(SUBDIRS); do \
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +080098 make -C $$i; \
Gaurav Shah322536d2010-01-28 15:01:23 -080099 done
100
101clean:
vbendeb70e95092010-06-14 15:41:27 -0700102 /bin/rm -rf ${BUILD}
Bill Richardson371df8b2010-05-27 14:19:47 -0700103
104install:
105 $(MAKE) -C utility install
Bill Richardsonf1372d92010-06-11 09:15:55 -0700106 $(MAKE) -C cgpt install
Gaurav Shahe6421982010-06-03 07:49:32 -0700107
108runtests:
109 $(MAKE) -C tests runtests
Luigi Semenzato18b814d2010-07-08 17:17:02 -0700110
111rbtest:
112 $(MAKE) -C tests rbtest
Bill Richardson856e0722011-02-07 15:39:45 -0800113
114runbmptests:
115 $(MAKE) -C tests runbmptests