1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# This Makefile requires GNU make, sometimes available as gmake.
#
# A simple test suite for libmseed.
# See README for description.
#
# Build environment can be configured the following
# environment variables:
# CC : Specify the C compiler to use
# CFLAGS : Specify compiler options to use
# Required compiler parameters
CFLAGS += -I..
LDFLAGS = -L..
LDLIBS = -lmseed
SRCS := $(sort $(wildcard *.c))
BINS := $(SRCS:%.c=%)
TESTS := $(sort $(wildcard *.test))
TESTOUTS := $(TESTS:%.test=%.test.out)
# ASCII color coding for test results, green for PASSED and red for FAILED
PASSED := \033[0;32mPASSED\033[0m
FAILED := \033[0;31mFAILED\033[0m
TESTCOUNT := 0
test all: $(BINS) $(TESTOUTS)
@printf '%d tests conducted\n' $(TESTCOUNT)
# Build programs and check for executable
$(BINS) : % : %.c
@$(eval TESTCOUNT=$(shell echo $$(($(TESTCOUNT)+1))))
@$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDLIBS); exit 0;
@if test -x $@; \
then printf '$(PASSED) Building $<\n'; \
else printf '$(FAILED) Building $<\n'; exit 1; \
fi
# Run test scripts, create %.test.out files and compare to %.test.ref references
$(TESTOUTS) : %.test.out : %.test $(BINS) FORCE
@$(eval TESTCOUNT=$(shell echo $$(($(TESTCOUNT)+1))))
@$(shell ./$< > $@ 2>&1)
@diff $<.ref $@ >/dev/null; \
if [ $$? -eq 0 ]; \
then printf '$(PASSED) Test $<\n'; \
else printf '$(FAILED) Test $<, Compare $<.ref $@\n'; \
exit 0; \
fi
clean:
@rm -f $(BINS) $(TESTOUTS)
# Any targets using this empty FORCE rule as a prerequisite will always run
FORCE:
|