mirror of
https://github.com/uutils/coreutils
synced 2024-11-15 01:17:09 +00:00
251 lines
4.2 KiB
Makefile
251 lines
4.2 KiB
Makefile
# Config options
|
|
ENABLE_RELEASE ?= n
|
|
PROFILE ?= debug
|
|
MULTICALL ?= n
|
|
|
|
PROFILE_CMD :=
|
|
ifeq (${PROFILE},release)
|
|
PROFILE_CMD = --release
|
|
endif
|
|
|
|
# Binaries
|
|
CARGO ?= cargo
|
|
|
|
# Install directories
|
|
PREFIX ?= /usr/local
|
|
BINDIR ?= /bin
|
|
LIBDIR ?= /lib
|
|
|
|
INSTALLDIR=$(DESTDIR)$(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/
|
|
|
|
|
|
|
|
# Possible programs
|
|
PROGS := \
|
|
base64 \
|
|
basename \
|
|
cat \
|
|
chmod \
|
|
cksum \
|
|
comm \
|
|
cp \
|
|
cut \
|
|
dirname \
|
|
echo \
|
|
env \
|
|
expand \
|
|
expr \
|
|
factor \
|
|
false \
|
|
fmt \
|
|
fold \
|
|
link \
|
|
hashsum \
|
|
ln \
|
|
mkdir \
|
|
nl \
|
|
nproc \
|
|
od \
|
|
paste \
|
|
printenv \
|
|
ptx \
|
|
pwd \
|
|
readlink \
|
|
realpath \
|
|
relpath \
|
|
rm \
|
|
rmdir \
|
|
sleep \
|
|
split \
|
|
seq \
|
|
shuf \
|
|
sort \
|
|
sum \
|
|
sync \
|
|
tac \
|
|
tee \
|
|
test_uu \
|
|
tr \
|
|
true \
|
|
truncate \
|
|
tsort \
|
|
unexpand \
|
|
uniq \
|
|
wc \
|
|
yes \
|
|
head \
|
|
tail \
|
|
whoami
|
|
|
|
UNIX_PROGS := \
|
|
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
|
|
|
|
ALIASES := \
|
|
hashsum:md5sum \
|
|
hashsum:sha1sum \
|
|
hashsum:sha224sum \
|
|
hashsum:sha256sum \
|
|
hashsum:sha384sum \
|
|
hashsum:sha512sum
|
|
|
|
BUILD ?= $(PROGS)
|
|
|
|
# Programs with usable tests
|
|
TEST_PROGS := \
|
|
base64 \
|
|
basename \
|
|
cat \
|
|
cksum \
|
|
cp \
|
|
cut \
|
|
env \
|
|
dirname \
|
|
echo \
|
|
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 \
|
|
unlink \
|
|
unexpand \
|
|
wc
|
|
|
|
TESTS := \
|
|
$(filter $(PROGS),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
|
|
|
|
TEST ?= $(TEST_PROGS)
|
|
|
|
# Output names
|
|
EXES := \
|
|
$(sort $(filter $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS))))
|
|
|
|
INSTALLEES := \
|
|
$(filter $(INSTALL),$(filter-out $(DONT_INSTALL),$(EXES) uutils))
|
|
|
|
INSTALL ?= $(EXES)
|
|
|
|
# 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
|
|
|
|
crates:
|
|
echo "okay" $(EXES)
|
|
|
|
build_uutils = ${CARGO} build --features "${1}" ${PROFILE_CMD} --no-default-features
|
|
build_pkg = ${CARGO} build ${PROFILE_CMD} -p "${1}"
|
|
run_integration_tests = ${CARGO} test --test ${1}
|
|
run_unit_tests = ${CARGO} test -p ${1}
|
|
do_install = install ${1}
|
|
use_default := 1
|
|
|
|
test:
|
|
$(call build_uutils, ${TESTS})
|
|
$(foreach util, ${TESTS}, $(call run_integration_tests, ${util});)
|
|
$(foreach util, ${TESTS}, $(call run_unit_tests, ${util});)
|
|
|
|
build:
|
|
$(call build_uutils,${EXES})
|
|
$(foreach util, ${EXES}, $(call build_pkg,${util});)
|
|
|
|
clean:
|
|
$(RM) -rf $(BUILDDIR)
|
|
|
|
distclean: clean
|
|
$(CARGO) clean && $(CARGO) update
|
|
|
|
build-check: build clean
|
|
test-check: test clean
|
|
|
|
# TODO: figure out if there is way for prefixes to work with the symlinks
|
|
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;)
|
|
else
|
|
$(foreach prog, $(INSTALLEES); \
|
|
install $(PKG_BUILDDIR)/$$prog $(INSTALLDIR)$(BINDIR)/$(PROG_PREFIX)$$prog;)
|
|
endif
|
|
mkdir -p $(INSTALLDIR)$(LIBDIR)
|
|
$(foreach lib, $(LIBS), install $(BUILDDIR)/$$lib $(INSTALLDIR)$(LIBDIR)/$$lib;)
|
|
|
|
uninstall:
|
|
rm -f $(addprefix $(INSTALLDIR)$(BINDIR)/$(PROG_PREFIX),$(PROGS))
|
|
rm -f $(addprefix $(INSTALLDIR)$(LIBDIR)/,$(LIBS))
|
|
|
|
uninstall-multicall:
|
|
rm -f $(addprefix $(INSTALLDIR)$(BINDIR)/,$(PROGS) $(PROG_PREFIX)uutils)
|
|
rm -f $(addprefix $(INSTALLDIR)$(LIBDIR)/,$(LIBS))
|
|
|
|
.PHONY: $(TEMPDIR) all build test distclean clean busytest install uninstall
|