# Language default (options override)
LANG=C
LC_ALL=C

TESTS = test_4_1.sh

# Comment the following line if you don't have "awk", "join", or "sed"
# We are testing not only xcols, but the instructions in the user manual.
TESTS += test_xcols.sh

HASCHECK = $(shell if [ -f /usr/include/check.h ]; then echo -n "yes"; else if [ -f /usr/local/include/check.h ]; then echo -n "yes"; fi; fi)

ifeq ("$(HASCHECK)", "yes")
TESTS += check_memory_handling
CHECKMSG =''
else
CHECKMSG ="NOTE: You can run an additional test if you install the check library."
endif

TESTS_ENVIRONMENT=LANG=$(LANG)

CHECK_PREFIX=../../check

.POSIX:

check:: check-TESTS check-Message


# section inspired by a Makefile from check 
# which was generated by autoconf, automake
check-TESTS: $(TESTS)
	@failed=0; all=0; \
        for tst in $(TESTS); do \
          if $(TESTS_ENVIRONMENT) ./$$tst; then \
            all=`expr $$all + 1`; \
            echo "PASS: $$tst"; \
          elif test $$? -ne 77; then \
            all=`expr $$all + 1`; \
            failed=`expr $$failed + 1`; \
            echo "FAIL: $$tst"; \
          fi; \
        done; \
        if test "$$failed" -eq 0; then \
          banner="All $$all tests passed"; \
        else \
          banner="$$failed of $$all tests failed"; \
        fi; \
        dashes=`echo "$$banner" | sed s/./=/g`; \
        echo "$$dashes"; \
        echo "$$banner"; \
        echo "$$dashes"; \
        test "$$failed" -eq 0

check-Message:
	@echo $(CHECKMSG)

CPPFLAGS= -I../src/ -I$(CHECK_PREFIX)/include
CFLAGS=-Wall -pedantic
LDFLAGS=-L$(CHECK_PREFIX)/lib 

COMPILE = $(CC) $(CPPFLAGS) $(CFLAGS) 
LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@

.c.o:
	- $(COMPILE) -c $<




check_memory_handling: statist_check_dummies.o check_memory_handling.o ../src/memory_handling.o 
	@rm -f check_memory_handling
	- $(LINK) $+ -lcheck

CLEANFILES=*.o check_memory_handling

clean:
	-test -z "$(CLEANFILES)" || rm $(CLEANFILES)

