forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
112 lines (93 loc) · 1.79 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
include common.mk
# Possible programs
PROGS := \
base64 \
basename \
cat \
dirname \
echo \
env \
du \
false \
fold \
md5sum \
mkdir \
paste \
printenv \
pwd \
rm \
rmdir \
sleep \
seq \
tac \
tee \
true \
truncate \
wc \
yes \
hostname \
head \
UNIX_PROGS := \
kill \
logname \
users \
whoami \
tty \
groups \
id \
uptime \
uname
ifneq ($(OS),Windows_NT)
PROGS := $(PROGS) $(UNIX_PROGS)
endif
BUILD ?= $(PROGS)
# Output names
EXES := \
$(sort $(filter $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS))))
# Programs with usable tests
TEST_PROGS := \
cat \
mkdir \
seq \
truncate \
TEST ?= $(TEST_PROGS)
TESTS := \
$(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
# Utils stuff
EXES_PATHS := $(addprefix build/,$(EXES))
command = sh -c '$(1)'
# Main exe build rule
define EXE_BUILD
ifeq ($(wildcard $(1)/Makefile),)
build/$(1): $(1)/$(1).rs
$(call command,$(RUSTC) $(RUSTCFLAGS) -o build/$(1) $(1)/$(1).rs)
clean_$(1):
else
build/$(1): $(1)/$(1).rs
cd $(1) && make
clean_$(1):
cd $(1) && make clean
endif
endef
# Test exe built rules
define TEST_BUILD
test_$(1): tmp/$(1)_test build build/$(1)
$(call command,tmp/$(1)_test)
tmp/$(1)_test: $(1)/test.rs
$(call command,$(RUSTC) $(RUSTCFLAGS) --test -o tmp/$(1)_test $(1)/test.rs)
endef
# Main rules
all: build $(EXES_PATHS)
test: tmp $(addprefix test_,$(TESTS))
$(RM) -rf tmp
clean: $(addprefix clean_,$(EXES))
$(RM) -rf build tmp
build:
git submodule update --init
mkdir build
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))))
.PHONY: all test clean