##############################################################
#  Structured Markov Chains Solver       [  SMCSolver  ]     #
#  Dario Bini, Beatrice Meini, Sergio Steffe'                #
#  bini@dm.unipi.it, meini@dm.unipi.it, steffe@dm.unipi.it   #
#  Dipartimento di Matematica "Leonida Tonelli"              # 
#  Largo Pontecorvo 5                                        #  
#  56127 Pisa                                                # 
#  Italy                                                     # 
#  Version 1.1 - Oct 2006                                    #
##############################################################
# 
#    Makefile 
# 
##############################################################
#
#   C Compiler is gcc 
CC=gcc
CFLAGS=-Wall
#
#
DATESTRING=`date +"%Y.%m.%d"`
#
#   Lahey Fortran Compiler  (32 bits CPU)
#      
FF=/usr/local/lf9562/bin/lf95 
#   lf95 requires that the main routine has name MAIN__ instead of main
#   so set the variable LAHEY to null for other compilers
#   and to LAHEY_MAIN for Lahey Fortran Compiler
LAHEY= -D "LAHEY_MAIN"
#   choose optimization level
FFOPT=
#FFOPT= --chk s
#FFOPT= --o2
#   staticlink links statically the Lahey Fortran Libraries
#   gtk-2 routines will remain dinamically linked
FFLAGSM=--staticlink --warn $(FFOPT) 
FFLAGSG= --staticlink --warn $(FFOPT) 
#   leave blank this
NOSECOND=
#   blas, lapack, lapack95, and its Fortran 95 modules for the compiler
#   Fortran routine need them. Lapack95 must be compiled with the same
#   Fortran Compiler lf95.
FFLIBS=-I./only_lahey_32 -L./only_lahey_32 -llapack95 -llapackmt  -lblasmt 
#
#
#   G95 GNU Fortran Compiler (64 bits CPU)
#
#FF= g95
#   leave blank this
#LAHEY=
#   choose optimization level
#FFOPT=
#FFOPT=-O2
#   -fzero to set up to 0 new variables
#FFLAGSM= -Wall -fzero $(FFOPT)
#FFLAGSG= -Wall -fzero $(FFOPT)
#   to let Fortran and C routines interact the external names
#   must agree, and in some routine the second underscore must
#   not be added by g95 compiler
#NOSECOND=-fno-second-underscore
#   blas, lapack, lapack95, and its Fortran 95 modules for the compiler
#   Fortran routine need them. apack95 must be compiled with the same
#   Fortran Compiler g95.
#FFLIBS= -I./only_g95_64 -L./only_g95_64 -llapack95 -llapack -lblas 
#
#
# Intel Fortran Compiler   (32 bits CPU)
#
#FF = ifort
#   leave blank this
#LAHEY=
#   leave blank this
#NOSECOND=
#   choose optimization level
#FFOPT= -mp1 -O
#FFOPT= -check all
#FFOPT=-xP -O3
#   -nofor_main is required by ifort if the main program is in C and not in Fortran
#   as we use thread wi choose the corresponding reentrancy.
#FFLAGSM = -nofor_main -reentrancy threaded  -static-libcxa  -warn all  $(FFOPT)
#FFLAGSG = -reentrancy threaded -static-libcxa  -warn all  $(FFOPT)
#   blas, lapack, lapack95, and its Fortran 95 modules for the compiler
#   Fortran routine need them. apack95 must be compiled with the same
#   Fortran Compiler g95.
#FFLIBS= -I./only_ifort_32 -L./only_ifort_32 -llapack95 -llapack -lblas 
#
#
# NAG Fortran Compiler   (32 bits CPU)
#
#FF = f95
#   leave blank this
#LAHEY=
#   leave blank this
#NOSECOND=
#   choose optimization level
#FFOPT=  -thread_safe  -unsharedf95
#FFOPT= -O4
#   -nofor_main is required by ifort if the main program is in C and not in Fortran
#   as we use thread wi choose the corresponding reentrancy.
#FFLAGSM =  $(FFOPT)
#FFLAGSG =  $(FFOPT)
#   blas, lapack, lapack95, and its Fortran 95 modules for the compiler
#   Fortran routine need them. apack95 must be compiled with the same
#   Fortran Compiler g95.
#FFLIBS=  ./only_nag_32/lapack95.a -I./only_nag_32/ -L./only_nag_32/  -llapack -lblas /usr/lib/gcc-lib/i386-redhat-linux/3.2/libg2c.a
#
#

#   gtk include and libs are found with pkg-config command
#
GTKINCLUDE=`pkg-config --cflags gtk+-2.0`
GTKLIBS=`pkg-config --libs gtk+-2.0`
#
#   add the treads libraries and ncurses
LIBS=${GTKLIBS} -lgthread-2.0 -lncurses -lrt
INCLUDE=${GTKINCLUDE}
#   Now the dependency tree for the compilation in C and Fortran
#   The main program must be linked by Fortran Compiler, the order of terms is important

