Detect and report VM environment in crossystem
[vboot.git] / Makefile
1 # Copyright 2013 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # This Makefile normally builds in a 'build' subdir, but use
6 #
7 #    make BUILD=<dir>
8 #
9 # 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
38 # We should only run pwd once, not every time we refer to ${BUILD}.
39 SRCDIR := $(shell pwd)
40 export SRCDIR
41 BUILD = ${SRCDIR}/build
42 export BUILD
43
44 # Stuff for 'make install'
45 INSTALL = install
46 DESTDIR = /usr/local
47 LIBDIR ?= lib
48
49 # Default values
50 DEV_DEBUG_FORCE=
51
52 # Where exactly do the pieces go?
53 #  UB_DIR = utility binary directory
54 #  ULP_DIR = pkgconfig directory, usually /usr/lib/pkgconfig
55 #  UI_DIR = include directory for library headers
56 #  US_DIR = shared data directory (for static content like devkeys)
57 #  DF_DIR = utility defaults directory
58 #  VB_DIR = vboot binary directory for dev-mode-only scripts
59 ifeq (${MINIMAL},)
60 # Host install just puts everything where it's told
61 UB_DIR=${DESTDIR}/bin
62 UL_DIR=${DESTDIR}/${LIBDIR}
63 ULP_DIR=${UL_DIR}/pkgconfig
64 UI_DIR=${DESTDIR}/include/vboot
65 US_DIR=${DESTDIR}/share/vboot
66 DF_DIR=${DESTDIR}/default
67 VB_DIR=${DESTDIR}/bin
68 else
69 # Target install puts things into different places
70 UB_DIR=${DESTDIR}/usr/bin
71 UL_DIR=${DESTDIR}/usr/${LIBDIR}
72 ULP_DIR=${UL_DIR}/pkgconfig
73 UI_DIR=${DESTDIR}/usr/include/vboot
74 US_DIR=${DESTDIR}/usr/share/vboot
75 DF_DIR=${DESTDIR}/etc/default
76 VB_DIR=${US_DIR}/bin
77 endif
78
79 # Where to install the (exportable) executables for testing?
80 TEST_INSTALL_DIR = ${BUILD}/install_for_test
81
82 # Verbose? Use V=1
83 ifeq (${V},)
84 Q := @
85 endif
86
87 # Quiet? Use QUIET=1
88 ifeq (${QUIET},)
89 PRINTF := printf
90 else
91 PRINTF := :
92 endif
93
94 # Architecture detection
95 _machname := $(shell uname -m)
96 HOST_ARCH ?= ${_machname}
97
98 # ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
99 # Pick a sane target architecture if none is defined.
100 ifeq (${ARCH},)
101   ARCH := ${HOST_ARCH}
102 endif
103
104 ifeq (${ARCH},armv7l)
105   override ARCH := arm
106 else ifeq (${ARCH},i386)
107   override ARCH := x86
108 else ifeq (${ARCH},amd64)
109   override ARCH := x86_64
110 endif
111
112 # FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
113 # for a firmware target (such as u-boot or depthcharge). It must map
114 # to the same consistent set of architectures as the host.
115 ifeq (${FIRMWARE_ARCH},i386)
116   override FIRMWARE_ARCH := x86
117 else ifeq (${FIRMWARE_ARCH},amd64)
118   override FIRMWARE_ARCH := x86_64
119 else ifeq (${FIRMWARE_ARCH},armv7)
120   override FIRMWARE_ARCH := arm
121 endif
122
123 # Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
124 # please add them after this point (e.g., -DVBOOT_DEBUG).
125 #
126 # TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
127 # temporarily. As we are still investigating which flags are necessary for
128 # maintaining a compatible ABI, etc. between u-boot and vboot_reference.
129 #
130 # As a first step, this makes the setting of CC and CFLAGS here optional, to
131 # permit a calling script or Makefile to set these.
132 #
133 # Flag ordering: arch, then -f, then -m, then -W
134 DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
135 WERROR := -Werror
136 COMMON_FLAGS := -nostdinc -pipe \
137         -ffreestanding -fno-builtin -fno-stack-protector \
138         ${WERROR} -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
139
140 # Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
141 ifeq (${FIRMWARE_ARCH}, arm)
142 CC ?= armv7a-cros-linux-gnueabi-gcc
143 CFLAGS ?= -march=armv5 \
144         -fno-common -ffixed-r8 \
145         -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
146         ${COMMON_FLAGS}
147 else ifeq (${FIRMWARE_ARCH}, x86)
148 CC ?= i686-pc-linux-gnu-gcc
149 # Drop -march=i386 to permit use of SSE instructions
150 CFLAGS ?= \
151         -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
152         -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
153         -mpreferred-stack-boundary=2 \
154         ${COMMON_FLAGS}
155 else ifeq (${FIRMWARE_ARCH}, x86_64)
156 CFLAGS ?= ${COMMON_FLAGS} \
157         -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
158 else
159 # FIRMWARE_ARCH not defined; assuming local compile.
160 CC ?= gcc
161 CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall ${WERROR} ${DEBUG_FLAGS}
162 endif
163
164 ifneq (${CUSTOM_MUSIC},)
165 CFLAGS += -DCUSTOM_MUSIC
166 endif
167
168 ifneq (${DEBUG},)
169 CFLAGS += -DVBOOT_DEBUG
170 endif
171
172 ifeq (${DISABLE_NDEBUG},)
173 CFLAGS += -DNDEBUG
174 endif
175
176 ifneq (${FORCE_LOGGING_ON},)
177 CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
178 endif
179
180 ifneq (${PD_SYNC},)
181 CFLAGS += -DPD_SYNC
182 endif
183
184 ifneq (${USE_MTD},)
185 CFLAGS += -DUSE_MTD
186 LDLIBS += -lmtdutils
187 endif
188
189 ifneq (${TPM2_MODE},)
190 CFLAGS += -DTPM2_MODE
191 endif
192
193 # NOTE: We don't use these files but they are useful for other packages to
194 # query about required compiling/linking flags.
195 PC_IN_FILES = vboot_host.pc.in
196
197 # Create / use dependency files
198 CFLAGS += -MMD -MF $@.d
199
200 ifeq (${FIRMWARE_ARCH},)
201 # Creates position independent code for non firmware target.
202 CFLAGS += -fPIE
203 endif
204
205 # These are required to access large disks and files on 32-bit systems.
206 CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
207
208 # Code coverage
209 ifneq (${COV},)
210   COV_FLAGS = -O0 --coverage -DCOVERAGE
211   CFLAGS += ${COV_FLAGS}
212   LDFLAGS += ${COV_FLAGS}
213   COV_INFO = ${BUILD}/coverage.info
214 endif
215
216 ifdef HAVE_MACOS
217   CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
218 endif
219
220 # Musl doesn't have execinfo.h.
221 ifndef HAVE_MUSL
222   CFLAGS += -DHAVE_EXECINFO_H
223 endif
224
225 # And a few more default utilities
226 LD = ${CC}
227 CXX ?= g++
228 PKG_CONFIG ?= pkg-config
229
230 # Static?
231 ifneq (${STATIC},)
232 LDFLAGS += -static
233 PKG_CONFIG += --static
234 endif
235
236 # Determine QEMU architecture needed, if any
237 ifeq (${ARCH},${HOST_ARCH})
238   # Same architecture; no need for QEMU
239   QEMU_ARCH :=
240 else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
241   # 64-bit host can run 32-bit targets directly
242   QEMU_ARCH :=
243 else
244   QEMU_ARCH := ${ARCH}
245 endif
246
247 # The top of the chroot for qemu must be passed in via the SYSROOT environment
248 # variable.  In the Chromium OS chroot, this is done automatically by the
249 # ebuild.
250
251 ifeq (${QEMU_ARCH},)
252   # Path to build output for running tests is same as for building
253   BUILD_RUN = ${BUILD}
254   SRC_RUN = ${SRCDIR}
255 else
256   $(info Using qemu for testing.)
257   # Path to build output for running tests is different in the chroot
258   BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
259   SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
260
261   QEMU_BIN = qemu-${QEMU_ARCH}
262   QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
263   export QEMU_RUN
264
265   RUNTEST = tests/test_using_qemu.sh
266 endif
267
268 export BUILD_RUN
269
270 ##############################################################################
271 # The default target is here, to allow dependencies to be expressed below
272 # without accidentally changing the default target.
273
274 # Default target.
275 .PHONY: all
276 all: fwlib fwlib2x fwlib20 fwlib21 \
277         $(if ${FIRMWARE_ARCH},,host_stuff) \
278         $(if ${COV},coverage)
279
280 ##############################################################################
281 # Now we need to describe everything we might want or need to build
282
283 # Everything wants these headers.
284 INCLUDES += \
285         -Ifirmware/include \
286         -Ifirmware/lib/include \
287         -Ifirmware/lib/cgptlib/include \
288         -Ifirmware/lib/cryptolib/include \
289         -Ifirmware/lib/tpm_lite/include \
290         -Ifirmware/2lib/include \
291         -Ifirmware/lib20/include
292
293 # If we're not building for a specific target, just stub out things like the
294 # TPM commands and various external functions that are provided by the BIOS.
295 ifeq (${FIRMWARE_ARCH},)
296 INCLUDES += -Ihost/include -Ihost/lib/include
297 INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
298 endif
299
300 # Firmware library, used by the other firmware components (depthcharge,
301 # coreboot, etc.). It doesn't need exporting to some other place; they'll build
302 # this source tree locally and link to it directly.
303 FWLIB = ${BUILD}/vboot_fw.a
304
305 # Smaller firmware library common to all vboot 2.x, used only for
306 # 1) compile-time tests of the public API or
307 # 2) linking with an actual 2.0 or 2.1 implementation
308 FWLIB2X = ${BUILD}/vboot_fw2x.a
309
310 # Vboot 2.0 (deprecated - see firmware/README)
311 FWLIB20 = ${BUILD}/vboot_fw20.a
312 # Vboot 2.1 (not yet ready - see firmware/README)
313 FWLIB21 = ${BUILD}/vboot_fw21.a
314
315 BDBLIB = ${BUILD}/bdb.a
316
317 # Firmware library sources needed by VbInit() call
318 VBINIT_SRCS = \
319         firmware/lib/crc8.c \
320         firmware/lib/utility.c \
321         firmware/lib/vboot_common_init.c \
322         firmware/lib/vboot_nvstorage.c \
323         firmware/lib/region-init.c \
324
325 # Additional firmware library sources needed by VbSelectFirmware() call
326 VBSF_SRCS = \
327         firmware/lib/cryptolib/padding.c \
328         firmware/lib/cryptolib/rsa.c \
329         firmware/lib/cryptolib/rsa_utility.c \
330         firmware/lib/stateful_util.c \
331         firmware/lib/vboot_common.c \
332         firmware/lib/region-fw.c \
333
334 # Additional firmware library sources needed by VbSelectAndLoadKernel() call
335 VBSLK_SRCS = \
336         firmware/lib/cgptlib/cgptlib.c \
337         firmware/lib/cgptlib/cgptlib_internal.c \
338         firmware/lib/cgptlib/crc32.c \
339         firmware/lib/gpt_misc.c \
340         firmware/lib/utility_string.c \
341         firmware/lib/vboot_api_kernel.c \
342         firmware/lib/vboot_audio.c \
343         firmware/lib/vboot_display.c \
344         firmware/lib/vboot_kernel.c \
345         firmware/lib/region-kernel.c \
346
347 # Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
348 FWLIB2X_SRCS = \
349         firmware/2lib/2api.c \
350         firmware/2lib/2common.c \
351         firmware/2lib/2crc8.c \
352         firmware/2lib/2misc.c \
353         firmware/2lib/2nvstorage.c \
354         firmware/2lib/2rsa.c \
355         firmware/2lib/2secdata.c \
356         firmware/2lib/2secdatak.c \
357         firmware/2lib/2sha1.c \
358         firmware/2lib/2sha256.c \
359         firmware/2lib/2sha512.c \
360         firmware/2lib/2sha_utility.c \
361         firmware/2lib/2tpm_bootmode.c \
362         firmware/2lib/2hmac.c
363
364 FWLIB20_SRCS = \
365         firmware/lib20/api.c \
366         firmware/lib20/api_kernel.c \
367         firmware/lib20/common.c \
368         firmware/lib20/kernel.c \
369         firmware/lib20/misc.c \
370         firmware/lib20/packed_key.c
371
372 FWLIB21_SRCS = \
373         firmware/lib21/api.c \
374         firmware/lib21/common.c \
375         firmware/lib21/misc.c \
376         firmware/lib21/packed_key.c
377
378 BDBLIB_SRCS = \
379         firmware/bdb/bdb.c \
380         firmware/bdb/misc.c \
381         firmware/bdb/rsa.c \
382         firmware/bdb/secrets.c \
383         firmware/bdb/stub.c \
384         firmware/bdb/nvm.c
385
386 # TPM lightweight command library
387 ifeq (${TPM2_MODE},)
388 TLCL_SRCS = \
389         firmware/lib/tpm_lite/tlcl.c
390 else
391 TLCL_SRCS = \
392         firmware/lib/tpm2_lite/tlcl.c \
393         firmware/lib/tpm2_lite/marshaling.c
394 endif
395 TLCL_OBJS_FOR_TEST = $(TLCL_SRCS:%.c=${BUILD}/%_for_test.o)
396
397 # Support real TPM unless BIOS sets MOCK_TPM
398 ifeq (${MOCK_TPM},)
399 VBINIT_SRCS += \
400         firmware/lib/rollback_index.c \
401         ${TLCL_SRCS}
402 else
403 VBINIT_SRCS += \
404         firmware/lib/mocked_rollback_index.c \
405         firmware/lib/tpm_lite/mocked_tlcl.c
406 endif
407
408 ifeq (${FIRMWARE_ARCH},)
409 # Include BIOS stubs in the firmware library when compiling for host
410 # TODO: split out other stub funcs too
411 VBINIT_SRCS += \
412         firmware/stub/tpm_lite_stub.c \
413         firmware/stub/utility_stub.c \
414         firmware/stub/vboot_api_stub_init.c \
415         firmware/stub/vboot_api_stub_region.c
416
417 VBSF_SRCS += \
418         firmware/stub/vboot_api_stub_sf.c
419
420 VBSLK_SRCS += \
421         firmware/stub/vboot_api_stub.c \
422         firmware/stub/vboot_api_stub_disk.c \
423         firmware/stub/vboot_api_stub_stream.c
424
425 FWLIB2X_SRCS += \
426         firmware/2lib/2stub.c
427
428 endif
429
430 VBSF_SRCS += ${VBINIT_SRCS}
431 FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
432
433 VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
434 VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
435 ALL_OBJS +=  ${VBINIT_OBJS} ${VBSF_OBJS}
436
437 FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
438 FWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
439 FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
440 FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
441 BDBLIB_OBJS = ${BDBLIB_SRCS:%.c=${BUILD}/%.o}
442 ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS} \
443         $(BDBLIB_OBJS}
444
445 # Intermediate library for the vboot_reference utilities to link against.
446 UTILLIB = ${BUILD}/libvboot_util.a
447 UTILBDB = ${BUILD}/libvboot_utilbdb.a
448
449 UTILLIB_SRCS = \
450         cgpt/cgpt_create.c \
451         cgpt/cgpt_add.c \
452         cgpt/cgpt_boot.c \
453         cgpt/cgpt_show.c \
454         cgpt/cgpt_repair.c \
455         cgpt/cgpt_prioritize.c \
456         cgpt/cgpt_common.c \
457         futility/dump_kernel_config_lib.c \
458         host/arch/${ARCH}/lib/crossystem_arch.c \
459         host/lib/crossystem.c \
460         host/lib/file_keys.c \
461         host/lib/fmap.c \
462         host/lib/host_common.c \
463         host/lib/host_common2.c \
464         host/lib/host_key.c \
465         host/lib/host_key2.c \
466         host/lib/host_keyblock.c \
467         host/lib/host_misc.c \
468         host/lib/util_misc.c \
469         host/lib/host_signature.c \
470         host/lib/host_signature2.c \
471         host/lib/signature_digest.c \
472         host/lib21/host_fw_preamble.c \
473         host/lib21/host_key.c \
474         host/lib21/host_keyblock.c \
475         host/lib21/host_misc.c \
476         host/lib21/host_signature.c
477
478 UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
479 ALL_OBJS += ${UTILLIB_OBJS}
480
481 UTILBDB_SRCS += \
482         firmware/bdb/host.c
483
484 UTILBDB_OBJS = ${UTILBDB_SRCS:%.c=${BUILD}/%.o}
485 ALL_OBJS += ${UTILBDB_OBJS}
486
487 # Externally exported library for some target userspace apps to link with
488 # (cryptohome, updater, etc.)
489 HOSTLIB = ${BUILD}/libvboot_host.a
490
491 HOSTLIB_SRCS = \
492         cgpt/cgpt_add.c \
493         cgpt/cgpt_boot.c \
494         cgpt/cgpt_common.c \
495         cgpt/cgpt_create.c \
496         cgpt/cgpt_prioritize.c \
497         firmware/lib/cgptlib/cgptlib_internal.c \
498         firmware/lib/cgptlib/crc32.c \
499         firmware/lib/crc8.c \
500         firmware/lib/gpt_misc.c \
501         ${TLCL_SRCS} \
502         firmware/lib/utility_string.c \
503         firmware/lib/vboot_nvstorage.c \
504         firmware/stub/tpm_lite_stub.c \
505         firmware/stub/utility_stub.c \
506         firmware/stub/vboot_api_stub.c \
507         firmware/stub/vboot_api_stub_disk.c \
508         firmware/stub/vboot_api_stub_init.c \
509         firmware/stub/vboot_api_stub_sf.c \
510         futility/dump_kernel_config_lib.c \
511         host/arch/${ARCH}/lib/crossystem_arch.c \
512         host/lib/crossystem.c \
513         host/lib/extract_vmlinuz.c \
514         host/lib/fmap.c \
515         host/lib/host_misc.c
516
517 HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
518 ALL_OBJS += ${HOSTLIB_OBJS}
519
520 # Sigh. For historical reasons, the autoupdate installer must sometimes be a
521 # 32-bit executable, even when everything else is 64-bit. But it only needs a
522 # few functions, so let's just build those.
523 TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
524
525 TINYHOSTLIB_SRCS = \
526         cgpt/cgpt_add.c \
527         cgpt/cgpt_boot.c \
528         cgpt/cgpt_common.c \
529         cgpt/cgpt_create.c \
530         cgpt/cgpt_prioritize.c \
531         firmware/lib/cgptlib/cgptlib_internal.c \
532         firmware/lib/cgptlib/crc32.c \
533         firmware/lib/gpt_misc.c \
534         firmware/lib/utility_string.c \
535         firmware/stub/vboot_api_stub.c \
536         firmware/stub/vboot_api_stub_disk.c \
537         firmware/stub/vboot_api_stub_sf.c \
538         firmware/stub/utility_stub.c \
539         futility/dump_kernel_config_lib.c \
540         host/lib/extract_vmlinuz.c
541
542 TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
543
544 # ----------------------------------------------------------------------------
545 # Now for the userspace binaries
546
547 CGPT = ${BUILD}/cgpt/cgpt
548
549 CGPT_SRCS = \
550         cgpt/cgpt.c \
551         cgpt/cgpt_add.c \
552         cgpt/cgpt_boot.c \
553         cgpt/cgpt_common.c \
554         cgpt/cgpt_create.c \
555         cgpt/cgpt_find.c \
556         cgpt/cgpt_legacy.c \
557         cgpt/cgpt_nor.c \
558         cgpt/cgpt_prioritize.c \
559         cgpt/cgpt_repair.c \
560         cgpt/cgpt_show.c \
561         cgpt/cmd_add.c \
562         cgpt/cmd_boot.c \
563         cgpt/cmd_create.c \
564         cgpt/cmd_find.c \
565         cgpt/cmd_legacy.c \
566         cgpt/cmd_prioritize.c \
567         cgpt/cmd_repair.c \
568         cgpt/cmd_show.c
569
570 CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
571
572 ALL_OBJS += ${CGPT_OBJS}
573
574 CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
575
576 CGPT_WRAPPER_SRCS = \
577         cgpt/cgpt_nor.c \
578         cgpt/cgpt_wrapper.c
579
580 CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
581
582 ALL_OBJS += ${CGPT_WRAPPER_OBJS}
583
584 # Utility defaults
585 UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
586
587 # Scripts to install directly (not compiled)
588 UTIL_SCRIPTS = \
589         utility/dev_debug_vboot \
590         utility/enable_dev_usb_boot
591
592 ifeq (${MINIMAL},)
593 UTIL_SCRIPTS += \
594         utility/dev_make_keypair \
595         utility/vbutil_what_keys
596 endif
597
598 # These utilities should be linked statically.
599 UTIL_NAMES_STATIC = \
600         utility/crossystem
601
602 UTIL_NAMES = ${UTIL_NAMES_STATIC} \
603         utility/dumpRSAPublicKey \
604         utility/tpmc
605
606 ifeq (${TPM2_MODE},)
607 UTIL_NAMES += utility/tpm_init_temp_fix
608 endif
609
610 # TODO: Do we still need eficompress and efidecompress for anything?
611 ifeq (${MINIMAL},)
612 UTIL_NAMES += \
613         utility/bmpblk_font \
614         utility/bmpblk_utility \
615         utility/eficompress \
616         utility/efidecompress \
617         utility/load_kernel_test \
618         utility/pad_digest_utility \
619         utility/signature_digest_utility \
620         utility/verify_data
621
622 LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
623 YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
624 endif
625
626 UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
627 UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
628 ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
629
630
631 # Scripts for signing stuff.
632 SIGNING_SCRIPTS = \
633         utility/tpm-nvsize \
634         utility/chromeos-tpm-recovery
635
636 # These go in a different place.
637 SIGNING_SCRIPTS_DEV = \
638         scripts/image_signing/resign_firmwarefd.sh \
639         scripts/image_signing/make_dev_firmware.sh \
640         scripts/image_signing/make_dev_ssd.sh \
641         scripts/image_signing/set_gbb_flags.sh
642
643 # Installed, but not made executable.
644 SIGNING_COMMON = scripts/image_signing/common_minimal.sh
645
646
647 # The unified firmware utility will eventually replace all the others
648 FUTIL_BIN = ${BUILD}/futility/futility
649 # But we still need both static (tiny) and dynamic (with openssl) versions.
650 FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
651
652 # These are the executables that are now built in to futility. We'll create
653 # symlinks for these so the old names will still work.
654 FUTIL_SYMLINKS = \
655         dump_fmap \
656         dump_kernel_config \
657         gbb_utility \
658         vbutil_firmware \
659         vbutil_kernel \
660         vbutil_key \
661         vbutil_keyblock
662
663 FUTIL_STATIC_SRCS = \
664         futility/futility.c \
665         futility/cmd_dump_fmap.c \
666         futility/cmd_gbb_utility.c \
667         futility/misc.c \
668         futility/ryu_root_header.c
669
670 FUTIL_SRCS = \
671         ${FUTIL_STATIC_SRCS} \
672         futility/cmd_create.c \
673         futility/cmd_dump_kernel_config.c \
674         futility/cmd_load_fmap.c \
675         futility/cmd_pcr.c \
676         futility/cmd_show.c \
677         futility/cmd_sign.c \
678         futility/cmd_vbutil_firmware.c \
679         futility/cmd_vbutil_kernel.c \
680         futility/cmd_vbutil_key.c \
681         futility/cmd_vbutil_keyblock.c \
682         futility/file_type.c \
683         futility/file_type_bios.c \
684         futility/file_type_rwsig.c \
685         futility/file_type_usbpd1.c \
686         futility/vb1_helper.c \
687         futility/vb2_helper.c
688
689 # List of commands built in futility and futility_s.
690 FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
691 FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
692
693 # Workaround for TODO(crbug.com/437107).
694 FUTIL_STATIC_WORKAROUND_SRCS = firmware/stub/vboot_api_stub_static_sf.c
695
696 FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
697         ${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
698         ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
699 FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
700
701 ${FUTIL_OBJS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
702
703 ALL_OBJS += ${FUTIL_OBJS}
704
705
706 # Library of handy test functions.
707 TESTLIB = ${BUILD}/tests/test.a
708
709 TESTLIB_SRCS = \
710         tests/test_common.c \
711         tests/timer_utils.c \
712         tests/crc32_test.c
713
714 TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
715 TEST_OBJS += ${TESTLIB_OBJS}
716
717
718 # And some compiled tests.
719 TEST_NAMES = \
720         tests/cgptlib_test \
721         tests/rollback_index3_tests \
722         tests/rsa_padding_test \
723         tests/rsa_utility_tests \
724         tests/rsa_verify_benchmark \
725         tests/sha_benchmark \
726         tests/stateful_util_tests \
727         tests/utility_string_tests \
728         tests/utility_tests \
729         tests/vboot_api_devmode_tests \
730         tests/vboot_api_kernel_tests \
731         tests/vboot_api_kernel2_tests \
732         tests/vboot_api_kernel3_tests \
733         tests/vboot_api_kernel4_tests \
734         tests/vboot_api_kernel5_tests \
735         tests/vboot_api_kernel6_tests \
736         tests/vboot_audio_tests \
737         tests/vboot_common_tests \
738         tests/vboot_common2_tests \
739         tests/vboot_common3_tests \
740         tests/vboot_display_tests \
741         tests/vboot_kernel_tests \
742         tests/vboot_nvstorage_test \
743         tests/verify_kernel
744
745 ifeq (${TPM2_MODE},)
746 # TODO(apronin): tests for TPM2 case?
747 TEST_NAMES += \
748         tests/tlcl_tests \
749         tests/rollback_index2_tests
750 endif
751
752 ifdef REGION_READ
753 TEST_NAMES += tests/vboot_region_tests
754 endif
755
756 TEST_FUTIL_NAMES  = \
757         tests/futility/binary_editor \
758         tests/futility/test_file_types \
759         tests/futility/test_not_really
760
761 TEST_NAMES += ${TEST_FUTIL_NAMES}
762
763 TEST2X_NAMES = \
764         tests/vb2_api_tests \
765         tests/vb2_common_tests \
766         tests/vb2_misc_tests \
767         tests/vb2_nvstorage_tests \
768         tests/vb2_rsa_utility_tests \
769         tests/vb2_secdata_tests \
770         tests/vb2_secdatak_tests \
771         tests/vb2_sha_tests \
772         tests/hmac_test
773
774 TEST20_NAMES = \
775         tests/vb20_api_tests \
776         tests/vb20_api_kernel_tests \
777         tests/vb20_common_tests \
778         tests/vb20_common2_tests \
779         tests/vb20_verify_fw.c \
780         tests/vb20_common3_tests \
781         tests/vb20_kernel_tests \
782         tests/vb20_misc_tests \
783         tests/vb20_rsa_padding_tests \
784         tests/vb20_verify_fw
785
786 TEST21_NAMES = \
787         tests/vb21_api_tests \
788         tests/vb21_common_tests \
789         tests/vb21_common2_tests \
790         tests/vb21_misc_tests \
791         tests/vb21_host_fw_preamble_tests \
792         tests/vb21_host_key_tests \
793         tests/vb21_host_keyblock_tests \
794         tests/vb21_host_misc_tests \
795         tests/vb21_host_sig_tests
796
797 TESTBDB_NAMES = \
798         tests/bdb_test \
799         tests/bdb_nvm_test \
800         tests/bdb_sprw_test
801
802 TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES} ${TESTBDB_NAMES}
803
804 # And a few more...
805 ifeq (${TPM2_MODE},)
806 TLCL_TEST_NAMES = \
807         tests/tpm_lite/tpmtest_earlyextend \
808         tests/tpm_lite/tpmtest_earlynvram \
809         tests/tpm_lite/tpmtest_earlynvram2 \
810         tests/tpm_lite/tpmtest_enable \
811         tests/tpm_lite/tpmtest_fastenable \
812         tests/tpm_lite/tpmtest_globallock \
813         tests/tpm_lite/tpmtest_redefine_unowned \
814         tests/tpm_lite/tpmtest_spaceperm \
815         tests/tpm_lite/tpmtest_testsetup \
816         tests/tpm_lite/tpmtest_timing \
817         tests/tpm_lite/tpmtest_writelimit
818 else
819 # TODO(apronin): tests for TPM2 case?
820 TLCL_TEST_NAMES =
821 endif
822
823 TEST_NAMES += ${TLCL_TEST_NAMES}
824
825 # Finally
826 TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
827 TEST_OBJS += $(addsuffix .o,${TEST_BINS})
828
829 TEST_FUTIL_BINS = $(addprefix ${BUILD}/,${TEST_FUTIL_NAMES})
830 TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
831 TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
832 TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
833 TESTBDB_BINS = $(addprefix ${BUILD}/,${TESTBDB_NAMES})
834
835 # Directory containing test keys
836 TEST_KEYS = ${SRC_RUN}/tests/testkeys
837
838
839 ##############################################################################
840 # Finally, some targets. High-level ones first.
841
842 # Create output directories if necessary.  Do this via explicit shell commands
843 # so it happens before trying to generate/include dependencies.
844 SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
845 _dir_create := $(foreach d, \
846         $(shell find ${SUBDIRS} -name '*.c' -exec  dirname {} \; | sort -u), \
847         $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
848
849 # Host targets
850 .PHONY: host_stuff
851 host_stuff: utillib hostlib cgpt utils futil tests
852
853 .PHONY: clean
854 clean:
855         ${Q}/bin/rm -rf ${BUILD}
856
857 .PHONY: install
858 install: cgpt_install utils_install signing_install futil_install \
859         pc_files_install
860
861 .PHONY: install_dev
862 install_dev: headers_install lib_install
863
864 .PHONY: install_mtd
865 install_mtd: install cgpt_wrapper_install
866
867 .PHONY: install_for_test
868 install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
869 install_for_test: install
870
871 # Don't delete intermediate object files
872 .SECONDARY:
873
874 # ----------------------------------------------------------------------------
875 # Firmware library
876
877 # TPM-specific flags.  These depend on the particular TPM we're targeting for.
878 # They are needed here only for compiling parts of the firmware code into
879 # user-level tests.
880
881 # TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
882 # the self test has completed.
883
884 ${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
885
886 # TPM_MANUAL_SELFTEST is defined if the self test must be started manually
887 # (with a call to TPM_ContinueSelfTest) instead of starting automatically at
888 # power on.
889 #
890 # We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
891 # are not both defined at the same time.  (See comment in code.)
892
893 # CFLAGS += -DTPM_MANUAL_SELFTEST
894
895 ifeq (${FIRMWARE_ARCH},i386)
896 # Unrolling loops in cryptolib makes it faster
897 ${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
898 ${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
899 ${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
900 ${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
901 ${BDBLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
902
903 # Workaround for coreboot on x86, which will power off asynchronously
904 # without giving us a chance to react. This is not an example of the Right
905 # Way to do things. See chrome-os-partner:7689, and the commit message
906 # that made this change.
907 ${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
908
909 # On x86 we don't actually read the GBB data into RAM until it is needed.
910 # Therefore it makes sense to cache it rather than reading it each time.
911 # Enable this feature.
912 ${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
913 endif
914
915 ifdef REGION_READ
916 ${FWLIB_OBJS}: CFLAGS += -DREGION_READ
917 endif
918
919 ifeq (${FIRMWARE_ARCH},)
920 # Disable rollback TPM when compiling locally, since otherwise
921 # load_kernel_test attempts to talk to the TPM.
922 ${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
923 endif
924
925 ${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
926 ${BDBLIB_OBJS}: INCLUDES += -Ifirmware/bdb
927
928 # Linktest ensures firmware lib doesn't rely on outside libraries
929 ${BUILD}/firmware/linktest/main: ${FWLIB}
930 ${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
931 TEST_OBJS += ${BUILD}/firmware/linktest/main.o
932
933 .PHONY: fwlinktest
934 fwlinktest: ${BUILD}/firmware/linktest/main
935
936 .PHONY: fwlib
937 fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
938
939 ${FWLIB}: ${FWLIB_OBJS} ${FWLIB2X_OBJS}
940         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
941         ${Q}rm -f $@
942         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
943         ${Q}ar qc $@ $^
944
945 .PHONY: fwlib2x
946 fwlib2x: ${FWLIB2X}
947
948 ${FWLIB2X}: ${FWLIB2X_OBJS}
949         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
950         ${Q}rm -f $@
951         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
952         ${Q}ar qc $@ $^
953
954 .PHONY: fwlib20
955 fwlib20: ${FWLIB20}
956
957 ${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
958         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
959         ${Q}rm -f $@
960         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
961         ${Q}ar qc $@ $^
962
963 .PHONY: fwlib21
964 fwlib21: ${FWLIB21}
965
966 ${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
967         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
968         ${Q}rm -f $@
969         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
970         ${Q}ar qc $@ $^
971
972 .PHONY: bdblib
973 bdblib: ${BDBLIB}
974
975 ${BDBLIB}: ${FWLIB2X_OBJS} ${BDBLIB_OBJS}
976         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
977         ${Q}rm -f $@
978         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
979         ${Q}ar qc $@ $^
980
981 # ----------------------------------------------------------------------------
982 # Host library(s)
983
984 # Link tests for local utilities
985 ${BUILD}/host/linktest/main: ${UTILLIB}
986 ${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
987 TEST_OBJS += ${BUILD}/host/linktest/main.o
988
989 .PHONY: utillib
990 utillib: ${UTILLIB} \
991         ${BUILD}/host/linktest/main
992
993 # TODO: better way to make .a than duplicating this recipe each time?
994 ${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} \
995                 ${FWLIB21_OBJS}
996         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
997         ${Q}rm -f $@
998         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
999         ${Q}ar qc $@ $^
1000
1001 ${UTILBDB}: ${UTILBDB_OBJS} ${BDBLIB_OBJS}
1002         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1003         ${Q}rm -f $@
1004         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1005         ${Q}ar qc $@ $^
1006
1007 # Link tests for external repos
1008 ${BUILD}/host/linktest/extern: ${HOSTLIB}
1009 ${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
1010 ${BUILD}/host/linktest/extern: LDLIBS += -static
1011 TEST_OBJS += ${BUILD}/host/linktest/extern.o
1012
1013 .PHONY: hostlib
1014 hostlib: ${HOSTLIB} \
1015         ${BUILD}/host/linktest/extern
1016
1017 # TODO: better way to make .a than duplicating this recipe each time?
1018 ${HOSTLIB}: ${HOSTLIB_OBJS}
1019         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1020         ${Q}rm -f $@
1021         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1022         ${Q}ar qc $@ $^
1023
1024
1025 # Ugh. This is a very cut-down version of HOSTLIB just for the installer.
1026 .PHONY: tinyhostlib
1027 tinyhostlib: ${TINYHOSTLIB}
1028         ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
1029
1030 ${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
1031         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1032         ${Q}rm -f $@
1033         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1034         ${Q}ar qc $@ $^
1035
1036 .PHONY: headers_install
1037 headers_install:
1038         @${PRINTF} "    INSTALL       HEADERS\n"
1039         ${Q}mkdir -p ${UI_DIR}
1040         ${Q}${INSTALL} -t ${UI_DIR} -m644 \
1041                 host/include/* \
1042                 firmware/include/gpt.h \
1043                 firmware/include/tlcl.h \
1044                 firmware/include/tss_constants.h
1045
1046 .PHONY: lib_install
1047 lib_install: ${HOSTLIB}
1048         @${PRINTF} "    INSTALL       HOSTLIB\n"
1049         ${Q}mkdir -p ${UL_DIR}
1050         ${Q}${INSTALL} -t ${UL_DIR} -m644 $^
1051
1052 .PHONY: devkeys_install
1053 devkeys_install:
1054         @${PRINTF} "    INSTALL       DEVKEYS\n"
1055         ${Q}mkdir -p ${US_DIR}/devkeys
1056         ${Q}${INSTALL} -t ${US_DIR}/devkeys -m644 tests/devkeys/*
1057
1058 # ----------------------------------------------------------------------------
1059 # CGPT library and utility
1060
1061 .PHONY: cgpt_wrapper
1062 cgpt_wrapper: ${CGPT_WRAPPER}
1063
1064 ${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
1065         @$(PRINTF) "    LD            $(subst ${BUILD}/,,$@)\n"
1066         ${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
1067
1068 .PHONY: cgpt
1069 cgpt: ${CGPT} ${CGPT_WRAPPER}
1070
1071 ${CGPT}: LDLIBS += -luuid
1072
1073 ${CGPT}: ${CGPT_OBJS} ${UTILLIB}
1074         @${PRINTF} "    LDcgpt        $(subst ${BUILD}/,,$@)\n"
1075         ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
1076
1077 .PHONY: cgpt_install
1078 cgpt_install: ${CGPT}
1079         @${PRINTF} "    INSTALL       CGPT\n"
1080         ${Q}mkdir -p ${UB_DIR}
1081         ${Q}${INSTALL} -t ${UB_DIR} $^
1082
1083 .PHONY: cgpt_wrapper_install
1084 cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
1085         @$(PRINTF) "    INSTALL       cgpt_wrapper\n"
1086         ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
1087         ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
1088                 ${UB_DIR}/$(notdir ${CGPT}).bin
1089         ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
1090                 ${UB_DIR}/$(notdir ${CGPT})
1091
1092 # ----------------------------------------------------------------------------
1093 # Utilities
1094
1095 # These have their own headers too.
1096 ${BUILD}/utility/%: INCLUDES += -Iutility/include
1097
1098 ${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
1099 ${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
1100
1101 # Utilities for auto-update toolkits must be statically linked.
1102 ${UTIL_BINS_STATIC}: LDFLAGS += -static
1103
1104
1105 .PHONY: utils
1106 utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
1107         ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
1108         ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
1109
1110 .PHONY: utils_install
1111 utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
1112         @${PRINTF} "    INSTALL       UTILS\n"
1113         ${Q}mkdir -p ${UB_DIR}
1114         ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
1115         ${Q}mkdir -p ${DF_DIR}
1116         ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
1117
1118 # And some signing stuff for the target
1119 .PHONY: signing_install
1120 signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
1121         @${PRINTF} "    INSTALL       SIGNING\n"
1122         ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
1123         ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
1124         ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
1125         ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
1126
1127 # ----------------------------------------------------------------------------
1128 # new Firmware Utility
1129
1130 .PHONY: futil
1131 futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
1132
1133 ${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
1134         @${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
1135         ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
1136
1137 ${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS} ${FWLIB20}
1138 ${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB} ${FWLIB20}
1139         @${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
1140         ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
1141
1142 .PHONY: futil_install
1143 futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1144         @${PRINTF} "    INSTALL       futility\n"
1145         ${Q}mkdir -p ${UB_DIR}
1146         ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
1147         ${Q}for prog in ${FUTIL_SYMLINKS}; do \
1148                 ln -sf futility "${UB_DIR}/$$prog"; done
1149
1150 # ----------------------------------------------------------------------------
1151 # Utility to generate TLCL structure definition header file.
1152
1153 ${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
1154
1155 STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
1156 STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
1157
1158 .PHONY: update_tlcl_structures
1159 update_tlcl_structures: ${BUILD}/utility/tlcl_generator
1160         @${PRINTF} "    Rebuilding TLCL structures\n"
1161         ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
1162         ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
1163                 ( echo "%% Updating structures.h %%" && \
1164                   cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
1165
1166 # ----------------------------------------------------------------------------
1167 # Tests
1168
1169 .PHONY: tests
1170 tests: ${TEST_BINS}
1171
1172 ${TEST_BINS}: ${UTILLIB} ${TESTLIB}
1173 ${TEST_BINS}: INCLUDES += -Itests
1174 ${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
1175
1176 # Futility tests need almost everything that futility needs.
1177 ${TEST_FUTIL_BINS}: ${FUTIL_OBJS} ${UTILLIB}
1178 ${TEST_FUTIL_BINS}: INCLUDES += -Ifutility
1179 ${TEST_FUTIL_BINS}: OBJS += ${FUTIL_OBJS} ${UTILLIB}
1180 ${TEST_FUTIL_BINS}: LDLIBS += ${CRYPTO_LIBS}
1181
1182 ${TEST2X_BINS}: ${FWLIB2X}
1183 ${TEST2X_BINS}: LIBS += ${FWLIB2X}
1184
1185 ${TEST20_BINS}: ${FWLIB20}
1186 ${TEST20_BINS}: LIBS += ${FWLIB20}
1187
1188 ${TESTBDB_BINS}: ${FWLIB2X} ${UTILBDB}
1189 ${TESTBDB_BINS}: INCLUDES += -Ifirmware/bdb
1190 ${TESTBDB_BINS}: LIBS += ${UTILBDB_OBJS} ${BDBLIB_OBJS} ${FWLIB2X}
1191
1192 ${TESTLIB}: ${TESTLIB_OBJS}
1193         @${PRINTF} "    RM            $(subst ${BUILD}/,,$@)\n"
1194         ${Q}rm -f $@
1195         @${PRINTF} "    AR            $(subst ${BUILD}/,,$@)\n"
1196         ${Q}ar qc $@ $^
1197
1198
1199 # ----------------------------------------------------------------------------
1200 # Generic build rules. LIBS and OBJS can be overridden to tweak the generic
1201 # rules for specific targets.
1202
1203 ${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
1204         @${PRINTF} "    LD            $(subst ${BUILD}/,,$@)\n"
1205         ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
1206
1207 ${BUILD}/%.o: %.c
1208         @${PRINTF} "    CC            $(subst ${BUILD}/,,$@)\n"
1209         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1210
1211 ${BUILD}/%.o: ${BUILD}/%.c
1212         @${PRINTF} "    CC            $(subst ${BUILD}/,,$@)\n"
1213         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1214
1215 # Rules to recompile a single source file for library and test
1216 # TODO: is there a tidier way to do this?
1217 ${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
1218 ${BUILD}/%_for_lib.o: %.c
1219         @${PRINTF} "    CC-for-lib    $(subst ${BUILD}/,,$@)\n"
1220         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1221
1222 ${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
1223 ${BUILD}/%_for_test.o: %.c
1224         @${PRINTF} "    CC-for-test   $(subst ${BUILD}/,,$@)\n"
1225         ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1226
1227 # TODO: C++ files don't belong in vboot reference at all.  Convert to C.
1228 ${BUILD}/%.o: %.cc
1229         @${PRINTF} "    CXX           $(subst ${BUILD}/,,$@)\n"
1230         ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
1231
1232 # ----------------------------------------------------------------------------
1233 # Here are the special tweaks to the generic rules.
1234
1235 # Always create the defaults file, since it depends on input variables
1236 .PHONY: ${UTIL_DEFAULTS}
1237 ${UTIL_DEFAULTS}:
1238         @${PRINTF} "    CREATE        $(subst ${BUILD}/,,$@)\n"
1239         ${Q}rm -f $@
1240         ${Q}mkdir -p $(dir $@)
1241         ${Q}echo '# Generated file. Do not edit.' > $@.tmp
1242         ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
1243         ${Q}mv -f $@.tmp $@
1244
1245 # Some utilities need external crypto functions
1246 CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
1247
1248 ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
1249 ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1250 ${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
1251
1252 ${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
1253 ${BUILD}/tests/vboot_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1254 ${BUILD}/tests/vboot_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1255 ${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
1256 ${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
1257 ${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
1258 ${BUILD}/tests/bdb_test: LDLIBS += ${CRYPTO_LIBS}
1259 ${BUILD}/tests/bdb_nvm_test: LDLIBS += ${CRYPTO_LIBS}
1260 ${BUILD}/tests/bdb_sprw_test: LDLIBS += ${CRYPTO_LIBS}
1261 ${BUILD}/tests/hmac_test: LDLIBS += ${CRYPTO_LIBS}
1262
1263 ${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
1264
1265 ${BUILD}/utility/bmpblk_utility: LD = ${CXX}
1266 ${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
1267
1268 BMPBLK_UTILITY_DEPS = \
1269         ${BUILD}/utility/bmpblk_util.o \
1270         ${BUILD}/utility/image_types.o \
1271         ${BUILD}/utility/eficompress_for_lib.o \
1272         ${BUILD}/utility/efidecompress_for_lib.o
1273
1274 ${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
1275 ${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
1276 ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
1277
1278 ${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
1279 ${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
1280 ALL_OBJS += ${BUILD}/utility/image_types.o
1281
1282 # Allow multiple definitions, so tests can mock functions from other libraries
1283 ${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
1284 ${BUILD}/tests/%: LDLIBS += -lrt -luuid
1285 ${BUILD}/tests/%: LIBS += ${TESTLIB}
1286
1287 ifeq (${TPM2_MODE},)
1288 # TODO(apronin): tests for TPM2 case?
1289 ${BUILD}/tests/rollback_index2_tests: OBJS += \
1290         ${BUILD}/firmware/lib/rollback_index_for_test.o
1291 ${BUILD}/tests/rollback_index2_tests: \
1292         ${BUILD}/firmware/lib/rollback_index_for_test.o
1293 TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
1294 endif
1295
1296 ${BUILD}/tests/tlcl_tests: OBJS += \
1297         ${TLCL_OBJS_FOR_TEST}
1298 ${BUILD}/tests/tlcl_tests: \
1299         ${TLCL_OBJS_FOR_TEST}
1300 TEST_OBJS += ${TLCL_OBJS_FOR_TEST}
1301
1302 ${BUILD}/tests/vboot_audio_tests: OBJS += \
1303         ${BUILD}/firmware/lib/vboot_audio_for_test.o
1304 ${BUILD}/tests/vboot_audio_tests: \
1305         ${BUILD}/firmware/lib/vboot_audio_for_test.o
1306 TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
1307
1308 ifeq (${TPM2_MODE},)
1309 # TODO(apronin): tests for TPM2 case?
1310 TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
1311 ${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1312 ${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
1313 TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
1314 endif
1315
1316 # ----------------------------------------------------------------------------
1317 # Here are the special rules that don't fit in the generic rules.
1318
1319 # Generates the list of commands defined in futility by running grep in the
1320 # source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
1321 ${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
1322 ${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
1323 ${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
1324         @${PRINTF} "    GEN           $(subst ${BUILD}/,,$@)\n"
1325         ${Q}rm -f $@ $@_t $@_commands
1326         ${Q}mkdir -p ${BUILD}/gen
1327         ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
1328                 | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
1329                 | sort >>$@_commands
1330         ${Q}./scripts/getversion.sh >> $@_t
1331         ${Q}echo '#define _CMD(NAME) extern const struct' \
1332                 'futil_cmd_t __cmd_##NAME;' >> $@_t
1333         ${Q}cat $@_commands >> $@_t
1334         ${Q}echo '#undef _CMD' >> $@_t
1335         ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
1336         ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
1337         ${Q}cat $@_commands >> $@_t
1338         ${Q}echo '0};  /* null-terminated */' >> $@_t
1339         ${Q}echo '#undef _CMD' >> $@_t
1340         ${Q}mv $@_t $@
1341         ${Q}rm -f $@_commands
1342
1343 ##############################################################################
1344 # Targets that exist just to run tests
1345
1346 # Frequently-run tests
1347 .PHONY: test_targets
1348 test_targets:: runcgpttests runmisctests run2tests runbdbtests
1349
1350 ifeq (${MINIMAL},)
1351 # Bitmap utility isn't compiled for minimal variant
1352 test_targets:: runbmptests runfutiltests
1353 # Scripts don't work under qemu testing
1354 # TODO: convert scripts to makefile so they can be called directly
1355 test_targets:: runtestscripts
1356 endif
1357
1358 .PHONY: test_setup
1359 test_setup:: cgpt utils futil tests install_for_test
1360
1361 # Qemu setup for cross-compiled tests.  Need to copy qemu binary into the
1362 # sysroot.
1363 ifneq (${QEMU_ARCH},)
1364 test_setup:: qemu_install
1365
1366 .PHONY: qemu_install
1367 qemu_install:
1368 ifeq (${SYSROOT},)
1369         $(error SYSROOT must be set to the top of the target-specific root \
1370 when cross-compiling for qemu-based tests to run properly.)
1371 endif
1372         @${PRINTF} "    Copying qemu binary.\n"
1373         ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
1374         ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
1375 endif
1376
1377 .PHONY: runtests
1378 runtests: test_setup test_targets
1379
1380 # Generate test keys
1381 .PHONY: genkeys
1382 genkeys: utils test_setup
1383         tests/gen_test_keys.sh
1384
1385 # Generate test cases for fuzzing
1386 .PHONY: genfuzztestcases
1387 genfuzztestcases: utils test_setup
1388         tests/gen_fuzz_test_cases.sh
1389
1390 .PHONY: runbmptests
1391 runbmptests: test_setup
1392         cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
1393                 ./TestBmpBlock.py -v
1394
1395 .PHONY: runcgpttests
1396 runcgpttests: test_setup
1397         ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
1398
1399 .PHONY: runtestscripts
1400 runtestscripts: test_setup genfuzztestcases
1401         tests/load_kernel_tests.sh
1402         tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
1403         tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
1404         tests/run_preamble_tests.sh
1405         tests/run_rsa_tests.sh
1406         tests/run_vbutil_kernel_arg_tests.sh
1407         tests/run_vbutil_tests.sh
1408         tests/vb2_rsa_tests.sh
1409         tests/vb2_firmware_tests.sh
1410
1411 .PHONY: runmisctests
1412 runmisctests: test_setup
1413         ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
1414         ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
1415         ${RUNTEST} ${BUILD_RUN}/tests/rsa_utility_tests
1416         ${RUNTEST} ${BUILD_RUN}/tests/stateful_util_tests
1417         ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
1418         ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
1419         ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
1420         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
1421         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
1422         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
1423         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel3_tests
1424         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
1425         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel5_tests
1426         ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel6_tests
1427         ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
1428         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
1429         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS}
1430         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS}
1431         ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
1432         ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
1433         ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
1434
1435 .PHONY: run2tests
1436 run2tests: test_setup
1437         ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
1438         ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
1439         ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
1440         ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
1441         ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
1442         ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
1443         ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdatak_tests
1444         ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
1445         ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
1446         ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_kernel_tests
1447         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
1448         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
1449         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
1450         ${RUNTEST} ${BUILD_RUN}/tests/vb20_kernel_tests
1451         ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
1452         ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
1453         ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
1454         ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
1455         ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
1456         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
1457         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD}
1458         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
1459         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD}
1460         ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
1461         ${RUNTEST} ${BUILD_RUN}/tests/hmac_test
1462
1463 .PHONY: runbdbtests
1464 runbdbtests: test_setup
1465         ${RUNTEST} ${BUILD_RUN}/tests/bdb_test ${TEST_KEYS}
1466         ${RUNTEST} ${BUILD_RUN}/tests/bdb_sprw_test ${TEST_KEYS}
1467
1468 .PHONY: runfutiltests
1469 runfutiltests: test_setup
1470         tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
1471         ${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types
1472         ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
1473
1474 # Run long tests, including all permutations of encryption keys (instead of
1475 # just the ones we use) and tests of currently-unused code.
1476 # Not run by automated build.
1477 .PHONY: runlongtests
1478 runlongtests: test_setup genkeys genfuzztestcases
1479         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} --all
1480         ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} --all
1481         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
1482         ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
1483         ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
1484         tests/run_preamble_tests.sh --all
1485         tests/run_vbutil_tests.sh --all
1486
1487 # TODO: There were a number of ancient tests that hadn't been run in years.
1488 # They were removed with https://chromium-review.googlesource.com/#/c/214610/
1489 # Some day it might be nice to see what they were supposed to do.
1490
1491 .PHONY: runalltests
1492 runalltests: runtests runfutiltests runlongtests
1493
1494 # Code coverage
1495 .PHONY: coverage_init
1496 coverage_init: test_setup
1497         rm -f ${COV_INFO}*
1498         lcov -c -i -d . -b . -o ${COV_INFO}.initial
1499
1500 .PHONY: coverage_html
1501 coverage_html:
1502         lcov -c -d . -b . -o ${COV_INFO}.tests
1503         lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
1504         lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
1505         genhtml ${COV_INFO}.local -o ${BUILD}/coverage
1506 # Generate addtional coverage stats just for firmware subdir, because the stats
1507 # for the whole project don't include subdirectory summaries. This will print
1508 # the summary for just the firmware sources.
1509         lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
1510         lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
1511                 -o ${COV_INFO}.firmware
1512
1513 .PHONY: coverage
1514 ifeq (${COV},)
1515 coverage:
1516         $(error Build coverage like this: make clean && COV=1 make coverage)
1517 else
1518 coverage: coverage_init runtests coverage_html
1519 endif
1520
1521 # Include generated dependencies
1522 ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
1523 TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
1524 -include ${ALL_DEPS}
1525 -include ${TEST_DEPS}
1526
1527 # We want to use only relative paths in cscope.files, especially since the
1528 # paths inside and outside the chroot are different.
1529 SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
1530
1531 # Note: vboot 2.0 is deprecated, so don't index those files
1532 ${BUILD}/cscope.files: all test_setup
1533         ${Q}rm -f $@
1534         ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
1535                 grep -v /lib20/ | \
1536                 sed -e "s/${SRCDIRPAT}//" | \
1537                 egrep '\.[chS]$$' | sort | uniq > $@
1538
1539 cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
1540 cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
1541 run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
1542
1543 .PHONY: tags TAGS xrefs
1544 tags TAGS xrefs: ${BUILD}/cscope.files
1545         ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
1546         ${Q}$(call run_if_prog,etags,${cmd_etags})
1547         ${Q}$(call run_if_prog,ctags,${cmd_ctags})
1548
1549 PC_FILES = ${PC_IN_FILES:%.pc.in=${BUILD}/%.pc}
1550 ${PC_FILES}: ${PC_IN_FILES}
1551         ${Q}sed \
1552                 -e 's:@LDLIBS@:${LDLIBS}:' \
1553                 -e 's:@LIBDIR@:${LIBDIR}:' \
1554                 $< > $@
1555
1556 .PHONY: pc_files_install
1557 pc_files_install: ${PC_FILES}
1558         ${Q}mkdir -p ${ULP_DIR}
1559         ${Q}${INSTALL} -D -m 0644 $< ${ULP_DIR}/$(notdir $<)