Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 1 | # 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 Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 5 | export FIRMWARE_ARCH |
Che-Liang Chiou | 8511f78 | 2011-04-22 16:01:38 +0800 | [diff] [blame] | 6 | export MOCK_TPM |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 7 | |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 8 | # |
| 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 Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 11 | # |
Che-Liang Chiou | 6b0003c | 2011-10-14 11:11:28 +0800 | [diff] [blame] | 12 | # 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 Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 15 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 16 | # 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 Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 18 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 19 | # Flag ordering: arch, then -f, then -m, then -W |
| 20 | DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os) |
| 21 | COMMON_FLAGS := -nostdinc -pipe \ |
| 22 | -ffreestanding -fno-builtin -fno-stack-protector \ |
| 23 | -Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS) |
| 24 | |
Che-Liang Chiou | 7604a7d | 2011-06-21 17:40:34 -0700 | [diff] [blame] | 25 | ifeq ($(FIRMWARE_ARCH), arm) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 26 | CC ?= armv7a-cros-linux-gnueabi-gcc |
| 27 | CFLAGS ?= -march=armv5 \ |
| 28 | -fno-common -ffixed-r8 \ |
| 29 | -msoft-float -marm -mabi=aapcs-linux -mno-thumb-interwork \ |
| 30 | $(COMMON_FLAGS) |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 31 | endif |
Che-Liang Chiou | 7604a7d | 2011-06-21 17:40:34 -0700 | [diff] [blame] | 32 | ifeq ($(FIRMWARE_ARCH), i386) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 33 | CC ?= i686-pc-linux-gnu-gcc |
| 34 | # Drop -march=i386 to permit use of SSE instructions |
| 35 | CFLAGS ?= \ |
| 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 Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 40 | endif |
Simon Glass | 8e85e98 | 2011-11-22 13:54:50 -0800 | [diff] [blame^] | 41 | ifeq ($(FIRMWARE_ARCH), x86_64) |
| 42 | CFLAGS ?= $(COMMON_FLAGS) \ |
| 43 | -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer |
| 44 | endif |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 45 | |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 46 | CC ?= gcc |
| 47 | CXX ?= g++ |
| 48 | |
Randall Spangler | 287beae | 2011-04-11 12:46:40 -0700 | [diff] [blame] | 49 | # Fix compiling directly on host (outside of emake) |
| 50 | ifeq ($(ARCH),) |
| 51 | export ARCH=amd64 |
| 52 | endif |
| 53 | |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 54 | ifeq ($(FIRMWARE_ARCH),) |
| 55 | CFLAGS += -DCHROMEOS_ENVIRONMENT |
| 56 | endif |
| 57 | |
| 58 | ifneq (${DEBUG},) |
| 59 | CFLAGS += -DVBOOT_DEBUG |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 60 | endif |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 61 | |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 62 | ifeq (${DISABLE_NDEBUG},) |
| 63 | CFLAGS += -DNDEBUG |
| 64 | endif |
| 65 | |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 66 | export CC CXX CFLAGS |
| 67 | |
Gaurav Shah | 7ca31f3 | 2010-02-16 19:04:11 -0800 | [diff] [blame] | 68 | export TOP = $(shell pwd) |
Randall Spangler | 620c38c | 2010-06-17 14:45:22 -0700 | [diff] [blame] | 69 | export FWDIR=$(TOP)/firmware |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 70 | export HOSTDIR=$(TOP)/host |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 71 | ifeq ($(FIRMWARE_ARCH),) |
Randall Spangler | d0dae7a | 2010-06-21 18:25:31 -0700 | [diff] [blame] | 72 | export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/stub/include |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 73 | else |
| 74 | export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/arch/$(FIRMWARE_ARCH)/include |
| 75 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 76 | |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 77 | export BUILD = ${TOP}/build |
| 78 | export FWLIB = ${BUILD}/vboot_fw.a |
Che-Liang Chiou | 8967860 | 2010-11-09 08:33:36 +0800 | [diff] [blame] | 79 | export HOSTLIB = ${BUILD}/vboot_host.a |
Bill Richardson | 0b8f35c | 2010-05-26 09:18:38 -0700 | [diff] [blame] | 80 | |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 81 | ifeq ($(FIRMWARE_ARCH),) |
Randall Spangler | 39f6611 | 2010-07-14 09:10:23 -0700 | [diff] [blame] | 82 | SUBDIRS = firmware host utility cgpt tests tests/tpm_lite |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 83 | else |
| 84 | SUBDIRS = firmware |
| 85 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 86 | |
| 87 | all: |
Louis Yung-Chieh Lo | b31ddce | 2010-05-21 16:35:44 +0800 | [diff] [blame] | 88 | set -e; \ |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 89 | 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 Semenzato | 5896b96 | 2010-08-25 07:16:03 -0700 | [diff] [blame] | 95 | done; \ |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 96 | [ -z "$(FIRMWARE_ARCH)" ] && make -C utility update_tlcl_structures; \ |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 97 | for i in $(SUBDIRS); do \ |
Louis Yung-Chieh Lo | b31ddce | 2010-05-21 16:35:44 +0800 | [diff] [blame] | 98 | make -C $$i; \ |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 99 | done |
| 100 | |
| 101 | clean: |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 102 | /bin/rm -rf ${BUILD} |
Bill Richardson | 371df8b | 2010-05-27 14:19:47 -0700 | [diff] [blame] | 103 | |
| 104 | install: |
| 105 | $(MAKE) -C utility install |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 106 | $(MAKE) -C cgpt install |
Gaurav Shah | e642198 | 2010-06-03 07:49:32 -0700 | [diff] [blame] | 107 | |
| 108 | runtests: |
| 109 | $(MAKE) -C tests runtests |
Luigi Semenzato | 18b814d | 2010-07-08 17:17:02 -0700 | [diff] [blame] | 110 | |
| 111 | rbtest: |
| 112 | $(MAKE) -C tests rbtest |
Bill Richardson | 856e072 | 2011-02-07 15:39:45 -0800 | [diff] [blame] | 113 | |
| 114 | runbmptests: |
| 115 | $(MAKE) -C tests runbmptests |