Randall Spangler | e8cfa31 | 2013-01-02 16:49:38 -0800 | [diff] [blame^] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 5 | ifneq ($(V),1) |
| 6 | Q := @ |
| 7 | endif |
| 8 | |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 9 | export FIRMWARE_ARCH |
Che-Liang Chiou | 8511f78 | 2011-04-22 16:01:38 +0800 | [diff] [blame] | 10 | export MOCK_TPM |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 11 | export Q |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 12 | |
Simon Glass | 6d696e5 | 2011-11-14 13:46:33 -0800 | [diff] [blame] | 13 | # This Makefile normally builds in a 'build' subdir, but use |
| 14 | # |
| 15 | # make BUILD=<dir> |
| 16 | # |
| 17 | # to put the output somewhere else |
| 18 | |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 19 | # |
| 20 | # Provide default CC and CFLAGS for firmware builds; if you have any -D flags, |
| 21 | # please add them after this point (e.g., -DVBOOT_DEBUG). |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 22 | # |
Che-Liang Chiou | 6b0003c | 2011-10-14 11:11:28 +0800 | [diff] [blame] | 23 | # TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just |
| 24 | # temporarily. As we are still investigating which flags are necessary for |
| 25 | # maintaining a compatible ABI, etc. between u-boot and vboot_reference. |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 26 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 27 | # As a first step, this makes the setting of CC and CFLAGS here optional, to |
| 28 | # permit a calling script or Makefile to set these. |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 29 | # |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 30 | # Flag ordering: arch, then -f, then -m, then -W |
| 31 | DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os) |
| 32 | COMMON_FLAGS := -nostdinc -pipe \ |
| 33 | -ffreestanding -fno-builtin -fno-stack-protector \ |
| 34 | -Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS) |
| 35 | |
Che-Liang Chiou | 7604a7d | 2011-06-21 17:40:34 -0700 | [diff] [blame] | 36 | ifeq ($(FIRMWARE_ARCH), arm) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 37 | CC ?= armv7a-cros-linux-gnueabi-gcc |
| 38 | CFLAGS ?= -march=armv5 \ |
| 39 | -fno-common -ffixed-r8 \ |
Doug Anderson | d50b27d | 2012-05-11 12:08:02 -0700 | [diff] [blame] | 40 | -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \ |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 41 | $(COMMON_FLAGS) |
Che-Liang Chiou | 74359b7 | 2011-06-21 15:25:51 -0700 | [diff] [blame] | 42 | endif |
Che-Liang Chiou | 7604a7d | 2011-06-21 17:40:34 -0700 | [diff] [blame] | 43 | ifeq ($(FIRMWARE_ARCH), i386) |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 44 | CC ?= i686-pc-linux-gnu-gcc |
| 45 | # Drop -march=i386 to permit use of SSE instructions |
| 46 | CFLAGS ?= \ |
| 47 | -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \ |
| 48 | -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \ |
| 49 | -mpreferred-stack-boundary=2 -mregparm=3 \ |
| 50 | $(COMMON_FLAGS) |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 51 | endif |
Simon Glass | 8e85e98 | 2011-11-22 13:54:50 -0800 | [diff] [blame] | 52 | ifeq ($(FIRMWARE_ARCH), x86_64) |
| 53 | CFLAGS ?= $(COMMON_FLAGS) \ |
| 54 | -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer |
| 55 | endif |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 56 | |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 57 | CC ?= gcc |
| 58 | CXX ?= g++ |
| 59 | |
Mike Frysinger | 121f3db | 2012-06-07 12:13:57 -0400 | [diff] [blame] | 60 | PKG_CONFIG ?= pkg-config |
| 61 | ifneq ($(filter-out -static,$(LDFLAGS)),$(LDFLAGS)) |
| 62 | PKG_CONFIG += --static |
| 63 | endif |
| 64 | |
Randall Spangler | 287beae | 2011-04-11 12:46:40 -0700 | [diff] [blame] | 65 | # Fix compiling directly on host (outside of emake) |
| 66 | ifeq ($(ARCH),) |
| 67 | export ARCH=amd64 |
| 68 | endif |
| 69 | |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 70 | ifeq ($(FIRMWARE_ARCH),) |
Bill Richardson | f472919 | 2012-05-02 23:30:16 -0700 | [diff] [blame] | 71 | CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror |
Che-Liang Chiou | 34be827 | 2011-01-27 16:44:36 +0800 | [diff] [blame] | 72 | endif |
| 73 | |
| 74 | ifneq (${DEBUG},) |
| 75 | CFLAGS += -DVBOOT_DEBUG |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 76 | endif |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 77 | |
vbendeb | b2b0fcc | 2010-07-15 15:09:47 -0700 | [diff] [blame] | 78 | ifeq (${DISABLE_NDEBUG},) |
| 79 | CFLAGS += -DNDEBUG |
| 80 | endif |
| 81 | |
Mike Frysinger | 121f3db | 2012-06-07 12:13:57 -0400 | [diff] [blame] | 82 | export CC CXX PKG_CONFIG CFLAGS |
Simon Glass | b265c34 | 2011-11-16 15:09:51 -0800 | [diff] [blame] | 83 | |
Gaurav Shah | 7ca31f3 | 2010-02-16 19:04:11 -0800 | [diff] [blame] | 84 | export TOP = $(shell pwd) |
Randall Spangler | 620c38c | 2010-06-17 14:45:22 -0700 | [diff] [blame] | 85 | export FWDIR=$(TOP)/firmware |
Randall Spangler | d183644 | 2010-06-10 09:59:04 -0700 | [diff] [blame] | 86 | export HOSTDIR=$(TOP)/host |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 87 | ifeq ($(FIRMWARE_ARCH),) |
Randall Spangler | d0dae7a | 2010-06-21 18:25:31 -0700 | [diff] [blame] | 88 | export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/stub/include |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 89 | else |
| 90 | export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/arch/$(FIRMWARE_ARCH)/include |
| 91 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 92 | |
Simon Glass | 6d696e5 | 2011-11-14 13:46:33 -0800 | [diff] [blame] | 93 | export BUILD ?= ${TOP}/build |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 94 | export FWLIB = ${BUILD}/vboot_fw.a |
Che-Liang Chiou | 8967860 | 2010-11-09 08:33:36 +0800 | [diff] [blame] | 95 | export HOSTLIB = ${BUILD}/vboot_host.a |
Don Garrett | ed5fcc0 | 2012-02-14 12:47:57 -0800 | [diff] [blame] | 96 | export DUMPKERNELCONFIGLIB = ${BUILD}/libdump_kernel_config.a |
Bill Richardson | 0b8f35c | 2010-05-26 09:18:38 -0700 | [diff] [blame] | 97 | |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 98 | ifeq ($(FIRMWARE_ARCH),) |
Randall Spangler | 39f6611 | 2010-07-14 09:10:23 -0700 | [diff] [blame] | 99 | SUBDIRS = firmware host utility cgpt tests tests/tpm_lite |
Che-Liang Chiou | 0a0e8d0 | 2010-11-30 09:30:45 +0800 | [diff] [blame] | 100 | else |
| 101 | SUBDIRS = firmware |
| 102 | endif |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 103 | |
| 104 | all: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 105 | $(Q)set -e; \ |
vbendeb | 70e9509 | 2010-06-14 15:41:27 -0700 | [diff] [blame] | 106 | for d in $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; |\ |
| 107 | sort -u); do \ |
| 108 | newdir=${BUILD}/$$d; \ |
| 109 | if [ ! -d $$newdir ]; then \ |
| 110 | mkdir -p $$newdir; \ |
| 111 | fi; \ |
Luigi Semenzato | 5896b96 | 2010-08-25 07:16:03 -0700 | [diff] [blame] | 112 | done; \ |
Simon Glass | 6d696e5 | 2011-11-14 13:46:33 -0800 | [diff] [blame] | 113 | [ -z "$(FIRMWARE_ARCH)" ] && $(MAKE) -C utility update_tlcl_structures; \ |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 114 | for i in $(SUBDIRS); do \ |
Mike Frysinger | 121f3db | 2012-06-07 12:13:57 -0400 | [diff] [blame] | 115 | $(MAKE) -C $$i; \ |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 116 | done |
| 117 | |
Jay Srinivasan | 5fac757 | 2012-02-23 10:59:01 -0800 | [diff] [blame] | 118 | libcgpt_cc: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 119 | $(Q)mkdir -p ${BUILD}/cgpt ${BUILD}/firmware/lib/cgptlib ${BUILD}/firmware/stub |
| 120 | $(Q)$(MAKE) -C cgpt libcgpt_cc |
Jay Srinivasan | 5fac757 | 2012-02-23 10:59:01 -0800 | [diff] [blame] | 121 | |
| 122 | cgptmanager_tests: libcgpt_cc |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 123 | $(Q)mkdir -p ${BUILD}/tests |
| 124 | $(Q)$(MAKE) -C tests cgptmanager_tests |
Jay Srinivasan | 5fac757 | 2012-02-23 10:59:01 -0800 | [diff] [blame] | 125 | |
| 126 | libdump_kernel_config: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 127 | $(Q)mkdir -p ${BUILD}/utility |
| 128 | $(Q)$(MAKE) -C utility $(DUMPKERNELCONFIGLIB) |
Jay Srinivasan | 250549d | 2012-02-16 17:40:45 -0800 | [diff] [blame] | 129 | |
Gaurav Shah | 322536d | 2010-01-28 15:01:23 -0800 | [diff] [blame] | 130 | clean: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 131 | $(Q)/bin/rm -rf ${BUILD} |
Bill Richardson | 371df8b | 2010-05-27 14:19:47 -0700 | [diff] [blame] | 132 | |
| 133 | install: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 134 | $(Q)$(MAKE) -C utility install |
| 135 | $(Q)$(MAKE) -C cgpt install |
Gaurav Shah | e642198 | 2010-06-03 07:49:32 -0700 | [diff] [blame] | 136 | |
| 137 | runtests: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 138 | $(Q)$(MAKE) -C tests runtests |
Luigi Semenzato | 18b814d | 2010-07-08 17:17:02 -0700 | [diff] [blame] | 139 | |
Randall Spangler | e8cfa31 | 2013-01-02 16:49:38 -0800 | [diff] [blame^] | 140 | runlongtests: |
| 141 | $(MAKE) -C tests runlongtests |
| 142 | |
Jay Srinivasan | 250549d | 2012-02-16 17:40:45 -0800 | [diff] [blame] | 143 | runcgptmanagertests: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 144 | $(Q)$(MAKE) -C tests runcgptmanagertests |
Jay Srinivasan | 250549d | 2012-02-16 17:40:45 -0800 | [diff] [blame] | 145 | |
Luigi Semenzato | 18b814d | 2010-07-08 17:17:02 -0700 | [diff] [blame] | 146 | rbtest: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 147 | $(Q)$(MAKE) -C tests rbtest |
Bill Richardson | 856e072 | 2011-02-07 15:39:45 -0800 | [diff] [blame] | 148 | |
| 149 | runbmptests: |
Gabe Black | 0aedbe1 | 2012-12-20 00:26:59 -0800 | [diff] [blame] | 150 | $(Q)$(MAKE) -C tests runbmptests |