Prepared for cross-compiling

This commit is contained in:
Dennis Schwerdel 2016-04-12 09:20:47 +02:00
parent 8d4f1ef345
commit cd2259c09d
2 changed files with 19 additions and 2 deletions

View File

@ -3,11 +3,17 @@ extern crate pkg_config;
use std::process::Command; use std::process::Command;
use std::path::Path; use std::path::Path;
use std::env;
fn main() { fn main() {
if ! Path::new("libsodium/src/libsodium/.libs/libsodium.a").exists() { if ! Path::new("libsodium/src/libsodium/.libs/libsodium.a").exists() {
let target = env::var("TARGET").unwrap();
Command::new("sh").arg("autogen.sh").current_dir("libsodium").status().unwrap(); Command::new("sh").arg("autogen.sh").current_dir("libsodium").status().unwrap();
Command::new("sh").arg("configure").current_dir("libsodium").status().unwrap(); let mut args = vec!["configure", "--host", &target];
if target.starts_with("i686-") {
args.extend(vec!["CFLAGS=-m32", "CXXFLAGS=-m32", "LDFLAGS=-m32"]);
}
Command::new("sh").args(&args).current_dir("libsodium").status().unwrap();
Command::new("make").current_dir("libsodium").status().unwrap(); Command::new("make").current_dir("libsodium").status().unwrap();
} }
gcc::Config::new().file("src/c/tuntap.c").include("src").compile("libtuntap.a"); gcc::Config::new().file("src/c/tuntap.c").include("src").compile("libtuntap.a");

View File

@ -2,16 +2,27 @@
// Copyright (C) 2015-2016 Dennis Schwerdel // Copyright (C) 2015-2016 Dennis Schwerdel
// This software is licensed under GPL-3 or newer (see LICENSE.md) // This software is licensed under GPL-3 or newer (see LICENSE.md)
#[cfg(target_os = "linux")]
use libc; use libc;
#[cfg(not(target_os = "linux"))]
use time;
pub type Duration = u32; pub type Duration = u32;
pub type Time = i64; pub type Time = i64;
#[inline] #[inline]
#[cfg(target_os = "linux")]
pub fn now() -> Time { pub fn now() -> Time {
let mut tv = libc::timespec { tv_sec: 0, tv_nsec: 0 }; let mut tv = libc::timespec { tv_sec: 0, tv_nsec: 0 };
unsafe { libc::clock_gettime(6, &mut tv); } unsafe { libc::clock_gettime(6, &mut tv); }
tv.tv_sec tv.tv_sec as Time
}
#[inline]
#[cfg(not(target_os = "linux"))]
pub fn now() -> Time {
time::get_time().sec
} }
const HEX_CHARS: &'static [u8] = b"0123456789abcdef"; const HEX_CHARS: &'static [u8] = b"0123456789abcdef";