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
!("{out_dir}/include");
11 let ppport_h_file
= format
!("{include_dir}/ppport.h");
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("{ppport_h_file_string_inner}");"#
29 .expect("failed to create ppport
.h file using perl's Devel
::PPPort
");
32 // perl -MConfig -e 'print $Config{archlib}'
33 let perl_archlib = Command::new("perl
")
36 .arg("print $Config{archlib}
")
38 .expect("failed to get perl arch include directory
");
39 // technically not a true Path, but we expect a system path which should be utf8-compatible
40 let archlib_include_path = format!(
42 std::str::from_utf8(&perl_archlib.stdout).expect("expected perl include path to be utf8
")
46 // perl -MConfig -e 'print $Config{ccflags}'
47 let perl_ccflags = Command::new("perl
")
50 .arg("print $Config{ccflags}
")
52 .expect("failed to get perl cflags
");
53 // technically garbage as it may contain paths, but since this should only contain system
54 // paths and otherwise also might contain quotes and what not let's just not really care:
55 let ccflags = std::str::from_utf8(&perl_ccflags.stdout).expect("expected cflags to be utf8
");
57 let mut cc = cc::Build::new();
63 .include(archlib_include_path);
65 for flag in ccflags.split_ascii_whitespace() {
69 // now build the static library:
70 cc.file("src
/glue
.c
").compile("libglue
.a
");
72 // get perl's MULTIPLICITY flag:
73 // perl -MConfig -e 'print $Config{usemultiplicity}'
74 let perl_multiplicity = Command::new("perl
")
77 .arg("print $Config{usemultiplicity}
")
79 .expect("failed to get perl usemultiplicity flag
");
81 // pass the multiplicity cfg flag:
82 if perl_multiplicity.stdout == b"define
" {
83 println!("cargo
:rustc
-cfg
=perlmod
=\"multiplicity
\"");
86 // the debian package should include src/glue.c
88 "dh
-cargo
:deb
-built
-using
=glue
=1={}
",
89 env::var("CARGO_MANIFEST_DIR
").unwrap()