SMCSolver: main.o callbacks.o interface.o help.o rw.o padwrite.o examples.o edit_a.o edit_b.o view_mat.o view_pi.o ponte.o examplesf.o smc_int.o smc_sub.o  pwcr_int.o fft_int.o pi_int.o is_int.o pwcr_fft.o pwcr_sub.o  fi_int.o fi_sub.o  is_sub.o pi_sub.o fcalls.o 
	$(FF) ${FFLAGSM} ${INCLUDE} -o SMCSolver main.o callbacks.o interface.o help.o rw.o padwrite.o examples.o edit_a.o edit_b.o view_mat.o view_pi.o ponte.o examplesf.o smc_int.o smc_sub.o  pwcr_int.o pi_int.o fft_int.o is_int.o pwcr_fft.o pwcr_sub.o  fi_int.o fi_sub.o  is_sub.o pi_sub.o fcalls.o  ${LIBS} ${FFLIBS}

main.o: main.c 	structures.h main.h 
	$(CC) ${CFLAGS} ${INCLUDE} ${LAHEY} -c main.c

callbacks.o: callbacks.c structures.h callbacks.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c  callbacks.c

interface.o: interface.c structures.h interface.h examples.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c  interface.c

help.o: help.c structures.h help.h doc.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c  help.c

rw.o: rw.c structures.h callbacks.h interface.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c rw.c

padwrite.o: padwrite.c structures.h padwrite.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c padwrite.c

examples.o: examples.c structures.h examples.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c examples.c

edit_a.o: edit_a.c structures.h edit_a.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c edit_a.c

edit_b.o: edit_b.c structures.h edit_b.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c edit_b.c

view_mat.o: view_mat.c structures.h view_mat.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c view_mat.c

view_pi.o: view_pi.c structures.h view_pi.h
	$(CC) ${CFLAGS} ${INCLUDE}  -c view_pi.c

ponte.o: ponte.f90 
	$(FF) $(FFLAGSG) ${FFLIBS} ${NOSECOND} -c ponte.f90

examplesf.o: examplesf.f90
	$(FF) $(FFLAGSG) ${FFLIBS} ${NOSECOND} -c examplesf.f90

smc_int.o: Fortran/smc_int.f90
	 $(FF)  $(FFLAGSG) ${FFLIBS} -c Fortran/smc_int.f90

pwcr_int.o:Fortran/pwcr_int.f90
	$(FF) $(FFLAGSG) ${FFLIBS} -c Fortran/pwcr_int.f90

fft_int.o:Fortran/fft_int.f90
	$(FF) $(FFLAGSG) ${FFLIBS} -c Fortran/fft_int.f90

pi_int.o:Fortran/pi_int.f90
	$(FF) $(FFLAGSG) ${FFLIBS} -c Fortran/pi_int.f90

smc_sub.o: Fortran/smc_sub.f90 
	$(FF) $(FFLAGSG) ${FFLIBS} -c Fortran/smc_sub.f90

is_int.o:Fortran/is_int.f90
	$(FF) ${FFLIBS} -c Fortran/is_int.f90

pwcr_fft.o:Fortran/pwcr_fft.f90
	$(FF) $(FFLAGSG) ${FFLIBS} -c Fortran/pwcr_fft.f90

pwcr_sub.o:Fortran/pwcr_sub.f90
	$(FF) ${FFLIBS} -c Fortran/pwcr_sub.f90

fi_int.o:Fortran/fi_int.f90
	$(FF) ${FFLIBS} -c Fortran/fi_int.f90

fi_sub.o:Fortran/fi_sub.f90
	$(FF) ${FFLIBS} -c Fortran/fi_sub.f90

is_sub.o:Fortran/is_sub.f90
	$(FF) ${FFLIBS} -c Fortran/is_sub.f90

pi_sub.o:Fortran/pi_sub.f90
	$(FF) ${FFLIBS} -c Fortran/pi_sub.f90

fcalls.o: fcalls.f90
	$(FF) $(FFLAGSG) ${FFLIBS} ${NOSECOND} -c fcalls.f90

clean:
	rm -f SMCSolver  main.o callbacks.o interface.o help.o rw.o padwrite.o examples.o edit_a.o edit_b.o view_mat.o view_pi.o ponte.o examplesf.o smc_int.o pwcr_int.o fft_int.o smc_sub.o pwcr_fft.o pwcr_sub.o fcalls.o fi_int.o is_int.o fi_sub.o is_sub.o pi_int.o pi_sub.o fft_interface.mod  ponte_f_f.mod  pwcr_interface.mod  roots.mod  schur_interface.mod  smc_int.mod  smc_tools.mod  fi_int.mod  is_int.mod pi_int.mod

dist: clean
	date>TIMESTAMP; 
	cd ..; tar czvf SMCSolver_1.1-$(DATESTRING).tgz ./SMCSolver_1.1

