4 use std
::process
::Command
;
5 use std
::{env, fs, io}
;
8 let out_dir
= env
::var("OUT_DIR").expect("expected OUT_DIR to be set by cargo");
10 let include_dir
= format
!("{}/include", out_dir
);
11 let ppport_h_file
= format
!("{}/ppport.h", include_dir
);
12 // quoted, without exterial double qoutes
13 let ppport_h_file_string_inner
= ppport_h_file
.replace('
"', "\\\"");
15 if let Err(err) = fs::create_dir(Path::new(&include_dir)) {
16 if err.kind() != io::ErrorKind::AlreadyExists {
17 panic!("failed to make include dir
in OUT_DIR
");
21 // perl -MDevel::PPPort -e 'Devel::PPPort::WriteFile("include
/ppport
.h
");'
23 .arg("-MDevel
::PPPort
")
26 r#"Devel
::PPPort
::WriteFile("{}");"#,
27 ppport_h_file_string_inner
30 .expect("failed to create ppport
.h file using perl's Devel
::PPPort
");
33 // perl -MConfig -e 'print $Config{archlib}'
34 let perl_archlib = Command::new("perl
")
37 .arg("print $Config{archlib}
")
39 .expect("failed to get perl arch include directory
");
40 // technically not a true Path, but we expect a system path which should be utf8-compatible
41 let archlib_include_path = format!(
43 std::str::from_utf8(&perl_archlib.stdout).expect("expected perl include path to be utf8
")
47 // perl -MConfig -e 'print $Config{ccflags}'
48 let perl_ccflags = Command::new("perl
")
51 .arg("print $Config{ccflags}
")
53 .expect("failed to get perl cflags
");
54 // technically garbage as it may contain paths, but since this should only contain system
55 // paths and otherwise also might contain quotes and what not let's just not really care:
56 let ccflags = std::str::from_utf8(&perl_ccflags.stdout).expect("expected cflags to be utf8
");
58 let mut cc = cc::Build::new();
64 .include(archlib_include_path);
66 for flag in ccflags.split_ascii_whitespace() {
70 // now build the static library:
71 cc.file("src
/glue
.c
").compile("libglue
.a
");
73 // get perl's MULTIPLICITY flag:
74 // perl -MConfig -e 'print $Config{usemultiplicity}'
75 let perl_multiplicity = Command::new("perl
")
78 .arg("print $Config{usemultiplicity}
")
80 .expect("failed to get perl usemultiplicity flag
");
82 // pass the multiplicity cfg flag:
83 if perl_multiplicity.stdout == b"define
" {
84 println!("cargo
:rustc
-cfg
=perlmod
=\"multiplicity
\"");
87 // the debian package should include src/glue.c
89 "dh
-cargo
:deb
-built
-using
=glue
=1={}
",
90 env::var("CARGO_MANIFEST_DIR
").unwrap()