2014-03-24 23:48:40 +00:00
|
|
|
include common.mk
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2014-06-13 01:43:52 +00:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
BINDIR ?= /bin
|
|
|
|
|
2014-06-01 18:26:58 +00:00
|
|
|
SRC_DIR=$(shell pwd)
|
|
|
|
|
2013-12-27 07:48:38 +00:00
|
|
|
# Possible programs
|
|
|
|
PROGS := \
|
2013-12-20 19:34:45 +00:00
|
|
|
base64 \
|
2014-01-07 00:54:02 +00:00
|
|
|
basename \
|
2013-12-02 11:50:24 +00:00
|
|
|
cat \
|
2014-05-16 21:01:20 +00:00
|
|
|
cksum \
|
2014-05-16 17:43:17 +00:00
|
|
|
comm \
|
2014-05-17 17:01:17 +00:00
|
|
|
cp \
|
2013-12-03 09:29:32 +00:00
|
|
|
dirname \
|
2013-12-02 11:50:24 +00:00
|
|
|
echo \
|
|
|
|
env \
|
2013-12-03 23:59:47 +00:00
|
|
|
du \
|
2014-05-30 00:39:33 +00:00
|
|
|
factor \
|
2013-12-02 11:50:24 +00:00
|
|
|
false \
|
2014-06-19 00:56:53 +00:00
|
|
|
fmt \
|
2014-03-27 01:34:58 +00:00
|
|
|
fold \
|
2014-06-22 14:28:51 +00:00
|
|
|
link \
|
2014-06-22 20:27:43 +00:00
|
|
|
hashsum \
|
2014-01-01 23:32:21 +00:00
|
|
|
mkdir \
|
2014-06-14 14:43:39 +00:00
|
|
|
nl \
|
2014-02-28 17:19:32 +00:00
|
|
|
paste \
|
2013-12-02 11:50:24 +00:00
|
|
|
printenv \
|
2013-12-05 11:36:08 +00:00
|
|
|
pwd \
|
2013-12-18 06:09:32 +00:00
|
|
|
rm \
|
2013-12-18 18:39:23 +00:00
|
|
|
rmdir \
|
2013-12-18 17:26:42 +00:00
|
|
|
sleep \
|
2014-02-05 19:46:28 +00:00
|
|
|
seq \
|
2014-05-28 00:57:33 +00:00
|
|
|
sum \
|
2014-06-26 06:05:31 +00:00
|
|
|
sync \
|
2014-02-27 18:59:51 +00:00
|
|
|
tac \
|
2013-12-23 17:12:26 +00:00
|
|
|
tee \
|
2014-05-24 04:47:42 +00:00
|
|
|
touch \
|
2014-05-18 15:17:04 +00:00
|
|
|
tr \
|
2013-12-02 11:50:24 +00:00
|
|
|
true \
|
2014-02-01 05:18:57 +00:00
|
|
|
truncate \
|
2014-05-16 23:45:12 +00:00
|
|
|
unlink \
|
2013-12-02 11:50:24 +00:00
|
|
|
wc \
|
|
|
|
yes \
|
2014-01-03 03:09:59 +00:00
|
|
|
head \
|
2014-06-12 21:27:37 +00:00
|
|
|
tail \
|
2014-06-15 20:41:23 +00:00
|
|
|
whoami
|
2013-12-02 11:50:24 +00:00
|
|
|
|
2014-02-08 03:35:03 +00:00
|
|
|
UNIX_PROGS := \
|
2014-06-16 15:37:03 +00:00
|
|
|
chroot \
|
2014-06-15 14:25:00 +00:00
|
|
|
groups \
|
2014-04-03 20:56:36 +00:00
|
|
|
hostid \
|
2014-06-04 05:28:22 +00:00
|
|
|
hostname \
|
2014-06-15 14:25:00 +00:00
|
|
|
id \
|
2014-04-03 13:59:58 +00:00
|
|
|
kill \
|
2014-02-24 21:24:01 +00:00
|
|
|
logname \
|
2014-06-22 12:39:46 +00:00
|
|
|
mkfifo \
|
2014-06-24 12:51:57 +00:00
|
|
|
nohup \
|
2014-02-19 05:59:48 +00:00
|
|
|
tty \
|
2014-06-15 14:25:00 +00:00
|
|
|
uname \
|
2014-04-02 00:13:07 +00:00
|
|
|
uptime \
|
2014-06-15 20:41:23 +00:00
|
|
|
users
|
2014-02-08 03:35:03 +00:00
|
|
|
|
|
|
|
ifneq ($(OS),Windows_NT)
|
|
|
|
PROGS := $(PROGS) $(UNIX_PROGS)
|
|
|
|
endif
|
|
|
|
|
2014-06-22 20:27:43 +00:00
|
|
|
ALIASES := \
|
|
|
|
hashsum:md5sum \
|
|
|
|
hashsum:sha1sum \
|
|
|
|
hashsum:sha224sum \
|
|
|
|
hashsum:sha256sum \
|
|
|
|
hashsum:sha384sum \
|
|
|
|
hashsum:sha512sum
|
|
|
|
|
2013-12-27 07:48:38 +00:00
|
|
|
BUILD ?= $(PROGS)
|
|
|
|
|
|
|
|
# Output names
|
|
|
|
EXES := \
|
2014-02-08 03:35:03 +00:00
|
|
|
$(sort $(filter $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS))))
|
2013-12-02 11:50:24 +00:00
|
|
|
|
2014-05-28 11:43:37 +00:00
|
|
|
CRATES := \
|
2014-06-20 12:48:14 +00:00
|
|
|
$(sort $(filter $(EXES), $(filter-out true false, $(EXES))))
|
2014-05-28 11:43:37 +00:00
|
|
|
|
2014-06-13 02:14:56 +00:00
|
|
|
INSTALL ?= $(EXES)
|
|
|
|
|
|
|
|
INSTALLEES := \
|
|
|
|
$(filter $(INSTALL),$(filter-out $(DONT_INSTALL),$(EXES)))
|
|
|
|
|
2013-12-27 21:32:56 +00:00
|
|
|
# Programs with usable tests
|
|
|
|
TEST_PROGS := \
|
2013-12-02 11:50:24 +00:00
|
|
|
cat \
|
2014-01-05 22:22:04 +00:00
|
|
|
mkdir \
|
2014-06-14 14:43:39 +00:00
|
|
|
nl \
|
2014-02-05 19:46:28 +00:00
|
|
|
seq \
|
2014-05-18 15:58:56 +00:00
|
|
|
tr \
|
2014-02-04 06:54:57 +00:00
|
|
|
truncate \
|
2013-12-02 11:50:24 +00:00
|
|
|
|
2013-12-27 21:32:56 +00:00
|
|
|
TEST ?= $(TEST_PROGS)
|
|
|
|
|
|
|
|
TESTS := \
|
|
|
|
$(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2013-10-25 11:10:52 +00:00
|
|
|
# Utils stuff
|
2013-10-25 16:00:39 +00:00
|
|
|
EXES_PATHS := $(addprefix build/,$(EXES))
|
2013-10-25 16:33:24 +00:00
|
|
|
command = sh -c '$(1)'
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2014-06-20 12:47:39 +00:00
|
|
|
|
2013-10-25 11:10:52 +00:00
|
|
|
# Main exe build rule
|
2013-10-23 15:09:40 +00:00
|
|
|
define EXE_BUILD
|
2014-06-19 00:31:00 +00:00
|
|
|
-include build/$(1).d
|
2014-06-20 21:31:55 +00:00
|
|
|
|
2014-06-20 21:50:32 +00:00
|
|
|
build/$(1): $(1)/$(1).rs | build deps
|
2014-06-20 12:47:39 +00:00
|
|
|
$(call command,$(RUSTC) $(RUSTCFLAGS) -L build/ --dep-info build/$(1).d -o build/$(1) $(1)/$(1).rs)
|
2013-10-23 15:09:40 +00:00
|
|
|
endef
|
|
|
|
|
2014-05-28 11:43:37 +00:00
|
|
|
define CRATE_BUILD
|
2014-06-19 00:31:00 +00:00
|
|
|
-include build/$(1).d
|
2014-06-20 21:31:55 +00:00
|
|
|
|
2014-06-20 21:50:32 +00:00
|
|
|
build/$(2): $(1)/$(1).rs | build deps
|
2014-06-20 12:47:39 +00:00
|
|
|
$(call command,$(RUSTC) $(RUSTCFLAGS) -L build/ --crate-type rlib --dep-info build/$(1).d $(1)/$(1).rs --out-dir build)
|
2014-05-28 11:43:37 +00:00
|
|
|
endef
|
|
|
|
|
2014-06-22 20:27:43 +00:00
|
|
|
# Aliases build rule
|
|
|
|
ALIAS_SOURCE = $(firstword $(subst :, ,$(1)))
|
|
|
|
ALIAS_TARGET = $(word 2,$(subst :, ,$(1)))
|
|
|
|
define MAKE_ALIAS
|
|
|
|
all: build/$(call ALIAS_TARGET,$(1))
|
|
|
|
build/$(call ALIAS_TARGET,$(1)): build/$(call ALIAS_SOURCE,$(1))
|
|
|
|
$(call command,install build/$(call ALIAS_SOURCE,$(1)) build/$(call ALIAS_TARGET,$(1)))
|
|
|
|
endef
|
|
|
|
|
2013-10-25 11:10:52 +00:00
|
|
|
# Test exe built rules
|
2013-10-23 15:09:40 +00:00
|
|
|
define TEST_BUILD
|
2014-06-13 01:43:52 +00:00
|
|
|
test_$(1): tmp/$(1)_test build/$(1)
|
2013-10-23 15:09:40 +00:00
|
|
|
$(call command,tmp/$(1)_test)
|
|
|
|
|
2013-10-25 16:00:39 +00:00
|
|
|
tmp/$(1)_test: $(1)/test.rs
|
2013-11-27 23:14:19 +00:00
|
|
|
$(call command,$(RUSTC) $(RUSTCFLAGS) --test -o tmp/$(1)_test $(1)/test.rs)
|
2013-10-23 15:09:40 +00:00
|
|
|
endef
|
|
|
|
|
2013-10-25 11:10:52 +00:00
|
|
|
# Main rules
|
2014-05-28 11:43:37 +00:00
|
|
|
ifneq ($(MULTICALL), 1)
|
2014-06-20 21:50:32 +00:00
|
|
|
all: $(EXES_PATHS)
|
2014-05-28 11:43:37 +00:00
|
|
|
else
|
2014-06-20 21:50:32 +00:00
|
|
|
all: build/uutils
|
2014-05-28 11:43:37 +00:00
|
|
|
|
2014-06-19 00:31:00 +00:00
|
|
|
-include build/uutils.d
|
|
|
|
|
2014-05-28 11:43:37 +00:00
|
|
|
build/uutils: uutils/uutils.rs $(addprefix build/, $(foreach crate,$(CRATES),$(shell $(RUSTC) --crate-type rlib --crate-file-name $(crate)/$(crate).rs)))
|
2014-06-19 00:31:00 +00:00
|
|
|
$(RUSTC) $(RUSTCFLAGS) -L build/ --dep-info $@.d uutils/uutils.rs -o $@
|
2014-05-28 11:43:37 +00:00
|
|
|
endif
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2014-06-20 12:47:39 +00:00
|
|
|
# Dependencies
|
2014-06-20 21:31:55 +00:00
|
|
|
LIBCRYPTO = $(shell $(RUSTC) --crate-file-name --crate-type rlib deps/rust-crypto/src/rust-crypto/lib.rs)
|
2014-06-20 12:47:39 +00:00
|
|
|
-include build/rust-crypto.d
|
2014-06-20 21:50:32 +00:00
|
|
|
build/$(LIBCRYPTO): | build
|
2014-06-20 12:47:39 +00:00
|
|
|
$(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info build/rust-crypto.d deps/rust-crypto/src/rust-crypto/lib.rs --out-dir build/
|
|
|
|
|
2014-06-20 21:31:55 +00:00
|
|
|
deps: build/$(LIBCRYPTO)
|
2014-06-20 12:47:39 +00:00
|
|
|
|
2013-10-25 16:00:39 +00:00
|
|
|
test: tmp $(addprefix test_,$(TESTS))
|
|
|
|
$(RM) -rf tmp
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2014-06-20 21:31:55 +00:00
|
|
|
clean:
|
2013-10-25 16:00:39 +00:00
|
|
|
$(RM) -rf build tmp
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2013-08-02 17:24:20 +00:00
|
|
|
build:
|
2014-03-31 16:40:21 +00:00
|
|
|
git submodule update --init
|
2013-08-02 17:24:20 +00:00
|
|
|
mkdir build
|
2013-10-23 15:09:40 +00:00
|
|
|
|
|
|
|
tmp:
|
2013-10-22 13:31:51 +00:00
|
|
|
mkdir tmp
|
|
|
|
|
2013-10-25 11:10:52 +00:00
|
|
|
# Creating necessary rules for each targets
|
2014-06-13 01:43:52 +00:00
|
|
|
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
|
2013-10-23 15:09:40 +00:00
|
|
|
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
|
2014-06-22 20:27:43 +00:00
|
|
|
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
|
2014-06-13 01:43:52 +00:00
|
|
|
endif
|
2013-10-23 15:09:40 +00:00
|
|
|
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
|
2014-06-13 01:43:52 +00:00
|
|
|
|
2014-05-28 11:43:37 +00:00
|
|
|
ifeq ($(MULTICALL), 1)
|
2014-06-13 01:43:52 +00:00
|
|
|
install: build/uutils
|
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
|
|
|
|
install build/uutils $(DESTDIR)$(PREFIX)$(BINDIR)/uutils
|
|
|
|
|
|
|
|
uninstall:
|
|
|
|
rm -f $(DESTDIR)$(PREFIX)$(BINDIR)/uutils
|
|
|
|
else
|
2014-06-13 02:14:56 +00:00
|
|
|
install: $(addprefix build/,$(INSTALLEES))
|
2014-06-13 01:43:52 +00:00
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
|
2014-06-13 02:14:56 +00:00
|
|
|
for prog in $(INSTALLEES); do \
|
2014-06-13 01:43:52 +00:00
|
|
|
install build/$$prog $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX)$$prog; \
|
|
|
|
done
|
|
|
|
|
|
|
|
uninstall:
|
|
|
|
rm -f $(addprefix $(DESTDIR)$(PREFIX)$(BINDIR)/$(PROG_PREFIX),$(PROGS))
|
2014-05-28 11:43:37 +00:00
|
|
|
endif
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2014-06-01 18:26:58 +00:00
|
|
|
# Test under the busybox testsuite
|
|
|
|
ifeq ($(MULTICALL), 1)
|
|
|
|
build/busybox: build/uutils
|
|
|
|
rm -f build/busybox
|
|
|
|
ln -s $(SRC_DIR)/build/uutils build/busybox
|
|
|
|
|
2014-06-09 02:03:38 +00:00
|
|
|
# This is a busybox-specific config file their test suite wants to parse.
|
|
|
|
# For now it's blank.
|
|
|
|
build/.config: build/uutils
|
|
|
|
touch $@
|
|
|
|
|
2014-06-01 18:26:58 +00:00
|
|
|
ifeq ($(BUSYBOX_SRC),)
|
|
|
|
busytest:
|
|
|
|
@echo
|
|
|
|
@echo "To run \`busytest\` set BUSYBOX_SRC to the directory of the compiled busybox source code."
|
|
|
|
@echo "Optionally set RUNTEST_ARGS to arguments to pass to the busybox \`runtest\` program."
|
|
|
|
@echo
|
|
|
|
@false
|
|
|
|
else
|
2014-06-09 02:03:38 +00:00
|
|
|
busytest: build/busybox build/.config
|
2014-06-19 16:31:47 +00:00
|
|
|
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(SRC_DIR)/build ./runtest $(RUNTEST_ARGS))
|
2014-06-01 18:26:58 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-06-20 12:47:39 +00:00
|
|
|
.PHONY: all deps test clean busytest install uninstall
|