coreutils/Makefile

302 lines
5.4 KiB
Makefile
Raw Normal View History

# 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
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
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/
2015-12-21 00:48:26 +00:00
BUSYBOX_ROOT := $(BASEDIR)/tmp/
BUSYBOX_VER := 1.24.1
BUSYBOX_SRC:=$(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER)/
# 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-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 \
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 \
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-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 := \
chmod \
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 \
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 \
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 \
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
BUILD ?= $(PROGS)
# Programs with usable tests
TEST_PROGS := \
base64 \
basename \
cat \
2016-01-04 15:58:49 +00:00
chmod \
cksum \
2015-11-28 19:36:29 +00:00
comm \
cp \
cut \
dirname \
echo \
env \
2015-12-22 13:10:43 +00:00
expr \
factor \
false \
fold \
hashsum \
head \
link \
ln \
mkdir \
2016-01-03 10:10:47 +00:00
mktemp \
mv \
nl \
paste \
ptx \
pwd \
readlink \
realpath \
rm \
rmdir \
seq \
sort \
split \
stdbuf \
sum \
tac \
2015-12-12 21:24:48 +00:00
tail \
test \
touch \
tr \
true \
truncate \
tsort \
unexpand \
unlink \
wc
TEST ?= $(TEST_PROGS)
TESTS := \
$(sort $(filter $(TEST),$(filter-out $(DONT_TEST),$(TEST_PROGS))))
2015-12-25 08:05:21 +00:00
INSTALL ?= $(PROGS)
2015-12-21 00:48:26 +00:00
BUSYTEST ?= $(PROGS)
2015-12-25 08:05:21 +00:00
ifneq (,$(filter install, $(MAKECMDGOALS)))
override BUILD:=$(INSTALL)
override DONT_BUILD:=$(DONT_INSTALL)
else
ifneq (,$(filter busytest, $(MAKECMDGOALS)))
override BUILD:=$(BUSYTEST)
override DONT_BUILD:=$(DONT_BUSYTEST)
endif
2015-12-25 08:05:21 +00:00
endif
2015-12-21 00:48:26 +00:00
define BUILD_EXE
build_exe_$(1):
2015-12-18 22:03:57 +00:00
${CARGO} build ${CARGOFLAGS} ${PROFILE_CMD} -p $(1)
endef
define TEST_INTEGRATION
test_integration_$(1): build_exe_$(1)
2015-12-18 22:03:57 +00:00
${CARGO} test ${CARGOFLAGS} --test $(1) --features $(1) --no-default-features
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 $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS))))
2013-12-02 11:50:24 +00:00
INSTALL ?= $(EXES)
2014-06-13 02:14:56 +00:00
INSTALLEES := \
$(sort $(filter $(INSTALL),$(filter-out $(DONT_INSTALL),$(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))
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,$(TESTS),$(eval $(call TEST_INTEGRATION,$(test))))
2015-12-21 00:48:26 +00:00
$(foreach test,$(PROGS),$(eval $(call TEST_BUSYBOX,$(test))))
test: $(addprefix test_integration_,$(TESTS))
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.
$(BUILDDIR)/.config: $(BASEDIR)/.busybox-config
cp $< $@
2015-12-21 00:48:26 +00:00
# Test under the busybox testsuite
$(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_,$(EXES))
2015-12-21 00:48:26 +00:00
endif
2014-06-20 21:31:55 +00:00
clean:
$(RM) -rf $(BUILDDIR)
distclean: clean
2015-12-18 22:03:57 +00:00
$(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