topsrc = @top_srcdir@

tooldir = $(topsrc)/tools
libsrc = $(topsrc)/lib/src

CC = @CC@
CFLAGS = @CFLAGS@
have_gtk = @have_gtk@
GMP_LIBS = @GMP_LIBS@
FLIB = @FLIB@

ifeq ($(CC),)
  CC = gcc
endif

LIBGRETL = ../lib/libgretl-1.0.la
RAND_LIBS = $(LIBGRETL)

ifeq ($(GMP_LIBS),)
  DEFINES = -DNO_GMP -DSTANDALONE
else
  DEFINES = -DUSE_GMP -DSTANDALONE
endif

ifeq ($(havegtk),2.0)
  RAND_LIBS += $(GLIB_LIBS)
endif

VPATH = $(topsrc)/tests

override CFLAGS += -I$(libsrc) $(DEFINES)

all: nistcheck

nistcheck: nistcheck.o
	../libtool --mode=link $(CC) -o $@ $< $(LIBGRETL)

nistcheck.o: $(LIBGRETL)

randcheck: diehard mtrand
	if [ `pwd` != "$(topsrc)/tests" ] ; then \
	cp $(topsrc)/tests/operm5.data . ; \
	cp $(topsrc)/tests/randtests.txt . ; fi
	./mtrand && ./diehard

diehard: diehard.c
	$(CC) -o $@ $< $(FLIB) -lm

mtrand: mtrand.o
	../libtool --mode=link $(CC) -o $@ $< $(RAND_LIBS)

.PHONY :

check: nistcheck
	./nistcheck $(topsrc)/tests

clean:
	rm -f nistcheck diehard mtrand *.o test.out
	rm -f gretl_output.32 gretl_rand.txt
	if [ `pwd` != "$(topsrc)/tests" ] ; then \
	rm -f operm5.data randtests.txt ; fi
	rm -rf .libs

distclean: clean
	rm -f Makefile


