1# Copyright 2015 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# Minimal makefile capable of compiling futility to sign images
6
7LOCAL_PATH := $(call my-dir)
8include $(CLEAR_VARS)
9
10LOCAL_MODULE := libvboot_util-host
11
12ifeq ($(HOST_OS),darwin)
13LOCAL_CFLAGS += -DHAVE_MACOS -DO_LARGEFILE=0
14endif
15
16# These are required to access large disks and files on 32-bit systems.
17LOCAL_CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
18
19LOCAL_C_INCLUDES += \
20	$(LOCAL_PATH)/firmware/include \
21	$(LOCAL_PATH)/firmware/lib/include \
22	$(LOCAL_PATH)/firmware/lib/cgptlib/include \
23	$(LOCAL_PATH)/firmware/lib/cryptolib/include \
24	$(LOCAL_PATH)/firmware/lib/tpm_lite/include \
25	$(LOCAL_PATH)/firmware/2lib/include \
26	$(LOCAL_PATH)/host/include \
27	$(LOCAL_PATH)/host/lib/include
28
29# Firmware library sources needed by VbInit() call
30VBINIT_SRCS = \
31	firmware/lib/crc8.c \
32	firmware/lib/utility.c \
33	firmware/lib/vboot_api_init.c \
34	firmware/lib/vboot_common_init.c \
35	firmware/lib/vboot_nvstorage.c \
36	firmware/lib/vboot_nvstorage_rollback.c \
37	firmware/lib/region-init.c \
38
39# Additional firmware library sources needed by VbSelectFirmware() call
40VBSF_SRCS = \
41	firmware/lib/cryptolib/padding.c \
42	firmware/lib/cryptolib/rsa.c \
43	firmware/lib/cryptolib/rsa_utility.c \
44	firmware/lib/cryptolib/sha1.c \
45	firmware/lib/cryptolib/sha256.c \
46	firmware/lib/cryptolib/sha512.c \
47	firmware/lib/cryptolib/sha_utility.c \
48	firmware/lib/stateful_util.c \
49	firmware/lib/vboot_api_firmware.c \
50	firmware/lib/vboot_common.c \
51	firmware/lib/vboot_firmware.c \
52	firmware/lib/region-fw.c \
53
54# Additional firmware library sources needed by VbSelectAndLoadKernel() call
55VBSLK_SRCS = \
56	firmware/lib/cgptlib/cgptlib.c \
57	firmware/lib/cgptlib/cgptlib_internal.c \
58	firmware/lib/cgptlib/crc32.c \
59	firmware/lib/gpt_misc.c \
60	firmware/lib/utility_string.c \
61	firmware/lib/vboot_api_kernel.c \
62	firmware/lib/vboot_audio.c \
63	firmware/lib/vboot_display.c \
64	firmware/lib/vboot_kernel.c \
65	firmware/lib/region-kernel.c \
66
67VBINIT_SRCS += \
68	firmware/stub/tpm_lite_stub.c \
69	firmware/stub/utility_stub.c \
70	firmware/stub/vboot_api_stub_init.c \
71	firmware/stub/vboot_api_stub_region.c
72
73VBSF_SRCS += \
74	firmware/stub/vboot_api_stub_sf.c
75
76VBSLK_SRCS += \
77	firmware/stub/vboot_api_stub.c \
78	firmware/stub/vboot_api_stub_disk.c \
79	firmware/stub/vboot_api_stub_stream.c
80
81UTILLIB_SRCS = \
82	cgpt/cgpt_create.c \
83	cgpt/cgpt_add.c \
84	cgpt/cgpt_boot.c \
85	cgpt/cgpt_show.c \
86	cgpt/cgpt_repair.c \
87	cgpt/cgpt_prioritize.c \
88	cgpt/cgpt_common.c \
89	futility/dump_kernel_config_lib.c \
90	host/lib/crossystem.c \
91	host/lib/file_keys.c \
92	host/lib/fmap.c \
93	host/lib/host_common.c \
94	host/lib/host_key.c \
95	host/lib/host_keyblock.c \
96	host/lib/host_misc.c \
97	host/lib/util_misc.c \
98	host/lib/host_signature.c \
99	host/lib/signature_digest.c
100
101#	host/arch/${HOST_ARCH}/lib/crossystem_arch.c \
102
103LOCAL_SRC_FILES := \
104	$(VBINIT_SRCS) \
105	$(VBSF_SRCS) \
106	$(VBSLK_SRCS) \
107	$(UTILLIB_SRCS)
108
109LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_C_INCLUDES)
110LOCAL_STATIC_LIBRARIES := libcrypto_static
111
112include $(BUILD_HOST_STATIC_LIBRARY)
113
114include $(CLEAR_VARS)
115
116LOCAL_MODULE := futility-host
117LOCAL_IS_HOST_MODULE := true
118LOCAL_MODULE_CLASS := EXECUTABLES
119generated_sources := $(call local-generated-sources-dir)
120
121ifeq ($(HOST_OS),darwin)
122LOCAL_CFLAGS += -DHAVE_MACOS
123endif
124
125# These are required to access large disks and files on 32-bit systems.
126LOCAL_CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
127
128FUTIL_STATIC_SRCS = \
129	futility/futility.c \
130	futility/cmd_dump_fmap.c \
131	futility/cmd_gbb_utility.c \
132	futility/misc.c
133
134FUTIL_SRCS = \
135	${FUTIL_STATIC_SRCS} \
136	futility/cmd_dump_kernel_config.c \
137	futility/cmd_load_fmap.c \
138	futility/cmd_pcr.c \
139	futility/cmd_show.c \
140	futility/cmd_sign.c \
141	futility/cmd_vbutil_firmware.c \
142	futility/cmd_vbutil_kernel.c \
143	futility/cmd_vbutil_key.c \
144	futility/cmd_vbutil_keyblock.c \
145	futility/file_type.c \
146	futility/traversal.c \
147	futility/vb1_helper.c
148
149#	${FUTIL_STATIC_WORKAROUND_SRCS:%.c=${BUILD}/%.o} \
150
151LOCAL_SRC_FILES := \
152	$(FUTIL_SRCS) \
153
154$(generated_sources)/futility_cmds.c: ${FUTIL_SRCS:%=${LOCAL_PATH}/%}
155	@echo making $< from ${FUTIL_SRCS}
156	@rm -f $@ $@_t $@_commands
157	@mkdir -p $(dir $@)
158	@grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
159		| sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
160		| sort >>$@_commands
161	@external/vboot_reference/scripts/getversion.sh >> $@_t
162	@echo '#define _CMD(NAME) extern const struct' \
163		'futil_cmd_t __cmd_##NAME;' >> $@_t
164	@cat $@_commands >> $@_t
165	@echo '#undef _CMD' >> $@_t
166	@echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
167	@echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
168	@cat $@_commands >> $@_t
169	@echo '0};  /* null-terminated */' >> $@_t
170	@echo '#undef _CMD' >> $@_t
171	@mv $@_t $@
172	@rm -f $@_commands
173
174LOCAL_GENERATED_SOURCES := $(generated_sources)/futility_cmds.c
175
176LOCAL_STATIC_LIBRARIES := libvboot_util-host
177LOCAL_SHARED_LIBRARIES := libcrypto-host
178include $(BUILD_HOST_EXECUTABLE)
179
180