blob: b56818ab6f04e4e1f22206bae4295b34fc06eaa9 [file] [log] [blame]
Bill Richardson6f396152014-07-15 12:52:19 -07001# Copyright 2013 The Chromium OS Authors. All rights reserved.
Gaurav Shah322536d2010-01-28 15:01:23 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Simon Glass6d696e52011-11-14 13:46:33 -08005# This Makefile normally builds in a 'build' subdir, but use
6#
7# make BUILD=<dir>
8#
Bill Richardsoneecc18f2013-01-17 15:28:17 -08009# to put the output somewhere else.
10
11##############################################################################
12# Make variables come in two flavors, immediate or deferred.
13#
14# Variable definitions are parsed like this:
15#
16# IMMEDIATE = DEFERRED
17# or
18# IMMEDIATE := IMMEDIATE
19#
20# Rules are parsed this way:
21#
22# IMMEDIATE : IMMEDIATE
23# DEFERRED
24#
25# So you can assign variables in any order if they're only to be used in
26# actions, but if you use a variable in either the target or prerequisite of a
27# rule, the rule will be constructed using only the top-down, immediate value.
28#
29# So we'll try to define all the variables first. Then the rules.
30#
31
32##############################################################################
33# Configuration variables come first.
34#
35# Our convention is that we only use := for variables that will never be
36# changed or appended. They must be defined before being used anywhere.
37
Bill Richardsonc9bf3482013-02-13 14:38:29 -080038# We should only run pwd once, not every time we refer to ${BUILD}.
Randall Spanglere061a252013-01-22 15:34:07 -080039SRCDIR := $(shell pwd)
Bill Richardson64ddad72014-08-29 23:49:23 -070040export SRCDIR
Bill Richardsonfeb25182013-03-07 12:54:29 -080041BUILD = $(SRCDIR)/build
Randall Spangler844bce52013-01-15 16:16:43 -080042export BUILD
Simon Glass6d696e52011-11-14 13:46:33 -080043
Bill Richardsonc9bf3482013-02-13 14:38:29 -080044# Stuff for 'make install'
Bill Richardsonfeb25182013-03-07 12:54:29 -080045INSTALL = install
Bill Richardsonefa87562014-09-11 10:41:51 -070046DESTDIR = /usr/local
Bill Richardsonc9bf3482013-02-13 14:38:29 -080047
Bill Richardsonfeb25182013-03-07 12:54:29 -080048# Where exactly do the pieces go?
Bill Richardson6f396152014-07-15 12:52:19 -070049# UB_DIR = utility binary directory
50# VB_DIR = vboot binary directory for dev-mode-only scripts
Bill Richardsonc9bf3482013-02-13 14:38:29 -080051ifeq (${MINIMAL},)
Bill Richardson6f396152014-07-15 12:52:19 -070052# Host install just puts everything where it's told
Bill Richardsonefa87562014-09-11 10:41:51 -070053UB_DIR=${DESTDIR}/bin
54VB_DIR=${DESTDIR}/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080055else
Bill Richardsonefa87562014-09-11 10:41:51 -070056# Target install puts things into different places
Bill Richardson6f396152014-07-15 12:52:19 -070057UB_DIR=${DESTDIR}/usr/bin
Bill Richardsonc9bf3482013-02-13 14:38:29 -080058VB_DIR=${DESTDIR}/usr/share/vboot/bin
59endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -080060
Bill Richardsoneecc18f2013-01-17 15:28:17 -080061# Where to install the (exportable) executables for testing?
62TEST_INSTALL_DIR = ${BUILD}/install_for_test
63
64# Verbose? Use V=1
65ifeq (${V},)
66Q := @
67endif
68
Simon Glass661ae9e2013-03-26 11:39:21 -070069# Quiet? Use QUIET=1
70ifeq ($(QUIET),)
71PRINTF := printf
72else
73PRINTF := :
74endif
75
Randall Spangler61a2eb32013-01-23 10:20:16 -080076# Architecture detection
77_machname := $(shell uname -m)
78HOST_ARCH ?= ${_machname}
79
80# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
81# Pick a sane target architecture if none is defined.
82ifeq (${ARCH},)
83 ARCH := ${HOST_ARCH}
84else ifeq (${ARCH},i386)
85 override ARCH := x86
86else ifeq (${ARCH},amd64)
87 override ARCH := x86_64
88endif
89
90# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
91# for a firmware target (such as u-boot or depthcharge). It must map
92# to the same consistent set of architectures as the host.
93ifeq (${FIRMWARE_ARCH},i386)
94 override FIRMWARE_ARCH := x86
95else ifeq (${FIRMWARE_ARCH},amd64)
96 override FIRMWARE_ARCH := x86_64
Stefan Reinauerd96b25d2013-09-19 14:24:29 -070097else ifeq (${FIRMWARE_ARCH},armv7)
98 override FIRMWARE_ARCH := arm
Randall Spangler61a2eb32013-01-23 10:20:16 -080099endif
100
Simon Glassb265c342011-11-16 15:09:51 -0800101# Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
102# please add them after this point (e.g., -DVBOOT_DEBUG).
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700103#
Che-Liang Chiou6b0003c2011-10-14 11:11:28 +0800104# TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
105# temporarily. As we are still investigating which flags are necessary for
106# maintaining a compatible ABI, etc. between u-boot and vboot_reference.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700107#
Simon Glassb265c342011-11-16 15:09:51 -0800108# As a first step, this makes the setting of CC and CFLAGS here optional, to
109# permit a calling script or Makefile to set these.
Che-Liang Chiou74359b72011-06-21 15:25:51 -0700110#
Simon Glassb265c342011-11-16 15:09:51 -0800111# Flag ordering: arch, then -f, then -m, then -W
112DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
113COMMON_FLAGS := -nostdinc -pipe \
114 -ffreestanding -fno-builtin -fno-stack-protector \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800115 -Werror -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
Simon Glassb265c342011-11-16 15:09:51 -0800116
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800117# Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
118ifeq (${FIRMWARE_ARCH}, arm)
Simon Glassb265c342011-11-16 15:09:51 -0800119CC ?= armv7a-cros-linux-gnueabi-gcc
120CFLAGS ?= -march=armv5 \
121 -fno-common -ffixed-r8 \
Doug Andersond50b27d2012-05-11 12:08:02 -0700122 -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800123 ${COMMON_FLAGS}
Randall Spangler61a2eb32013-01-23 10:20:16 -0800124else ifeq (${FIRMWARE_ARCH}, x86)
Simon Glassb265c342011-11-16 15:09:51 -0800125CC ?= i686-pc-linux-gnu-gcc
126# Drop -march=i386 to permit use of SSE instructions
127CFLAGS ?= \
128 -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
129 -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
Gabe Black46e00e62013-12-18 18:23:24 -0800130 -mpreferred-stack-boundary=2 \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800131 ${COMMON_FLAGS}
132else ifeq (${FIRMWARE_ARCH}, x86_64)
133CFLAGS ?= ${COMMON_FLAGS} \
Simon Glass8e85e982011-11-22 13:54:50 -0800134 -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
Randall Spangler844bce52013-01-15 16:16:43 -0800135else
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800136# FIRMWARE_ARCH not defined; assuming local compile.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800137CC ?= gcc
Bill Richardsond4621012014-07-09 23:31:13 -0700138CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall -Werror ${DEBUG_FLAGS}
Che-Liang Chiou34be8272011-01-27 16:44:36 +0800139endif
140
141ifneq (${DEBUG},)
142CFLAGS += -DVBOOT_DEBUG
vbendebb2b0fcc2010-07-15 15:09:47 -0700143endif
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800144
vbendebb2b0fcc2010-07-15 15:09:47 -0700145ifeq (${DISABLE_NDEBUG},)
146CFLAGS += -DNDEBUG
147endif
148
Bill Richardsonfeb25182013-03-07 12:54:29 -0800149ifneq (${FORCE_LOGGING_ON},)
150CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
151endif
152
Randall Spangler6014c042014-07-22 14:42:58 -0700153ifneq (${PD_SYNC},)
154CFLAGS += -DPD_SYNC
155endif
156
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800157# Create / use dependency files
158CFLAGS += -MMD -MF $@.d
Simon Glassb265c342011-11-16 15:09:51 -0800159
Bertrand SIMONNETf8f807a2014-06-30 09:41:13 -0700160ifeq (${FIRMWARE_ARCH},)
161# Creates position independent code for non firmware target.
162CFLAGS += -fPIE
163endif
164
Bill Richardson0c3ba242013-03-29 11:09:30 -0700165# These are required to access large disks and files on 32-bit systems.
166CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
167
Randall Spangler59d75082013-01-23 09:29:54 -0800168# Code coverage
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800169ifneq (${COV},)
Bill Richardsond2d08b22014-07-08 16:31:40 -0700170 COV_FLAGS = -O0 --coverage -DCOVERAGE
Randall Spangler59d75082013-01-23 09:29:54 -0800171 CFLAGS += ${COV_FLAGS}
172 LDFLAGS += ${COV_FLAGS}
173 COV_INFO = ${BUILD}/coverage.info
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800174endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800175
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800176# And a few more default utilities
177LD = ${CC}
Bill Richardson6df3e332014-10-02 18:50:33 -0700178CXX ?= g++
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800179PKG_CONFIG ?= pkg-config
180
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800181# Determine QEMU architecture needed, if any
182ifeq (${ARCH},${HOST_ARCH})
183 # Same architecture; no need for QEMU
184 QEMU_ARCH :=
Randall Spangler61a2eb32013-01-23 10:20:16 -0800185else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800186 # 64-bit host can run 32-bit targets directly
187 QEMU_ARCH :=
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800188else
189 QEMU_ARCH := ${ARCH}
190endif
191
192# The top of the chroot for qemu must be passed in via the SYSROOT environment
193# variable. In the Chromium OS chroot, this is done automatically by the
194# ebuild.
195
196ifeq (${QEMU_ARCH},)
197 # Path to build output for running tests is same as for building
198 BUILD_RUN = ${BUILD}
Randall Spanglere061a252013-01-22 15:34:07 -0800199 SRC_RUN = ${SRCDIR}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800200else
201 $(info Using qemu for testing.)
202 # Path to build output for running tests is different in the chroot
203 BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
Randall Spanglere061a252013-01-22 15:34:07 -0800204 SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800205
206 QEMU_BIN = qemu-${QEMU_ARCH}
Randall Spanglere061a252013-01-22 15:34:07 -0800207 QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
208 export QEMU_RUN
209
210 RUNTEST = tests/test_using_qemu.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800211endif
212
Randall Spanglere061a252013-01-22 15:34:07 -0800213export BUILD_RUN
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800214
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800215##############################################################################
216# Now we need to describe everything we might want or need to build
217
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800218# Everything wants these headers.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800219INCLUDES += \
220 -Ifirmware/include \
221 -Ifirmware/lib/include \
222 -Ifirmware/lib/cgptlib/include \
223 -Ifirmware/lib/cryptolib/include \
Randall Spangler786acda2014-05-22 13:27:07 -0700224 -Ifirmware/lib/tpm_lite/include \
225 -Ifirmware/2lib/include
Bill Richardson0b8f35c2010-05-26 09:18:38 -0700226
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800227# If we're not building for a specific target, just stub out things like the
228# TPM commands and various external functions that are provided by the BIOS.
229ifeq (${FIRMWARE_ARCH},)
Bill Richardson0e6ae292014-08-26 10:34:40 -0700230INCLUDES += -Ihost/include -Ihost/lib/include
Che-Liang Chiou0a0e8d02010-11-30 09:30:45 +0800231endif
Gaurav Shah322536d2010-01-28 15:01:23 -0800232
Bill Richardson78299022014-06-20 14:33:00 -0700233# Firmware library, used by the other firmware components (depthcharge,
234# coreboot, etc.). It doesn't need exporting to some other place; they'll build
235# this source tree locally and link to it directly.
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800236FWLIB = ${BUILD}/vboot_fw.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800237
Randall Spangler786acda2014-05-22 13:27:07 -0700238# Smaller firmware library. TODO: Do we still need to export this?
Randall Spangleraaaff862014-12-01 15:40:08 -0800239FWLIB20 = ${BUILD}/vboot_fw2.a
Randall Spanglera5b69b02014-12-02 13:41:29 -0800240FWLIB21 = ${BUILD}/vboot_fw21.a
Randall Spangler786acda2014-05-22 13:27:07 -0700241
Randall Spangler93943262013-02-26 11:03:57 -0800242# Firmware library sources needed by VbInit() call
243VBINIT_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800244 firmware/lib/crc8.c \
Randall Spangler93943262013-02-26 11:03:57 -0800245 firmware/lib/utility.c \
246 firmware/lib/vboot_api_init.c \
247 firmware/lib/vboot_common_init.c \
248 firmware/lib/vboot_nvstorage.c \
Bill Richardson78299022014-06-20 14:33:00 -0700249 firmware/lib/vboot_nvstorage_rollback.c \
Simon Glass527ba812013-07-25 08:48:47 -0600250 firmware/lib/region-init.c \
Randall Spangler93943262013-02-26 11:03:57 -0800251
252# Additional firmware library sources needed by VbSelectFirmware() call
253VBSF_SRCS = \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800254 firmware/lib/cryptolib/padding.c \
255 firmware/lib/cryptolib/rsa.c \
256 firmware/lib/cryptolib/rsa_utility.c \
257 firmware/lib/cryptolib/sha1.c \
258 firmware/lib/cryptolib/sha256.c \
259 firmware/lib/cryptolib/sha512.c \
260 firmware/lib/cryptolib/sha_utility.c \
261 firmware/lib/stateful_util.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800262 firmware/lib/vboot_api_firmware.c \
Randall Spangler93943262013-02-26 11:03:57 -0800263 firmware/lib/vboot_common.c \
Simon Glass527ba812013-07-25 08:48:47 -0600264 firmware/lib/vboot_firmware.c \
265 firmware/lib/region-fw.c \
Randall Spangler93943262013-02-26 11:03:57 -0800266
267# Additional firmware library sources needed by VbSelectAndLoadKernel() call
268VBSLK_SRCS = \
269 firmware/lib/cgptlib/cgptlib.c \
270 firmware/lib/cgptlib/cgptlib_internal.c \
271 firmware/lib/cgptlib/crc32.c \
Dan Ehrenberg7c2beb02014-10-21 16:15:54 -0700272 firmware/lib/gpt_misc.c \
Randall Spangler93943262013-02-26 11:03:57 -0800273 firmware/lib/utility_string.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800274 firmware/lib/vboot_api_kernel.c \
275 firmware/lib/vboot_audio.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800276 firmware/lib/vboot_display.c \
Simon Glass527ba812013-07-25 08:48:47 -0600277 firmware/lib/vboot_kernel.c \
278 firmware/lib/region-kernel.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800279
Randall Spangler786acda2014-05-22 13:27:07 -0700280# Firmware library source needed for smaller library 2
Randall Spangler108d9912014-12-02 15:55:56 -0800281FWLIB2_SRCS = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700282 firmware/2lib/2api.c \
Randall Spangler786acda2014-05-22 13:27:07 -0700283 firmware/2lib/2common.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700284 firmware/2lib/2crc8.c \
285 firmware/2lib/2misc.c \
286 firmware/2lib/2nvstorage.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700287 firmware/2lib/2rsa.c \
Randall Spangler3333e572014-05-14 11:37:52 -0700288 firmware/2lib/2secdata.c \
Randall Spanglere166d042014-05-13 09:24:52 -0700289 firmware/2lib/2sha1.c \
290 firmware/2lib/2sha256.c \
291 firmware/2lib/2sha512.c \
Randall Spanglera5b69b02014-12-02 13:41:29 -0800292 firmware/2lib/2sha_utility.c
293
Randall Spangler108d9912014-12-02 15:55:56 -0800294FWLIB20_SRCS = \
295 firmware/2lib/2packed_key.c
296
Randall Spanglera5b69b02014-12-02 13:41:29 -0800297FWLIB21_SRCS = \
298 firmware/lib21/api.c \
299 firmware/lib21/common.c \
300 firmware/lib21/misc.c \
301 firmware/lib21/packed_key.c
Randall Spangler786acda2014-05-22 13:27:07 -0700302
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800303# Support real TPM unless BIOS sets MOCK_TPM
304ifeq (${MOCK_TPM},)
Randall Spangler93943262013-02-26 11:03:57 -0800305VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800306 firmware/lib/rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800307 firmware/lib/tpm_lite/tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800308
309VBSF_SRCS += \
310 firmware/lib/tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800311else
Randall Spangler93943262013-02-26 11:03:57 -0800312VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800313 firmware/lib/mocked_rollback_index.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800314 firmware/lib/tpm_lite/mocked_tlcl.c
Randall Spangler93943262013-02-26 11:03:57 -0800315
316VBSF_SRCS += \
317 firmware/lib/mocked_tpm_bootmode.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800318endif
319
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800320ifeq (${FIRMWARE_ARCH},)
321# Include BIOS stubs in the firmware library when compiling for host
Randall Spangler93943262013-02-26 11:03:57 -0800322# TODO: split out other stub funcs too
323VBINIT_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800324 firmware/stub/tpm_lite_stub.c \
325 firmware/stub/utility_stub.c \
Simon Glass527ba812013-07-25 08:48:47 -0600326 firmware/stub/vboot_api_stub_init.c \
327 firmware/stub/vboot_api_stub_region.c
Randall Spangler93943262013-02-26 11:03:57 -0800328
329VBSF_SRCS += \
330 firmware/stub/vboot_api_stub_sf.c
331
332VBSLK_SRCS += \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800333 firmware/stub/vboot_api_stub.c \
Dan Ehrenberg5dc75d12014-10-07 14:55:37 -0700334 firmware/stub/vboot_api_stub_disk.c \
335 firmware/stub/vboot_api_stub_stream.c
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700336
Randall Spangler108d9912014-12-02 15:55:56 -0800337FWLIB2_SRCS += \
Randall Spanglerda2b49c2014-06-10 17:03:40 -0700338 firmware/2lib/2stub.c
339
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800340endif
341
Randall Spangler93943262013-02-26 11:03:57 -0800342VBSF_SRCS += ${VBINIT_SRCS}
343FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
344
345VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
346VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800347ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800348
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800349FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler108d9912014-12-02 15:55:56 -0800350FWLIB2_OBJS = ${FWLIB2_SRCS:%.c=${BUILD}/%.o}
Randall Spangleraaaff862014-12-01 15:40:08 -0800351FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800352FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
Randall Spangler108d9912014-12-02 15:55:56 -0800353ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800354
Bill Richardson78299022014-06-20 14:33:00 -0700355# Intermediate library for the vboot_reference utilities to link against.
356UTILLIB = ${BUILD}/libvboot_util.a
Randall Spangler108d9912014-12-02 15:55:56 -0800357UTILLIB21 = ${BUILD}/libvboot_util21.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800358
Bill Richardson78299022014-06-20 14:33:00 -0700359UTILLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800360 cgpt/cgpt_create.c \
361 cgpt/cgpt_add.c \
362 cgpt/cgpt_boot.c \
363 cgpt/cgpt_show.c \
364 cgpt/cgpt_repair.c \
365 cgpt/cgpt_prioritize.c \
366 cgpt/cgpt_common.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700367 futility/dump_kernel_config_lib.c \
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800368 host/arch/${ARCH}/lib/crossystem_arch.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800369 host/lib/crossystem.c \
370 host/lib/file_keys.c \
371 host/lib/fmap.c \
372 host/lib/host_common.c \
373 host/lib/host_key.c \
374 host/lib/host_keyblock.c \
375 host/lib/host_misc.c \
Bill Richardson78299022014-06-20 14:33:00 -0700376 host/lib/util_misc.c \
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800377 host/lib/host_signature.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700378 host/lib/signature_digest.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800379
Randall Spangleraaaff862014-12-01 15:40:08 -0800380UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
381ALL_OBJS += ${UTILLIB_OBJS}
382
Randall Spanglera5b69b02014-12-02 13:41:29 -0800383UTILLIB21_SRCS += \
384 host/lib21/host_fw_preamble.c \
385 host/lib21/host_key.c \
386 host/lib21/host_keyblock.c \
387 host/lib21/host_misc.c \
388 host/lib21/host_signature.c
Randall Spangler02e11b32014-11-19 12:48:36 -0800389
Randall Spanglera5b69b02014-12-02 13:41:29 -0800390UTILLIB21_OBJS = ${UTILLIB21_SRCS:%.c=${BUILD}/%.o}
391ALL_OBJS += ${UTILLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700392
393# Externally exported library for some target userspace apps to link with
394# (cryptohome, updater, etc.)
395HOSTLIB = ${BUILD}/libvboot_host.a
396
397HOSTLIB_SRCS = \
398 cgpt/cgpt_add.c \
399 cgpt/cgpt_boot.c \
400 cgpt/cgpt_common.c \
401 cgpt/cgpt_create.c \
402 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700403 firmware/lib/cgptlib/cgptlib_internal.c \
404 firmware/lib/cgptlib/crc32.c \
Bill Richardson78299022014-06-20 14:33:00 -0700405 firmware/lib/crc8.c \
Bill Richardson78299022014-06-20 14:33:00 -0700406 firmware/lib/tpm_lite/tlcl.c \
407 firmware/lib/utility_string.c \
408 firmware/lib/vboot_nvstorage.c \
409 firmware/stub/tpm_lite_stub.c \
410 firmware/stub/utility_stub.c \
411 firmware/stub/vboot_api_stub_init.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700412 futility/dump_kernel_config_lib.c \
Bill Richardson78299022014-06-20 14:33:00 -0700413 host/arch/${ARCH}/lib/crossystem_arch.c \
414 host/lib/crossystem.c \
Nam T. Nguyen6ee52d92014-10-24 13:20:39 -0700415 host/lib/fmap.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700416 host/lib/host_misc.c
Bill Richardson78299022014-06-20 14:33:00 -0700417
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800418HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800419ALL_OBJS += ${HOSTLIB_OBJS}
420
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800421# Sigh. For historical reasons, the autoupdate installer must sometimes be a
422# 32-bit executable, even when everything else is 64-bit. But it only needs a
423# few functions, so let's just build those.
424TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
425
426TINYHOSTLIB_SRCS = \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800427 cgpt/cgpt_add.c \
428 cgpt/cgpt_boot.c \
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800429 cgpt/cgpt_common.c \
Bill Richardson78299022014-06-20 14:33:00 -0700430 cgpt/cgpt_create.c \
431 cgpt/cgpt_prioritize.c \
Bill Richardson78299022014-06-20 14:33:00 -0700432 firmware/lib/cgptlib/cgptlib_internal.c \
433 firmware/lib/cgptlib/crc32.c \
Bill Richardson5fed2a62013-03-04 15:11:38 -0800434 firmware/lib/utility_string.c \
Bill Richardson78299022014-06-20 14:33:00 -0700435 firmware/stub/utility_stub.c \
Nam T. Nguyenab899592014-11-13 19:30:46 -0800436 futility/dump_kernel_config_lib.c
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800437
438TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800439
440# ----------------------------------------------------------------------------
441# Now for the userspace binaries
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800442
443CGPT = ${BUILD}/cgpt/cgpt
444
445CGPT_SRCS = \
446 cgpt/cgpt.c \
447 cgpt/cgpt_add.c \
448 cgpt/cgpt_boot.c \
449 cgpt/cgpt_common.c \
450 cgpt/cgpt_create.c \
451 cgpt/cgpt_find.c \
452 cgpt/cgpt_legacy.c \
453 cgpt/cgpt_prioritize.c \
454 cgpt/cgpt_repair.c \
455 cgpt/cgpt_show.c \
456 cgpt/cmd_add.c \
457 cgpt/cmd_boot.c \
458 cgpt/cmd_create.c \
459 cgpt/cmd_find.c \
460 cgpt/cmd_legacy.c \
461 cgpt/cmd_prioritize.c \
462 cgpt/cmd_repair.c \
Nam T. Nguyen8577b532014-11-25 13:26:53 -0800463 cgpt/cmd_show.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800464
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800465CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800466ALL_OBJS += ${CGPT_OBJS}
467
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800468
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800469# Scripts to install directly (not compiled)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800470UTIL_SCRIPTS = \
471 utility/dev_debug_vboot \
Bill Richardson4d49d342014-10-02 10:52:41 -0700472 utility/enable_dev_usb_boot
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800473
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800474ifeq (${MINIMAL},)
475UTIL_SCRIPTS += \
Bill Richardson4d49d342014-10-02 10:52:41 -0700476 utility/dev_make_keypair \
477 utility/vbutil_what_keys
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800478endif
479
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800480# These utilities should be linked statically.
481UTIL_NAMES_STATIC = \
Bill Richardson6f396152014-07-15 12:52:19 -0700482 utility/crossystem
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800483
484UTIL_NAMES = ${UTIL_NAMES_STATIC} \
Bill Richardson339f7e02013-04-05 09:49:24 -0700485 utility/tpm_init_temp_fix \
Duncan Laurie0f078672014-09-19 14:39:09 -0700486 utility/dumpRSAPublicKey \
Bill Richardson6f396152014-07-15 12:52:19 -0700487 utility/tpmc
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800488
Bill Richardson6f396152014-07-15 12:52:19 -0700489# TODO: Do we still need eficompress and efidecompress for anything?
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800490ifeq (${MINIMAL},)
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800491UTIL_NAMES += \
Bill Richardson339f7e02013-04-05 09:49:24 -0700492 utility/bmpblk_font \
493 utility/bmpblk_utility \
494 utility/eficompress \
495 utility/efidecompress \
496 utility/load_kernel_test \
497 utility/pad_digest_utility \
498 utility/signature_digest_utility \
499 utility/verify_data
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700500
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800501endif
502
Bill Richardson339f7e02013-04-05 09:49:24 -0700503UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
504UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
Bill Richardson1912bba2013-04-04 21:08:50 -0700505ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800506
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800507
508# Scripts for signing stuff.
509SIGNING_SCRIPTS = \
510 utility/tpm-nvsize \
511 utility/chromeos-tpm-recovery
512
513# These go in a different place.
514SIGNING_SCRIPTS_DEV = \
515 scripts/image_signing/resign_firmwarefd.sh \
516 scripts/image_signing/make_dev_firmware.sh \
517 scripts/image_signing/make_dev_ssd.sh \
518 scripts/image_signing/set_gbb_flags.sh
519
520# Installed, but not made executable.
521SIGNING_COMMON = scripts/image_signing/common_minimal.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800522
Bill Richardson826db092013-01-14 12:37:15 -0800523
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800524# The unified firmware utility will eventually replace all the others
525FUTIL_BIN = ${BUILD}/futility/futility
Bill Richardson6db8c752013-04-05 13:30:43 -0700526# But we still need both static (tiny) and dynamic (with openssl) versions.
527FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800528
Bill Richardson6f396152014-07-15 12:52:19 -0700529# These are the executables that are now built in to futility. We'll create
530# symlinks for these so the old names will still work.
531# TODO: Do we still need dev_sign_file for anything?
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700532FUTIL_SYMLINKS = \
Bill Richardsone1550442014-07-17 11:32:17 -0700533 dev_sign_file \
Bill Richardsone1550442014-07-17 11:32:17 -0700534 dump_fmap \
535 dump_kernel_config \
Bill Richardsone1550442014-07-17 11:32:17 -0700536 gbb_utility \
Bill Richardsone1550442014-07-17 11:32:17 -0700537 vbutil_firmware \
538 vbutil_kernel \
539 vbutil_key \
Bill Richardson6f396152014-07-15 12:52:19 -0700540 vbutil_keyblock
Bill Richardsonfeb25182013-03-07 12:54:29 -0800541
Bill Richardson6db8c752013-04-05 13:30:43 -0700542FUTIL_STATIC_SRCS = \
Bill Richardsonfeb25182013-03-07 12:54:29 -0800543 futility/futility.c \
Bill Richardson20807b62013-04-09 10:15:26 -0700544 futility/cmd_dump_fmap.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700545 futility/cmd_gbb_utility.c \
546 futility/misc.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800547
Bill Richardson6db8c752013-04-05 13:30:43 -0700548FUTIL_SRCS = \
549 $(FUTIL_STATIC_SRCS) \
Bill Richardson6f396152014-07-15 12:52:19 -0700550 futility/cmd_dev_sign_file.c \
551 futility/cmd_dump_kernel_config.c \
Bill Richardson2e25e812014-09-03 11:34:27 -0700552 futility/cmd_load_fmap.c \
Bill Richardsonf4f395e2014-10-22 17:42:20 -0700553 futility/cmd_pcr.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700554 futility/cmd_show.c \
555 futility/cmd_sign.c \
Bill Richardson6f396152014-07-15 12:52:19 -0700556 futility/cmd_vbutil_firmware.c \
557 futility/cmd_vbutil_kernel.c \
Bill Richardsonf1dba022014-10-01 14:10:45 -0700558 futility/cmd_vbutil_kernel0.c \
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700559 futility/cmd_vbutil_key.c \
Randall Spanglerb8ff3972014-08-27 13:34:35 -0700560 futility/cmd_vbutil_keyblock.c \
Bill Richardsoncf6e78d2014-08-27 15:50:25 -0700561 futility/cmd_verify_kernel.c \
Bill Richardsonf318ee22014-09-23 14:30:30 -0700562 futility/traversal.c \
563 futility/vb1_helper.c
Bill Richardson6db8c752013-04-05 13:30:43 -0700564
Randall Spangler028f4682014-08-19 14:42:08 -0700565ifneq (${VBOOT2},)
566FUTIL_SRCS += \
567 futility/cmd_vb2_verify_fw.c
568endif
569
Alex Deymoe08ee282014-08-29 01:07:48 -0700570# List of commands built in futility and futility_s.
571FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
572FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800573
Bill Richardson91852e72014-11-28 12:28:04 -0800574# Workaround for TODO(crbug.com/437107).
575FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
576
Alex Deymoe08ee282014-08-29 01:07:48 -0700577FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
Bill Richardson91852e72014-11-28 12:28:04 -0800578 ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
Alex Deymoe08ee282014-08-29 01:07:48 -0700579 ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
580FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800581
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800582ALL_OBJS += ${FUTIL_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800583
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800584
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800585# Library of handy test functions.
586TESTLIB = ${BUILD}/tests/test.a
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800587
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800588TESTLIB_SRCS = \
589 tests/test_common.c \
590 tests/timer_utils.c \
591 tests/crc32_test.c
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800592
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800593TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
Bill Richardson80872db2014-10-03 10:26:11 -0700594TEST_OBJS += ${TESTLIB_OBJS}
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800595
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800596
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800597# And some compiled tests.
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800598TEST_NAMES = \
Bill Richardson339f7e02013-04-05 09:49:24 -0700599 tests/cgptlib_test \
600 tests/rollback_index2_tests \
601 tests/rollback_index3_tests \
602 tests/rsa_padding_test \
603 tests/rsa_utility_tests \
604 tests/rsa_verify_benchmark \
605 tests/sha_benchmark \
606 tests/sha_tests \
607 tests/stateful_util_tests \
608 tests/tlcl_tests \
609 tests/tpm_bootmode_tests \
610 tests/utility_string_tests \
611 tests/utility_tests \
612 tests/vboot_api_init_tests \
613 tests/vboot_api_devmode_tests \
614 tests/vboot_api_firmware_tests \
615 tests/vboot_api_kernel_tests \
616 tests/vboot_api_kernel2_tests \
617 tests/vboot_api_kernel3_tests \
618 tests/vboot_api_kernel4_tests \
619 tests/vboot_audio_tests \
620 tests/vboot_common_tests \
621 tests/vboot_common2_tests \
622 tests/vboot_common3_tests \
623 tests/vboot_display_tests \
624 tests/vboot_firmware_tests \
625 tests/vboot_kernel_tests \
626 tests/vboot_nvstorage_test \
Bill Richardson6f396152014-07-15 12:52:19 -0700627 tests/futility/binary_editor \
Bill Richardson339f7e02013-04-05 09:49:24 -0700628 tests/futility/test_not_really
Randall Spangler5d9bbf22013-01-08 10:44:23 -0800629
Simon Glass527ba812013-07-25 08:48:47 -0600630ifdef REGION_READ
631TEST_NAMES += tests/vboot_region_tests
632endif
633
Randall Spangleraaaff862014-12-01 15:40:08 -0800634TEST20_NAMES = \
Randall Spanglera7ab8b52014-06-10 17:05:08 -0700635 tests/vb2_api_tests \
Randall Spangler786acda2014-05-22 13:27:07 -0700636 tests/vb2_common_tests \
Randall Spangler7141d732014-05-15 15:34:54 -0700637 tests/vb2_common2_tests \
638 tests/vb2_common3_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700639 tests/vb2_misc_tests \
Randall Spangler18030682014-06-11 16:01:08 -0700640 tests/vb2_misc2_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700641 tests/vb2_nvstorage_tests \
Randall Spanglere166d042014-05-13 09:24:52 -0700642 tests/vb2_rsa_padding_tests \
643 tests/vb2_rsa_utility_tests \
Randall Spangler3333e572014-05-14 11:37:52 -0700644 tests/vb2_secdata_tests \
Randall Spangler108d9912014-12-02 15:55:56 -0800645 tests/vb2_sha_tests
646
647TEST21_NAMES = \
648 tests/vb21_api_tests \
649 tests/vb21_common_tests \
650 tests/vb21_common2_tests \
651 tests/vb21_misc_tests \
652 tests/vb21_host_fw_preamble_tests \
653 tests/vb21_host_key_tests \
654 tests/vb21_host_keyblock_tests \
655 tests/vb21_host_misc_tests \
656 tests/vb21_host_sig_tests
Randall Spangler786acda2014-05-22 13:27:07 -0700657
Randall Spangleraaaff862014-12-01 15:40:08 -0800658ifneq (${VBOOT2},)
Randall Spangler108d9912014-12-02 15:55:56 -0800659TEST_NAMES += ${TEST20_NAMES} ${TEST21_NAMES}
Randall Spangler786acda2014-05-22 13:27:07 -0700660endif
661
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800662# And a few more...
Bill Richardson339f7e02013-04-05 09:49:24 -0700663TLCL_TEST_NAMES = \
664 tests/tpm_lite/tpmtest_earlyextend \
665 tests/tpm_lite/tpmtest_earlynvram \
666 tests/tpm_lite/tpmtest_earlynvram2 \
667 tests/tpm_lite/tpmtest_enable \
668 tests/tpm_lite/tpmtest_fastenable \
669 tests/tpm_lite/tpmtest_globallock \
670 tests/tpm_lite/tpmtest_redefine_unowned \
671 tests/tpm_lite/tpmtest_spaceperm \
672 tests/tpm_lite/tpmtest_testsetup \
673 tests/tpm_lite/tpmtest_timing \
674 tests/tpm_lite/tpmtest_writelimit
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800675
676TEST_NAMES += ${TLCL_TEST_NAMES}
677
Bill Richardson339f7e02013-04-05 09:49:24 -0700678# Finally
679TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
Bill Richardson80872db2014-10-03 10:26:11 -0700680TEST_OBJS += $(addsuffix .o,${TEST_BINS})
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800681
Randall Spangleraaaff862014-12-01 15:40:08 -0800682TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
Randall Spangler108d9912014-12-02 15:55:56 -0800683TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
Randall Spangleraaaff862014-12-01 15:40:08 -0800684
Randall Spanglere061a252013-01-22 15:34:07 -0800685# Directory containing test keys
686TEST_KEYS = ${SRC_RUN}/tests/testkeys
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800687
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800688
689##############################################################################
690# Finally, some targets. High-level ones first.
691
692# Create output directories if necessary. Do this via explicit shell commands
693# so it happens before trying to generate/include dependencies.
694SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
695_dir_create := $(foreach d, \
696 $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
697 $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
698
699
700# Default target.
701.PHONY: all
Randall Spangleraaaff862014-12-01 15:40:08 -0800702all: fwlib \
Randall Spanglera5b69b02014-12-02 13:41:29 -0800703 $(if ${VBOOT2},fwlib2 fwlib21) \
Randall Spangleraaaff862014-12-01 15:40:08 -0800704 $(if ${FIRMWARE_ARCH},,host_stuff) \
Randall Spangler786acda2014-05-22 13:27:07 -0700705 $(if ${COV},coverage)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800706
707# Host targets
708.PHONY: host_stuff
Randall Spanglera5b69b02014-12-02 13:41:29 -0800709host_stuff: utillib hostlib cgpt utils futil tests $(if ${VBOOT2},utillib21)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800710
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800711.PHONY: clean
712clean:
713 ${Q}/bin/rm -rf ${BUILD}
714
715.PHONY: install
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800716install: cgpt_install utils_install signing_install futil_install
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800717
Bill Richardson3e3790d2014-07-14 15:05:54 -0700718.PHONY: install_for_test
719install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
720install_for_test: install
721
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800722# Don't delete intermediate object files
723.SECONDARY:
724
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800725# ----------------------------------------------------------------------------
726# Firmware library
727
728# TPM-specific flags. These depend on the particular TPM we're targeting for.
729# They are needed here only for compiling parts of the firmware code into
730# user-level tests.
731
732# TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
733# the self test has completed.
734
Randall Spangler45cc0f22013-01-25 09:34:26 -0800735${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800736
737# TPM_MANUAL_SELFTEST is defined if the self test must be started manually
738# (with a call to TPM_ContinueSelfTest) instead of starting automatically at
739# power on.
740#
741# We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
742# are not both defined at the same time. (See comment in code.)
743
744# CFLAGS += -DTPM_MANUAL_SELFTEST
745
746ifeq (${FIRMWARE_ARCH},i386)
747# Unrolling loops in cryptolib makes it faster
Randall Spangler45cc0f22013-01-25 09:34:26 -0800748${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangler108d9912014-12-02 15:55:56 -0800749${FWLIB2_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spangleraaaff862014-12-01 15:40:08 -0800750${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
Randall Spanglera5b69b02014-12-02 13:41:29 -0800751${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800752
753# Workaround for coreboot on x86, which will power off asynchronously
754# without giving us a chance to react. This is not an example of the Right
755# Way to do things. See chrome-os-partner:7689, and the commit message
756# that made this change.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800757${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800758
759# On x86 we don't actually read the GBB data into RAM until it is needed.
760# Therefore it makes sense to cache it rather than reading it each time.
761# Enable this feature.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800762${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800763endif
764
Simon Glass527ba812013-07-25 08:48:47 -0600765ifdef REGION_READ
766${FWLIB_OBJS}: CFLAGS += -DREGION_READ
767endif
768
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800769ifeq (${FIRMWARE_ARCH},)
770# Disable rollback TPM when compiling locally, since otherwise
771# load_kernel_test attempts to talk to the TPM.
Randall Spangler45cc0f22013-01-25 09:34:26 -0800772${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800773endif
774
Randall Spangler108d9912014-12-02 15:55:56 -0800775${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
776
Bill Richardsona130e0b2013-04-04 18:16:39 -0700777# Linktest ensures firmware lib doesn't rely on outside libraries
778${BUILD}/firmware/linktest/main_vbinit: ${VBINIT_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800779${BUILD}/firmware/linktest/main_vbinit: OBJS = ${VBINIT_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700780TEST_OBJS += ${BUILD}/firmware/linktest/main_vbinit.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700781${BUILD}/firmware/linktest/main_vbsf: ${VBSF_OBJS}
Randall Spangler93943262013-02-26 11:03:57 -0800782${BUILD}/firmware/linktest/main_vbsf: OBJS = ${VBSF_OBJS}
Bill Richardson80872db2014-10-03 10:26:11 -0700783TEST_OBJS += ${BUILD}/firmware/linktest/main_vbsf.o
Bill Richardsona130e0b2013-04-04 18:16:39 -0700784${BUILD}/firmware/linktest/main: ${FWLIB}
785${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700786TEST_OBJS += ${BUILD}/firmware/linktest/main.o
Randall Spangler93943262013-02-26 11:03:57 -0800787
Bill Richardsond2d08b22014-07-08 16:31:40 -0700788.PHONY: fwlinktest
789fwlinktest: \
Randall Spangler93943262013-02-26 11:03:57 -0800790 ${BUILD}/firmware/linktest/main_vbinit \
791 ${BUILD}/firmware/linktest/main_vbsf \
792 ${BUILD}/firmware/linktest/main
793
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800794.PHONY: fwlib
Bill Richardsona130e0b2013-04-04 18:16:39 -0700795fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800796
797${FWLIB}: ${FWLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700798 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800799 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700800 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800801 ${Q}ar qc $@ $^
802
Randall Spanglera5b69b02014-12-02 13:41:29 -0800803.PHONY: fwlib2
804fwlib2: ${FWLIB20}
805
Randall Spangler108d9912014-12-02 15:55:56 -0800806${FWLIB20}: ${FWLIB2_OBJS} ${FWLIB20_OBJS}
Randall Spangler786acda2014-05-22 13:27:07 -0700807 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
808 ${Q}rm -f $@
809 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
810 ${Q}ar qc $@ $^
811
Randall Spanglera5b69b02014-12-02 13:41:29 -0800812.PHONY: fwlib21
813fwlib21: ${FWLIB21}
814
Randall Spangler108d9912014-12-02 15:55:56 -0800815${FWLIB21}: ${FWLIB2_OBJS} ${FWLIB21_OBJS}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800816 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
817 ${Q}rm -f $@
818 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
819 ${Q}ar qc $@ $^
820
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800821# ----------------------------------------------------------------------------
Bill Richardson78299022014-06-20 14:33:00 -0700822# Host library(s)
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800823
Bill Richardson78299022014-06-20 14:33:00 -0700824# Link tests for local utilities
825${BUILD}/host/linktest/main: ${UTILLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700826${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
Bill Richardson80872db2014-10-03 10:26:11 -0700827TEST_OBJS += ${BUILD}/host/linktest/main.o
Bill Richardson78299022014-06-20 14:33:00 -0700828
829.PHONY: utillib
830utillib: ${UTILLIB} \
831 ${BUILD}/host/linktest/main
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800832
833# TODO: better way to make .a than duplicating this recipe each time?
Randall Spangleraaaff862014-12-01 15:40:08 -0800834${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS}
835 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
836 ${Q}rm -f $@
837 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
838 ${Q}ar qc $@ $^
839
Randall Spanglera5b69b02014-12-02 13:41:29 -0800840.PHONY: utillib21
841utillib21: ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -0800842
Randall Spangler108d9912014-12-02 15:55:56 -0800843${UTILLIB21}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
Randall Spanglera5b69b02014-12-02 13:41:29 -0800844
845# TODO: right now, firmware lib 2.1 isn't a complete standalone copy
Randall Spangler108d9912014-12-02 15:55:56 -0800846${UTILLIB21}: ${UTILLIB21_OBJS} ${FWLIB2_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS}
Bill Richardson78299022014-06-20 14:33:00 -0700847 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
848 ${Q}rm -f $@
849 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
850 ${Q}ar qc $@ $^
851
852
853# Link tests for external repos
854${BUILD}/host/linktest/extern: ${HOSTLIB}
Bill Richardson78299022014-06-20 14:33:00 -0700855${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
856${BUILD}/host/linktest/extern: LDLIBS += -static
Bill Richardson80872db2014-10-03 10:26:11 -0700857TEST_OBJS += ${BUILD}/host/linktest/extern.o
Bill Richardson78299022014-06-20 14:33:00 -0700858
859.PHONY: hostlib
860hostlib: ${HOSTLIB} \
861 ${BUILD}/host/linktest/extern
862
863# TODO: better way to make .a than duplicating this recipe each time?
Bill Richardson78299022014-06-20 14:33:00 -0700864${HOSTLIB}: ${HOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700865 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800866 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700867 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800868 ${Q}ar qc $@ $^
869
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800870
871# Ugh. This is a very cut-down version of HOSTLIB just for the installer.
872.PHONY: tinyhostlib
873tinyhostlib: ${TINYHOSTLIB}
874 ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
875
876${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700877 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800878 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700879 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardson81a0b3d2013-02-28 13:53:09 -0800880 ${Q}ar qc $@ $^
881
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800882# ----------------------------------------------------------------------------
883# CGPT library and utility
884
885.PHONY: cgpt
886cgpt: ${CGPT}
887
888${CGPT}: LDFLAGS += -static
889${CGPT}: LDLIBS += -luuid
890
Bill Richardson78299022014-06-20 14:33:00 -0700891${CGPT}: ${CGPT_OBJS} ${UTILLIB}
Simon Glass661ae9e2013-03-26 11:39:21 -0700892 @$(PRINTF) " LDcgpt $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700893 ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800894
895.PHONY: cgpt_install
896cgpt_install: ${CGPT}
Simon Glass661ae9e2013-03-26 11:39:21 -0700897 @$(PRINTF) " INSTALL CGPT\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800898 ${Q}mkdir -p ${UB_DIR}
899 ${Q}${INSTALL} -t ${UB_DIR} $^
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800900
901# ----------------------------------------------------------------------------
902# Utilities
903
904# These have their own headers too.
Bill Richardson0f6679e2014-07-10 15:49:52 -0700905${BUILD}/utility/%: INCLUDES += -Iutility/include
906
907${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
908${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800909
910# Utilities for auto-update toolkits must be statically linked.
911${UTIL_BINS_STATIC}: LDFLAGS += -static
912
Bill Richardsona130e0b2013-04-04 18:16:39 -0700913
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800914.PHONY: utils
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800915utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800916 ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
917 ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
918
919.PHONY: utils_install
Bill Richardsonc7c6e5d2013-02-28 10:10:29 -0800920utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700921 @$(PRINTF) " INSTALL UTILS\n"
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800922 ${Q}mkdir -p ${UB_DIR}
923 ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800924
925# And some signing stuff for the target
926.PHONY: signing_install
927signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
Simon Glass661ae9e2013-03-26 11:39:21 -0700928 @$(PRINTF) " INSTALL SIGNING\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700929 ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
Bill Richardsonc9bf3482013-02-13 14:38:29 -0800930 ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
Bill Richardson6f396152014-07-15 12:52:19 -0700931 ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
932 ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800933
934# ----------------------------------------------------------------------------
935# new Firmware Utility
936
937.PHONY: futil
Bill Richardson6db8c752013-04-05 13:30:43 -0700938futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
939
Randall Spangleraaaff862014-12-01 15:40:08 -0800940${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB} \
Randall Spanglera5b69b02014-12-02 13:41:29 -0800941 $(if ${VBOOT2},${UTILLIB21})
Bill Richardson6db8c752013-04-05 13:30:43 -0700942 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
943 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800944
Bill Richardsonb84b81d2014-07-14 14:48:31 -0700945${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS}
Randall Spanglera5b69b02014-12-02 13:41:29 -0800946${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB} $(if ${VBOOT2},${UTILLIB21})
Simon Glass661ae9e2013-03-26 11:39:21 -0700947 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -0700948 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800949
950.PHONY: futil_install
Bill Richardsonefa87562014-09-11 10:41:51 -0700951futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Simon Glass661ae9e2013-03-26 11:39:21 -0700952 @$(PRINTF) " INSTALL futility\n"
Bill Richardson6f396152014-07-15 12:52:19 -0700953 ${Q}mkdir -p ${UB_DIR}
954 ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
Bill Richardsona1d9fe62014-09-05 12:52:27 -0700955 ${Q}for prog in ${FUTIL_SYMLINKS}; do \
Bill Richardson6f396152014-07-15 12:52:19 -0700956 ln -sf futility "${UB_DIR}/$$prog"; done
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800957
958# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800959# Utility to generate TLCL structure definition header file.
960
961${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
962
963STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
964STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
965
966.PHONY: update_tlcl_structures
967update_tlcl_structures: ${BUILD}/utility/tlcl_generator
Simon Glass661ae9e2013-03-26 11:39:21 -0700968 @$(PRINTF) " Rebuilding TLCL structures\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800969 ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
970 ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
971 ( echo "%% Updating structures.h %%" && \
972 cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
973
974# ----------------------------------------------------------------------------
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800975# Tests
976
977.PHONY: tests
978tests: ${TEST_BINS}
979
Bill Richardson78299022014-06-20 14:33:00 -0700980${TEST_BINS}: ${UTILLIB} ${TESTLIB}
Bill Richardson339f7e02013-04-05 09:49:24 -0700981${TEST_BINS}: INCLUDES += -Itests
Randall Spanglerefa37b82014-11-12 16:20:50 -0800982${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800983
Randall Spangler108d9912014-12-02 15:55:56 -0800984${TEST20_BINS}: ${FWLIB20}
985${TEST20_BINS}: LIBS += ${FWLIB20}
986
987${TEST21_BINS}: ${UTILLIB21}
988${TEST21_BINS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
989${TEST21_BINS}: LIBS += ${UTILLIB21}
Randall Spangleraaaff862014-12-01 15:40:08 -0800990
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800991${TESTLIB}: ${TESTLIB_OBJS}
Simon Glass661ae9e2013-03-26 11:39:21 -0700992 @$(PRINTF) " RM $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800993 ${Q}rm -f $@
Simon Glass661ae9e2013-03-26 11:39:21 -0700994 @$(PRINTF) " AR $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -0800995 ${Q}ar qc $@ $^
996
997
998# ----------------------------------------------------------------------------
999# Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1000# rules for specific targets.
1001
1002${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
Simon Glass661ae9e2013-03-26 11:39:21 -07001003 @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
Bill Richardson6db8c752013-04-05 13:30:43 -07001004 ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001005
1006${BUILD}/%.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -07001007 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001008 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1009
Alex Deymoe08ee282014-08-29 01:07:48 -07001010${BUILD}/%.o: ${BUILD}/%.c
1011 @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n"
1012 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1013
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001014# Rules to recompile a single source file for library and test
1015# TODO: is there a tidier way to do this?
1016${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1017${BUILD}/%_for_lib.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -07001018 @$(PRINTF) " CC-for-lib $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001019 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1020
1021${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1022${BUILD}/%_for_test.o: %.c
Simon Glass661ae9e2013-03-26 11:39:21 -07001023 @$(PRINTF) " CC-for-test $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001024 ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1025
1026# TODO: C++ files don't belong in vboot reference at all. Convert to C.
1027${BUILD}/%.o: %.cc
Simon Glass661ae9e2013-03-26 11:39:21 -07001028 @$(PRINTF) " CXX $(subst ${BUILD}/,,$@)\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001029 ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1030
1031# ----------------------------------------------------------------------------
1032# Here are the special tweaks to the generic rules.
1033
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001034# Some utilities need external crypto functions
Bill Richardson78299022014-06-20 14:33:00 -07001035CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1036
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001037${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1038${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1039${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001040
1041${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1042${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1043${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
Randall Spangler108d9912014-12-02 15:55:56 -08001044${BUILD}/tests/vb2_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1045${BUILD}/tests/vb2_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1046
1047${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001048
1049${BUILD}/utility/bmpblk_utility: LD = ${CXX}
1050${BUILD}/utility/bmpblk_utility: LDLIBS = -llzma -lyaml
1051
1052BMPBLK_UTILITY_DEPS = \
1053 ${BUILD}/utility/bmpblk_util.o \
1054 ${BUILD}/utility/image_types.o \
1055 ${BUILD}/utility/eficompress_for_lib.o \
1056 ${BUILD}/utility/efidecompress_for_lib.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001057
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001058${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1059${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
Bill Richardson1912bba2013-04-04 21:08:50 -07001060ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001061
1062${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1063${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
Bill Richardson1912bba2013-04-04 21:08:50 -07001064ALL_OBJS += ${BUILD}/utility/image_types.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001065
1066# Allow multiple definitions, so tests can mock functions from other libraries
1067${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001068${BUILD}/tests/%: LDLIBS += -lrt -luuid
1069${BUILD}/tests/%: LIBS += ${TESTLIB}
1070
1071${BUILD}/tests/rollback_index2_tests: OBJS += \
1072 ${BUILD}/firmware/lib/rollback_index_for_test.o
1073${BUILD}/tests/rollback_index2_tests: \
1074 ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001075TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001076
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001077${BUILD}/tests/tlcl_tests: OBJS += \
1078 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
1079${BUILD}/tests/tlcl_tests: \
1080 ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001081TEST_OBJS += ${BUILD}/firmware/lib/tpm_lite/tlcl_for_test.o
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001082
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001083${BUILD}/tests/vboot_audio_tests: OBJS += \
1084 ${BUILD}/firmware/lib/vboot_audio_for_test.o
1085${BUILD}/tests/vboot_audio_tests: \
1086 ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardson80872db2014-10-03 10:26:11 -07001087TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001088
Bill Richardson339f7e02013-04-05 09:49:24 -07001089TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001090${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1091${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardson80872db2014-10-03 10:26:11 -07001092TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001093
Alex Deymoe08ee282014-08-29 01:07:48 -07001094# ----------------------------------------------------------------------------
1095# Here are the special rules that don't fit in the generic rules.
1096
1097# Generates the list of commands defined in futility by running grep in the
1098# source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1099${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1100${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1101${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1102 @$(PRINTF) " GEN $(subst ${BUILD}/,,$@)\n"
1103 ${Q}rm -f $@ $@_t $@_commands
1104 ${Q}mkdir -p ${BUILD}/gen
Bill Richardson779796f2014-09-23 11:47:40 -07001105 ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
Alex Deymoe08ee282014-08-29 01:07:48 -07001106 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1107 | sort >>$@_commands
Bill Richardsone1486c32014-10-30 17:41:51 -07001108 ${Q}./scripts/getversion.sh >> $@_t
Alex Deymoe08ee282014-08-29 01:07:48 -07001109 ${Q}echo '#define _CMD(NAME) extern const struct' \
1110 'futil_cmd_t __cmd_##NAME;' >> $@_t
1111 ${Q}cat $@_commands >> $@_t
1112 ${Q}echo '#undef _CMD' >> $@_t
1113 ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1114 ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1115 ${Q}cat $@_commands >> $@_t
1116 ${Q}echo '0}; /* null-terminated */' >> $@_t
1117 ${Q}echo '#undef _CMD' >> $@_t
1118 ${Q}mv $@_t $@
1119 ${Q}rm -f $@_commands
1120
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001121##############################################################################
1122# Targets that exist just to run tests
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001123
1124# Frequently-run tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001125.PHONY: test_targets
Randall Spangler786acda2014-05-22 13:27:07 -07001126test_targets:: runcgpttests runmisctests $(if ${VBOOT2},run2tests)
Randall Spangler844bce52013-01-15 16:16:43 -08001127
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001128ifeq (${MINIMAL},)
Randall Spangler844bce52013-01-15 16:16:43 -08001129# Bitmap utility isn't compiled for minimal variant
Bill Richardsonfeb25182013-03-07 12:54:29 -08001130test_targets:: runbmptests runfutiltests
Randall Spangler844bce52013-01-15 16:16:43 -08001131# Scripts don't work under qemu testing
1132# TODO: convert scripts to makefile so they can be called directly
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001133test_targets:: runtestscripts
Randall Spangler844bce52013-01-15 16:16:43 -08001134endif
1135
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001136.PHONY: test_setup
Bill Richardson3e3790d2014-07-14 15:05:54 -07001137test_setup:: cgpt utils futil tests install_for_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001138
Randall Spangler844bce52013-01-15 16:16:43 -08001139# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
1140# sysroot.
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001141ifneq (${QEMU_ARCH},)
1142test_setup:: qemu_install
Randall Spangler844bce52013-01-15 16:16:43 -08001143
1144.PHONY: qemu_install
1145qemu_install:
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001146ifeq (${SYSROOT},)
1147 $(error SYSROOT must be set to the top of the target-specific root \
1148when cross-compiling for qemu-based tests to run properly.)
1149endif
Simon Glass661ae9e2013-03-26 11:39:21 -07001150 @$(PRINTF) " Copying qemu binary.\n"
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001151 ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1152 ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
Randall Spangler844bce52013-01-15 16:16:43 -08001153endif
1154
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001155.PHONY: runtests
Bill Richardsona130e0b2013-04-04 18:16:39 -07001156runtests: test_setup test_targets
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001157
1158# Generate test keys
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001159.PHONY: genkeys
Randall Spangler844bce52013-01-15 16:16:43 -08001160genkeys: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001161 tests/gen_test_keys.sh
1162
1163# Generate test cases for fuzzing
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001164.PHONY: genfuzztestcases
Randall Spanglera808dc92013-01-14 12:59:05 -08001165genfuzztestcases: utils
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001166 tests/gen_fuzz_test_cases.sh
1167
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001168.PHONY: runbmptests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001169runbmptests: test_setup
1170 cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001171 ./TestBmpBlock.py -v
1172
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001173.PHONY: runcgpttests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001174runcgpttests: test_setup
1175 ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001176
Randall Spangler844bce52013-01-15 16:16:43 -08001177.PHONY: runtestscripts
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001178runtestscripts: test_setup genfuzztestcases
Randall Spanglerb8ff3972014-08-27 13:34:35 -07001179 tests/load_kernel_tests.sh
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001180 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
Nam T. Nguyenab899592014-11-13 19:30:46 -08001181 tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001182 tests/run_preamble_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001183 tests/run_rsa_tests.sh
Randall Spangler844bce52013-01-15 16:16:43 -08001184 tests/run_vbutil_kernel_arg_tests.sh
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001185 tests/run_vbutil_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001186ifneq (${VBOOT2},)
1187 tests/vb2_rsa_tests.sh
Randall Spangler539cbc22014-06-18 14:15:04 -07001188 tests/vb2_firmware_tests.sh
Randall Spanglere166d042014-05-13 09:24:52 -07001189endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001190
Randall Spangler844bce52013-01-15 16:16:43 -08001191.PHONY: runmisctests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001192runmisctests: test_setup
1193 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
Randall Spanglera3eac792013-01-23 13:04:05 -08001194 ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001195 ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1196 ${RUNTEST} ${BUILD_RUN}/tests/sha_tests
1197 ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
Randall Spanglerc3d488d2013-01-28 16:23:48 -08001198 ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001199 ${RUNTEST} ${BUILD_RUN}/tests/tpm_bootmode_tests
1200 ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1201 ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1202 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001203 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_firmware_tests
Randall Spangler0714d9d2013-02-05 10:23:38 -08001204 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_init_tests
1205 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
Randall Spangler7f436692013-02-05 12:42:36 -08001206 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1207 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1208 ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001209 ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
Randall Spanglere061a252013-01-22 15:34:07 -08001210 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1211 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1212 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
Randall Spangler786a5dc2013-01-24 14:19:56 -08001213 ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001214 ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests
Randall Spangler49cb0d32013-01-29 14:28:16 -08001215 ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
Randall Spangler6dbf9d92013-01-23 12:25:10 -08001216 ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001217
Randall Spangler786acda2014-05-22 13:27:07 -07001218.PHONY: run2tests
1219run2tests: test_setup
Randall Spanglera7ab8b52014-06-10 17:05:08 -07001220 ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
Randall Spangler786acda2014-05-22 13:27:07 -07001221 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
Randall Spangler7141d732014-05-15 15:34:54 -07001222 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS}
1223 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS}
Randall Spangler3333e572014-05-14 11:37:52 -07001224 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
Randall Spangler18030682014-06-11 16:01:08 -07001225 ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc2_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001226 ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001227 ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
Randall Spangler3333e572014-05-14 11:37:52 -07001228 ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
Randall Spanglere166d042014-05-13 09:24:52 -07001229 ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
Randall Spangler108d9912014-12-02 15:55:56 -08001230 ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1231 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1232 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1233 ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1234 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1235 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
1236 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1237 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
1238 ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
Randall Spangler786acda2014-05-22 13:27:07 -07001239
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001240.PHONY: runfutiltests
Bill Richardson3e3790d2014-07-14 15:05:54 -07001241runfutiltests: test_setup
Bill Richardsonefa87562014-09-11 10:41:51 -07001242 tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
Bill Richardson339f7e02013-04-05 09:49:24 -07001243 ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
Randall Spangler844bce52013-01-15 16:16:43 -08001244
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001245# Run long tests, including all permutations of encryption keys (instead of
Randall Spangler786a5dc2013-01-24 14:19:56 -08001246# just the ones we use) and tests of currently-unused code.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001247# Not run by automated build.
Bill Richardsonacb2ee92013-01-11 22:53:00 -08001248.PHONY: runlongtests
Bill Richardsoneecc18f2013-01-17 15:28:17 -08001249runlongtests: test_setup genkeys genfuzztestcases
Randall Spanglere061a252013-01-22 15:34:07 -08001250 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1251 ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001252ifneq (${VBOOT2},)
1253 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
1254 ${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
Randall Spangler108d9912014-12-02 15:55:56 -08001255 ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
Randall Spangler7141d732014-05-15 15:34:54 -07001256endif
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001257 tests/run_preamble_tests.sh --all
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001258 tests/run_vbutil_tests.sh --all
1259
Bill Richardson78d59bf2014-08-27 16:17:04 -07001260# TODO: There were a number of ancient tests that hadn't been run in years.
1261# They were removed with https://chromium-review.googlesource.com/#/c/214610/
1262# Some day it might be nice to see what they were supposed to do.
Randall Spangler5d9bbf22013-01-08 10:44:23 -08001263
Bill Richardson78299022014-06-20 14:33:00 -07001264.PHONY: runalltests
1265runalltests: runtests runfutiltests runlongtests
1266
Randall Spangler59d75082013-01-23 09:29:54 -08001267# Code coverage
1268.PHONY: coverage_init
1269coverage_init: test_setup
1270 rm -f ${COV_INFO}*
1271 lcov -c -i -d . -b . -o ${COV_INFO}.initial
1272
1273.PHONY: coverage_html
1274coverage_html:
1275 lcov -c -d . -b . -o ${COV_INFO}.tests
1276 lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1277 lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1278 genhtml ${COV_INFO}.local -o ${BUILD}/coverage
Bill Richardsond2d08b22014-07-08 16:31:40 -07001279# Generate addtional coverage stats just for firmware subdir, because the stats
1280# for the whole project don't include subdirectory summaries. This will print
1281# the summary for just the firmware sources.
Randall Spangler49cb0d32013-01-29 14:28:16 -08001282 lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1283 lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
Randall Spangler59d75082013-01-23 09:29:54 -08001284 -o ${COV_INFO}.firmware
1285
1286.PHONY: coverage
1287ifeq (${COV},)
1288coverage:
1289 $(error Build coverage like this: make clean && COV=1 make)
1290else
1291coverage: coverage_init runtests coverage_html
1292endif
Bill Richardson1912bba2013-04-04 21:08:50 -07001293
1294# Include generated dependencies
1295ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
Bill Richardson80872db2014-10-03 10:26:11 -07001296TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1297
1298# We want to use only relative paths in cscope.files, especially since the
1299# paths inside and outside the chroot are different.
1300SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1301
1302${BUILD}/cscope.files: test_setup
1303 ${Q}rm -f $@
1304 ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1305 sed -e "s/${SRCDIRPAT}//" | \
1306 egrep '\.[chS]$$' | sort | uniq > $@
1307
1308cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1309cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1310run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1311
1312.PHONY: tags TAGS xrefs
1313tags TAGS xrefs: ${BUILD}/cscope.files
1314 ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1315 ${Q}$(call run_if_prog,etags,${cmd_etags})
1316 ${Q}$(call run_if_prog,ctags,${cmd_ctags})