#TESTDIR = /work3/makino/grape6tests.122/
#TESTDIR = /work2/makino/grape6tests/
#TESTDIR = /work3/makino/grape6tests.002/
TESTDIR = /work0/makino/grape6tests.002/
# as of 2000/7/10
FFLAGS = -DDEC -u
OPTS = -O4
CFLAGS = -DPHYSICALID=0x2 -DX86
#CC = ccc $(OPTS) $(CFLAGS)
CC = /usr/local/gcc-3.2/bin/gcc $(OPTS) $(CFLAGS)
CCTEST = $(CC) -DTEST
CSRCS = add.c cutoff_functions.c fadd.c forcepipe.c gauss.c \
        low_acc_power.c mult.c  padd.c pmult.c \
        power_functions.c predictor.c rsq.c subx.c tcalc.c utils.c \
        addtest.c test_predictor.c g6chip.c ecc64.c test_predictor_hex.c \
        test_force.c g6control.c test_fo_unit.c g6chip_simlib.c

BASELIBOBJS = tcalc.o pmult.o padd.o utils.o predictor.o \
	subx.o  mult.o add.o rsq.o normalize.o power_functions.o \
	fadd.o   forcepipe.o \
         low_acc_power.o  cutoff_functions.o    gauss.o  ecc64.o g6control.o
LIBOBJS = g6chip.o $(BASELIBOBJ)
SIMLIBOBJS = g6chip_simlib.o $(BASELIBOBJS)
BINS = predictor predictor_hex test_predictor test_predictor_hex  \
	forcepipe forcepipe_hex test_force \
        g6control_ipw g6control_jpw  g6control_fo  g6control_calc
PSSRCS =  g6_spec.ps g6_function.ps
SRCS    =  README $(CSRCS) $(PSSRCS) \
	grape6sim.h \
	g6chip.h \
	g6control.h \
	testchip.F \
	Makefile \
	move_backup  \
	predictor_test.dat \
	predictor_test_hex.dat \
	forcepipe_test_2.dat.0 \
	forcepipe_test_1.dat \
	forcepipe_test_1.dat_detailed \
	forcepipe_test_short.dat \
	README.PARTCHIP.TESTDATA\
	README.CONTROL.TESTDATA \
	README.TESTDATA \
	ipw_control.dat \
	jpw_control.dat \
	fo_control.dat  \
	testdata_2body\
	calc_control.dat 
TESTS  =  \
	$(TESTDIR)forcepipe_test_0.dat \
	$(TESTDIR)forcepipe_test_0.dat_detailed \
	$(TESTDIR)chip_test_0.dat \
	$(TESTDIR)chip_test_1.dat.0 \
	$(TESTDIR)chip_test_1.dat.1 \
	$(TESTDIR)chip_test_2.dat \
	$(TESTDIR)chip_test_3.dat \
	$(TESTDIR)chip_test_4.dat \
	$(TESTDIR)chip_test_5.dat\
	$(TESTDIR)chip_test_6.dat \
	$(TESTDIR)chip_test_7.dat \
	$(TESTDIR)chip_test_8.dat \
	$(TESTDIR)chip_test_9.dat \
	$(TESTDIR)chip_test_10.dat \
	$(TESTDIR)chip_test_11.dat \
	$(TESTDIR)chip_test_11.dat.a1 \
	$(TESTDIR)chip_test_12.dat
libs : libg6lxsim.a  libg6lxsim2.a
	ls -al libg6lxsim.a
	ar t libg6lxsim.a

bins : $(BINS)
	ls -al $(BINS)

libg6lxsim.a : $(LIBOBJS)
	ar rvu libg6lxsim.a  $(LIBOBJS)
libg6lxsim2.a : $(SIMLIBOBJS)
	ar rvu libg6lxsim2.a  $(SIMLIBOBJS)
clean :
	rm *.o

backup : grape6.tar.Z $(TESTDIR)tests.tar.Z
	csh -f move_backup
grape6.tar.Z : $(SRCS)
	tar cvf grape6.tar $(SRCS)
	compress grape6.tar
$(TESTDIR)tests.tar.Z : $(TESTS)
	rm -f $(TESTDIR)tests.tar.Z
	(cd $(TESTDIR) ; tar cvf - . )  | compress > /var/tmp/tests.tar.Z
	mv /var/tmp/tests.tar.Z $(TESTDIR)
tcalc : tcalc.c
	$(CCTEST) -o tcalc tcalc.c -lm
tcalctest : tcalc.c tcalctest.c
	$(CC) -o tcalctest tcalctest.c tcalc.c -lm
tcalc.o : tcalc.c
	$(CC) -c tcalc.c 
pmult : pmult.c utils.o
	$(CCTEST) -o pmult pmult.c utils.o -lm
