From ea8d6e8ff0a2f5067434572fc61d4d76441fd50a Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 4 Jul 2019 23:50:09 +0200 Subject: [PATCH] Write a deltachat.pc file at build time This is writes pkg-config/deltachat.pc file in the target directory, using the PREFIX environment variable at build time. If this is undefined at build time /usr/local is used. --- deltachat-ffi/build.rs | 33 +++++++++++++++++++++++++++++++++ deltachat-ffi/deltachat.pc.in | 11 +++++++++++ 2 files changed, 44 insertions(+) create mode 100644 deltachat-ffi/build.rs create mode 100644 deltachat-ffi/deltachat.pc.in diff --git a/deltachat-ffi/build.rs b/deltachat-ffi/build.rs new file mode 100644 index 000000000..58e4a2258 --- /dev/null +++ b/deltachat-ffi/build.rs @@ -0,0 +1,33 @@ +use std::io::Write; +use std::path::PathBuf; +use std::{env, fs}; + +fn main() { + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let target_path = out_path.join("../../.."); + let target_triple = env::var("TARGET").unwrap(); + + // macOS or iOS, inherited from rpgp + let libs_priv = if target_triple.contains("apple") || target_triple.contains("darwin") { + // needed for OsRng + "-framework Security -framework Foundation" + } else { + "" + }; + + let pkg_config = format!( + include_str!("deltachat.pc.in"), + name = "deltachat", + description = env::var("CARGO_PKG_DESCRIPTION").unwrap(), + url = env::var("CARGO_PKG_HOMEPAGE").unwrap_or("".to_string()), + version = env::var("CARGO_PKG_VERSION").unwrap(), + libs_priv = libs_priv, + prefix = env::var("PREFIX").unwrap_or("/usr/local".to_string()), + ); + + fs::create_dir_all(target_path.join("pkgconfig")).unwrap(); + fs::File::create(target_path.join("pkgconfig").join("deltachat.pc")) + .unwrap() + .write_all(&pkg_config.as_bytes()) + .unwrap(); +} diff --git a/deltachat-ffi/deltachat.pc.in b/deltachat-ffi/deltachat.pc.in new file mode 100644 index 000000000..956948020 --- /dev/null +++ b/deltachat-ffi/deltachat.pc.in @@ -0,0 +1,11 @@ +prefix={prefix} +libdir=${{prefix}}/lib +includedir=${{prefix}}/include + +Name: {name} +Description: {description} +URL: {url} +Version: {version} +Cflags: -I${{includedir}} +Libs: -L${{libdir}} -ldeltachat +Libs.private: {libs_priv}