# Makefile for neon test suite.

SHELL = @SHELL@
CPPFLAGS = @CPPFLAGS@ -I. -I$(top_srcdir)/src -I$(top_srcdir)/test/common
CFLAGS = @CFLAGS@ @NEON_CFLAGS@
LDFLAGS = -L. @LDFLAGS@ -L$(top_srcdir)/src -L../src/.libs
DEFS = @DEFS@

top_builddir = ..
top_srcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@

AR = ar

RANLIB = @RANLIB@
LIBS = -ltest -lneon @NEON_LIBS@
CC = @CC@

HELPERS = file1.gz file2.gz @HELPERS@
SSL_HELPERS = server.pem
BASIC_TESTS = uri-tests util-tests string-tests request auth \
	regress basic
ZLIB_TESTS = compress
DAV_TESTS = acl lock
SSL_TESTS = ssl
TESTS = @TESTS@
HDRS = common/tests.h common/child.h utils.h $(top_builddir)/config.h

LIBTEST = libtest.a

# By default, compile but don't run the tests.
all: $(TESTS)

clean:
	rm -f $(TESTS) $(HELPERS) *.o common/*.o libtest.a

check: $(TESTS) $(HELPERS)
	@SRCDIR=$(srcdir) $(SHELL) $(srcdir)/run.sh $(TESTS)

file1.gz: ../NEWS
	gzip -c --no-name $(top_srcdir)/NEWS > $@

file2.gz: ../NEWS
	gzip -c --name $(top_srcdir)/NEWS > $@

# Don't need to have really random data for this.
server.key:
	openssl genrsa -rand $(top_srcdir)/configure > server.key

# TODO: mock up an openssl config file instead of this.
server.pem: server.key
	(echo GB; echo Cambridgeshire; echo Cambridge; \
	 echo Neon Hackers Ltd.; echo Neon QA Dept; echo localhost; \
	 echo neon@webdav.org) | \
	openssl req -x509 -new -key server.key -out server.pem

Makefile: $(srcdir)/Makefile.in
	cd .. && ./config.status test/Makefile

LIBOBJS = common/tests.o common/child.o utils.o

$(LIBTEST): $(LIBOBJS) $(HDRS) ../src/@NEON_TARGET@
	$(AR) cru $@ $(LIBOBJS)
	$(RANLIB) $@

.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

uri-tests: uri-tests.o $(LIBTEST)
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ uri-tests.o $(LIBS)

request: request.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ request.o $(LIBS)

string-tests: string-tests.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ string-tests.o $(LIBS)

sock-tests: sock-tests.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ sock-tests.o $(LIBS)

regress: regress.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ regress.o $(LIBS)

compress: compress.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ compress.o $(LIBS)

acl: acl.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ acl.o $(LIBS)

utils: utils.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ utils.o $(LIBS)

util-tests: util-tests.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ util-tests.o $(LIBS)

auth: auth.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ auth.o $(LIBS)

lock: lock.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ lock.o $(LIBS)

basic: basic.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ basic.o $(LIBS)

ssl: ssl.o $(LIBTEST)
	$(CC) $(LDFLAGS) -o $@ ssl.o $(LIBS)


#FOO: FOO.o $(LIBTEST)
#	$(CC) $(LDFLAGS) -o $@ FOO.o $(LIBS)

auth.o: auth.c $(HDRS)
uri-tests.o: uri-tests.c $(HDRS)
util-tests.o: util-tests.c $(HDRS)
string-tests.o: string-tests.c $(HDRS)
sock-tests.o: sock-tests.c $(HDRS)
server.o: server.c $(HDRS)
request.o: request.c $(HDRS)
regress.o: regress.c $(HDRS)
compress.o: compress.c $(HDRS)
acl.o: acl.c $(HDRS)
utils.o: utils.c $(HDRS)
