@@ -65,6 +65,7 @@ pub struct Config {
65
65
// misc
66
66
pub channel : String ,
67
67
pub musl_root : Option < PathBuf > ,
68
+ pub prefix : Option < String > ,
68
69
}
69
70
70
71
/// Per-target configuration stored in the global configuration structure.
@@ -246,6 +247,111 @@ impl Config {
246
247
247
248
return config
248
249
}
250
+
251
+ pub fn update_with_config_mk ( & mut self ) {
252
+ let mut config = String :: new ( ) ;
253
+ File :: open ( "config.mk" ) . unwrap ( ) . read_to_string ( & mut config) . unwrap ( ) ;
254
+ for line in config. lines ( ) {
255
+ let mut parts = line. splitn ( 2 , ":=" ) . map ( |s| s. trim ( ) ) ;
256
+ let key = parts. next ( ) . unwrap ( ) ;
257
+ let value = match parts. next ( ) {
258
+ Some ( n) if n. starts_with ( '\"' ) => & n[ 1 ..n. len ( ) - 1 ] ,
259
+ Some ( n) => n,
260
+ None => continue
261
+ } ;
262
+
263
+ macro_rules! check {
264
+ ( $( ( $name: expr, $val: expr) , ) * ) => {
265
+ if value == "1" {
266
+ $(
267
+ if key == concat!( "CFG_ENABLE_" , $name) {
268
+ $val = true ;
269
+ continue
270
+ }
271
+ if key == concat!( "CFG_DISABLE_" , $name) {
272
+ $val = false ;
273
+ continue
274
+ }
275
+ ) *
276
+ }
277
+ }
278
+ }
279
+
280
+ check ! {
281
+ ( "CCACHE" , self . ccache) ,
282
+ ( "MANAGE_SUBMODULES" , self . submodules) ,
283
+ ( "COMPILER_DOCS" , self . compiler_docs) ,
284
+ ( "DOCS" , self . docs) ,
285
+ ( "LLVM_ASSERTIONS" , self . llvm_assertions) ,
286
+ ( "OPTIMIZE_LLVM" , self . llvm_optimize) ,
287
+ ( "LLVM_VERSION_CHECK" , self . llvm_version_check) ,
288
+ ( "LLVM_STATIC_STDCPP" , self . llvm_static_stdcpp) ,
289
+ ( "OPTIMIZE" , self . rust_optimize) ,
290
+ ( "DEBUG_ASSERTIONS" , self . rust_debug_assertions) ,
291
+ ( "DEBUGINFO" , self . rust_debuginfo) ,
292
+ ( "JEMALLOC" , self . use_jemalloc) ,
293
+ ( "DEBUG_JEMALLOC" , self . debug_jemalloc) ,
294
+ ( "RPATH" , self . rust_rpath) ,
295
+ }
296
+
297
+ match key {
298
+ "CFG_BUILD" => self . build = value. to_string ( ) ,
299
+ "CFG_HOST" => {
300
+ self . host = value. split ( " " ) . map ( |s| s. to_string ( ) )
301
+ . collect ( ) ;
302
+ }
303
+ "CFG_TARGET" => {
304
+ self . target = value. split ( " " ) . map ( |s| s. to_string ( ) )
305
+ . collect ( ) ;
306
+ }
307
+ "CFG_MUSL_ROOT" if value. len ( ) > 0 => {
308
+ self . musl_root = Some ( PathBuf :: from ( value) ) ;
309
+ }
310
+ "CFG_DEFAULT_AR" if value. len ( ) > 0 => {
311
+ self . rustc_default_ar = Some ( value. to_string ( ) ) ;
312
+ }
313
+ "CFG_DEFAULT_LINKER" if value. len ( ) > 0 => {
314
+ self . rustc_default_linker = Some ( value. to_string ( ) ) ;
315
+ }
316
+ "CFG_RELEASE_CHANNEL" => {
317
+ self . channel = value. to_string ( ) ;
318
+ }
319
+ "CFG_PREFIX" => {
320
+ self . prefix = Some ( value. to_string ( ) ) ;
321
+ }
322
+ "CFG_LLVM_ROOT" if value. len ( ) > 0 => {
323
+ let target = self . target_config . entry ( self . build . clone ( ) )
324
+ . or_insert ( Target :: default ( ) ) ;
325
+ let root = PathBuf :: from ( value) ;
326
+ target. llvm_config = Some ( root. join ( "bin/llvm-config" ) ) ;
327
+ }
328
+ "CFG_JEMALLOC_ROOT" if value. len ( ) > 0 => {
329
+ let target = self . target_config . entry ( self . build . clone ( ) )
330
+ . or_insert ( Target :: default ( ) ) ;
331
+ target. jemalloc = Some ( PathBuf :: from ( value) ) ;
332
+ }
333
+ "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value. len ( ) > 0 => {
334
+ let target = "arm-linux-androideabi" . to_string ( ) ;
335
+ let target = self . target_config . entry ( target)
336
+ . or_insert ( Target :: default ( ) ) ;
337
+ target. ndk = Some ( PathBuf :: from ( value) ) ;
338
+ }
339
+ "CFG_I686_LINUX_ANDROID_NDK" if value. len ( ) > 0 => {
340
+ let target = "i686-linux-androideabi" . to_string ( ) ;
341
+ let target = self . target_config . entry ( target)
342
+ . or_insert ( Target :: default ( ) ) ;
343
+ target. ndk = Some ( PathBuf :: from ( value) ) ;
344
+ }
345
+ "CFG_AARCH64_LINUX_ANDROID_NDK" if value. len ( ) > 0 => {
346
+ let target = "aarch64-linux-androideabi" . to_string ( ) ;
347
+ let target = self . target_config . entry ( target)
348
+ . or_insert ( Target :: default ( ) ) ;
349
+ target. ndk = Some ( PathBuf :: from ( value) ) ;
350
+ }
351
+ _ => { }
352
+ }
353
+ }
354
+ }
249
355
}
250
356
251
357
fn set < T > ( field : & mut T , val : Option < T > ) {
0 commit comments