forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
296 lines (258 loc) · 5.27 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# Config options
PROFILE ?= debug
MULTICALL ?= n
ifneq (,$(filter install, $(MAKECMDGOALS)))
override PROFILE:=release
endif
PROFILE_CMD :=
ifeq ($(PROFILE),release)
PROFILE_CMD = --release
endif
# Binaries
CARGO ?= cargo
CARGOFLAGS ?=
# Install directories
PREFIX ?= /usr/local
DESTDIR ?=
BINDIR ?= /bin
LIBDIR ?= /lib
INSTALLDIR_BIN=$(DESTDIR)$(PREFIX)$(BINDIR)
INSTALLDIR_LIB=$(DESTDIR)$(PREFIX)$(LIBDIR)
#prefix to apply to uutils binary and all tool binaries
PROG_PREFIX ?=
# This won't support any directory with spaces in its name, but you can just
# make a symlink without spaces that points to the directory.
BASEDIR ?= $(shell pwd)
BUILDDIR := $(BASEDIR)/target/${PROFILE}/
PKG_BUILDDIR := $(BUILDDIR)/deps/
BUSYBOX_ROOT := $(BASEDIR)/tmp/
BUSYBOX_VER := 1.24.1
BUSYBOX_SRC:=$(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER)/
# Possible programs
PROGS := \
base64 \
basename \
cat \
cksum \
comm \
cp \
cut \
dirname \
echo \
env \
expand \
expr \
factor \
false \
fmt \
fold \
hashsum \
head \
link \
ln \
ls \
mkdir \
mktemp \
nl \
nproc \
od \
paste \
printenv \
printf \
ptx \
pwd \
readlink \
realpath \
relpath \
rm \
rmdir \
seq \
shred \
shuf \
sleep \
sort \
split \
sum \
sync \
tac \
tail \
tee \
test \
tr \
true \
truncate \
tsort \
unexpand \
uniq \
wc \
whoami \
yes
UNIX_PROGS := \
chmod \
chroot \
du \
groups \
hostid \
hostname \
id \
kill \
logname \
mkfifo \
mv \
nice \
nohup \
stdbuf \
timeout \
touch \
tty \
uname \
unlink \
uptime \
users
ifneq ($(OS),Windows_NT)
PROGS := $(PROGS) $(UNIX_PROGS)
endif
UTILS ?= $(PROGS)
# Programs with usable tests
TEST_PROGS := \
base64 \
basename \
cat \
chmod \
cksum \
comm \
cp \
cut \
dirname \
echo \
env \
expr \
factor \
false \
fold \
hashsum \
head \
link \
ln \
ls \
mkdir \
mktemp \
mv \
nl \
od \
paste \
printf \
ptx \
pwd \
readlink \
realpath \
rm \
rmdir \
seq \
sort \
split \
stdbuf \
sum \
tac \
tail \
test \
touch \
tr \
true \
truncate \
tsort \
unexpand \
uniq \
unlink \
wc
TESTS := \
$(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(TEST_PROGS))))
TEST_NO_FAIL_FAST :=
TEST_SPEC_FEATURE :=
ifneq ($(SPEC),)
TEST_NO_FAIL_FAST :=--no-fail-fast
TEST_SPEC_FEATURE := test_unimplemented
endif
define BUILD_EXE
build_exe_$(1):
${CARGO} build ${CARGOFLAGS} ${PROFILE_CMD} -p $(1)
endef
define TEST_INTEGRATION
test_integration_$(1): build_exe_$(1)
${CARGO} test ${CARGOFLAGS} --test $(1) --features "$(1) $(TEST_SPEC_FEATURE)" --no-default-features $(TEST_NO_FAIL_FAST)
endef
define TEST_BUSYBOX
test_busybox_$(1):
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(BUILDDIR) ./runtest $(RUNTEST_ARGS) $(1) )
endef
# Output names
EXES := \
$(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(PROGS))))
INSTALLEES := ${EXES} uutils
# Shared library extension
SYSTEM := $(shell uname)
DYLIB_EXT :=
ifeq ($(SYSTEM),Linux)
DYLIB_EXT := so
DYLIB_FLAGS := -shared
endif
ifeq ($(SYSTEM),Darwin)
DYLIB_EXT := dylib
DYLIB_FLAGS := -dynamiclib -undefined dynamic_lookup
endif
# Libaries to install
LIBS :=
ifneq (,$(findstring stdbuf, $(INSTALLEES)))
LIBS += libstdbuf.$(DYLIB_EXT)
endif
all: build
do_install = install ${1}
use_default := 1
$(foreach util,$(EXES),$(eval $(call BUILD_EXE,$(util))))
build-pkgs: $(addprefix build_exe_,$(EXES))
build-uutils:
${CARGO} build ${CARGOFLAGS} --features "${EXES}" ${PROFILE_CMD} --no-default-features
build: build-uutils build-pkgs
$(foreach test,$(TESTS),$(eval $(call TEST_INTEGRATION,$(test))))
$(foreach test,$(filter-out $(SKIP_UTILS),$(PROGS)),$(eval $(call TEST_BUSYBOX,$(test))))
test: $(addprefix test_integration_,$(TESTS))
busybox-src:
if [ ! -e $(BUSYBOX_SRC) ]; then \
mkdir -p $(BUSYBOX_ROOT); \
wget https://busybox.net/downloads/busybox-$(BUSYBOX_VER).tar.bz2 -P $(BUSYBOX_ROOT); \
tar -C $(BUSYBOX_ROOT) -xf $(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER).tar.bz2; \
fi; \
# This is a busybox-specific config file their test suite wants to parse.
$(BUILDDIR)/.config: $(BASEDIR)/.busybox-config
cp $< $@
# Test under the busybox testsuite
$(BUILDDIR)/busybox: busybox-src build-uutils $(BUILDDIR)/.config
cp $(BUILDDIR)/uutils $(BUILDDIR)/busybox; \
chmod +x $@;
ifeq ($(EXES),)
busytest:
else
busytest: $(BUILDDIR)/busybox $(addprefix test_busybox_,$(filter-out $(SKIP_UTILS),$(EXES)))
endif
clean:
$(RM) -rf $(BUILDDIR)
distclean: clean
$(CARGO) clean $(CARGOFLAGS) && $(CARGO) update $(CARGOFLAGS)
install: build
mkdir -p $(INSTALLDIR_BIN)
ifeq (${MULTICALL}, y)
install $(BUILDDIR)/uutils $(INSTALLDIR_BIN)/$(PROG_PREFIX)uutils
$(foreach prog, $(INSTALLEES), cd $(INSTALLDIR_BIN) && ln -fs $(PROG_PREFIX)uutils $(PROG_PREFIX)$(prog);)
else
$(foreach prog, $(INSTALLEES), \
install $(PKG_BUILDDIR)/$(prog) $(INSTALLDIR_BIN)/$(PROG_PREFIX)$(prog);)
endif
mkdir -p $(INSTALLDIR_LIB)
$(foreach lib, $(LIBS), install $(BUILDDIR)/$$lib $(INSTALLDIR_LIB)/$(lib);)
uninstall:
ifeq (${MULTICALL}, y)
rm -f $(addprefix $(INSTALLDIR_BIN)/,$(PROG_PREFIX)uutils)
endif
rm -f $(addprefix $(INSTALLDIR_BIN)/$(PROG_PREFIX),$(PROGS))
rm -f $(addprefix $(INSTALLDIR_LIB)/,$(LIBS))
.PHONY: all build test distclean clean busytest install uninstall