coreutils/Makefile

311 lines
5.3 KiB
Makefile
Raw Normal View History

# 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
2016-08-04 13:27:32 +00:00
RM := rm -rf
# Binaries
CARGO ?= cargo
2015-12-18 22:03:57 +00:00
CARGOFLAGS ?=
2013-10-23 15:09:40 +00:00
# Install directories
2015-12-25 05:58:37 +00:00
PREFIX ?= /usr/local
2016-05-07 06:57:47 +00:00
DESTDIR ?=
BINDIR ?= /bin
LIBDIR ?= /lib
2015-12-25 05:58:37 +00:00
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)
2015-12-21 00:48:26 +00:00
# Possible programs
PROGS := \
2016-08-06 03:45:03 +00:00
base32 \
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 \
cut \
2016-05-10 15:29:29 +00:00
dircolors \
2013-12-03 09:29:32 +00:00
dirname \
2013-12-02 11:50:24 +00:00
echo \
env \
2014-07-25 22:34:45 +00:00
expand \
Implement expr. Implemented as follows: Usage: expr EXPRESSION or: expr OPTION --help display this help and exit --version output version information and exit Print the value of EXPRESSION to standard output. A blank line below separates increasing precedence groups. EXPRESSION may be: ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2 ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0 ARG1 < ARG2 ARG1 is less than ARG2 ARG1 <= ARG2 ARG1 is less than or equal to ARG2 ARG1 = ARG2 ARG1 is equal to ARG2 ARG1 != ARG2 ARG1 is unequal to ARG2 ARG1 >= ARG2 ARG1 is greater than or equal to ARG2 ARG1 > ARG2 ARG1 is greater than ARG2 ARG1 + ARG2 arithmetic sum of ARG1 and ARG2 ARG1 - ARG2 arithmetic difference of ARG1 and ARG2 ARG1 * ARG2 arithmetic product of ARG1 and ARG2 ARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2 ARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2 STRING : REGEXP [NOT IMPLEMENTED] anchored pattern match of REGEXP in STRING match STRING REGEXP [NOT IMPLEMENTED] same as STRING : REGEXP substr STRING POS LENGTH [NOT IMPLEMENTED] substring of STRING, POS counted from 1 index STRING CHARS [NOT IMPLEMENTED] index in STRING where any CHARS is found, or 0 length STRING [NOT IMPLEMENTED] length of STRING + TOKEN interpret TOKEN as a string, even if it is a keyword like 'match' or an operator like '/' ( EXPRESSION ) value of EXPRESSION Beware that many operators need to be escaped or quoted for shells. Comparisons are arithmetic if both ARGs are numbers, else lexicographical. Pattern matches return the string matched between \( and \) or null; if \( and \) are not used, they return the number of characters matched or 0. Exit status is 0 if EXPRESSION is neither null nor 0, 1 if EXPRESSION is null or 0, 2 if EXPRESSION is syntactically invalid, and 3 if an error occurred. Environment variables: * EXPR_DEBUG_TOKENS=1 dump expression's tokens * EXPR_DEBUG_RPN=1 dump expression represented in reverse polish notation * EXPR_DEBUG_SYA_STEP=1 dump each parser step * EXPR_DEBUG_AST=1 dump expression represented abstract syntax tree
2015-10-09 09:31:25 +00:00
expr \
2014-05-30 00:39:33 +00:00
factor \
2013-12-02 11:50:24 +00:00
false \
fmt \
2014-03-27 01:34:58 +00:00
fold \
2014-06-22 20:27:43 +00:00
hashsum \
head \
link \
ln \
2016-03-25 21:00:27 +00:00
ls \
mkdir \
2016-01-03 10:10:47 +00:00
mktemp \
2014-06-14 14:43:39 +00:00
nl \
2014-10-18 21:17:33 +00:00
nproc \
od \
2014-02-28 17:19:32 +00:00
paste \
2013-12-02 11:50:24 +00:00
printenv \
2015-12-24 06:11:00 +00:00
printf \
2015-01-27 15:37:07 +00:00
ptx \
2013-12-05 11:36:08 +00:00
pwd \
2014-12-23 11:27:21 +00:00
readlink \
2014-06-29 19:57:54 +00:00
realpath \
2014-06-29 19:59:25 +00:00
relpath \
2013-12-18 06:09:32 +00:00
rm \
2013-12-18 18:39:23 +00:00
rmdir \
2014-02-05 19:46:28 +00:00
seq \
2015-12-29 07:18:19 +00:00
shred \
2014-07-10 01:19:59 +00:00
shuf \
sleep \
sort \
split \
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 \
tail \
2013-12-23 17:12:26 +00:00
tee \
test \
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 \
tsort \
2014-07-28 00:11:49 +00:00
unexpand \
2014-07-06 00:27:22 +00:00
uniq \
2013-12-02 11:50:24 +00:00
wc \
whoami \
yes
2013-12-02 11:50:24 +00:00
UNIX_PROGS := \
arch \
chmod \
2016-06-22 13:36:50 +00:00
chown \
2014-06-16 15:37:03 +00:00
chroot \
du \
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 \
2016-07-13 18:47:04 +00:00
install \
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 \
2016-05-07 06:57:47 +00:00
mknod \
mv \
2014-12-16 04:03:21 +00:00
nice \
2014-06-24 12:51:57 +00:00
nohup \
pathchk \
2016-07-12 10:40:48 +00:00
pinky \
2016-06-01 12:20:32 +00:00
stat \
2014-12-30 19:11:36 +00:00
stdbuf \
2014-07-22 01:50:53 +00:00
timeout \
touch \
2014-02-19 05:59:48 +00:00
tty \
2014-06-15 14:25:00 +00:00
uname \
unlink \
2014-04-02 00:13:07 +00:00
uptime \
2014-06-15 20:41:23 +00:00
users
ifneq ($(OS),Windows_NT)
PROGS := $(PROGS) $(UNIX_PROGS)
endif
UTILS ?= $(PROGS)
# Programs with usable tests
TEST_PROGS := \
2016-08-06 03:45:03 +00:00
base32 \
base64 \
basename \
cat \
2016-01-04 15:58:49 +00:00
chmod \
2016-06-22 13:36:50 +00:00
chown \
cksum \
2015-11-28 19:36:29 +00:00
comm \
cp \
cut \
2016-05-10 15:29:29 +00:00
dircolors \
dirname \
echo \
env \
2015-12-22 13:10:43 +00:00
expr \
factor \
false \
fold \
hashsum \
head \
install \
link \
ln \
2016-03-25 22:30:25 +00:00
ls \
mkdir \
2016-01-03 10:10:47 +00:00
mktemp \
mv \
nl \
2016-04-26 03:06:38 +00:00
od \
paste \
pathchk \
2016-07-12 10:40:48 +00:00
pinky \
2015-12-24 06:11:00 +00:00
printf \
ptx \
pwd \
readlink \
realpath \
rm \
rmdir \
seq \
sort \
split \
2016-06-01 12:20:32 +00:00
stat \
stdbuf \
sum \
tac \
2015-12-12 21:24:48 +00:00
tail \
test \
touch \
tr \
true \
truncate \
tsort \
unexpand \
2016-02-29 05:37:16 +00:00
uniq \
unlink \
wc
TESTS := \
$(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(TEST_PROGS))))
2015-12-21 00:48:26 +00:00
TEST_NO_FAIL_FAST :=
2016-05-07 06:57:47 +00:00
TEST_SPEC_FEATURE :=
ifneq ($(SPEC),)
TEST_NO_FAIL_FAST :=--no-fail-fast
TEST_SPEC_FEATURE := test_unimplemented
endif
define BUILD_EXE
build_exe_$(1):
2015-12-18 22:03:57 +00:00
${CARGO} build ${CARGOFLAGS} ${PROFILE_CMD} -p $(1)
endef
2015-12-21 00:48:26 +00:00
define TEST_BUSYBOX
test_busybox_$(1):
2015-12-21 00:48:26 +00:00
(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
2014-06-13 02:14:56 +00:00
2014-12-30 19:11:36 +00:00
# Shared library extension
SYSTEM := $(shell uname)
Implement expr. Implemented as follows: Usage: expr EXPRESSION or: expr OPTION --help display this help and exit --version output version information and exit Print the value of EXPRESSION to standard output. A blank line below separates increasing precedence groups. EXPRESSION may be: ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2 ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0 ARG1 < ARG2 ARG1 is less than ARG2 ARG1 <= ARG2 ARG1 is less than or equal to ARG2 ARG1 = ARG2 ARG1 is equal to ARG2 ARG1 != ARG2 ARG1 is unequal to ARG2 ARG1 >= ARG2 ARG1 is greater than or equal to ARG2 ARG1 > ARG2 ARG1 is greater than ARG2 ARG1 + ARG2 arithmetic sum of ARG1 and ARG2 ARG1 - ARG2 arithmetic difference of ARG1 and ARG2 ARG1 * ARG2 arithmetic product of ARG1 and ARG2 ARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2 ARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2 STRING : REGEXP [NOT IMPLEMENTED] anchored pattern match of REGEXP in STRING match STRING REGEXP [NOT IMPLEMENTED] same as STRING : REGEXP substr STRING POS LENGTH [NOT IMPLEMENTED] substring of STRING, POS counted from 1 index STRING CHARS [NOT IMPLEMENTED] index in STRING where any CHARS is found, or 0 length STRING [NOT IMPLEMENTED] length of STRING + TOKEN interpret TOKEN as a string, even if it is a keyword like 'match' or an operator like '/' ( EXPRESSION ) value of EXPRESSION Beware that many operators need to be escaped or quoted for shells. Comparisons are arithmetic if both ARGs are numbers, else lexicographical. Pattern matches return the string matched between \( and \) or null; if \( and \) are not used, they return the number of characters matched or 0. Exit status is 0 if EXPRESSION is neither null nor 0, 1 if EXPRESSION is null or 0, 2 if EXPRESSION is syntactically invalid, and 3 if an error occurred. Environment variables: * EXPR_DEBUG_TOKENS=1 dump expression's tokens * EXPR_DEBUG_RPN=1 dump expression represented in reverse polish notation * EXPR_DEBUG_SYA_STEP=1 dump each parser step * EXPR_DEBUG_AST=1 dump expression represented abstract syntax tree
2015-10-09 09:31:25 +00:00
DYLIB_EXT :=
2014-12-30 19:11:36 +00:00
ifeq ($(SYSTEM),Linux)
2015-01-25 12:40:18 +00:00
DYLIB_EXT := so
DYLIB_FLAGS := -shared
2014-12-30 19:11:36 +00:00
endif
ifeq ($(SYSTEM),Darwin)
2015-01-25 12:40:18 +00:00
DYLIB_EXT := dylib
DYLIB_FLAGS := -dynamiclib -undefined dynamic_lookup
2014-12-30 19:11:36 +00:00
endif
# Libaries to install
LIBS :=
ifneq (,$(findstring stdbuf, $(INSTALLEES)))
2015-01-25 12:40:18 +00:00
LIBS += libstdbuf.$(DYLIB_EXT)
2014-12-30 19:11:36 +00:00
endif
all: build
do_install = $(INSTALL) ${1}
use_default := 1
$(foreach util,$(EXES),$(eval $(call BUILD_EXE,$(util))))
build-pkgs: $(addprefix build_exe_,$(EXES))
2016-05-07 06:57:47 +00:00
build-uutils:
2015-12-18 22:03:57 +00:00
${CARGO} build ${CARGOFLAGS} --features "${EXES}" ${PROFILE_CMD} --no-default-features
build: build-uutils build-pkgs
2013-10-23 15:09:40 +00:00
$(foreach test,$(filter-out $(SKIP_UTILS),$(PROGS)),$(eval $(call TEST_BUSYBOX,$(test))))
2016-07-31 17:02:41 +00:00
test:
${CARGO} test ${CARGOFLAGS} --features "$(TESTS) $(TEST_SPEC_FEATURE)" --no-default-features $(TEST_NO_FAIL_FAST)
2015-12-21 00:48:26 +00:00
busybox-src:
if [ ! -e $(BUSYBOX_SRC) ]; then \
mkdir -p $(BUSYBOX_ROOT); \
2015-12-21 20:37:57 +00:00
wget https://busybox.net/downloads/busybox-$(BUSYBOX_VER).tar.bz2 -P $(BUSYBOX_ROOT); \
2015-12-21 00:48:26 +00:00
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.
2016-05-07 06:57:47 +00:00
$(BUILDDIR)/.config: $(BASEDIR)/.busybox-config
cp $< $@
2015-12-21 00:48:26 +00:00
# Test under the busybox testsuite
2016-05-07 06:57:47 +00:00
$(BUILDDIR)/busybox: busybox-src build-uutils $(BUILDDIR)/.config
cp $(BUILDDIR)/uutils $(BUILDDIR)/busybox; \
2015-12-21 00:48:26 +00:00
chmod +x $@;
ifeq ($(EXES),)
2015-12-21 00:48:26 +00:00
busytest:
else
busytest: $(BUILDDIR)/busybox $(addprefix test_busybox_,$(filter-out $(SKIP_UTILS),$(EXES)))
2015-12-21 00:48:26 +00:00
endif
2014-06-20 21:31:55 +00:00
clean:
2016-08-04 13:27:32 +00:00
$(RM) $(BUILDDIR)
distclean: clean
2015-12-18 22:03:57 +00:00
$(CARGO) clean $(CARGOFLAGS) && $(CARGO) update $(CARGOFLAGS)
2016-05-07 06:57:47 +00:00
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