2014-07-20 08:27:47 +00:00
|
|
|
# Config options
|
2015-11-22 20:45:04 +00:00
|
|
|
ENABLE_RELEASE ?= n
|
|
|
|
PROFILE ?= debug
|
|
|
|
MULTICALL ?= n
|
|
|
|
|
|
|
|
PROFILE_CMD :=
|
|
|
|
ifeq (${PROFILE},release)
|
|
|
|
PROFILE_CMD = --release
|
|
|
|
endif
|
2014-07-20 08:27:47 +00:00
|
|
|
|
2014-07-19 21:25:28 +00:00
|
|
|
# Binaries
|
2015-01-23 16:35:54 +00:00
|
|
|
CARGO ?= cargo
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2014-11-29 21:32:33 +00:00
|
|
|
# Install directories
|
2015-01-23 16:35:54 +00:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
BINDIR ?= /bin
|
|
|
|
LIBDIR ?= /lib
|
2014-11-29 21:32:33 +00:00
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
INSTALLDIR=$(DESTDIR)$(PREFIX)
|
|
|
|
|
2014-11-29 21:32:33 +00:00
|
|
|
# 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.
|
2015-01-10 21:00:15 +00:00
|
|
|
BASEDIR ?= $(shell pwd)
|
2015-11-22 20:45:04 +00:00
|
|
|
BUILDDIR := $(BASEDIR)/target/${PROFILE}/
|
|
|
|
PKG_BUILDDIR := $(BUILDDIR)/deps/
|
2014-11-29 21:32:33 +00:00
|
|
|
|
2015-01-10 21:00:15 +00:00
|
|
|
|
2014-07-19 21:25:28 +00:00
|
|
|
|
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-10-26 03:27:45 +00:00
|
|
|
chmod \
|
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 \
|
2014-06-12 21:04:01 +00:00
|
|
|
cut \
|
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 \
|
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 \
|
2015-07-05 18:52:31 +00:00
|
|
|
ln \
|
2014-01-01 23:32:21 +00:00
|
|
|
mkdir \
|
2014-06-14 14:43:39 +00:00
|
|
|
nl \
|
2014-10-18 21:17:33 +00:00
|
|
|
nproc \
|
2014-07-10 20:49:20 +00:00
|
|
|
od \
|
2014-02-28 17:19:32 +00:00
|
|
|
paste \
|
2013-12-02 11:50:24 +00:00
|
|
|
printenv \
|
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 \
|
2013-12-18 17:26:42 +00:00
|
|
|
sleep \
|
2014-07-01 22:30:08 +00:00
|
|
|
split \
|
2014-02-05 19:46:28 +00:00
|
|
|
seq \
|
2014-07-10 01:19:59 +00:00
|
|
|
shuf \
|
2014-07-07 14:55:47 +00:00
|
|
|
sort \
|
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 \
|
2015-11-22 20:45:04 +00:00
|
|
|
test_uu \
|
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-07-20 03:19:38 +00:00
|
|
|
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 \
|
|
|
|
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 \
|
2015-07-20 00:25:48 +00:00
|
|
|
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 \
|
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 \
|
2015-07-20 00:25:48 +00:00
|
|
|
mv \
|
2014-12-16 04:03:21 +00:00
|
|
|
nice \
|
2014-06-24 12:51:57 +00:00
|
|
|
nohup \
|
2014-12-30 19:11:36 +00:00
|
|
|
stdbuf \
|
2014-07-22 01:50:53 +00:00
|
|
|
timeout \
|
2015-07-20 00:25:48 +00:00
|
|
|
touch \
|
2014-02-19 05:59:48 +00:00
|
|
|
tty \
|
2014-06-15 14:25:00 +00:00
|
|
|
uname \
|
2015-07-20 00:25:48 +00:00
|
|
|
unlink \
|
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)
|
|
|
|
|
2015-11-25 06:50:57 +00:00
|
|
|
# Programs with usable tests
|
|
|
|
TEST_PROGS := \
|
|
|
|
base64 \
|
|
|
|
basename \
|
|
|
|
cat \
|
|
|
|
cksum \
|
|
|
|
cp \
|
|
|
|
cut \
|
|
|
|
dirname \
|
|
|
|
echo \
|
2015-11-25 08:36:28 +00:00
|
|
|
env \
|
2015-11-25 06:50:57 +00:00
|
|
|
factor \
|
|
|
|
false \
|
|
|
|
fold \
|
|
|
|
hashsum \
|
|
|
|
head \
|
|
|
|
link \
|
|
|
|
ln \
|
|
|
|
mkdir \
|
|
|
|
mv \
|
|
|
|
nl \
|
|
|
|
paste \
|
|
|
|
ptx \
|
|
|
|
pwd \
|
|
|
|
readlink \
|
|
|
|
realpath \
|
|
|
|
rm \
|
|
|
|
rmdir \
|
|
|
|
seq \
|
|
|
|
sort \
|
|
|
|
split \
|
|
|
|
stdbuf \
|
|
|
|
sum \
|
|
|
|
tac \
|
|
|
|
test \
|
|
|
|
touch \
|
|
|
|
tr \
|
|
|
|
true \
|
|
|
|
truncate \
|
|
|
|
tsort \
|
|
|
|
unexpand \
|
2015-11-25 08:36:28 +00:00
|
|
|
unlink \
|
2015-11-25 06:50:57 +00:00
|
|
|
wc
|
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
TESTS := \
|
|
|
|
$(filter $(PROGS),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
|
|
|
|
|
|
|
|
TEST ?= $(TEST_PROGS)
|
|
|
|
|
2013-12-27 07:48:38 +00:00
|
|
|
# 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-06-13 02:14:56 +00:00
|
|
|
INSTALLEES := \
|
2014-06-25 16:47:34 +00:00
|
|
|
$(filter $(INSTALL),$(filter-out $(DONT_INSTALL),$(EXES) uutils))
|
2014-06-13 02:14:56 +00:00
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
INSTALL ?= $(EXES)
|
|
|
|
|
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
|
2015-07-09 00:34:48 +00:00
|
|
|
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
|
2015-07-09 22:39:46 +00:00
|
|
|
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
|
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
all: build
|
2015-08-26 16:50:07 +00:00
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
crates:
|
|
|
|
echo "okay" $(EXES)
|
2014-07-01 03:45:51 +00:00
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
do_install = install ${1}
|
|
|
|
use_default := 1
|
2014-07-11 06:38:18 +00:00
|
|
|
|
2015-11-25 22:32:02 +00:00
|
|
|
$(foreach util,$(EXES),$(eval $(call BUILD_EXE,$(util))))
|
2015-04-29 23:24:20 +00:00
|
|
|
|
2015-11-25 22:32:02 +00:00
|
|
|
build-uutils:
|
|
|
|
${CARGO} build --features "${EXES}" ${PROFILE_CMD} --no-default-features
|
|
|
|
|
|
|
|
build: build-uutils $(addprefix build_exe_,$(EXES))
|
2015-11-25 08:36:28 +00:00
|
|
|
$(foreach util, ${EXES}, $(call build_pkg, ${util});)
|
2013-10-23 15:09:40 +00:00
|
|
|
|
2015-11-25 22:32:02 +00:00
|
|
|
$(foreach test,$(TESTS),$(eval $(call TEST_INTEGRATION,$(test))))
|
|
|
|
$(foreach test,$(TESTS),$(eval $(call TEST_UNIT,$(test))))
|
|
|
|
|
|
|
|
test: $(addprefix test_integration_,$(TESTS)) $(addprefix test_unit_,$(TESTS))
|
|
|
|
|
2014-06-20 21:31:55 +00:00
|
|
|
clean:
|
2015-11-22 20:45:04 +00:00
|
|
|
$(RM) -rf $(BUILDDIR)
|
2015-04-25 22:22:56 +00:00
|
|
|
|
|
|
|
distclean: clean
|
2015-11-22 20:45:04 +00:00
|
|
|
$(CARGO) clean && $(CARGO) update
|
2013-10-22 13:31:51 +00:00
|
|
|
|
2014-07-01 08:07:16 +00:00
|
|
|
# TODO: figure out if there is way for prefixes to work with the symlinks
|
2015-11-22 20:45:04 +00:00
|
|
|
install: build
|
|
|
|
PROFILE_CMD=--release
|
|
|
|
mkdir -p $(INSTALLDIR)$(BINDIR)
|
|
|
|
ifeq (${MULTICALL}, y)
|
|
|
|
install $(BUILDDIR)/uutils $(INSTALLDIR)$(BINDIR)/$(PROG_PREFIX)uutils
|
|
|
|
cd $(INSTALLDIR)$(BINDIR)
|
|
|
|
$(foreach prog, $(INSTALLEES), ln -s $(PROG_PREFIX)uutils $$prog;)
|
2014-06-01 18:26:58 +00:00
|
|
|
else
|
2015-11-22 20:45:04 +00:00
|
|
|
$(foreach prog, $(INSTALLEES); \
|
|
|
|
install $(PKG_BUILDDIR)/$$prog $(INSTALLDIR)$(BINDIR)/$(PROG_PREFIX)$$prog;)
|
2014-06-01 18:26:58 +00:00
|
|
|
endif
|
2015-11-22 20:45:04 +00:00
|
|
|
mkdir -p $(INSTALLDIR)$(LIBDIR)
|
|
|
|
$(foreach lib, $(LIBS), install $(BUILDDIR)/$$lib $(INSTALLDIR)$(LIBDIR)/$$lib;)
|
2014-06-01 18:26:58 +00:00
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
uninstall:
|
|
|
|
rm -f $(addprefix $(INSTALLDIR)$(BINDIR)/$(PROG_PREFIX),$(PROGS))
|
|
|
|
rm -f $(addprefix $(INSTALLDIR)$(LIBDIR)/,$(LIBS))
|
2015-04-27 05:42:21 +00:00
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
uninstall-multicall:
|
|
|
|
rm -f $(addprefix $(INSTALLDIR)$(BINDIR)/,$(PROGS) $(PROG_PREFIX)uutils)
|
|
|
|
rm -f $(addprefix $(INSTALLDIR)$(LIBDIR)/,$(LIBS))
|
2015-05-07 20:59:34 +00:00
|
|
|
|
2015-11-22 20:45:04 +00:00
|
|
|
.PHONY: $(TEMPDIR) all build test distclean clean busytest install uninstall
|