1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

Force programs to rebuild when a dependency changes

This commit is contained in:
Arcterus 2014-07-19 14:25:28 -07:00
parent ab0a51fcb0
commit 9b3b8622ed
5 changed files with 41 additions and 29 deletions

View file

@ -1,5 +1,12 @@
include common.mk # Binaries
RUSTC ?= rustc
RM := rm
# Flags
RUSTCFLAGS := --opt-level=3
RMFLAGS :=
# Install directories
PREFIX ?= /usr/local PREFIX ?= /usr/local
BINDIR ?= /bin BINDIR ?= /bin
@ -87,8 +94,7 @@ BUILD ?= $(PROGS)
EXES := \ EXES := \
$(sort $(filter $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS)))) $(sort $(filter $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS))))
CRATES := \ CRATE_RLIBS :=
$(sort $(EXES))
INSTALL ?= $(EXES) INSTALL ?= $(EXES)
@ -109,25 +115,33 @@ TEST ?= $(TEST_PROGS)
TESTS := \ TESTS := \
$(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS))))) $(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
# Setup for building crates
define BUILD_SETUP
X := $(shell $(RUSTC) --print-file-name --crate-type rlib $(1)/$(1).rs)
$(1)_RLIB := $$(X)
CRATE_RLIBS += $$(X)
endef
$(foreach crate,$(EXES),$(eval $(call BUILD_SETUP,$(crate))))
# Utils stuff # Utils stuff
EXES_PATHS := $(addprefix build/,$(EXES)) EXES_PATHS := $(addprefix build/,$(EXES))
RLIB_PATHS := $(addprefix build/,$(CRATE_RLIBS))
command = sh -c '$(1)' command = sh -c '$(1)'
# Main exe build rule # Main exe build rule
define EXE_BUILD define EXE_BUILD
build/gen/$(1).rs: build/mkmain build/gen/$(1).rs: build/mkmain
build/mkmain $(1) build/gen/$(1).rs build/mkmain $(1) build/gen/$(1).rs
build/$(1): build/gen/$(1).rs build/$(1).timestamp | build deps build/$(1): build/gen/$(1).rs build/$($(1)_RLIB) | build deps
$(RUSTC) $(RUSTCFLAGS) -L build/ -o build/$(1) build/gen/$(1).rs $(RUSTC) $(RUSTCFLAGS) -L build/ -o build/$(1) build/gen/$(1).rs
endef endef
define CRATE_BUILD define CRATE_BUILD
-include build/$(1).d -include build/$(1).d
build/$(1).timestamp: $(1)/$(1).rs | build deps
build/$($(1)_RLIB): $(1)/$(1).rs | build deps
$(RUSTC) $(RUSTCFLAGS) -L build/ --crate-type rlib --dep-info build/$(1).d $(1)/$(1).rs --out-dir build $(RUSTC) $(RUSTCFLAGS) -L build/ --crate-type rlib --dep-info build/$(1).d $(1)/$(1).rs --out-dir build
@touch build/$(1).timestamp
endef endef
# Aliases build rule # Aliases build rule
@ -155,16 +169,22 @@ endef
# Main rules # Main rules
all: $(EXES_PATHS) build/uutils all: $(EXES_PATHS) build/uutils
# Creating necessary rules for each targets
$(foreach crate,$(EXES),$(eval $(call CRATE_BUILD,$(crate))))
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
-include build/uutils.d -include build/uutils.d
build/uutils: uutils/uutils.rs build/mkuutils $(addprefix build/, $(addsuffix .timestamp, $(CRATES))) build/uutils: uutils/uutils.rs build/mkuutils $(RLIB_PATHS)
build/mkuutils build/gen/uutils.rs $(BUILD) build/mkuutils build/gen/uutils.rs $(BUILD)
$(RUSTC) $(RUSTCFLAGS) -L build/ --dep-info $@.d build/gen/uutils.rs -o $@ $(RUSTC) $(RUSTCFLAGS) -L build/ --dep-info $@.d build/gen/uutils.rs -o $@
# Dependencies # Dependencies
LIBCRYPTO := $(shell $(RUSTC) --print-file-name --crate-type rlib deps/rust-crypto/src/rust-crypto/lib.rs)
-include build/rust-crypto.d -include build/rust-crypto.d
build/$(LIBCRYPTO): | build build/.rust-crypto: | build
$(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info build/rust-crypto.d deps/rust-crypto/src/rust-crypto/lib.rs --out-dir build/ $(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info build/rust-crypto.d deps/rust-crypto/src/rust-crypto/lib.rs --out-dir build/
@touch $@
build/mkmain: mkmain.rs | build build/mkmain: mkmain.rs | build
$(RUSTC) $(RUSTCFLAGS) -L build mkmain.rs -o $@ $(RUSTC) $(RUSTCFLAGS) -L build mkmain.rs -o $@
@ -175,7 +195,7 @@ build/mkuutils: mkuutils.rs | build
cksum/crc_table.rs: cksum/gen_table.rs cksum/crc_table.rs: cksum/gen_table.rs
cd cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table cd cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
deps: build/$(LIBCRYPTO) cksum/crc_table.rs deps: build/.rust-crypto cksum/crc_table.rs
crates: crates:
echo $(EXES) echo $(EXES)
@ -193,12 +213,6 @@ build:
tmp: tmp:
mkdir tmp mkdir tmp
# Creating necessary rules for each targets
$(foreach crate,$(CRATES),$(eval $(call CRATE_BUILD,$(crate))))
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
install: $(addprefix build/,$(INSTALLEES)) install: $(addprefix build/,$(INSTALLEES))
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR) mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
for prog in $(INSTALLEES); do \ for prog in $(INSTALLEES); do \

View file

@ -1,7 +0,0 @@
# Binaries
RUSTC ?= rustc
RM := rm
# Flags
RUSTCFLAGS := --opt-level=3
RMFLAGS :=

View file

@ -3,7 +3,7 @@ use std::os;
use std::path::Path; use std::path::Path;
use std::str::replace; use std::str::replace;
static TEMPLATE : &'static str = r" static TEMPLATE: &'static str = "\
extern crate @UTIL_CRATE@; extern crate @UTIL_CRATE@;
use std::os; use std::os;

View file

@ -15,12 +15,18 @@ fn main() {
let mut hashsum = false; let mut hashsum = false;
for prog in args.slice_from(2).iter() { for prog in args.slice_from(2).iter() {
match prog.as_slice() { match prog.as_slice() {
"md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => { "hashsum" | "md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => {
if !hashsum { if !hashsum {
crates.push_str("extern crate hashsum;\n"); crates.push_str("extern crate hashsum;\n");
util_map.push_str("map.insert(\"hashsum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"md5sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha1sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha224sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha256sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha384sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha512sum\", hashsum::uumain);\n");
hashsum = true; hashsum = true;
} }
util_map.push_str(format!("map.insert(\"{}\", hashsum::uumain);\n", prog).as_slice());
} }
"test" => { "test" => {
crates.push_str("extern crate uutest;\n"); crates.push_str("extern crate uutest;\n");

View file

@ -29,14 +29,13 @@ fn usage(cmap: &HashMap<&'static str, fn(Vec<String>) -> int>) {
println!("{} {}", NAME, VERSION); println!("{} {}", NAME, VERSION);
println!(""); println!("");
println!("Usage:"); println!("Usage:");
println!(" {} [util [arguments...]", NAME); println!(" {} [util [arguments...]]\n", NAME);
println!("Currently defined functions:"); println!("Currently defined functions:");
let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect(); let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect();
utils.sort(); utils.sort();
for util in utils.iter() { for util in utils.iter() {
println!("\t{}", util); println!("\t{}", util);
} }
println!("");
} }
fn main() { fn main() {