2022-03-09 09:11:13 +00:00
|
|
|
# spell-checker:ignore (misc) testsuite runtest findstring (targets) busytest distclean manpages pkgs ; (vars/env) BINDIR BUILDDIR CARGOFLAGS DESTDIR DOCSDIR INSTALLDIR INSTALLEES MULTICALL
|
2021-05-31 02:59:38 +00:00
|
|
|
|
2019-04-28 02:14:22 +00:00
|
|
|
# Config options
|
|
|
|
PROFILE ?= debug
|
|
|
|
MULTICALL ?= n
|
|
|
|
INSTALL ?= install
|
|
|
|
ifneq (,$(filter install, $(MAKECMDGOALS)))
|
|
|
|
override PROFILE:=release
|
|
|
|
endif
|
|
|
|
|
|
|
|
PROFILE_CMD :=
|
|
|
|
ifeq ($(PROFILE),release)
|
|
|
|
PROFILE_CMD = --release
|
|
|
|
endif
|
|
|
|
|
|
|
|
RM := rm -rf
|
|
|
|
|
|
|
|
# Binaries
|
|
|
|
CARGO ?= cargo
|
|
|
|
CARGOFLAGS ?=
|
|
|
|
|
|
|
|
# Install directories
|
|
|
|
PREFIX ?= /usr/local
|
|
|
|
DESTDIR ?=
|
|
|
|
BINDIR ?= /bin
|
|
|
|
|
|
|
|
INSTALLDIR_BIN=$(DESTDIR)$(PREFIX)$(BINDIR)
|
|
|
|
|
2021-04-02 20:18:31 +00:00
|
|
|
#prefix to apply to coreutils binary and all tool binaries
|
2019-04-28 02:14:22 +00:00
|
|
|
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
|
|
|
|
DOCSDIR := $(BASEDIR)/docs
|
|
|
|
|
|
|
|
BUSYBOX_ROOT := $(BASEDIR)/tmp
|
2021-03-10 22:13:57 +00:00
|
|
|
BUSYBOX_VER := 1.32.1
|
2019-04-28 02:14:22 +00:00
|
|
|
BUSYBOX_SRC := $(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER)
|
|
|
|
|
2021-08-05 04:39:37 +00:00
|
|
|
ifeq ($(SELINUX_ENABLED),)
|
2022-01-02 00:05:10 +00:00
|
|
|
SELINUX_ENABLED := 0
|
|
|
|
ifneq ($(OS),Windows_NT)
|
|
|
|
ifeq ($(shell /sbin/selinuxenabled 2>/dev/null ; echo $$?),0)
|
|
|
|
SELINUX_ENABLED := 1
|
|
|
|
endif
|
|
|
|
endif
|
2021-08-05 04:39:37 +00:00
|
|
|
endif
|
|
|
|
|
2019-04-28 02:14:22 +00:00
|
|
|
# Possible programs
|
|
|
|
PROGS := \
|
2020-05-11 02:14:58 +00:00
|
|
|
base32 \
|
|
|
|
base64 \
|
2022-03-28 21:10:33 +00:00
|
|
|
basenc \
|
2020-05-11 02:14:58 +00:00
|
|
|
basename \
|
|
|
|
cat \
|
|
|
|
cksum \
|
|
|
|
comm \
|
|
|
|
cp \
|
2020-12-27 14:24:02 +00:00
|
|
|
csplit \
|
2020-05-11 02:14:58 +00:00
|
|
|
cut \
|
2021-01-16 20:15:03 +00:00
|
|
|
date \
|
2022-02-08 14:50:09 +00:00
|
|
|
dd \
|
2020-05-11 02:14:58 +00:00
|
|
|
df \
|
|
|
|
dircolors \
|
|
|
|
dirname \
|
|
|
|
echo \
|
|
|
|
env \
|
|
|
|
expand \
|
|
|
|
expr \
|
|
|
|
factor \
|
|
|
|
false \
|
|
|
|
fmt \
|
|
|
|
fold \
|
|
|
|
hashsum \
|
|
|
|
head \
|
|
|
|
join \
|
|
|
|
link \
|
|
|
|
ln \
|
|
|
|
ls \
|
|
|
|
mkdir \
|
|
|
|
mktemp \
|
|
|
|
more \
|
|
|
|
mv \
|
|
|
|
nl \
|
|
|
|
numfmt \
|
|
|
|
nproc \
|
|
|
|
od \
|
|
|
|
paste \
|
2021-05-30 22:15:24 +00:00
|
|
|
pr \
|
2020-05-11 02:14:58 +00:00
|
|
|
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
|
2019-04-28 02:14:22 +00:00
|
|
|
|
|
|
|
UNIX_PROGS := \
|
2020-05-11 02:14:58 +00:00
|
|
|
arch \
|
|
|
|
chgrp \
|
|
|
|
chmod \
|
|
|
|
chown \
|
|
|
|
chroot \
|
|
|
|
du \
|
|
|
|
groups \
|
|
|
|
hostid \
|
|
|
|
hostname \
|
|
|
|
id \
|
|
|
|
install \
|
|
|
|
kill \
|
|
|
|
logname \
|
|
|
|
mkfifo \
|
|
|
|
mknod \
|
|
|
|
nice \
|
|
|
|
nohup \
|
|
|
|
pathchk \
|
|
|
|
pinky \
|
|
|
|
stat \
|
|
|
|
stdbuf \
|
|
|
|
timeout \
|
|
|
|
touch \
|
|
|
|
tty \
|
|
|
|
uname \
|
|
|
|
unlink \
|
|
|
|
uptime \
|
|
|
|
users \
|
|
|
|
who
|
2019-04-28 02:14:22 +00:00
|
|
|
|
2021-08-05 04:39:37 +00:00
|
|
|
SELINUX_PROGS := \
|
2021-08-20 01:38:57 +00:00
|
|
|
chcon \
|
|
|
|
runcon
|
2021-08-05 04:39:37 +00:00
|
|
|
|
2019-04-28 02:14:22 +00:00
|
|
|
ifneq ($(OS),Windows_NT)
|
2022-01-02 00:05:10 +00:00
|
|
|
PROGS := $(PROGS) $(UNIX_PROGS)
|
2019-04-28 02:14:22 +00:00
|
|
|
endif
|
|
|
|
|
2021-08-05 04:39:37 +00:00
|
|
|
ifeq ($(SELINUX_ENABLED),1)
|
2022-01-02 00:05:10 +00:00
|
|
|
PROGS := $(PROGS) $(SELINUX_PROGS)
|
2021-08-05 04:39:37 +00:00
|
|
|
endif
|
|
|
|
|
2019-04-28 02:14:22 +00:00
|
|
|
UTILS ?= $(PROGS)
|
|
|
|
|
|
|
|
# Programs with usable tests
|
|
|
|
TEST_PROGS := \
|
|
|
|
base32 \
|
|
|
|
base64 \
|
|
|
|
basename \
|
|
|
|
cat \
|
2021-08-05 04:39:37 +00:00
|
|
|
chcon \
|
2019-04-28 02:14:22 +00:00
|
|
|
chgrp \
|
|
|
|
chmod \
|
|
|
|
chown \
|
|
|
|
cksum \
|
|
|
|
comm \
|
|
|
|
cp \
|
2020-12-27 14:24:02 +00:00
|
|
|
csplit \
|
2019-04-28 02:14:22 +00:00
|
|
|
cut \
|
2021-01-16 20:15:03 +00:00
|
|
|
date \
|
2019-04-28 02:14:22 +00:00
|
|
|
dircolors \
|
|
|
|
dirname \
|
|
|
|
echo \
|
|
|
|
env \
|
|
|
|
expr \
|
|
|
|
factor \
|
|
|
|
false \
|
|
|
|
fold \
|
|
|
|
hashsum \
|
|
|
|
head \
|
|
|
|
install \
|
|
|
|
link \
|
|
|
|
ln \
|
|
|
|
ls \
|
|
|
|
mkdir \
|
|
|
|
mktemp \
|
|
|
|
mv \
|
|
|
|
nl \
|
|
|
|
numfmt \
|
|
|
|
od \
|
|
|
|
paste \
|
|
|
|
pathchk \
|
|
|
|
pinky \
|
2021-05-31 07:39:11 +00:00
|
|
|
pr \
|
2019-04-28 02:14:22 +00:00
|
|
|
printf \
|
|
|
|
ptx \
|
|
|
|
pwd \
|
|
|
|
readlink \
|
|
|
|
realpath \
|
|
|
|
rm \
|
|
|
|
rmdir \
|
2021-08-20 01:38:57 +00:00
|
|
|
runcon \
|
2019-04-28 02:14:22 +00:00
|
|
|
seq \
|
|
|
|
sort \
|
|
|
|
split \
|
|
|
|
stat \
|
|
|
|
stdbuf \
|
|
|
|
sum \
|
|
|
|
tac \
|
|
|
|
tail \
|
|
|
|
test \
|
|
|
|
touch \
|
|
|
|
tr \
|
|
|
|
true \
|
|
|
|
truncate \
|
|
|
|
tsort \
|
2020-04-30 22:24:06 +00:00
|
|
|
uname \
|
2019-04-28 02:14:22 +00:00
|
|
|
unexpand \
|
|
|
|
uniq \
|
|
|
|
unlink \
|
|
|
|
wc \
|
|
|
|
who
|
|
|
|
|
|
|
|
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
|
2021-08-05 04:39:37 +00:00
|
|
|
else ifeq ($(SELINUX_ENABLED),1)
|
|
|
|
TEST_NO_FAIL_FAST :=
|
|
|
|
TEST_SPEC_FEATURE := feat_selinux
|
2019-04-28 02:14:22 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
define TEST_BUSYBOX
|
|
|
|
test_busybox_$(1):
|
2021-03-10 22:13:57 +00:00
|
|
|
-(cd $(BUSYBOX_SRC)/testsuite && bindir=$(BUILDDIR) ./runtest $(RUNTEST_ARGS) $(1))
|
2019-04-28 02:14:22 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
# Output names
|
|
|
|
EXES := \
|
2020-05-11 02:14:58 +00:00
|
|
|
$(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(PROGS))))
|
2019-04-28 02:14:22 +00:00
|
|
|
|
|
|
|
INSTALLEES := ${EXES}
|
|
|
|
ifeq (${MULTICALL}, y)
|
2021-04-02 20:18:31 +00:00
|
|
|
INSTALLEES := ${INSTALLEES} coreutils
|
2019-04-28 02:14:22 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
all: build
|
|
|
|
|
|
|
|
do_install = $(INSTALL) ${1}
|
|
|
|
use_default := 1
|
|
|
|
|
|
|
|
build-pkgs:
|
|
|
|
ifneq (${MULTICALL}, y)
|
2020-06-09 19:29:29 +00:00
|
|
|
${CARGO} build ${CARGOFLAGS} ${PROFILE_CMD} $(foreach pkg,$(EXES),-p uu_$(pkg))
|
2019-04-28 02:14:22 +00:00
|
|
|
endif
|
|
|
|
|
2021-04-02 20:18:31 +00:00
|
|
|
build-coreutils:
|
2019-04-28 02:14:22 +00:00
|
|
|
${CARGO} build ${CARGOFLAGS} --features "${EXES}" ${PROFILE_CMD} --no-default-features
|
|
|
|
|
2022-01-20 22:21:48 +00:00
|
|
|
build: build-coreutils build-pkgs
|
2019-04-28 02:14:22 +00:00
|
|
|
|
|
|
|
$(foreach test,$(filter-out $(SKIP_UTILS),$(PROGS)),$(eval $(call TEST_BUSYBOX,$(test))))
|
|
|
|
|
|
|
|
test:
|
|
|
|
${CARGO} test ${CARGOFLAGS} --features "$(TESTS) $(TEST_SPEC_FEATURE)" --no-default-features $(TEST_NO_FAIL_FAST)
|
|
|
|
|
|
|
|
busybox-src:
|
2021-06-06 16:18:12 +00:00
|
|
|
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 ;
|
2019-04-28 02:14:22 +00:00
|
|
|
|
|
|
|
# This is a busybox-specific config file their test suite wants to parse.
|
|
|
|
$(BUILDDIR)/.config: $(BASEDIR)/.busybox-config
|
|
|
|
cp $< $@
|
|
|
|
|
2021-05-31 02:59:38 +00:00
|
|
|
# Test under the busybox test suite
|
2021-04-02 20:18:31 +00:00
|
|
|
$(BUILDDIR)/busybox: busybox-src build-coreutils $(BUILDDIR)/.config
|
2021-06-06 16:18:12 +00:00
|
|
|
cp "$(BUILDDIR)/coreutils" "$(BUILDDIR)/busybox"
|
|
|
|
chmod +x $@
|
2019-04-28 02:14:22 +00:00
|
|
|
|
2021-03-14 19:30:53 +00:00
|
|
|
prepare-busytest: $(BUILDDIR)/busybox
|
2021-06-06 16:21:38 +00:00
|
|
|
# disable inapplicable tests
|
|
|
|
-( cd "$(BUSYBOX_SRC)/testsuite" ; if [ -e "busybox.tests" ] ; then mv busybox.tests busybox.tests- ; fi ; )
|
2021-03-14 19:30:53 +00:00
|
|
|
|
2019-04-28 02:14:22 +00:00
|
|
|
ifeq ($(EXES),)
|
|
|
|
busytest:
|
|
|
|
else
|
|
|
|
busytest: $(BUILDDIR)/busybox $(addprefix test_busybox_,$(filter-out $(SKIP_UTILS),$(EXES)))
|
|
|
|
endif
|
|
|
|
|
|
|
|
clean:
|
2022-01-26 18:48:31 +00:00
|
|
|
cargo clean
|
2020-04-28 02:20:20 +00:00
|
|
|
cd $(DOCSDIR) && $(MAKE) clean
|
2019-04-28 02:14:22 +00:00
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
$(CARGO) clean $(CARGOFLAGS) && $(CARGO) update $(CARGOFLAGS)
|
|
|
|
|
|
|
|
install: build
|
|
|
|
mkdir -p $(INSTALLDIR_BIN)
|
|
|
|
ifeq (${MULTICALL}, y)
|
2021-04-02 20:18:31 +00:00
|
|
|
$(INSTALL) $(BUILDDIR)/coreutils $(INSTALLDIR_BIN)/$(PROG_PREFIX)coreutils
|
|
|
|
cd $(INSTALLDIR_BIN) && $(foreach prog, $(filter-out coreutils, $(INSTALLEES)), \
|
|
|
|
ln -fs $(PROG_PREFIX)coreutils $(PROG_PREFIX)$(prog) &&) :
|
2021-07-09 22:36:12 +00:00
|
|
|
$(if $(findstring test,$(INSTALLEES)), cd $(INSTALLDIR_BIN) && ln -fs $(PROG_PREFIX)coreutils $(PROG_PREFIX)[)
|
2019-04-28 02:14:22 +00:00
|
|
|
else
|
|
|
|
$(foreach prog, $(INSTALLEES), \
|
|
|
|
$(INSTALL) $(BUILDDIR)/$(prog) $(INSTALLDIR_BIN)/$(PROG_PREFIX)$(prog);)
|
2021-06-27 16:23:10 +00:00
|
|
|
$(if $(findstring test,$(INSTALLEES)), $(INSTALL) $(BUILDDIR)/test $(INSTALLDIR_BIN)/$(PROG_PREFIX)[)
|
2019-04-28 02:14:22 +00:00
|
|
|
endif
|
2021-07-09 21:40:09 +00:00
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)/share/zsh/site-functions
|
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)/share/bash-completion/completions
|
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d
|
2021-06-15 13:35:49 +00:00
|
|
|
$(foreach prog, $(INSTALLEES), \
|
|
|
|
$(BUILDDIR)/coreutils completion $(prog) zsh > $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_$(PROG_PREFIX)$(prog); \
|
|
|
|
$(BUILDDIR)/coreutils completion $(prog) bash > $(DESTDIR)$(PREFIX)/share/bash-completion/completions/$(PROG_PREFIX)$(prog); \
|
|
|
|
$(BUILDDIR)/coreutils completion $(prog) fish > $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/$(PROG_PREFIX)$(prog).fish; \
|
|
|
|
)
|
2019-04-28 02:14:22 +00:00
|
|
|
|
|
|
|
uninstall:
|
|
|
|
ifeq (${MULTICALL}, y)
|
2021-04-02 20:18:31 +00:00
|
|
|
rm -f $(addprefix $(INSTALLDIR_BIN)/,$(PROG_PREFIX)coreutils)
|
2019-04-28 02:14:22 +00:00
|
|
|
endif
|
|
|
|
rm -f $(addprefix $(INSTALLDIR_BIN)/$(PROG_PREFIX),$(PROGS))
|
2021-06-27 16:23:10 +00:00
|
|
|
rm -f $(INSTALLDIR_BIN)/$(PROG_PREFIX)[
|
2021-06-19 10:31:23 +00:00
|
|
|
rm -f $(addprefix $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_$(PROG_PREFIX),$(PROGS))
|
|
|
|
rm -f $(addprefix $(DESTDIR)$(PREFIX)/share/bash-completion/completions/$(PROG_PREFIX),$(PROGS))
|
|
|
|
rm -f $(addprefix $(DESTDIR)$(PREFIX)/share/fish/vendor_completions.d/$(PROG_PREFIX),$(addsuffix .fish,$(PROGS)))
|
2019-04-28 02:14:22 +00:00
|
|
|
|
2022-01-20 22:21:48 +00:00
|
|
|
.PHONY: all build build-coreutils build-pkgs test distclean clean busytest install uninstall
|