#
#  Generic make commands for C-language library module test programs
#  For GNU make; will not work with most other make programs
#
#	PROGRAMS = a b ...
#	FILTER = | filter_log  # optional
#	include Make_lib_test
#


# $Id: Make_lib_test 1.24 1998/07/06 libtsp-v3r0 $

include Make_kernel

CI = ci

fdir := $(dir $(shell pwd))	# Lop off last directory component, i.e. test
DIR := $(notdir $(fdir:/=))	# Remove trailing /, pick off last component
DIR := $(strip $(DIR))

ifndef TEST_SCRIPT
  TEST_SCRIPT = ./t$(DIR)routines
endif
ifndef LOG_FILE
  LOG_FILE = t$(DIR).log
endif
ifndef REF_FILE
  REF_FILE = t$(DIR).ref
endif

# Put bins in the bin/ subdirectory
BINS = $(addprefix $(BINDIR)/, $(PROGRAMS))

.PHONY:	all test reference clean

all:	$(BINS)

# Static rules expand to one rule for each program
$(BINS): $(BINDIR)/%: %.c $(LIB)
	@-test -d $(BINDIR) || mkdir -p $(BINDIR)
	$(CC) -I$(includedir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
		$< $(LOADLIBES) -o $@

test:	$(BINS)
	@echo "$(TEST_SCRIPT) $(FILTER) > $(LOG_FILE)"
	@PATH=$(BINDIR):$$PATH \
		$(TEST_SCRIPT) $(FILTER) > $(LOG_FILE)
	diff $(LOG_FILE) $(REF_FILE)
	$(RM) $(LOG_FILE)

reference:
	$(CO) $(COFLAGS) -l $(REF_FILE)
	@echo "$(TEST_SCRIPT) $(FILTER) > $(LOG_FILE)"
	@PATH=$(BINDIR):$$PATH \
		$(TEST_SCRIPT) $(FILTER) > $(REF_FILE)
	$(CI) $(CIFLAGS) -u -m"- update" $(REF_FILE)

clean:
	$(RM) *.o
