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