##########################################################################################################################################################
#
#
#
#  Makefile for compiling the sqlite interface for XCLASS package
#  Copyright (C) 2021 - 2024  Thomas Moeller
#
#  I. Physikalisches Institut, University of Cologne
#
#
#
#  Versions of the program:
#
#  Who           When        What
#
#  T. Moeller    2021-12-09  Initial version
#
#
#
#
#  Makefile options:    - "all":    builds the sqlite library for XCLASS package
#
#                                   Used files:     SQLite3/sqlite3.c
#                                                   src/sqlite3_NumberEntries.c
#                                                   src/sqlite3_PartitionFunction.c
#                                                   src/sqlite3_RadTrans.c
#
#
##########################################################################################################################################################


#=========================================================================================================================================================
#=========================================================================================================================================================
# define subdirectories
#=========================================================================================================================================================
#=========================================================================================================================================================


# define output directory for final binary file
bindir = bin


# define directory of source files for SQLite3 interface
sqliteintsrcdir = src


# define directory of source files for SQLite3 library
sqlitesrcdir = SQLite3


# define directory of header files
includedir = -I$(sqlitesrcdir)


#=========================================================================================================================================================
#=========================================================================================================================================================
# define source and objects files
#=========================================================================================================================================================
#=========================================================================================================================================================


## define names of fortran source files for sqlite library
ARSRC = $(sqlitesrcdir)/sqlite3.c \
        $(sqliteintsrcdir)/sqlite3_NumberEntries.c \
        $(sqliteintsrcdir)/sqlite3_PartitionFunction.c \
        $(sqliteintsrcdir)/sqlite3_RadTrans.c


## define names of fortran object files for sqlite library
AROBJ = sqlite3.o \
        sqlite3_NumberEntries.o \
        sqlite3_PartitionFunction.o \
        sqlite3_RadTrans.o


#=========================================================================================================================================================
#=========================================================================================================================================================
# define C compiler and corresponding flags
#=========================================================================================================================================================
#=========================================================================================================================================================


# C compiler. Here: GCC.
CC = gcc
CFLAGS = -O2 -fPIC -c $(includedir)


#=========================================================================================================================================================
#=========================================================================================================================================================
# define programs tp create a static library
#=========================================================================================================================================================
#=========================================================================================================================================================


# library for XCLASS
RANLIB = ranlib
AR = ar
ARFLAGS = cr
LIBN = libsqlitex.a


#=========================================================================================================================================================
#=========================================================================================================================================================
# define rules
#=========================================================================================================================================================
#=========================================================================================================================================================


##--------------------------------------------------------------------------------------------------------------------------------------------------------
## define order of commands
all: sqlite libx ranlib move clean


##--------------------------------------------------------------------------------------------------------------------------------------------------------
## compile sqlite source files
sqlite:
	$(CC) $(CFLAGS) $(ARSRC)


## build sqlite library
libx:
	$(AR) $(ARFLAGS) $(LIBN) $(AROBJ)


## run ranlib
ranlib:
	$(RANLIB) $(LIBN)


# clean directories and previous compilations
clean:
	rm -f *.a *.o


# move compilation
move:
	mv $(LIBN) bin/


##--------------------------------------------------------------------------------------------------------------------------------------------------------
##--------------------------------------------------------------------------------------------------------------------------------------------------------
##--------------------------------------------------------------------------------------------------------------------------------------------------------
## done
##--------------------------------------------------------------------------------------------------------------------------------------------------------
##--------------------------------------------------------------------------------------------------------------------------------------------------------
##--------------------------------------------------------------------------------------------------------------------------------------------------------