pmult.o : pmult.c 
	$(CC) -c pmult.c  
padd : padd.c utils.o
	$(CCTEST) -o padd padd.c utils.o -lm
padd.o : padd.c 
	$(CC) -c padd.c  
utils : utils.c 
	$(CCTEST) -o utils utils.c -lm
utils.o : utils.c 
	$(CC) -c  utils.c 
predictor : predictor.c  utils.o pmult.o padd.o tcalc.o 
	$(CCTEST) -o predictor predictor.c utils.o  pmult.o padd.o tcalc.o 
predictor_hex : predictor.c  utils.o pmult.o padd.o tcalc.o 
	$(CC)  -DHEXTEST -o predictor_hex predictor.c utils.o  pmult.o padd.o tcalc.o 
predictor.o : predictor.c 
	$(CC) -c  predictor.c 
subx : subx.c  utils.o utils.o
	$(CCTEST) -o subx subx.c utils.o  -lm
subxtest : subxtest.c subx.c  utils.o utils.o
	$(CC) -o subxtest subxtest.c subx.c utils.o  -lm
subx.o : subx.c 
	$(CC) -c  subx.c 

mult : mult.c  utils.o utils.o
	$(CCTEST) -o mult mult.c utils.o  -lm
multtest24 : mult.c multtest.c  utils.o utils.o
	$(CC) -DBITS=24 -o multtest24 multtest.c mult.c utils.o  -lm
multtest20 : mult.c multtest.c  utils.o utils.o
	$(CC) -DBITS=20 -o multtest20 multtest.c mult.c utils.o  -lm
mult.o : mult.c 
	$(CC) -c  mult.c 

add : add.c  utils.o utils.o
	$(CCTEST) -o add add.c utils.o  
addtest24 : addtest.c add.c  utils.o utils.o
	$(CC)  -DBITS=24 -o addtest24 addtest.c add.c utils.o  -lm
add.o : add.c 
	$(CC) -c  add.c 

rsq : rsq.c  utils.o add.o mult.o
	$(CCTEST) -o rsq rsq.c utils.o  add.o mult.o -lm
rsq.o : rsq.c 
	$(CC) -c  rsq.c 

normalize : normalize.c  utils.o
	$(CCTEST) -o normalize normalize.c utils.o   -lm
normalize.o : normalize.c 
	$(CC) -c  normalize.c 

power_functions : power_functions.c  utils.o
	$(CCTEST) -o power_functions power_functions.c utils.o   -lm
power_functions_test : power_functions_test.c power_functions.c  utils.o
	$(CC) -o power_functions_test power_functions_test.c power_functions.c utils.o   -lm
power_functions.o : power_functions.c 
	$(CC) -c  power_functions.c 

fadd : fadd.c  utils.o  
	$(CCTEST) -o fadd fadd.c utils.o   -lm
faddtest64 : faddtest.c fadd.c  utils.o  
	$(CC) -o faddtest64 -DABITS=64 -DBITS=24 faddtest.c fadd.c utils.o   -lm
faddtest32 : faddtest.c fadd.c  utils.o  
	$(CC) -o faddtest32 -DABITS=32 -DBITS=20 faddtest.c fadd.c utils.o   -lm
fadd.o : fadd.c 
	$(CC) -c  fadd.c 
gauss : gauss.c  utils.o  
	$(CCTEST) -o gauss gauss.c utils.o   -lm
gauss.o : gauss.c 
	$(CC) -c  gauss.c 
FORCEPIPE_OBJS = rsq.o subx.o low_acc_power.o power_functions.o \
                 cutoff_functions.o mult.o fadd.o add.o  gauss.o  utils.o 
forcepipe_hex : forcepipe.c    $(FORCEPIPE_OBJS) 
	$(CC) -DHEXTEST -o forcepipe_hex forcepipe.c  $(FORCEPIPE_OBJS)    -lm
forcepipe_hex_1 : forcepipe.c    $(FORCEPIPE_OBJS) 
	$(CC) -DHEXTEST -DDEBUG_LEVEL=1 -o forcepipe_hex_1 forcepipe.c  $(FORCEPIPE_OBJS)    -lm
forcepipe : forcepipe.c    $(FORCEPIPE_OBJS) 
	$(CCTEST) -o forcepipe forcepipe.c  $(FORCEPIPE_OBJS)    -lm
forcepipe.o : forcepipe.c 
	$(CC) -c  forcepipe.c 
low_acc_power : low_acc_power.c  utils.o
	$(CCTEST) -o low_acc_power low_acc_power.c utils.o   -lm
low_acc_power_test  : low_acc_power.c low_acc_power_test.c  utils.o
	$(CC) -o low_acc_power_test low_acc_power_test.c  low_acc_power.c utils.o   -lm
