Makefile revision 844bce57471153664c78993dab453e87891bb969
1e8cfa31d548c069d73c304fea522b527fe7c7dd6Randall Spangler# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shah# Use of this source code is governed by a BSD-style license that can be
3322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shah# found in the LICENSE file.
4322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shah
50aedbe1950225f8c8f3e535efa9575dc3a9c970dGabe Blackifneq ($(V),1)
60aedbe1950225f8c8f3e535efa9575dc3a9c970dGabe BlackQ := @
70aedbe1950225f8c8f3e535efa9575dc3a9c970dGabe Blackendif
80aedbe1950225f8c8f3e535efa9575dc3a9c970dGabe Black
96d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass# This Makefile normally builds in a 'build' subdir, but use
106d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass#
116d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass#    make BUILD=<dir>
126d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass#
136d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass# to put the output somewhere else
145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerBUILD ?= $(shell pwd)/build
15844bce57471153664c78993dab453e87891bb969Randall Spanglerexport BUILD
165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Target for 'make install'
185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerDESTDIR ?= /usr/bin
19826db09fcec194951e1dc71002d6a92620fbb46bBill RichardsonINSTALL ?= install
206d696e532c6a0c93ad9b915c59dad4144e6f1b33Simon Glass
21b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
22b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# please add them after this point (e.g., -DVBOOT_DEBUG).
2374359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
246b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
256b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# temporarily. As we are still investigating which flags are necessary for
266b0003c6381a7e69818b0b34b358c2cfb1393043Che-Liang Chiou# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
2774359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
28b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# As a first step, this makes the setting of CC and CFLAGS here optional, to
29b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# permit a calling script or Makefile to set these.
3074359b755c4a203df0fe3bf51fc53d5de87d1fbfChe-Liang Chiou#
31b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Flag ordering: arch, then -f, then -m, then -W
32b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassDEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
33b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCOMMON_FLAGS := -nostdinc -pipe \
34b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffreestanding -fno-builtin -fno-stack-protector \
35b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-Werror -Wall -Wstrict-prototypes $(DEBUG_FLAGS)
36b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
377604a7dba239c1f4f1ce2561d3c5aa968dc53d8dChe-Liang Chiouifeq ($(FIRMWARE_ARCH), arm)
38b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= armv7a-cros-linux-gnueabi-gcc
39b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= -march=armv5 \
40b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fno-common -ffixed-r8 \
41d50b27d15de8cc9e37410fc52d3184f17e0db5bbDoug Anderson	-mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
42b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	$(COMMON_FLAGS)
43844bce57471153664c78993dab453e87891bb969Randall Spanglerelse ifeq ($(FIRMWARE_ARCH), i386)
44b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCC ?= i686-pc-linux-gnu-gcc
45b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass# Drop -march=i386 to permit use of SSE instructions
46b265c34321c01bd279f3a1df0a2fea3601f732eeSimon GlassCFLAGS ?= \
47b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
48b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
49b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	-mpreferred-stack-boundary=2 -mregparm=3 \
50b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass	$(COMMON_FLAGS)
51844bce57471153664c78993dab453e87891bb969Randall Spanglerelse ifeq ($(FIRMWARE_ARCH), x86_64)
528e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon GlassCFLAGS ?= $(COMMON_FLAGS) \
538e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glass	-fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
54844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
55844bce57471153664c78993dab453e87891bb969Randall Spangler$(info FIRMWARE_ARCH not defined; assuming local compile.)
568e85e987739281161ece1dbc9ff2b73f3e8e1e35Simon Glassendif
5734be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiou
58844bce57471153664c78993dab453e87891bb969Randall Spangler# Architecture detection
59844bce57471153664c78993dab453e87891bb969Randall SpanglerHOST_ARCH ?= $(shell uname -m)
60844bce57471153664c78993dab453e87891bb969Randall Spangler
61844bce57471153664c78993dab453e87891bb969Randall Spangler# Pick a sane target architecture if none defined (building outside emake)
62287beaed7f8ceff679c57664d4da008c6234edfdRandall Spanglerifeq ($(ARCH),)
63844bce57471153664c78993dab453e87891bb969Randall Spangler  ARCH := $(HOST_ARCH)
64844bce57471153664c78993dab453e87891bb969Randall Spangler  ifeq ($(ARCH), x86_64)
65844bce57471153664c78993dab453e87891bb969Randall Spangler    ARCH := amd64
66844bce57471153664c78993dab453e87891bb969Randall Spangler  endif
67844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
68844bce57471153664c78993dab453e87891bb969Randall Spangler
69844bce57471153664c78993dab453e87891bb969Randall Spangler# Determine QEMU architecture needed, if any
70844bce57471153664c78993dab453e87891bb969Randall Spanglerifeq ($(ARCH),$(HOST_ARCH))
71844bce57471153664c78993dab453e87891bb969Randall Spangler  # Same architecture; no need for QEMU
72844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
73844bce57471153664c78993dab453e87891bb969Randall Spanglerelse ifeq ($(HOST_ARCH)-$(ARCH),x86_64-i386)
74844bce57471153664c78993dab453e87891bb969Randall Spangler  # 64-bit host can run 32-bit targets directly
75844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
76844bce57471153664c78993dab453e87891bb969Randall Spanglerelse ifeq ($(HOST_ARCH)-$(ARCH),x86_64-amd64)
77844bce57471153664c78993dab453e87891bb969Randall Spangler  # 64-bit host can run 64-bit directly
78844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH :=
79844bce57471153664c78993dab453e87891bb969Randall Spanglerelse ifeq ($(ARCH),amd64)
80844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH := x86_64
81844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
82844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_ARCH := $(ARCH)
83844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
84844bce57471153664c78993dab453e87891bb969Randall Spangler
85844bce57471153664c78993dab453e87891bb969Randall Spangler# The top of the chroot for qemu must be passed in via the SYSROOT environment
86844bce57471153664c78993dab453e87891bb969Randall Spangler# variable.  In the Chromium OS chroot, this is done automatically by the
87844bce57471153664c78993dab453e87891bb969Randall Spangler# ebuild.
88844bce57471153664c78993dab453e87891bb969Randall Spangler
89844bce57471153664c78993dab453e87891bb969Randall Spangler# If SYSROOT is not defined, disable QEMU testing
90844bce57471153664c78993dab453e87891bb969Randall Spangler# TODO: which probably means attempting to test should simply fail
91844bce57471153664c78993dab453e87891bb969Randall Spanglerifneq ($(QEMU_ARCH),)
92844bce57471153664c78993dab453e87891bb969Randall Spangler  ifeq ($(SYSROOT),)
93844bce57471153664c78993dab453e87891bb969Randall Spangler    $(warning SYSROOT must be set to the top of the target-specific root \
94844bce57471153664c78993dab453e87891bb969Randall Spanglerwhen cross-compiling for qemu-based tests to run properly.)
95844bce57471153664c78993dab453e87891bb969Randall Spangler    QEMU_ARCH :=
96844bce57471153664c78993dab453e87891bb969Randall Spangler  endif
97844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
98844bce57471153664c78993dab453e87891bb969Randall Spangler
99844bce57471153664c78993dab453e87891bb969Randall Spanglerifeq ($(QEMU_ARCH),)
100844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is same as for building
101844bce57471153664c78993dab453e87891bb969Randall Spangler  BUILD_RUN = $(BUILD)
102844bce57471153664c78993dab453e87891bb969Randall Spanglerelse
103844bce57471153664c78993dab453e87891bb969Randall Spangler  $(info Using qemu for testing.)
104844bce57471153664c78993dab453e87891bb969Randall Spangler  # Path to build output for running tests is different in the chroot
105844bce57471153664c78993dab453e87891bb969Randall Spangler  BUILD_RUN = $(subst $(SYSROOT),,$(BUILD))
106844bce57471153664c78993dab453e87891bb969Randall Spangler
107844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_BIN = qemu-$(QEMU_ARCH)
108844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_OPTS = -drop-ld-preload \
109844bce57471153664c78993dab453e87891bb969Randall Spangler	-E LD_LIBRARY_PATH=/lib64:/lib:/usr/lib64:/usr/lib \
110844bce57471153664c78993dab453e87891bb969Randall Spangler	-E HOME=$(HOME) \
111844bce57471153664c78993dab453e87891bb969Randall Spangler	-E BUILD=$(BUILD_RUN)
112844bce57471153664c78993dab453e87891bb969Randall Spangler  QEMU_CMD = sudo chroot $(SYSROOT) $(BUILD_RUN)/$(QEMU_BIN) $(QEMU_OPTS) --
113844bce57471153664c78993dab453e87891bb969Randall Spangler  RUNTEST = $(QEMU_CMD)
114287beaed7f8ceff679c57664d4da008c6234edfdRandall Spanglerendif
115287beaed7f8ceff679c57664d4da008c6234edfdRandall Spangler
1165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Some things only compile inside the Chromium OS chroot
1175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: is there a better way to detect this?
1185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifneq ($(CROS_WORKON_SRCROOT),)
1195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerIN_CHROOT = 1
1205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
1215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCC ?= gcc
1235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCXX ?= g++
1245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerLD = $(CC)
1255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerPKG_CONFIG ?= pkg-config
1265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
12734be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiouifeq ($(FIRMWARE_ARCH),)
128f47291926afce3235421f73811a04324195f3e13Bill RichardsonCFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror
12934be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiouendif
13034be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiou
13134be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang Chiouifneq (${DEBUG},)
13234be8273e0fb80a6654deab650e581b0dc9046a4Che-Liang ChiouCFLAGS += -DVBOOT_DEBUG
133b2b0fcc0f62fadce6f854bf14826a9778c0f7632vbendebendif
1340a0e8d0bb26c951a895c5034a4c1c12f3d4e8707Che-Liang Chiou
135b2b0fcc0f62fadce6f854bf14826a9778c0f7632vbendebifeq (${DISABLE_NDEBUG},)
136b2b0fcc0f62fadce6f854bf14826a9778c0f7632vbendebCFLAGS += -DNDEBUG
137b2b0fcc0f62fadce6f854bf14826a9778c0f7632vbendebendif
138b2b0fcc0f62fadce6f854bf14826a9778c0f7632vbendeb
1395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Create / use dependency files
1405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCFLAGS += -MMD -MF $@.d
141b265c34321c01bd279f3a1df0a2fea3601f732eeSimon Glass
1425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Code coverage
143844bce57471153664c78993dab453e87891bb969Randall Spangler# Run like this: COV=1 make runtests coverage
1445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifneq (${COV},)
1455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#COV_FLAGS = -O0 -fprofile-arcs -ftest-coverage
1465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCOV_FLAGS = -O0 --coverage
1475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCFLAGS += $(COV_FLAGS)
1485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerLDFLAGS += $(COV_FLAGS)
1490a0e8d0bb26c951a895c5034a4c1c12f3d4e8707Che-Liang Chiouendif
150322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shah
1515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += \
1525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/include \
1535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/include \
1545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cgptlib/include \
1555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/cryptolib/include \
1565d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ifirmware/lib/tpm_lite/include
1570b8f35c6a56a0e645254dd7f07ca68e01c8ee629Bill Richardson
1580a0e8d0bb26c951a895c5034a4c1c12f3d4e8707Che-Liang Chiouifeq ($(FIRMWARE_ARCH),)
1595d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += -Ifirmware/stub/include
1600a0e8d0bb26c951a895c5034a4c1c12f3d4e8707Che-Liang Chiouelse
1615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerINCLUDES += -Ifirmware/arch/$(FIRMWARE_ARCH)/include
1625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
1635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Output libraries
1655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPTLIB := ${BUILD}/cgpt/libcgpt-cc.a
1665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerDUMPKERNELCONFIGLIB := ${BUILD}/libdump_kernel_config.a
1675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerFWLIB := ${BUILD}/vboot_fw.a
1685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerHOSTLIB := ${BUILD}/vboot_host.a
1695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerTEST_LIB := ${BUILD}/tests/test.a
1705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCRYPTO_LIBS := $(shell $(PKG_CONFIG) --libs libcrypto)
1725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifneq ($(IN_CHROOT),)
1745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerPC_BASE_VER ?= 125070
1755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerPC_DEPS = libchrome-$(PC_BASE_VER)
1765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerPC_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PC_DEPS))
1775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerPC_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PC_DEPS))
1785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
1795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Link with hostlib and crypto libs by default
1815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerLIBS = $(HOSTLIB)
1825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerLDLIBS = $(CRYPTO_LIBS)
1835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Create output directories if necessary.  Do this via explicit shell commands
1855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# so it happens before trying to generate/include dependencies.
1865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSUBDIRS := firmware host utility cgpt tests tests/tpm_lite
1875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler_dir_create := $(foreach d, \
1885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(shell find $(SUBDIRS) -name '*.c' -exec  dirname {} \; | sort -u), \
1895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(shell [ -d $(BUILD)/$(d) ] || mkdir -p $(BUILD)/$(d)))
1905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# First target
192acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: all
1935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerall: fwlib $(if $(FIRMWARE_ARCH),,host_stuff)
1945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
1955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Host targets
196acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: host_stuff
1975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerhost_stuff: fwlib hostlib cgpt utils tests
198250549d3e742cddaf72b4f53d5739e54faf5db96Jay Srinivasan
199acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: clean
200322536d2f9d30f42218cc9f2ab40574557da8a9Gaurav Shahclean:
2010aedbe1950225f8c8f3e535efa9575dc3a9c970dGabe Black	$(Q)/bin/rm -rf ${BUILD}
202371df8bbbf9088dc1206701bdc2294d9598bb339Bill Richardson
203acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: install
2045d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerinstall: cgpt_install utils_install
2055d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Coverage
207844bce57471153664c78993dab453e87891bb969Randall Spangler# TODO: only if COV=1
2085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCOV_INFO = $(BUILD)/coverage.info
2095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#coverage: runtests
210acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: coverage
2115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglercoverage:
2125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	rm -f $(COV_INFO)*
2135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	lcov --capture --directory . --base-directory . -o $(COV_INFO).1
2145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	lcov --remove $(COV_INFO).1 '/usr/*' -o $(COV_INFO)
2155d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	genhtml $(COV_INFO) --output-directory $(BUILD)/coverage
2165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Don't delete intermediate object files
2185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler.SECONDARY:
2195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Use second expansion phase for $$(LIBS) so dependencies on libraries are
2215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# properly evaluated for implicit rules.
2225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler.SECONDEXPANSION:
2235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
2255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Firmware library
2265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TPM-specific flags.  These depend on the particular TPM we're targeting for.
2285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# They are needed here only for compiling parts of the firmware code into
2295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# user-level tests.
2305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
2325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# the self test has completed.
2335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
234acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(FWLIB): CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
2355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2365d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
2375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
2385d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# power on.
2395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#
2405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
2415d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# are not both defined at the same time.  (See comment in code.)
2425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# CFLAGS += -DTPM_MANUAL_SELFTEST
2445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifeq ($(FIRMWARE_ARCH),i386)
2465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Unrolling loops in cryptolib makes it faster
247acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(FWLIB): CFLAGS += -DUNROLL_LOOPS
2485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Workaround for coreboot on x86, which will power off asynchronously
2505d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# without giving us a chance to react. This is not an example of the Right
2515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Way to do things. See chrome-os-partner:7689, and the commit message
2525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# that made this change.
253acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(FWLIB): CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
2545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# On x86 we don't actually read the GBB data into RAM until it is needed.
2565d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Therefore it makes sense to cache it rather than reading it each time.
2575d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Enable this feature.
258acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(FWLIB): CFLAGS += -DCOPY_BMP_DATA
2595d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
2605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifeq ($(FIRMWARE_ARCH),)
2625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Disable rollback TPM when compiling locally, since otherwise
2635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# load_kernel_test attempts to talk to the TPM.
264acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(FWLIB): CFLAGS += -DDISABLE_ROLLBACK_TPM
2655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
2665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# find lib -iname '*.c' | sort
2685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerFWLIB_SRCS = \
2695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cgptlib/cgptlib.c \
2705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cgptlib/cgptlib_internal.c \
2715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cgptlib/crc32.c \
2725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/crc8.c \
2735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/padding.c \
2745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa.c \
2755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/rsa_utility.c \
2765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha1.c \
2775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha256.c \
2785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha512.c \
2795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cryptolib/sha_utility.c \
2805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/stateful_util.c \
2815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/utility.c \
2825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/utility_string.c \
2835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_init.c \
2845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_firmware.c \
2855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_api_kernel.c \
2865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_audio.c \
2875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_common.c \
2885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_display.c \
2895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_firmware.c \
2905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_kernel.c \
2915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/vboot_nvstorage.c
2925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
2935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifeq ($(MOCK_TPM),)
2945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerFWLIB_SRCS += \
2955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/rollback_index.c \
2965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_bootmode.c \
2975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/tlcl.c
2985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerelse
2995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerFWLIB_SRCS += \
3005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/mocked_rollback_index.c \
3015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/mocked_tpm_bootmode.c \
3025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/tpm_lite/mocked_tlcl.c
3035d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3045d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3055d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifeq ($(FIRMWARE_ARCH),)
3065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Include stub into firmware lib if compiling for host
3075d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerFWLIB_SRCS += \
3085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/tpm_lite_stub.c \
3095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/utility_stub.c \
3105d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/vboot_api_stub.c \
3115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/vboot_api_stub_disk.c
3125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerFWLIB_OBJS = $(FWLIB_SRCS:%.c=${BUILD}/%.o)
3155d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${FWLIB_OBJS}
3165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
317acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: fwlib
3185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifeq ($(FIRMWARE_ARCH),)
3195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Link test ensures firmware lib doesn't rely on outside libraries
320acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/firmware/linktest/main: LIBS = $(FWLIB)
3215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
322acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsonfwlib: ${BUILD}/firmware/linktest/main
3235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerelse
324acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsonfwlib: $(FWLIB)
3255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
3265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
327acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(FWLIB): $(FWLIB_OBJS)
3285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    RM            $(subst $(BUILD)/,,$(@))\n"
3295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)rm -f $@
3305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    AR            $(subst $(BUILD)/,,$(@))\n"
3315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)ar qc $@ $^
3325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
3345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Host library
3355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
336acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: hostlib
337acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsonhostlib: $(HOSTLIB) ${BUILD}/host/linktest/main
3385d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
339acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/host/% ${HOSTLIB}: INCLUDES += \
3405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ihost/include\
3415d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	-Ihost/arch/$(ARCH)/include
3425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerHOSTLIB_SRCS = \
3445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/arch/$(ARCH)/lib/crossystem_arch.c \
3455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/crossystem.c \
3465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/file_keys.c \
3475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/fmap.c \
3485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_common.c \
3495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_key.c \
3505d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_keyblock.c \
3515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_misc.c \
3525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/host_signature.c \
3535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	host/lib/signature_digest.c
3545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerHOSTLIB_OBJS = $(HOSTLIB_SRCS:%.c=${BUILD}/%.o)
3565d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${HOSTLIB_OBJS}
3575d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: better way to make .a than duplicating this recipe each time?
359acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(HOSTLIB): $(HOSTLIB_OBJS) $(FWLIB_OBJS)
3605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    RM            $(subst $(BUILD)/,,$(@))\n"
3615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)rm -f $@
3625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    AR            $(subst $(BUILD)/,,$(@))\n"
3635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)ar qc $@ $^
3645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
3665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# CGPT library and utility
3675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT = ${BUILD}/cgpt/cgpt
3695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT_SRCS = \
3715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt.c \
3725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_add.c \
3735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_boot.c \
3745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_common.c \
3755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_create.c \
3765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_find.c \
3775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_legacy.c \
3785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_prioritize.c \
3795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_repair.c \
3805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_show.c \
3815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_add.c \
3825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_boot.c \
3835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_create.c \
3845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_find.c \
3855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_legacy.c \
3865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_prioritize.c \
3875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_repair.c \
3885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cmd_show.c
3895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPT_OBJS = $(CGPT_SRCS:%.c=${BUILD}/%.o)
3915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += ${CGPT_OBJS}
3925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
3935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: why not make this include *all* the cgpt files, and simply have
3945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# cgpt link against it?
3955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: CgptManager.cc should move to the installer project.  Shouldn't be
3965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# in libcgpt-cc.a.
3975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPTLIB_SRCS = \
3985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/CgptManager.cc \
3995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_create.c \
4005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_add.c \
4015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_boot.c \
4025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_show.c \
4035d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_repair.c \
4045d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_prioritize.c \
4055d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgpt/cgpt_common.c \
4065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cgptlib/crc32.c \
4075d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/lib/cgptlib/cgptlib_internal.c \
4085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	firmware/stub/utility_stub.c
4095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4105d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerCGPTLIB_OBJS = $(filter %.o, \
4115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(CGPTLIB_SRCS:%.c=${BUILD}/%.o) \
4125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(CGPTLIB_SRCS:%.cc=${BUILD}/%.o))
4135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_OBJS += $(CGPTLIB_OBJS)
4145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4155d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler.PHONY: cgpt
416acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsoncgpt: $(CGPT)
4175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
418acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: libcgpt_cc
419acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsonlibcgpt_cc: $(CGPTLIB)
4205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
421acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(CGPTLIB): INCLUDES += -Ifirmware/lib/cgptlib/include
422acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(CGPTLIB): $(CGPTLIB_OBJS)
4235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    RM            $(subst $(BUILD)/,,$(@))\n"
4245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)rm -f $@
4255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    AR            $(subst $(BUILD)/,,$(@))\n"
4265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)ar qc $@ $^
4275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
428acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(CGPT): INCLUDES += -Ifirmware/lib/cgptlib/include
429acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(CGPT): LDLIBS = -luuid
430acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(CGPT): LDFLAGS += -static
431acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(CGPT): $(CGPT_OBJS) $$(LIBS)
4325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    LDcgpt        $(subst $(BUILD)/,,$(@))\n"
4335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)$(LD) -o $(CGPT) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) $(LDLIBS)
4345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
435826db09fcec194951e1dc71002d6a92620fbb46bBill RichardsonC_DESTDIR = $(DESTDIR)
436826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson
437acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: cgpt_install
4385d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglercgpt_install: $(CGPT)
439826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson	@printf "    INSTALL       CGPT\n"
440826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson	${Q}mkdir -p $(C_DESTDIR)
441826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson	${Q}$(INSTALL) -t $(C_DESTDIR) $^
4425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
4445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Utilities
4455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
446acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/%: INCLUDES += -Ihost/include -Iutility/include
447acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/%: CFLAGS += $(PC_CFLAGS)
4485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerAU_NAMES = \
4505d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	crossystem \
4515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	dump_fmap \
4525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	gbb_utility
453acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill RichardsonAU_BINS:= $(addprefix ${BUILD}/utility/,$(AU_NAMES))
4545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Utilities for auto-update toolkits must be statically linked, and don't
4565d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# use the crypto libs.
457acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${AU_BINS}: LDFLAGS += -static
458acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${AU_BINS}: CRYPTO_LIBS =
4595d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Scripts to install
4615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_SCRIPTS = \
4625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/dev_debug_vboot \
4635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/dev_make_keypair \
4645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/enable_dev_usb_boot \
4655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility/vbutil_what_keys
4665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_NAMES = $(AU_NAMES) \
4685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	dev_sign_file \
4695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	dump_kernel_config \
4705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	dumpRSAPublicKey \
4715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	load_kernel_test \
4725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	pad_digest_utility \
4735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	signature_digest_utility \
4745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tpm_init_temp_fix \
4755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tpmc \
4765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_ec \
4775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_firmware \
4785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_kernel \
4795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_key \
4805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vbutil_keyblock \
4815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	verify_data
4825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifneq ($(IN_CHROOT),)
4845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_NAMES += mount-encrypted
4855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
4865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifeq ($(MINIMAL),)
4885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_NAMES += \
4895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	bmpblk_font \
4905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	bmpblk_utility \
4915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	eficompress \
4925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	efidecompress
4935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
4945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
4955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerUTIL_BINS = $(addprefix ${BUILD}/utility/,$(UTIL_NAMES))
4965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_DEPS += $(addsuffix .d,${UTIL_BINS})
4975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
498acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils
499acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsonutils: $(UTIL_BINS) $(UTIL_SCRIPTS)
5005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: change ebuild to pull scripts directly out of utility dir
5015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)cp -f $(UTIL_SCRIPTS) $(BUILD)/utility
5025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)chmod a+rx $(patsubst %,$(BUILD)/%,$(UTIL_SCRIPTS))
5035d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
504826db09fcec194951e1dc71002d6a92620fbb46bBill RichardsonU_DESTDIR = $(DESTDIR)
505826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson
506acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: utils_install
507acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsonutils_install: $(UTIL_BINS) $(UTIL_SCRIPTS)
508826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson	@printf "    INSTALL       UTILS\n"
509826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson	${Q}mkdir -p $(U_DESTDIR)
510826db09fcec194951e1dc71002d6a92620fbb46bBill Richardson	${Q}$(INSTALL) -t $(U_DESTDIR) $^
5115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
512acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/dump_kernel_config: LIBS += $(DUMPKERNELCONFIGLIB)
5135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# GBB utility needs C++ linker
515acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/gbb_utility: LD = $(CXX)
5165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
517acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/bmpblk_utility: LD = $(CXX)
518acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
519acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/bmpblk_utility: OBJS = \
5205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	${BUILD}/utility/bmpblk_util.o \
5215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	${BUILD}/utility/image_types.o \
52217f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/utility/eficompress_for_lib.o \
52317f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/utility/efidecompress_for_lib.o
5245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
5265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: fix load_firmware_test util; it never got refactored for the new APIs
5285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
5305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Mount-encrypted utility for cryptohome
5315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: mount-encrypted should move to cryptohome and just link against
5335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# vboot-host.a for tlcl and crossystem.
5345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5355d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# The embedded libcrypto conflicts with the shipped openssl,
5365d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# so mount-* builds without the common CFLAGS (and those includes).
5375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5385d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/utility/mount-helpers.o: \
5395d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		utility/mount-helpers.c \
5405d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		utility/mount-helpers.h \
5415d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		utility/mount-encrypted.h
5425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    CCm-e         $(subst $(BUILD)/,,$(@))\n"
5435d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
5445d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$(COV_FLAGS) \
5455d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
5465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		-c $< -o $@
5475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/utility/mount-encrypted: \
5495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		utility/mount-encrypted.c \
5505d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		utility/mount-encrypted.h \
5515d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		${BUILD}/utility/mount-helpers.o $$(LIBS)
5525d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    CCm-exe       $(subst $(BUILD)/,,$(@))\n"
5535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)$(CC) -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
5545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$(shell $(PKG_CONFIG) --cflags glib-2.0 openssl) \
5555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		-Ifirmware/include \
5565d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		-Ihost/include \
5575d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$(COV_FLAGS) \
5585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$(LDFLAGS) \
5595d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$< -o $@ \
5605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		${BUILD}/utility/mount-helpers.o $(LIBS) \
5615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$(shell $(PKG_CONFIG) --libs glib-2.0 openssl) \
5625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		-lm
5635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifneq (${COV},)
5645d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)mv -f mount-encrypted.gcno ${BUILD}/utility
5655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
5665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5675d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
5685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Utility to generate TLCL structure definition header file.
5695d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
570acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
571acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/utility/tlcl_generator: LIBS =
5725d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5735d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
5745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerSTRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
5755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
576acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: update_tlcl_structures
5775d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerupdate_tlcl_structures: ${BUILD}/utility/tlcl_generator
5785d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    Rebuilding TLCL structures\n"
5795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)${BUILD}/utility/tlcl_generator > $(STRUCTURES_TMP)
5805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)cmp -s $(STRUCTURES_TMP) $(STRUCTURES_SRC) || \
5815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		( echo "%% Updating structures.h %%" && \
5825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		  cp $(STRUCTURES_TMP) $(STRUCTURES_SRC) )
5835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
5855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Library to dump kernel config
58617f8d341099120da78a6ca71165834eefb0960edRandall Spangler# Used by platform/installer
5875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
588acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: libdump_kernel_config
5895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerlibdump_kernel_config: $(DUMPKERNELCONFIGLIB)
5905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
591acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson$(DUMPKERNELCONFIGLIB): ${BUILD}/utility/dump_kernel_config_lib.o
5925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    RM            $(subst $(BUILD)/,,$(@))\n"
5935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)rm -f $@
5945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    AR            $(subst $(BUILD)/,,$(@))\n"
5955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)ar qc $@ $^
5965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
5975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
5985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Tests
5995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Allow multiple definitions, so tests can mock functions from other libraries
601acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
602acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/%: INCLUDES += -Ihost/include
603acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/%: LDLIBS += -lrt -luuid
604acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/%: LIBS += $(TEST_LIB)
6055d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6065d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerTEST_NAMES = \
6075d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	cgptlib_test \
6085d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	rollback_index2_tests \
6095d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	rsa_padding_test \
6105d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	rsa_utility_tests \
6115d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	rsa_verify_benchmark \
6125d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	sha_benchmark \
6135d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	sha_tests \
6145d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	stateful_util_tests \
6155d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tpm_bootmode_tests \
6165d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility_string_tests \
6175d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	utility_tests \
6185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_nvstorage_test \
6195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_api_init_tests \
6205d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_api_devmode_tests \
6215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_api_firmware_tests \
6225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_api_kernel_tests \
6235d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_audio_tests \
6245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_common_tests \
6255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_common2_tests \
6265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_common3_tests \
6275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_ec_tests \
6285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	vboot_firmware_tests
6295d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifneq ($(IN_CHROOT),)
6315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerTEST_NAMES += CgptManagerTests
6325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
6335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6345d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerTLCL_TEST_NAMES = \
63517f8d341099120da78a6ca71165834eefb0960edRandall Spangler	tpmtest_earlyextend \
63617f8d341099120da78a6ca71165834eefb0960edRandall Spangler	tpmtest_earlynvram \
63717f8d341099120da78a6ca71165834eefb0960edRandall Spangler        tpmtest_earlynvram2 \
63817f8d341099120da78a6ca71165834eefb0960edRandall Spangler	tpmtest_enable \
63917f8d341099120da78a6ca71165834eefb0960edRandall Spangler	tpmtest_fastenable \
64017f8d341099120da78a6ca71165834eefb0960edRandall Spangler	tpmtest_globallock \
64117f8d341099120da78a6ca71165834eefb0960edRandall Spangler        tpmtest_redefine_unowned \
64217f8d341099120da78a6ca71165834eefb0960edRandall Spangler        tpmtest_spaceperm \
64317f8d341099120da78a6ca71165834eefb0960edRandall Spangler	tpmtest_testsetup \
64417f8d341099120da78a6ca71165834eefb0960edRandall Spangler	tpmtest_timing \
64517f8d341099120da78a6ca71165834eefb0960edRandall Spangler        tpmtest_writelimit
64617f8d341099120da78a6ca71165834eefb0960edRandall SpanglerTEST_NAMES += $(addprefix tpm_lite/,$(TLCL_TEST_NAMES))
6475d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerTEST_BINS = $(addprefix ${BUILD}/tests/,$(TEST_NAMES))
6495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_DEPS += $(addsuffix .d,${TEST_BINS})
6505d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
65117f8d341099120da78a6ca71165834eefb0960edRandall Spangler.PHONY: tests
652acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardsontests: $(TEST_BINS)
6535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${TEST_LIB}: \
6555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		${BUILD}/tests/test_common.o \
6565d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		${BUILD}/tests/timer_utils.o \
6575d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		${BUILD}/tests/crc32_test.o
6585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    RM            $(subst $(BUILD)/,,$(@))\n"
6595d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)rm -f $@
6605d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    AR            $(subst $(BUILD)/,,$(@))\n"
6615d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)ar qc $@ $^
6625d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6635d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/rollback_index2_tests: OBJS += \
66417f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/rollback_index_for_test.o
6655d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6665d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler${BUILD}/tests/vboot_audio_tests: OBJS += \
66717f8d341099120da78a6ca71165834eefb0960edRandall Spangler	${BUILD}/firmware/lib/vboot_audio_for_test.o
6685d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
669acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: cgptmanager_tests
6705d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglercgptmanager_tests: ${BUILD}/tests/CgptManagerTests
6715d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
672acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/CgptManagerTests: CFLAGS += $(PC_CFLAGS)
673acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/CgptManagerTests: LD = $(CXX)
674acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/CgptManagerTests: LDLIBS += -lgtest -lgflags $(PC_LDLIBS)
675acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/CgptManagerTests: LIBS = $(CGPTLIB)
6765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
677acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/rollback_index_test: INCLUDES += -I/usr/include
678acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/rollback_index_test: LIBS += -ltlcl
6795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
680acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/tests/tpm_lite/tpmtest_%: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
6815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: port these tests to new API, if not already eqivalent
6835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# functionality in other tests.  These don't even compile at present.
6845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#
6855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		big_firmware_tests
6865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		big_kernel_tests
6875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		firmware_image_tests
6885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		firmware_rollback_tests
6895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		firmware_splicing_tests
6905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		firmware_verify_benchmark
6915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		kernel_image_tests
6925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		kernel_rollback_tests
6935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		kernel_splicing_tests
6945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		kernel_verify_benchmark
6955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		rollback_index_test
6965d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		verify_firmware_fuzz_driver
6975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#		verify_kernel_fuzz_driver
6985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
6995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
7005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Targets to run tests
7015d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
7025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Frequently-run tests
703844bce57471153664c78993dab453e87891bb969Randall SpanglerTEST_TARGETS = runcgpttests runmisctests
704844bce57471153664c78993dab453e87891bb969Randall Spangler
705844bce57471153664c78993dab453e87891bb969Randall Spanglerifeq ($(MINIMAL),)
706844bce57471153664c78993dab453e87891bb969Randall Spangler# Bitmap utility isn't compiled for minimal variant
707844bce57471153664c78993dab453e87891bb969Randall SpanglerTEST_TARGETS += runbmptests
708844bce57471153664c78993dab453e87891bb969Randall Spangler# Scripts don't work under qemu testing
709844bce57471153664c78993dab453e87891bb969Randall Spangler# TODO: convert scripts to makefile so they can be called directly
710844bce57471153664c78993dab453e87891bb969Randall SpanglerTEST_TARGETS += runtestscripts
711844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
712844bce57471153664c78993dab453e87891bb969Randall Spangler
713844bce57471153664c78993dab453e87891bb969Randall Spangler# Qemu setup for cross-compiled tests.  Need to copy qemu binary into the
714844bce57471153664c78993dab453e87891bb969Randall Spangler# sysroot.
715844bce57471153664c78993dab453e87891bb969Randall Spanglerifneq ($(QEMU_ARCH),)
716844bce57471153664c78993dab453e87891bb969Randall SpanglerTEST_SETUP += qemu_install
717844bce57471153664c78993dab453e87891bb969Randall Spangler
718844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: qemu_install
719844bce57471153664c78993dab453e87891bb969Randall Spanglerqemu_install:
720844bce57471153664c78993dab453e87891bb969Randall Spangler	@printf "    Copying qemu binary.\n"
721844bce57471153664c78993dab453e87891bb969Randall Spangler	$(Q)cp -fu /usr/bin/$(QEMU_BIN) $(BUILD)/$(QEMU_BIN)
722844bce57471153664c78993dab453e87891bb969Randall Spangler	$(Q)chmod a+rx $(BUILD)/$(QEMU_BIN)
723844bce57471153664c78993dab453e87891bb969Randall Spanglerendif
724844bce57471153664c78993dab453e87891bb969Randall Spangler
725acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runtests
726844bce57471153664c78993dab453e87891bb969Randall Spanglerruntests: $(TEST_TARGETS)
7275d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
7285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test keys
729acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genkeys
730844bce57471153664c78993dab453e87891bb969Randall Spanglergenkeys: utils
7315d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_test_keys.sh
7325d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
7335d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Generate test cases for fuzzing
734acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: genfuzztestcases
735a808dc944284e6eba39a8f19ddb46bc61c34de8aRandall Spanglergenfuzztestcases: utils
7365d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/gen_fuzz_test_cases.sh
7375d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
738acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runbmptests
739844bce57471153664c78993dab453e87891bb969Randall Spanglerrunbmptests: $(TEST_SETUP) utils
740844bce57471153664c78993dab453e87891bb969Randall Spangler	cd tests/bitmaps && BMPBLK=$(BUILD_RUN)/utility/bmpblk_utility \
7415d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		./TestBmpBlock.py -v
7425d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
743acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runcgpttests
744844bce57471153664c78993dab453e87891bb969Randall Spanglerruncgpttests: $(TEST_SETUP) cgpt tests
745844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/cgptlib_test
7465d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerifneq ($(IN_CHROOT),)
747844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/CgptManagerTests --v=1
7485d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spanglerendif
7495d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
750844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runtestscripts
751844bce57471153664c78993dab453e87891bb969Randall Spanglerruntestscripts: $(TEST_SETUP) genfuzztestcases utils tests
752844bce57471153664c78993dab453e87891bb969Randall Spangler	tests/run_cgpt_tests.sh $(BUILD_RUN)/cgpt/cgpt
7535d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh
7545d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_rsa_tests.sh
7555d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vboot_common_tests.sh
756844bce57471153664c78993dab453e87891bb969Randall Spangler	tests/run_vbutil_kernel_arg_tests.sh
7575d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh
7585d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
759844bce57471153664c78993dab453e87891bb969Randall Spangler.PHONY: runmisctests
760844bce57471153664c78993dab453e87891bb969Randall Spanglerrunmisctests: $(TEST_SETUP) tests utils
761844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/rollback_index2_tests
762844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/rsa_utility_tests
763844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/sha_tests
764844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/stateful_util_tests
765844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/tpm_bootmode_tests
766844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/utility_string_tests
767844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/utility_tests
768844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/vboot_api_devmode_tests
769844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/vboot_api_init_tests
770844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/vboot_api_firmware_tests
771844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/vboot_audio_tests
772844bce57471153664c78993dab453e87891bb969Randall Spangler	$(RUNTEST) $(BUILD_RUN)/tests/vboot_firmware_tests
773844bce57471153664c78993dab453e87891bb969Randall Spangler
7745d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Run long tests, including all permutations of encryption keys (instead of
7755d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# just the ones we use) and tests of currently-unused code (e.g. vboot_ec).
7765d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Not run by automated build.
777acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson.PHONY: runlongtests
778844bce57471153664c78993dab453e87891bb969Randall Spanglerrunlongtests: $(TEST_SETUP) genkeys genfuzztestcases tests utils
7795d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_preamble_tests.sh --all
7805d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vboot_common_tests.sh --all
7815d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vboot_ec_tests.sh
7825d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	tests/run_vbutil_tests.sh --all
7835d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
7845d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: tests to run when ported to new API
7855d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	./run_image_verification_tests.sh
7865d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	# Splicing tests
7875d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/firmware_splicing_tests
7885d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/kernel_splicing_tests
7895d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	# Rollback Tests
7905d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/firmware_rollback_tests
7915d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler#	${BUILD}/tests/kernel_rollback_tests
7925d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
7935d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
7945d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Build rules
7955d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
796acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/%: ${BUILD}/%.o $$(OBJS) $$(LIBS)
7975d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    LD            $(subst $(BUILD)/,,$(@))\n"
7985d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)$(LD) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(OBJS) -o $@ \
7995d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler		$(LIBS) $(LDLIBS)
8005d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler
801acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/%.o: %.c
8025d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    CC            $(subst $(BUILD)/,,$(@))\n"
8035d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
804e642198b93cf2c50e279a6598f21f69564b13c6fGaurav Shah
80517f8d341099120da78a6ca71165834eefb0960edRandall Spangler# Rules to recompile a single source file for library and test
80617f8d341099120da78a6ca71165834eefb0960edRandall Spangler# TODO: is there a tidier way to do this?
807acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
808acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/%_for_lib.o: %.c
80917f8d341099120da78a6ca71165834eefb0960edRandall Spangler	@printf "    CC-for-lib    $(subst $(BUILD)/,,$(@))\n"
81017f8d341099120da78a6ca71165834eefb0960edRandall Spangler	$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
811acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
812acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/%_for_test.o: %.c
81317f8d341099120da78a6ca71165834eefb0960edRandall Spangler	@printf "    CC-for-test   $(subst $(BUILD)/,,$(@))\n"
81417f8d341099120da78a6ca71165834eefb0960edRandall Spangler	$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
81517f8d341099120da78a6ca71165834eefb0960edRandall Spangler
81617f8d341099120da78a6ca71165834eefb0960edRandall Spangler# TODO: C++ files don't belong in vboot reference at all.  Convert to C.
817acb2ee977b8dd139b01b68d0e269ea6bcc425c2bBill Richardson${BUILD}/%.o: %.cc
8185d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	@printf "    CXX           $(subst $(BUILD)/,,$(@))\n"
8195d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler	$(Q)$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
82018b814d9bc7fcf0a7e5d7fca57eed8229f0e9aacLuigi Semenzato
8215d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# -----------------------------------------------------------------------------
8225d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# Dependencies must come last after ALL_OBJS has been accumulated
823e8cfa31d548c069d73c304fea522b527fe7c7dd6Randall Spangler
8245d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# TODO: I suspect this is missing some object files.  Make a temp
8255d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# target which cleans all known obj/exe's and see what's left; those
8265d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler# are the files which need deps.
827250549d3e742cddaf72b4f53d5739e54faf5db96Jay Srinivasan
8285d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall SpanglerALL_DEPS += $(ALL_OBJS:%.o=%.o.d)
829856e072e8119cab07fd884e54853f1c3897452eeBill Richardson
8305d9bbf2bbd7b8dfad45d8ddfea6512987736e523Randall Spangler-include ${ALL_DEPS}
831