#
# This is a Makefile for reproducing a problem in building mixed Fortran and C code
# The problem occurs in linking but is in compiling the fortran code

testproblem:
	@echo ""
	@echo "   Executing default: make testproblem"
	@echo "     (clean, serial, clean, parallel, clean)"
	@echo ""
	$(MAKE) clean
	-$(MAKE) serial
	$(MAKE) clean
	-$(MAKE) parallel
	$(MAKE) clean

parallel: sys.a
	cpp -traditional -P  -DBINTRAJ -DMPI -I/include  myf.f > _myf.f
	mpif90 -c -O0 -ffree-form  -o myf.o _myf.f

	@echo "   Makefile comment:Linking the parallel compiled code (here the problem is expected to occur):"
	mpif90 -o myf myf.o sys.a

serial: sys.a
	cpp -traditional -P  -DBINTRAJ -DMPI -I/include  myf.f > _myf.f
	gfortran -c -O0 -ffree-form  -o myf.o _myf.f
	
	@echo "   Makefile comment:Linking the serially compiled code (here the problem is expected to not occur):"	
	gfortran -o myf myf.o sys.a

wallclock:
	@echo "   Makefile comment:Compiling wallclock--C part of the program"
	gcc -c -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DBINTRAJ   -o wallclock.o wallclock.c

sys.a:	wallclock
	@echo "   Makefile comment:Creating an arhive with the C function--like in Amber"
	ar rv sys.a wallclock.o

clean:
	$(RM) *.o *.mod myf sys.a _myf.f