low_acc_power.o : low_acc_power.c 
	$(CC) -c  low_acc_power.c 

cutoff_functions : cutoff_functions.c  gauss.o mult.o utils.o
	$(CCTEST) -o cutoff_functions cutoff_functions.c mult.o gauss.o utils.o   -lm
cutoff_functions.o : cutoff_functions.c 
	$(CC) -c  cutoff_functions.c 
g6chip.o : g6chip.c g6chip.h
	$(CC) -c  g6chip.c 
g6chip_simlib.o : g6chip_simlib.c g6chip.h
	$(CC) -c  g6chip_simlib.c 
g6control.o : g6control.c g6control.h
	$(CC) -c  g6control.c 
g6control_ipw : g6control.c g6control.h libg6lxsim.a
	$(CC) -DTEST_IPW -o g6control_ipw   g6control.c  -lm -L. -lg6sim
g6control_jpw : g6control.c g6control.h libg6lxsim.a
	$(CC) -DTEST_JPW -o g6control_jpw   g6control.c  -lm -L. -lg6sim

g6control_fo: g6control.c g6control.h libg6lxsim.a
	$(CC) -DTEST_FO -o g6control_fo   g6control.c  -lm -L. -lg6sim

g6control_calc: g6control.c g6control.h libg6lxsim.a
	$(CC) -DTEST_CALC -o g6control_calc   g6control.c  -lm -L. -lg6sim

ipw_control.dat : g6control_ipw
	g6control_ipw > ipw_control.dat
jpw_control.dat : g6control_jpw
	g6control_jpw > jpw_control.dat
fo_control.dat : g6control_fo
	g6control_fo > fo_control.dat

calc_control.dat : g6control_calc
	g6control_calc > calc_control.dat

predictor_test.dat : test_predictor predictor
	test_predictor | predictor | grep IN > predictor_test.dat
predictor_test_hex.dat : test_predictor_hex predictor_hex
	test_predictor_hex | predictor_hex | grep IN > predictor_test_hex.dat
$(TESTDIR)chip_test_9.dat : forcepipe_test_short.dat convert_forcepipe_vector
	convert_forcepipe_vector < forcepipe_test_short.dat >$(TESTDIR)chip_test_9.dat
forcepipe_test_short.dat : test_force forcepipe_hex_1
	echo 1 |test_force |head -8  | forcepipe_hex_1 > forcepipe_test_short.dat
forcepipe_test_1.dat_detailed : test_force forcepipe_hex_1
	echo 1 |test_force  | forcepipe_hex_1 > forcepipe_test_1.dat_detailed
$(TESTDIR)chip_test_10.dat : forcepipe_test_1.dat convert_forcepipe_vector
	convert_forcepipe_vector < forcepipe_test_1.dat >$(TESTDIR)chip_test_10.dat
forcepipe_test_1.dat : test_force forcepipe_hex
	echo 1 |test_force  | forcepipe_hex > forcepipe_test_1.dat
$(TESTDIR)forcepipe_test_0.dat_detailed : test_force forcepipe_hex
	echo 0 |test_force  | forcepipe_hex_1  > $(TESTDIR)forcepipe_test_0.dat_detailed
$(TESTDIR)chip_test_11.dat : $(TESTDIR)forcepipe_test_0.dat convert_forcepipe_vector
	convert_forcepipe_vector < $(TESTDIR)forcepipe_test_0.dat >$(TESTDIR)chip_test_11.dat
$(TESTDIR)chip_test_11.dat.a1 : convert_forcepipe_vector test_force_unit forcepipe_hex
	csh -f test_force_unit.csh  $(TESTDIR)chip_test_11.dat
$(TESTDIR)forcepipe_test_0.dat : test_force forcepipe_hex
	echo 0 |test_force  | forcepipe_hex > $(TESTDIR)forcepipe_test_0.dat
forcepipe_test_2.dat.0  :testchip_singlepipe  testchip_singlepipe.csh
	csh -f testchip_singlepipe.csh 0
$(TESTDIR)chip_test_1.dat.1  :testchip  testchip.csh
	csh -f testchip.csh 1 $(TESTDIR)
$(TESTDIR)chip_test_1.dat.0  :testchip  testchip.csh
	csh -f testchip.csh 0 $(TESTDIR)
../nbody1h/nbody1_g6sim : libg6lxsim.a
	cd ../nbody1h ; rm nbody1_g6sim; make nbody1_g6sim
$(TESTDIR)chip_test_0.dat : ../nbody1h/nbody1_g6sim  testdata_2body 
	csh -f make_nb1_dat.csh $(TESTDIR)
$(TESTDIR)chip_test_2.dat : ../nbody1h/nbody1_g6sim  testdata_10body
	csh -f make_nb2_dat.csh 10 2 $(TESTDIR)
