1 // Copyright 2023 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use std::env; 6 use std::fs::File; 7 use std::io::Write; 8 main()9fn main() { 10 let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); 11 12 // Override prefix from environment variable (with a default) 13 let prefix = format!( 14 r##"prefix={prefix}"##, 15 prefix = env::var("PREFIX").unwrap_or_else(|_| "/usr".to_string()) 16 ); 17 18 // Generate .pc file contents 19 let pc_contents = format!( 20 "{}{}", 21 prefix, 22 r###" 23 exec_prefix=${prefix} 24 includedir=${prefix}/include 25 libdir=${exec_prefix}/lib 26 27 Name: rutabaga_gfx_ffi 28 Description: C FFI bindings to Rutabaga VGI 29 Version: 0.1.3 30 Cflags: -I${includedir} 31 Libs: -L${libdir} -lrutabaga_gfx_ffi 32 "###, 33 ); 34 35 // Write the .pc file to the output directory 36 let mut pc_file = File::create(format!( 37 "{}/{}/rutabaga_gfx_ffi.pc", 38 env::var("CARGO_TARGET_DIR").as_deref().unwrap_or("target"), 39 env::var("PROFILE").unwrap() 40 )) 41 .unwrap(); 42 pc_file.write_all(pc_contents.as_bytes()).unwrap(); 43 44 println!("cargo:rerun-if-changed=build.rs"); // Rebuild if build.rs changes 45 46 if target_os.contains("linux") || target_os.contains("nto") { 47 println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,librutabaga_gfx_ffi.so.0"); 48 } 49 } 50