NAMES = $(NAME)
TESTS = tests-cutils
+# You may override these when calling make
PREFIX = /usr/local
dstdir = bin
test: mess-test $(TESTS)
# Main buildables
-M_OPTS=$(MAKECMDGOALS) --no-print-directory PREFIX=$(PREFIX) DEBUG=$(DEBUG)
+M_OPTS=$(MAKECMDGOALS) --no-print-directory \
+ PREFIX=$(PREFIX) DEBUG=$(DEBUG) dstdir=$(abspath $(dstdir))
$(NAMES) $(TESTS):
$(MAKE) -C src/$@ $(M_OPTS)
# Messages
mess-build:
@echo
- @echo ">>>>>>>>>> Building $(NAMES)..."
+ @echo ">>>>>>>>>> Building $(NAMES) in $(dstdir)..."
mess-run:
@echo
@echo ">>>>>>>>>> Running $(NAME)..."
@echo ">>>>>>>>>> Manual of $(NAME): $(MAKECMDGOALS)..."
mess-test:
@echo
- @echo ">>>>>>>>>> Building all tests: $(TESTS)..."
+ @echo ">>>>>>>>>> Building all tests in $(dstdir): $(TESTS)..."
mess-run-test:
@echo
@echo ">>>>>>>>>> Running tests: $(TESTS)..."
NAME = tests-cutils
NAMES = $(NAME)
srcdir = $(NAME)
-dstdir = ../bin
+
+ifeq ($(dstdir),)
+dstdir = $(srcdir)/bin
+endif
CFLAGS += -Wall -pedantic -I./ -std=c99
CXXFLAGS += -Wall -pedantic -I./
$(NAME): deps $(dstdir)/$(NAME)
+# Test program, so running = running tests
+run: run-test
+test: build
+run-test: test
+ @echo
+ $(dstdir)/$(NAME)
+run-test-more: test
+ @echo
+ $(dstdir)/$(NAME) --more
+
################
# Dependencies #
################
## Libs (if needed)
deps:
- $(MAKE) --no-print-directory -C cutils/ cutils
- $(MAKE) --no-print-directory -C cutils/ check
+ $(MAKE) dstdir=$(dstdir) --no-print-directory -C cutils/ cutils
+ $(MAKE) dstdir=$(dstdir) --no-print-directory -C cutils/ check
DEPS=$(dstdir)/libcutils.o $(dstdir)/libcutils-check.o
## Headers
mkdir -p $(dstdir)
$(CC) $(CFLAGS) $(LDFLAGS) $(DEPS) $(OBJECTS) -o $@
-# Test program, so running = running tests
-run: run-test
-test: build
-
-run-test: test
- @echo
- $(dstdir)/$(NAME)
-run-test-more: test
- @echo
- $(dstdir)/$(NAME) --more
-
clean:
- rm -f $(OBJECTS) $(DEPENDS)
+ rm -f $(OBJECTS)
+ rm -f $(DEPENDS)
+ rm -f $(DEPS)
mrproper: mrpropre
mrpropre: clean
rm -f $(dstdir)/$(NAME)
rmdir $(dstdir) 2>/dev/null || true
+install uninstall:
+ @echo Those are tests, nothing to install/uninstall
+