#CFLAGS = -O4 -g3    # -DUSE_SPECIAL_CONFIGULATION # -DINTERNAL_OUT  -DSIMULATOR
CFLAGS = -O4 -g3 -tune ev5 -arch ev5  # -DINTERNAL_OUT # -DSIMULATOR  # -DUSE_SPECIAL_CONFIGULATION
#CFLAGS = -O1 -tune ev5 -arch ev6    -DINTERNAL_OUT#  -DSIMULATOR
#CC = gcc -DGCC
CC = cc 
LD = cc
#LDFLAGS = -L ../grape6 -lg6sim2-linux -lm
LDFLAGS = -non_shared -L ../grape6 -lg6sim2 -lm
LDNEMO =  -L $(NEMOLIB) -lnemo -lm
#CC = cc
BINS = echoback g6libtest g6_test
LIBOBJS = memmap.o grape6util.o grape6utilsub.o
SIMLIBOBJS = memmap.o grape6util-sim.o grape6utilsub.o
DOCDIR = /usr2/makino/WWW/softwares/GRAPE6
all: g6hibtest g6libtest g6ptest g6cbtest libg6.a libg6sim.a
echoback:	echoback.o memmap.o g6util.o
	$(LD) $(CFLAGS) -o echoback echoback.o memmap.o g6util.o

g6nbtest:	nbtest.c libg6test.a
	$(CC) $(CFLAGS) -o g6nbtest nbtest.c -L .  -lg6test  $(LDFLAGS)
mpitest: mpitest.c  ../grape6/libg6sim2.a libg6sim.a
	$(CC) $(CFLAGS)  -DSIMULATOR  -o mpitest mpitest.c -L . -lg6sim $(LDFLAGS)
tsukubatest: tsukubatest.c  ../grape6/libg6sim2.a libg6.a
	$(CC) $(CFLAGS)    -o tsukubatest tsukubatest.c -L . -lg6 $(LDFLAGS)


g6hibtest:	g6hibtest.c libg6test.a
	$(CC) $(CFLAGS) -o g6hibtest g6hibtest.c -L .  -lg6test  $(LDFLAGS)


g6fpgatest: grape6utilsub.o memmap.o grape6util.c grape6util.h grape6util-local.h ../grape6/libg6sim2.a
	$(CC) $(CFLAGS)  -DFPGATEST -o g6fpgatest grape6util.c grape6utilsub.o memmap.o $(LDFLAGS)
g6libtest: grape6utilsub.o memmap.o grape6util.c grape6util.h grape6util-local.h ../grape6/libg6sim2.a libg6.a
	$(CC) $(CFLAGS)  -DSIMULATOR -DTESTMAIN -o g6libtest grape6util.c grape6utilsub.o memmap.o $(LDFLAGS)
g6mctest: grape6utilsub.o memmap.o grape6util.c grape6util.h grape6util-local.h ../grape6/libg6sim2.a 
	$(CC) $(CFLAGS)  -DSIMULATOR -DMCTESTMAIN -o g6mctest grape6util.c grape6utilsub.o memmap.o $(LDFLAGS)
g6ptest: grape6utilsub.o memmap.o grape6util.c grape6util.h grape6util-local.h ../grape6/libg6sim2.a
	$(CC) $(CFLAGS) -DSIMULATOR -DJPIPTEST  -o g6ptest grape6util.c grape6utilsub.o memmap.o $(LDFLAGS)
g6cbtest2: grape6utilsub.o memmap.o grape6util.c grape6util.h grape6util-local.h ../grape6/libg6sim2.a
	$(CC) $(CFLAGS)  -DSIMULATOR  -DCBTEST2  -o g6cbtest2 grape6util.c grape6utilsub.o memmap.o $(LDFLAGS)
g6cbtest: grape6utilsub.o memmap.o grape6util.c grape6util.h grape6util-local.h ../grape6/libg6sim2.a
	$(CC) $(CFLAGS)  -DCBTESTMAIN  -o g6cbtest grape6util.c grape6utilsub.o memmap.o $(LDFLAGS)
grape6util.o :  grape6util.c grape6util.h grape6util-local.h 
	$(CC) -c $(CFLAGS) grape6util.c 
grape6util-sim.o :  grape6util.c grape6util.h grape6util-local.h 
	$(CC) -c $(CFLAGS) -DSIMULATOR grape6util.c
	mv grape6util.o  grape6util-sim.o 
grape6utilsub.o :  grape6utilsub.c grape6util.h grape6util-local.h 
	$(CC) -c -O1 grape6utilsub.c 
gt:	gt.o memmap.o g6util.o
	$(LD) $(CFLAGS) -o gt gt.o memmap.o g6util.o
libg6.a : $(LIBOBJS)
	ar rvu libg6.a  $(LIBOBJS)
libg6test.a : $(LIBOBJS)
	ar rvu libg6test.a  $(LIBOBJS)
libg6sim.a : $(SIMLIBOBJS)
	ar rvu libg6sim.a  $(SIMLIBOBJS)

g6_write_test:	g6_write_test.o memmap.o g6util.o
	$(LD) $(CFLAGS) -o g6_write_test g6_write_test.o memmap.o g6util.o
g6_test:	g6_test.o memmap.o g6util.o
	$(LD) $(CFLAGS) -o g6_test g6_test.o memmap.o g6util.o

gt.o:	gt.c gt.h memmap.h g6util.h
	$(CC) $(CFLAGS) -c -o gt.o gt.c
g6_test.o:	g6_test.c gt.h memmap.h g6util.h
	$(CC) $(CFLAGS) -c -o g6_test.o g6_test.c

g6_write_test.o:	g6_write_test.c gt.h memmap.h g6util.h
	$(CC) $(CFLAGS) -c -o g6_write_test.o g6_write_test.c

echoback.o:	echoback.c gt.h memmap.h g6util.h
	$(CC) $(CFLAGS) -c -o echoback.o echoback.c

g6util.o:	g6util.c g6util.h
	$(CC) $(CFLAGS) -c -o g6util.o g6util.c

memmap.o:	memmap.c memmap.h
	$(CC) $(CFLAGS) -c -o memmap.o memmap.c

docs: grape6user.tex grape6multi.tex
	latex grape6user
	latex grape6user
	latex grape6multi
	latex grape6multi
	dvi2ps grape6user > $(DOCDIR)/grape6user.ps
	dvi2ps grape6multi > $(DOCDIR)/grape6multi.ps
	latex2web.csh  grape6user  $(DOCDIR)
	latex2web.csh  grape6multi  $(DOCDIR)
clean:
	rm -f *.o core *~ $(BINS)

bak:
	tar cvf bak.tar ./*.[ch] ./Makefile ./*.tex
	gzip bak.tar
