diff --git a/Makefile b/Makefile index 8ef8504e8..3a0a9f437 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ include common.mk +PREFIX ?= /usr/local +BINDIR ?= /bin + SRC_DIR=$(shell pwd) # Possible programs @@ -64,6 +67,11 @@ EXES := \ CRATES := \ $(sort $(filter $(EXES), $(filter-out md5sum true false, $(EXES)))) +INSTALL ?= $(EXES) + +INSTALLEES := \ + $(filter $(INSTALL),$(filter-out $(DONT_INSTALL),$(EXES))) + # Programs with usable tests TEST_PROGS := \ cat \ @@ -84,11 +92,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 +104,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 +119,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 +141,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: $(addprefix build/,$(INSTALLEES)) + mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR) + for prog in $(INSTALLEES); 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 +190,4 @@ busytest: build/busybox build/.config endif endif -.PHONY: all test clean busytest +.PHONY: all test clean busytest install uninstall diff --git a/README.md b/README.md index 4abdbfb52..0ebe47eea 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,57 @@ To build only a few of the available utilities: make BUILD='UTILITY_1 UTILITY_2' ``` +To build the multicall binary (_i.e._ BusyBox-like binary): +``` +make MULTICALL=1 +``` + +Installation Instructions +------------------------- + +To install all available utilities: +``` +make install +``` + +To install all but a few of the available utilities: +``` +make DONT_INSTALL='UTILITY_1 UTILITY_2' install +``` + +To install only a few of the available utilities: +``` +make INSTALL='UTILITY_1 UTILITY_2' install +``` + +To install the multicall binary: +``` +make MULTICALL=1 install +``` + +To install every program (other than the multicall binary) with a prefix: +``` +make PROG_PREFIX=PREFIX_GOES_HERE install +``` + +Uninstallation Instructions +--------------------------- + +To uninstall all utilities: +``` +make uninstall +``` + +To uninstall the multicall binary: +``` +make MULTICALL=1 uninstall +``` + +To uninstall every program (other than the multicall binary) with a set prefix: +``` +make PROG_PREFIX=PREFIX_GOES_HERE uninstall +``` + Test Instructions ----------------- @@ -76,6 +127,7 @@ To do - chown - chroot - copy +- cp (not much done) - cp-hash - csplit - cut