$(TESTDIR)chip_test_3.dat : ../nbody1h/nbody1_g6sim  testdata_50body
	csh -f make_nb2_dat.csh 50 3 $(TESTDIR)
$(TESTDIR)chip_test_3.dat.1 : ../nbody1h/nbody1_g6sim  testdata_50body
	csh -f make_nb3_dat.csh 50 3 $(TESTDIR)
$(TESTDIR)chip_test_12.dat : ../nbody1h/nbody1_g6sim  testdata_256body 
	csh -f make_nb2_dat.csh 256 12 $(TESTDIR)
$(TESTDIR)chip_test_4.dat: testchip
	csh -f make_testchip_dat.csh  2 1 2 1 1  $(TESTDIR)chip_test_4.dat
$(TESTDIR)chip_test_6.dat: testchip
	csh -f make_testchip_dat.csh  300 1 4 1 0  $(TESTDIR)chip_test_6.dat
#	echo 300 1 4 1 0 | testchip > $(TESTDIR)chip_test_6.dat
$(TESTDIR)chip_test_7.dat: testchip
	csh -f make_testchip_dat.csh  64 1 5 1 0  $(TESTDIR)chip_test_7.dat
$(TESTDIR)chip_test_7a.dat: testchip
	csh -f make_testchip_dat.csh  10 1 5 1 0  $(TESTDIR)chip_test_7a.dat
$(TESTDIR)chip_test_7b.dat: testchip
	csh -f make_testchip_dat.csh  55 1 7 1 0  $(TESTDIR)chip_test_7b.dat
$(TESTDIR)chip_test_7c.dat: testchip
	csh -f make_testchip_dat.csh  10 1 8 1 0  $(TESTDIR)chip_test_7c.dat
$(TESTDIR)chip_test_7d.dat: testchip
	csh -f make_testchip_dat.csh  10 1 8 1 0  $(TESTDIR)chip_test_7d.dat
$(TESTDIR)chip_test_7e.dat: testchip
	csh -f make_testchip_dat.csh  10 1 8 1 0  $(TESTDIR)chip_test_7e.dat
$(TESTDIR)chip_test_7f.dat: testchip
	csh -f make_testchip_dat.csh  10 1 8 1 0  $(TESTDIR)chip_test_7c.dat
$(TESTDIR)chip_test_7g.dat: testchip
	csh -f make_testchip_dat.csh  10 1 8 1 0  $(TESTDIR)chip_test_7c.dat
$(TESTDIR)chip_test_7h.dat: testchip
	csh -f make_testchip_dat.csh  10 1 8 1 0  $(TESTDIR)chip_test_7c.dat
$(TESTDIR)chip_test_7i.dat: testchip
	csh -f make_testchip_dat.csh  10 1 8 1 0  $(TESTDIR)chip_test_7c.dat
#	echo 64 1 5 1 0 | testchip > $(TESTDIR)chip_test_7.dat
$(TESTDIR)chip_test_8.dat: testchip
	csh -f make_testchip_dat.csh   32 1 6 1 0  $(TESTDIR)chip_test_8.dat
#	echo 32 1 6 1 0 | testchip > $(TESTDIR)chip_test_8.dat
$(TESTDIR)chip_test_5.dat : ../nbody1h/nbody1_g6sim  testdata_200body
	csh -f make_nb2_dat.csh 200 5 $(TESTDIR)
test_predictor : test_predictor.c
	$(CCTEST) -o test_predictor  test_predictor.c -lm
test_force : test_force.c utils.o
	$(CCTEST) -o test_force  test_force.c utils.o -lm
test_force_unit : test_force.c utils.o
	$(CCTEST) -DUNIT_TEST -o test_force_unit  test_force.c utils.o -lm
ecc64 : ecc64.c    
	$(CCTEST) -o ecc64 ecc64.c    -lm
ecc64.o : ecc64.c 
	$(CC) -c  ecc64.c 
testchip: testchip.F libg6lxsim.a
	f77 $(FFLAGS) testchip.F  -o testchip  -L. -lg6sim
make_testdata_for_power: make_testdata_for_power.F
	f77 $(FFLAGS) -o make_testdata_for_power make_testdata_for_power.F
convert_forcepipe_vector: convert_forcepipe_vector.c libg6lxsim.a
	$(CC)  convert_forcepipe_vector.c -o convert_forcepipe_vector  -L. -lg6sim -lm
testchip_singlepipe : testchip.F libg6lxsim.a
	f77 $(FFLAGS) -DSINGLEPIPE testchip.F  -o testchip_singlepipe  -L. -lg6sim
test_fo_unit: test_fo_unit.c  libg6lxsim.a
	$(CC) -o test_fo_unit test_fo_unit.c   -L. -lg6sim -lm

