##########################################################################################################################################################
#
#
#
#  Makefile for compiling the new updated myXCLASS package
#  Copyright (C) 2012 - 2016  Thomas Moeller
#
#  I. Physikalisches Institut, University of Cologne
#
#
#
#  Versions of the program:
#
#  Who           When        What
#
#  J. Pety       2004        Initial version for GILDAS
#  T. Moeller    25/05/2012  Initial version for the modified version
#
#
#
#  License:
#
#    GNU GENERAL PUBLIC LICENSE
#    Version 3, 29 June 2007
#    (Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>)
#
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
#
#  Makefile options:    - "all":    builds the myXCLASS program used by the myXCLASS function
#
#                                   Used files:     ../../MAGIX/Modules/lib/myXCLASS/sqlite/sqlite3.c
#                                                   ../../MAGIX/Modules/lib/myXCLASS/sqlite/sqlite3_NumberEntries.c
#                                                   ../../MAGIX/Modules/lib/myXCLASS/sqlite/sqlite3_PartitionFunction.c
#                                                   ../../MAGIX/Modules/lib/myXCLASS/sqlite/sqlite3_RadTrans.c
#
#                                                   ../../MAGIX/Modules/lib/general/Module_Variables.f90
#                                                   ../../MAGIX/Modules/lib/general/Module_FunctionCalling.f90
#                                                   ../../MAGIX/Modules/lib/myXCLASS/Module_myXCLASS__Core.f90
#                                                   GlobalVariables.f90
#                                                   CommandLineArguments.f90
#                                                   Read_XML.f90
#                                                   MainProgram.f90
#
#
#
#
##########################################################################################################################################################


#---------------------------------------------------------------------------------------------------------------------------------------------------------
# C compiler. Here: GCC.
CC = gcc
# CFLAGS = -O2 -Wall -fno-leading-underscore -I../../MAGIX/Modules/lib/myXCLASS/sqlite
# CFLAGS2 = -O2 -c -fno-leading-underscore -I../../MAGIX/Modules/lib/myXCLASS/sqlite
CFLAGS = -O2 -Wall -I../../MAGIX/Modules/lib/myXCLASS/sqlite
CFLAGS2 = -O2 -c -I../../MAGIX/Modules/lib/myXCLASS/sqlite
LDLIBSDB = -ldl -lpthread -lgomp


#---------------------------------------------------------------------------------------------------------------------------------------------------------
# FORTRAN compiler

# intel fortran compiler
FC = ifort
FFLAGS = -O3 -openmp -fp-model strict -check all -fstack-security-check -W1
LDFLAGS = -s


# gfortran compiler
# -fdefault-double-8 -fdefault-integer-8 -fdefault-real-8
FC = gfortran
FFLAGS = -g -O3 -fopenmp -ffree-form -ffree-line-length-none -ffpe-trap=invalid,zero,overflow -fbounds-check -frange-check -Wall


## define name of the executable file
EXEC = myNewXCLASS.exe


##--------------------------------------------------------------------------------------------------------------------------------------------------------
## define names of fortran source files
FDIR = ../../MAGIX/Modules/lib/myXCLASS
MAGIXDIR = ../../MAGIX/Modules/lib/general
FSRC = $(MAGIXDIR)/Module_Variables.f90 \
       $(MAGIXDIR)/Module_FunctionCalling.f90 \
       $(FDIR)/Module_myXCLASS__Core.f90 \
       GlobalVariables.f90 \
       CommandLineArguments.f90 \
       Read_XML.f90 \
       MainProgram.f90
FOBJ = Module_Variables.o \
       Module_FunctionCalling.o \
       Module_myXCLASS__Core.o \
       GlobalVariables.o \
       CommandLineArguments.o \
       Read_XML.o \
       MainProgram.o


## c compilation commands
myxclass:
	$(FC) -c $(FFLAGS) $(FSRC)


##--------------------------------------------------------------------------------------------------------------------------------------------------------
## define names of c source files
CDIR = ../../MAGIX/Modules/lib/myXCLASS/sqlite
CSRC = $(CDIR)/sqlite3.c $(CDIR)/sqlite3_NumberEntries.c $(CDIR)/sqlite3_PartitionFunction.c $(CDIR)/sqlite3_RadTrans.c
COBJ = sqlite3.o sqlite3_NumberEntries.o sqlite3_PartitionFunction.o sqlite3_RadTrans.o


## c compilation commands
.c.o: $(CDIR)/$(CSRC) Makefile
	$(CC) -c $(CFLAGS) $<
sqlite:
	$(CC) $(CFLAGS2) $(CSRC)



##--------------------------------------------------------------------------------------------------------------------------------------------------------
## define order of commands
all: sqlite myxclass build clean merge


##--------------------------------------------------------------------------------------------------------------------------------------------------------

build: $(OBJS)
	$(FC) -o $(EXEC) -I. $(COBJ) $(FOBJ) $(LDLIBSDB)

.SUFFIXES: $(SUFFIXES) .f90

clean:
	rm -f $(OBJS) *.mod *.o

move:
	mv $(EXEC) ../

merge:
	cat $(CSRC) $(FSRC) > myXCLASS_total.f90

