From 0bb67fe13a04fc008a36b0442e5a2a4d4455b60b Mon Sep 17 00:00:00 2001 From: Arcterus Date: Thu, 12 Jun 2014 18:43:52 -0700 Subject: [PATCH] Add the ability to install coreutils (resolves #216) --- Makefile | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 8ef8504e8..e51a8a0d9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ include common.mk +PREFIX ?= /usr/local +BINDIR ?= /bin + SRC_DIR=$(shell pwd) # Possible programs @@ -84,11 +87,11 @@ command = sh -c '$(1)' # Main exe build rule define EXE_BUILD ifeq ($(wildcard $(1)/Makefile),) -build/$(1): $(1)/$(1).rs +build/$(1): $(1)/$(1).rs | build $(call command,$(RUSTC) $(RUSTCFLAGS) -o build/$(1) $(1)/$(1).rs) clean_$(1): else -build/$(1): $(1)/$(1).rs +build/$(1): $(1)/$(1).rs | build cd $(1) && make clean_$(1): cd $(1) && make clean @@ -96,13 +99,13 @@ endif endef define CRATE_BUILD -build/$(2): $(1)/$(1).rs +build/$(2): $(1)/$(1).rs | build $(call command,$(RUSTC) $(RUSTCFLAGS) --crate-type rlib $(1)/$(1).rs --out-dir build) endef # Test exe built rules define TEST_BUILD -test_$(1): tmp/$(1)_test build build/$(1) +test_$(1): tmp/$(1)_test build/$(1) $(call command,tmp/$(1)_test) tmp/$(1)_test: $(1)/test.rs @@ -111,9 +114,9 @@ endef # Main rules ifneq ($(MULTICALL), 1) -all: build $(EXES_PATHS) +all: $(EXES_PATHS) else -all: build build/uutils +all: build/uutils build/uutils: uutils/uutils.rs $(addprefix build/, $(foreach crate,$(CRATES),$(shell $(RUSTC) --crate-type rlib --crate-file-name $(crate)/$(crate).rs))) $(RUSTC) $(RUSTCFLAGS) -L build/ uutils/uutils.rs -o $@ @@ -133,10 +136,29 @@ tmp: mkdir tmp # Creating necessary rules for each targets -$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe)))) -$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test)))) ifeq ($(MULTICALL), 1) $(foreach crate,$(CRATES),$(eval $(call CRATE_BUILD,$(crate),$(shell $(RUSTC) --crate-type rlib --crate-file-name --out-dir build $(crate)/$(crate).rs)))) +else +$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe)))) +endif +$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test)))) + +ifeq ($(MULTICALL), 1) +install: build/uutils + mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR) + install build/uutils $(DESTDIR)$(PREFIX)$(BINDIR)/uutils + +uninstall: + rm -f $(DESTDIR)$(PREFIX)$(BINDIR)/uutils +else +install: $(EXES_PATHS) + mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR) + for prog in $(EXES); do \ + install build/$$prog $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX)$$prog; \ + done + +uninstall: + rm -f $(addprefix $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX),$(PROGS)) endif # Test under the busybox testsuite @@ -163,4 +185,4 @@ busytest: build/busybox build/.config endif endif -.PHONY: all test clean busytest +.PHONY: all test clean busytest install uninstall