# Generated automatically from Makefile.in by configure.
include $(BLDDIR)/Make.conf

test: test-bin test-lib

test-bin: test-bin-1 test-bin-2

library: ../lib/$(LIBRARY)

../lib/$(LIBRARY):
	cd ../lib; $(MAKE) -f $(SRCDIR)/lib/Makefile TOPDIR=$(TOPDIR) BLDDIR=$(BLDDIR) library

binary: ../bin/preccx
	cd ../bin; $(MAKE) -f $(SRCDIR)/bin/Makefile TOPDIR=$(TOPDIR) BLDDIR=$(BLDDIR) binary

test-bin-1: library binary
	@# test done this way round to catch segfaults
	@if test -n "`../bin/preccx $(SRCDIR)/bin/preccx.y 2>/dev/null | $(GREP) hid338`"; then \
	  $(ECHO) preccx passed test-bin-1 OK; else \
	  $(ECHO) preccx failed in test-bin-1; fi; true

test-bin-2: library binary
	@# test done this way round to catch segfaults
	@if test "`../bin/preccx $(SRCDIR)/bin/preccx.y 2>/dev/null | diff - $(SRCDIR)/bin/preccx.c | wc -l`" -lt 7 ; then\
	  $(ECHO) preccx passed test-bin-2 OK; else \
	  $(ECHO) preccx failed in test-bin-2; fi; true

test-lib: test-calculat test-fib

test-calculat: calculat
	@# test done this way round to catch segfaults
	@if test -n "`$(ECHO) 1+1 | ./calculat 2>/dev/null | $(GREP) =2`"; then\
	  $(ECHO) calculat passed test-lib OK; else \
	  $(ECHO) calculat failed in test-lib; fi; true

test-fib: fib
	@# test done this way round to catch segfaults
	-@if test -n "`$(ECHO) 1,1,2,3,5,8,13,.. | ./fib 2>/dev/null | $(GREP) 21,34`"; then\
	  $(ECHO) fib passed test-lib OK; else \
	  $(ECHO) fib failed in test-lib "(but don't worry about it - read the source for why)"; fi; true

fib:	fib.o ../include/ccx.h libfib1.a
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(DEFS) $@.o -L. libfib1.a

libfib1.a: dummy
	$(MAKE) -f $(SRCDIR)/lib/Makefile "VALUE=struct{long count,nexta,nextb;}" "LIBRARY=libfib1.a" library BLDDIR=$(BLDDIR) TOPDIR=$(TOPDIR)

# we define what VALUE is in fib.y, not here. No -DVALUE=... needed.

fib.o:	$(SRCDIR)/test/fib.c ../include/ccx.h 
	-@ $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c $(SRCDIR)/test/fib.c -o $@ 

calculat:	library	calculat.o ../include/ccx.h 
	-@ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(DEFS) $@.o -L../lib ../lib/$(LIBRARY)

# we define what VALUE is in calculat.y, not here. No -DVALUE=...  needed.

calculat.o:	../include/ccx.h $(SRCDIR)/test/calculat.c
	-@ $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c $(SRCDIR)/test/calculat.c  -o $@

almostclean: dummy
	- $(RM) $(TESTOBJS) core *~ *.bak *.sw?

clean: almostclean
	- $(RM) $(TESTBINS)
	- $(RM) libfib1.a
	- $(RM) *.o

realclean: clean


include $(TOPDIR)/src/rules.mk
