blob: a2206c9c233596894969e00c822787fc88ceade1 [file] [log] [blame]
David Brown63902772017-07-12 09:47:49 -06001// Build mcuboot as a library, based on the requested features.
2
Fabio Utzig455cad52018-10-15 14:36:33 -07003extern crate cc;
David Brown63902772017-07-12 09:47:49 -06004
5use std::env;
6use std::fs;
7use std::io;
8use std::path::Path;
9
10fn main() {
11 // Feature flags.
12 let sig_rsa = env::var("CARGO_FEATURE_SIG_RSA").is_ok();
Fabio Utzig39297432019-05-08 18:51:10 -030013 let sig_rsa3072 = env::var("CARGO_FEATURE_SIG_RSA3072").is_ok();
David Brown63902772017-07-12 09:47:49 -060014 let sig_ecdsa = env::var("CARGO_FEATURE_SIG_ECDSA").is_ok();
David Brown641af452021-02-19 12:16:48 -070015 let sig_ecdsa_mbedtls = env::var("CARGO_FEATURE_SIG_ECDSA_MBEDTLS").is_ok();
Fabio Utzig97710282019-05-24 17:44:49 -030016 let sig_ed25519 = env::var("CARGO_FEATURE_SIG_ED25519").is_ok();
David Brown63902772017-07-12 09:47:49 -060017 let overwrite_only = env::var("CARGO_FEATURE_OVERWRITE_ONLY").is_ok();
Fabio Utzig031eb7d2019-11-28 10:13:14 -030018 let swap_move = env::var("CARGO_FEATURE_SWAP_MOVE").is_ok();
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020019 let swap_status = env::var("CARGO_FEATURE_SWAP_STATUS").is_ok();
David Vincze2d736ad2019-02-18 11:50:22 +010020 let validate_primary_slot =
21 env::var("CARGO_FEATURE_VALIDATE_PRIMARY_SLOT").is_ok();
Fabio Utzig1e48b912018-09-18 09:04:18 -030022 let enc_rsa = env::var("CARGO_FEATURE_ENC_RSA").is_ok();
23 let enc_kw = env::var("CARGO_FEATURE_ENC_KW").is_ok();
Fabio Utzig90f449e2019-10-24 07:43:53 -030024 let enc_ec256 = env::var("CARGO_FEATURE_ENC_EC256").is_ok();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -030025 let enc_x25519 = env::var("CARGO_FEATURE_ENC_X25519").is_ok();
Fabio Utzig9b97b132018-12-18 17:21:51 -020026 let bootstrap = env::var("CARGO_FEATURE_BOOTSTRAP").is_ok();
David Brown5e6f5e02019-04-04 10:50:05 +070027 let multiimage = env::var("CARGO_FEATURE_MULTIIMAGE").is_ok();
David Brown2ee5f7f2020-01-13 14:04:01 -070028 let downgrade_prevention = env::var("CARGO_FEATURE_DOWNGRADE_PREVENTION").is_ok();
David Brown63902772017-07-12 09:47:49 -060029
Fabio Utzig455cad52018-10-15 14:36:33 -070030 let mut conf = cc::Build::new();
David Brown63902772017-07-12 09:47:49 -060031 conf.define("__BOOTSIM__", None);
Fabio Utzig08fcfe92018-11-26 10:18:18 -020032 conf.define("MCUBOOT_HAVE_LOGGING", None);
David Brown63902772017-07-12 09:47:49 -060033 conf.define("MCUBOOT_USE_FLASH_AREA_GET_SECTORS", None);
Marti Bolivar248da082018-04-24 15:11:39 -040034 conf.define("MCUBOOT_HAVE_ASSERT_H", None);
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020035 if !swap_status {
36 conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("128"));
37 }
David Brown5e6f5e02019-04-04 10:50:05 +070038 conf.define("MCUBOOT_IMAGE_NUMBER", Some(if multiimage { "2" } else { "1" }));
Fabio Utzigebdc9692017-11-23 16:28:25 -020039
David Brown2ee5f7f2020-01-13 14:04:01 -070040 if downgrade_prevention && !overwrite_only {
41 panic!("Downgrade prevention requires overwrite only");
42 }
43
Fabio Utzig9b97b132018-12-18 17:21:51 -020044 if bootstrap {
45 conf.define("MCUBOOT_BOOTSTRAP", None);
46 }
47
David Vincze2d736ad2019-02-18 11:50:22 +010048 if validate_primary_slot {
49 conf.define("MCUBOOT_VALIDATE_PRIMARY_SLOT", None);
Fabio Utzigebdc9692017-11-23 16:28:25 -020050 }
David Brown63902772017-07-12 09:47:49 -060051
David Brown2ee5f7f2020-01-13 14:04:01 -070052 if downgrade_prevention {
53 conf.define("MCUBOOT_DOWNGRADE_PREVENTION", None);
54 }
55
Fabio Utzig39297432019-05-08 18:51:10 -030056 // Currently no more than one sig type can be used simultaneously.
Fabio Utzig97710282019-05-24 17:44:49 -030057 if vec![sig_rsa, sig_rsa3072, sig_ecdsa, sig_ed25519].iter()
Fabio Utzig39297432019-05-08 18:51:10 -030058 .fold(0, |sum, &v| sum + v as i32) > 1 {
59 panic!("mcuboot does not support more than one sig type at the same time");
David Brown704ac6f2017-07-12 10:14:47 -060060 }
David Brown63902772017-07-12 09:47:49 -060061
Fabio Utzig39297432019-05-08 18:51:10 -030062 if sig_rsa || sig_rsa3072 {
David Brown63902772017-07-12 09:47:49 -060063 conf.define("MCUBOOT_SIGN_RSA", None);
Fabio Utzig39297432019-05-08 18:51:10 -030064 // The Kconfig style defines must be added here as well because
65 // they are used internally by "config-rsa.h"
66 if sig_rsa {
67 conf.define("MCUBOOT_SIGN_RSA_LEN", "2048");
Fabio Utzig46268532020-01-04 21:12:55 -030068 conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "2048");
Fabio Utzig39297432019-05-08 18:51:10 -030069 } else {
70 conf.define("MCUBOOT_SIGN_RSA_LEN", "3072");
Fabio Utzig46268532020-01-04 21:12:55 -030071 conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "3072");
Fabio Utzig39297432019-05-08 18:51:10 -030072 }
David Brown63902772017-07-12 09:47:49 -060073 conf.define("MCUBOOT_USE_MBED_TLS", None);
74
Fabio Utzige60b12f2020-02-06 07:15:30 -030075 conf.include("../../ext/mbedtls/crypto/include");
76 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
Fabio Utzig806af0e2018-04-26 10:53:54 -030077 conf.file("csupport/keys.c");
David Brown63902772017-07-12 09:47:49 -060078
Fabio Utzige60b12f2020-02-06 07:15:30 -030079 conf.file("../../ext/mbedtls/crypto/library/rsa.c");
80 conf.file("../../ext/mbedtls/crypto/library/bignum.c");
81 conf.file("../../ext/mbedtls/crypto/library/platform.c");
82 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
83 conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
David Brown704ac6f2017-07-12 10:14:47 -060084 } else if sig_ecdsa {
Fabio Utzigc7865402017-12-05 08:50:52 -020085 conf.define("MCUBOOT_SIGN_EC256", None);
David Brown63902772017-07-12 09:47:49 -060086 conf.define("MCUBOOT_USE_TINYCRYPT", None);
Fabio Utzigc7865402017-12-05 08:50:52 -020087
Fabio Utzigb4d20c82018-12-27 16:08:39 -020088 if !enc_kw {
David Brownb748f6f2019-10-11 10:07:31 -060089 conf.include("../../ext/mbedtls-asn1/include");
Fabio Utzigb4d20c82018-12-27 16:08:39 -020090 }
Fabio Utzigc7865402017-12-05 08:50:52 -020091 conf.include("../../ext/tinycrypt/lib/include");
92
Fabio Utzig806af0e2018-04-26 10:53:54 -030093 conf.file("csupport/keys.c");
Fabio Utzigc7865402017-12-05 08:50:52 -020094
95 conf.file("../../ext/tinycrypt/lib/source/utils.c");
96 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
97 conf.file("../../ext/tinycrypt/lib/source/ecc.c");
98 conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c");
99 conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c");
100
David Brownb748f6f2019-10-11 10:07:31 -0600101 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
102 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
David Brown641af452021-02-19 12:16:48 -0700103 } else if sig_ecdsa_mbedtls {
104 conf.define("MCUBOOT_SIGN_EC256", None);
105 conf.define("MCUBOOT_USE_MBED_TLS", None);
106
107 conf.include("../../ext/mbedtls/crypto/include");
108 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
109 conf.file("csupport/keys.c");
110
111 conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
112 conf.file("../../ext/mbedtls/crypto/library/bignum.c");
113 conf.file("../../ext/mbedtls/crypto/library/ecdsa.c");
114 conf.file("../../ext/mbedtls/crypto/library/ecp.c");
115 conf.file("../../ext/mbedtls/crypto/library/ecp_curves.c");
116 conf.file("../../ext/mbedtls/crypto/library/platform.c");
117 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
Fabio Utzig97710282019-05-24 17:44:49 -0300118 } else if sig_ed25519 {
119 conf.define("MCUBOOT_SIGN_ED25519", None);
Fabio Utziga1c142d2020-01-03 08:28:11 -0300120 conf.define("MCUBOOT_USE_TINYCRYPT", None);
Fabio Utzig97710282019-05-24 17:44:49 -0300121
Fabio Utziga1c142d2020-01-03 08:28:11 -0300122 conf.include("../../ext/tinycrypt/lib/include");
123 conf.include("../../ext/tinycrypt-sha512/lib/include");
124 conf.include("../../ext/mbedtls-asn1/include");
125 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
126 conf.file("../../ext/tinycrypt-sha512/lib/source/sha512.c");
127 conf.file("../../ext/tinycrypt/lib/source/utils.c");
Fabio Utzig97710282019-05-24 17:44:49 -0300128 conf.file("csupport/keys.c");
129 conf.file("../../ext/fiat/src/curve25519.c");
Fabio Utziga1c142d2020-01-03 08:28:11 -0300130 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
131 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300132 } else if !enc_ec256 && !enc_x25519 {
Fabio Utzig90f449e2019-10-24 07:43:53 -0300133 // No signature type, only sha256 validation. The default
Marti Bolivara4818a52018-04-12 13:02:38 -0400134 // configuration file bundled with mbedTLS is sufficient.
Fabio Utzig90f449e2019-10-24 07:43:53 -0300135 // When using ECIES-P256 rely on Tinycrypt.
David Brown704ac6f2017-07-12 10:14:47 -0600136 conf.define("MCUBOOT_USE_MBED_TLS", None);
Fabio Utzige60b12f2020-02-06 07:15:30 -0300137 conf.include("../../ext/mbedtls/crypto/include");
138 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
David Brown63902772017-07-12 09:47:49 -0600139 }
140
141 if overwrite_only {
142 conf.define("MCUBOOT_OVERWRITE_ONLY", None);
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200143 conf.define("MCUBOOT_OVERWRITE_ONLY_FAST", None);
David Brown63902772017-07-12 09:47:49 -0600144 }
145
Fabio Utzig031eb7d2019-11-28 10:13:14 -0300146 if swap_move {
147 conf.define("MCUBOOT_SWAP_USING_MOVE", None);
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200148 conf.file("../../boot/bootutil/src/swap_move.c");
149 }
150
151 if swap_status {
152 conf.define("MCUBOOT_SWAP_USING_STATUS", None);
153 conf.define("MCUBOOT_LOG_LEVEL", "MCUBOOT_LOG_LEVEL_DEBUG");
154 conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("2000"));
155 conf.define("CY_FLASH_ALIGN", "512");
156 conf.file("../../boot/bootutil/src/swap_status.c");
157 conf.file("../../boot/bootutil/src/swap_status_part.c");
158 conf.file("../../boot/bootutil/src/swap_status_misc.c");
159 conf.file("../../boot/bootutil/src/crc32c.c");
160// conf.file("../../boot/cypress/cy_flash_pal/cy_my_support.c");
161 conf.include("../../boot/cypress/cy_flash_pal");
Fabio Utzig031eb7d2019-11-28 10:13:14 -0300162 }
163
Fabio Utzig1e48b912018-09-18 09:04:18 -0300164 if enc_rsa {
165 conf.define("MCUBOOT_ENCRYPT_RSA", None);
166 conf.define("MCUBOOT_ENC_IMAGES", None);
167 conf.define("MCUBOOT_USE_MBED_TLS", None);
Fabio Utzig1e48b912018-09-18 09:04:18 -0300168
169 conf.file("../../boot/bootutil/src/encrypted.c");
170 conf.file("csupport/keys.c");
171
Fabio Utzige60b12f2020-02-06 07:15:30 -0300172 conf.include("../../ext/mbedtls/crypto/include");
173 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
Fabio Utzig1e48b912018-09-18 09:04:18 -0300174
Fabio Utzige60b12f2020-02-06 07:15:30 -0300175 conf.file("../../ext/mbedtls/crypto/library/platform.c");
176 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
177 conf.file("../../ext/mbedtls/crypto/library/rsa.c");
178 conf.file("../../ext/mbedtls/crypto/library/rsa_internal.c");
179 conf.file("../../ext/mbedtls/crypto/library/md.c");
180 conf.file("../../ext/mbedtls/crypto/library/aes.c");
181 conf.file("../../ext/mbedtls/crypto/library/bignum.c");
182 conf.file("../../ext/mbedtls/crypto/library/asn1parse.c");
Fabio Utzig1e48b912018-09-18 09:04:18 -0300183 }
184
185 if enc_kw {
186 conf.define("MCUBOOT_ENCRYPT_KW", None);
187 conf.define("MCUBOOT_ENC_IMAGES", None);
Fabio Utzig1e48b912018-09-18 09:04:18 -0300188
189 conf.file("../../boot/bootutil/src/encrypted.c");
190 conf.file("csupport/keys.c");
191
Fabio Utzig39297432019-05-08 18:51:10 -0300192 if sig_rsa || sig_rsa3072 {
Fabio Utzige60b12f2020-02-06 07:15:30 -0300193 conf.file("../../ext/mbedtls/crypto/library/sha256.c");
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200194 }
Fabio Utzig1e48b912018-09-18 09:04:18 -0300195
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200196 /* Simulator uses Mbed-TLS to wrap keys */
Fabio Utzige60b12f2020-02-06 07:15:30 -0300197 conf.include("../../ext/mbedtls/crypto/include");
198 conf.file("../../ext/mbedtls/crypto/library/platform.c");
199 conf.file("../../ext/mbedtls/crypto/library/platform_util.c");
200 conf.file("../../ext/mbedtls/crypto/library/nist_kw.c");
201 conf.file("../../ext/mbedtls/crypto/library/cipher.c");
202 conf.file("../../ext/mbedtls/crypto/library/cipher_wrap.c");
203 conf.file("../../ext/mbedtls/crypto/library/aes.c");
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200204
205 if sig_ecdsa {
206 conf.define("MCUBOOT_USE_TINYCRYPT", None);
207
208 conf.include("../../ext/tinycrypt/lib/include");
209
210 conf.file("../../ext/tinycrypt/lib/source/utils.c");
211 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
212 conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c");
213 conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c");
Blaž Hrastnik4f4833d2020-09-14 13:53:31 +0900214 conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c");
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200215 }
Fabio Utzig97710282019-05-24 17:44:49 -0300216
217 if sig_ed25519 {
218 panic!("ed25519 does not support image encryption with KW yet");
219 }
Fabio Utzig1e48b912018-09-18 09:04:18 -0300220 }
221
Fabio Utzig90f449e2019-10-24 07:43:53 -0300222 if enc_ec256 {
223 conf.define("MCUBOOT_ENCRYPT_EC256", None);
224 conf.define("MCUBOOT_ENC_IMAGES", None);
225 conf.define("MCUBOOT_USE_TINYCRYPT", None);
Fabio Utzig4b4ed982020-01-06 09:09:51 -0300226 conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300227
228 conf.file("../../boot/bootutil/src/encrypted.c");
229 conf.file("csupport/keys.c");
230
231 conf.include("../../ext/mbedtls-asn1/include");
232 conf.include("../../ext/tinycrypt/lib/include");
233
234 /* FIXME: fail with other signature schemes ? */
235
236 conf.file("../../ext/tinycrypt/lib/source/utils.c");
237 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
238 conf.file("../../ext/tinycrypt/lib/source/ecc.c");
239 conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c");
240 conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c");
241
242 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
243 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
244
245 conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c");
246 conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c");
247 conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c");
248 conf.file("../../ext/tinycrypt/lib/source/hmac.c");
249 conf.file("../../ext/tinycrypt/lib/source/ecc_dh.c");
250 }
251
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300252 if enc_x25519 {
253 conf.define("MCUBOOT_ENCRYPT_X25519", None);
254 conf.define("MCUBOOT_ENC_IMAGES", None);
255 conf.define("MCUBOOT_USE_TINYCRYPT", None);
256 conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None);
257
258 conf.file("../../boot/bootutil/src/encrypted.c");
259 conf.file("csupport/keys.c");
260
261 conf.include("../../ext/mbedtls-asn1/include");
262 conf.include("../../ext/tinycrypt/lib/include");
263 conf.include("../../ext/tinycrypt-sha512/lib/include");
264
265 conf.file("../../ext/fiat/src/curve25519.c");
266
267 conf.file("../../ext/tinycrypt/lib/source/utils.c");
268 conf.file("../../ext/tinycrypt/lib/source/sha256.c");
269
270 conf.file("../../ext/mbedtls-asn1/src/platform_util.c");
271 conf.file("../../ext/mbedtls-asn1/src/asn1parse.c");
272
273 conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c");
274 conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c");
275 conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c");
276 conf.file("../../ext/tinycrypt/lib/source/hmac.c");
277 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300278
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200279 if sig_rsa && enc_kw {
280 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa-kw.h>"));
Fabio Utzig39297432019-05-08 18:51:10 -0300281 } else if sig_rsa || sig_rsa3072 || enc_rsa {
Fabio Utzig04fd63e2018-12-14 06:43:31 -0200282 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa.h>"));
David Brown641af452021-02-19 12:16:48 -0700283 } else if sig_ecdsa_mbedtls {
284 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ecdsa.h>"));
Fabio Utzig90f449e2019-10-24 07:43:53 -0300285 } else if (sig_ecdsa || enc_ec256) && !enc_kw {
Fabio Utzig04fd63e2018-12-14 06:43:31 -0200286 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>"));
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300287 } else if sig_ed25519 || enc_x25519 {
Fabio Utziga1c142d2020-01-03 08:28:11 -0300288 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>"));
Fabio Utzig04fd63e2018-12-14 06:43:31 -0200289 } else if enc_kw {
290 conf.define("MBEDTLS_CONFIG_FILE", Some("<config-kw.h>"));
291 }
292
David Brown704ac6f2017-07-12 10:14:47 -0600293 conf.file("../../boot/bootutil/src/image_validate.c");
Fabio Utzig39297432019-05-08 18:51:10 -0300294 if sig_rsa || sig_rsa3072 {
Fabio Utzigc7865402017-12-05 08:50:52 -0200295 conf.file("../../boot/bootutil/src/image_rsa.c");
David Brown641af452021-02-19 12:16:48 -0700296 } else if sig_ecdsa || sig_ecdsa_mbedtls {
Fabio Utzigc7865402017-12-05 08:50:52 -0200297 conf.file("../../boot/bootutil/src/image_ec256.c");
Fabio Utzig97710282019-05-24 17:44:49 -0300298 } else if sig_ed25519 {
299 conf.file("../../boot/bootutil/src/image_ed25519.c");
Fabio Utzigc7865402017-12-05 08:50:52 -0200300 }
David Brown63902772017-07-12 09:47:49 -0600301 conf.file("../../boot/bootutil/src/loader.c");
Fabio Utzig031eb7d2019-11-28 10:13:14 -0300302 conf.file("../../boot/bootutil/src/swap_misc.c");
303 conf.file("../../boot/bootutil/src/swap_scratch.c");
David Brown63902772017-07-12 09:47:49 -0600304 conf.file("../../boot/bootutil/src/caps.c");
305 conf.file("../../boot/bootutil/src/bootutil_misc.c");
Andrzej Puzdrowskif573b392020-11-10 14:35:15 +0100306 conf.file("../../boot/bootutil/src/bootutil_public.c");
Fabio Utzig61fd8882019-09-14 20:00:20 -0300307 conf.file("../../boot/bootutil/src/tlv.c");
Raef Colese8fe6cf2020-05-26 13:07:40 +0100308 conf.file("../../boot/bootutil/src/fault_injection_hardening.c");
David Brownd2b18532017-07-12 09:51:31 -0600309 conf.file("csupport/run.c");
David Brown63902772017-07-12 09:47:49 -0600310 conf.include("../../boot/bootutil/include");
Fabio Utzig57c40f72017-12-12 21:48:30 -0200311 conf.include("csupport");
Fabio Utzig9a4b9ba2018-05-07 08:31:27 -0300312 conf.include("../../boot/zephyr/include");
David Brown63902772017-07-12 09:47:49 -0600313 conf.debug(true);
314 conf.flag("-Wall");
David Brown0b693c02017-07-12 12:34:33 -0600315 conf.flag("-Werror");
David Brown63902772017-07-12 09:47:49 -0600316
Fabio Utzig0bccf9d2017-12-07 12:13:57 -0200317 // FIXME: travis-ci still uses gcc 4.8.4 which defaults to std=gnu90.
318 // It has incomplete std=c11 and std=c99 support but std=c99 was checked
319 // to build correctly so leaving it here to updated in the future...
320 conf.flag("-std=c99");
321
David Brown63902772017-07-12 09:47:49 -0600322 conf.compile("libbootutil.a");
323
324 walk_dir("../../boot").unwrap();
Fabio Utzigc7865402017-12-05 08:50:52 -0200325 walk_dir("../../ext/tinycrypt/lib/source").unwrap();
David Brownb748f6f2019-10-11 10:07:31 -0600326 walk_dir("../../ext/mbedtls-asn1").unwrap();
David Brownd2b18532017-07-12 09:51:31 -0600327 walk_dir("csupport").unwrap();
Fabio Utzige60b12f2020-02-06 07:15:30 -0300328 walk_dir("../../ext/mbedtls/crypto/include").unwrap();
329 walk_dir("../../ext/mbedtls/crypto/library").unwrap();
David Brown63902772017-07-12 09:47:49 -0600330}
331
332// Output the names of all files within a directory so that Cargo knows when to rebuild.
333fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
334 for ent in fs::read_dir(path.as_ref())? {
335 let ent = ent?;
336 let p = ent.path();
337 if p.is_dir() {
338 walk_dir(p)?;
339 } else {
340 // Note that non-utf8 names will fail.
341 let name = p.to_str().unwrap();
342 if name.ends_with(".c") || name.ends_with(".h") {
343 println!("cargo:rerun-if-changed={}", name);
344 }
345 }
346 }
347
348 Ok(())
349}