1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 06:57:47 +00:00

stdbuf: stop using GNU make as part of the build process

This commit is contained in:
Alex Lyon 2017-12-08 18:50:18 -08:00
parent 75f11e9635
commit 2b4a685286
No known key found for this signature in database
GPG key ID: B517F04B325131B1
3 changed files with 59 additions and 32 deletions

View file

@ -15,6 +15,8 @@ libstdbuf = { path="libstdbuf" }
[build-dependencies]
cc = "1.0"
glob = "0.2"
libstdbuf = { path = "libstdbuf" }
[[bin]]
name = "stdbuf"

View file

@ -1,31 +0,0 @@
BUILDDIR ?= $(OUT_DIR)
CC ?= gcc
RUSTC ?= rustc
# Shared library extension
SYSTEM := $(shell uname)
DYLIB_EXT :=
ifeq ($(SYSTEM),Linux)
DYLIB_EXT := so
DYLIB_FLAGS := -shared
DYLIB_LINK_START := -Wl,--whole-archive
DYLIB_LINK_END := -Wl,--no-whole-archive
endif
ifeq ($(SYSTEM),Darwin)
DYLIB_EXT := dylib
DYLIB_FLAGS := -dynamiclib -undefined dynamic_lookup
DYLIB_LINK_START :=
DYLIB_LINK_END :=
endif
all: $(BUILDDIR)/libstdbuf.$(DYLIB_EXT)
$(BUILDDIR):
mkdir -p $@
$(BUILDDIR)/libstdbuf.$(DYLIB_EXT): build.rs libstdbuf/libstdbuf.rs libstdbuf.c libstdbuf.h | $(BUILDDIR)
cp $(BUILDDIR)/../../../deps/liblibstdbuf-*.a $(BUILDDIR)/liblibstdbuf.a && \
$(CC) -c -Wall -Werror -fPIC libstdbuf.c -o $(BUILDDIR)/libstdbuf.o && \
$(CC) $(DYLIB_FLAGS) -o $@ $(BUILDDIR)/libstdbuf.o $(DYLIB_LINK_START) $(BUILDDIR)/liblibstdbuf.a $(DYLIB_LINK_END)

View file

@ -1,10 +1,66 @@
extern crate cc;
extern crate glob;
use std::env;
use std::process::Command;
use glob::glob;
#[path = "../../mkmain.rs"]
mod mkmain;
#[cfg(target_os = "macos")]
mod platform {
pub const DYLIB_EXT: &'static str = "dylib";
pub const DYLIB_FLAGS: [&'static str; 3] = ["-dynamiclib", "-undefined", "dynamic_lookup"];
pub const DYLIB_LINK_START: &'static str = "";
pub const DYLIB_LINK_END: &'static str = "";
}
#[cfg(target_os = "linux")]
mod platform {
pub const DYLIB_EXT: &'static str = "so";
pub const DYLIB_FLAGS: [&'static str; 1] = ["-shared"];
pub const DYLIB_LINK_START: &'static str = "-Wl,--whole-archive";
pub const DYLIB_LINK_END: &'static str = "-Wl,--no-whole-archive";
}
// FIXME: this entire thing is pretty fragile
fn main() {
mkmain::main();
Command::new("make").output().expect("failed to execute make");
let cc = env::var("CC").unwrap_or("gcc".to_string());
let out_dir = env::var("OUT_DIR").unwrap();
let entry = glob(&format!("{}/../../../deps/liblibstdbuf-*.a", out_dir)).unwrap()
.next()
.unwrap()
.unwrap();
cc::Build::new()
.flag("-Wall")
.flag("-Werror")
.pic(true)
.file("libstdbuf.c")
.compile("libstdbuf.a");
// XXX: we have to link manually because apparently cc-rs does not support shared libraries
let mut link = Command::new(cc);
for flag in platform::DYLIB_FLAGS.iter() {
link.arg(flag);
}
link.arg("-o")
.arg(format!("{}/libstdbuf.{}", out_dir, platform::DYLIB_EXT))
.arg(format!("{}/libstdbuf.a", out_dir));
if platform::DYLIB_LINK_START.len() > 0 {
link.arg(platform::DYLIB_LINK_START);
}
link.arg(entry);
if platform::DYLIB_LINK_END.len() > 0 {
link.arg(platform::DYLIB_LINK_END);
}
if !link.spawn().unwrap().wait().unwrap().success() {
panic!("linking failed");
}
}