# -*- Makefile -*- 
# Generic makefile for IMSL, MKL, blas/lapack, and FORTRAN libraries
# Generic makefile Tao's and Daniel's C routines 
# Generic makefile for various machines
# All output is to OUT_DIR

# MACHINE
#USE_HOME=USE_HOME
#USE_LAPTOP=USE_LAPTOP 
USE_WORK_64=USE_WORK_64
#USE_WORk_64_OLD=USE_WORK_64_OLD
#USE_WORK_32=USE_WORK_32
#USE_WULF=USE_WULF

# LIBRARIES
#USE_TAO = USE_TAO
USE_MKL = USE_MKL
#USE_ATLAS = USE_ATLAS
#USE_IMSL = USE_IMSL
USE_LAPACK = USE_LAPACK
#USE_FORTRAN = USE_FORTRAN
USE_MATH = USE_MATH
USE_GSL = USE_GLS
#USE_GSL_CBLAS = USE_GSL_CBLAS

# MACHINE DEPENDENT DIRECTORIES 

# HOME
ifdef USE_HOME
WORK_DIR =$(HOME)/data/flash/c-code
OUT_DIR = $(WORK_DIR)/utilities/DWCcode/test_routines/matrix_test/c++

#CC = /opt/intel/cc/10.1.018/bin/icc
CC = g++
FC = gfortran
CFLAGS = -g -static

TAO_DIR = $(WORK_DIR)/utilities/TZCcode
IMSL_BASE_DIR = /opt/vni/CTT6.0

GSL_INCLUDE_DIR = /usr/local/include/gsl
GSL_LIBS_DIR = /usr/local/lib

LAPACK_LIBS_DIR = $(HOME)/lapack-3.2/lib4.2.4
LAPACK_LIBS = -llapack_linux -lblas_linux

MKL_BASE_DIR = /opt/intel/Compiler/11.0/081/mkl
MKL_LIBS_DIR = $(MKL_BASE_DIR)/lib/32
MKL_LIBS = -lmkl_lapack -lmkl_ia32 -lguide

ATLAS_LIBS_BASE = $(HOME)/atlas-3.8.3/lib-atlas
ATLAS_LIBS = -llapack -lptf77blas -lptcblas -latlas

NPSOL_DIR = $(HOME)/npsol-5.0/lib

FORTRAN_LIBS = /usr/lib/gcc/i486-linux-gnu/4.2.4/libgfortran.a
endif

# LAPTOP
ifdef USE_LAPTOP
WORK_DIR =$(HOME)/data/svn_working/trunk
OUT_DIR = $(WORK_DIR)/dw_utilities/test_routines/matrix_test/c++

CC = g++
FC = gfortran
CFLAGS = -g -static

TAO_DIR = $(WORK_DIR)/utilities/TZCcode
IMSL_BASE_DIR = /opt/vni/CTT6.0

GSL_INCLUDE_DIR = /usr/local/include/gsl

GSL_LIBS_DIR = /usr/local/lib

MKL_BASE_DIR = /opt/intel/Compiler/11.0/081/mkl
MKL_LIBS_DIR = $(MKL_BASE_DIR)/lib/32
MKL_LIBS = -lmkl_lapack -lmkl_ia32 -lguide

NPSOL_DIR = /home/f1dfw14/data/npsol-5.0

#FORTRAN_LIBS = /usr/lib/gcc/i586-mandriva-linux-gnu/4.1.1/libgfortran.a
endif

# WORK_64
ifdef USE_WORK_64
WORK_DIR = $(HOME)/git/utilities_dw
OUT_DIR = $(WORK_DIR)/test_routines/matrix_test/c++

CC = g++
FC = gfortran
CFLAGS = -g -static

#CC = /opt/intel/Compiler/11.0/081/bin/intel64/icc
#FC = gfortran
#CFLAGS = -g -static

TAO_DIR = $(WORK_DIR)/utilities/TZCcode

MKL_BASE_DIR = /opt/intel/Compiler/11.0/081/mkl
MKL_LIBS_DIR = $(MKL_BASE_DIR)/lib/em64t
MKL_LIBS = -lmkl_lapack -lmkl_em64t /opt/intel/Compiler/11.0/081/lib/intel64/libguide.a

LAPACK_LIBS_DIR = $(HOME)/lapack-3.2/lib4.2.4
#LAPACK_LIBS = -llapack_linux -lblas_linux
LAPACK_LIBS = -llapack_debug -lblas_debug

ATLAS_LIBS_BASE = $(HOME)/atlas-3.8.3/lib-atlas
ATLAS_LIBS = -llapack -lptf77blas -lptcblas -latlas

GSL_INCLUDE_DIR = /usr/local/include/gsl
GSL_LIBS_DIR = /usr/local/lib

NPSOL_DIR = /home/f1dfw14/data/npsol-5.0

FORTRAN_LIBS = /usr/lib/gcc/x86_64-linux-gnu/4.2.4/libgfortran.a
endif

# WORK_64_OLD
ifdef USE_WORK_64_OLD
WORK_DIR = $(HOME)/data/git/utilities_dw
OUT_DIR = $(WORK_DIR)/utilities/DWCcode/test_routines/matrix_test/c++

CC = g++
FC = gfortran
CFLAGS = -g -static

TAO_DIR = $(WORK_DIR)/utilities/TZCcode

#USE_MKL=USE_MKL
MKL_BASE_DIR = /opt/intel/mkl/9.1.021
MKL_LIBS_DIR = $(MKL_BASE_DIR)/lib/em64t
MKL_LIBS = -lmkl_lapack -lmkl_em64t lguide

GSL_INCLUDE_DIR = /usr/local/include/gsl
GSL_LIBS_DIR = /usr/local/lib

NPSOL_DIR = /home/f1dfw14/data/npsol-5.0

FORTRAN_LIBS = /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgfortran.a
endif

# WORK_32
ifdef USE_WORK_32
WORK_DIR = $(HOME)/data/Dynare
OUT_DIR = $(HOME)/data/working/dynare

CC = /opt/intel/cc/10.0.023/bin/icc
FC = gfortran
CFLAGS = -g -static -m32

TAO_DIR = $(WORK_DIR)/utilities/TZCcode
IMSL_BASE_DIR = /opt/vni/CTT6.0

MKL_BASE_DIR = /opt/intel/mkl/9.1.021
MKL_LIBS_DIR = $(MKL_BASE_DIR)/lib/32
MKL_LIBS = -lmkl_lapack -lmkl_ia32 -lguide
endif

#WULF
ifdef USE_WULF
WORK_DIR = $(HOME)/nas02/common
CFLAGS = -g -static

MKL_BASE_DIR = /opt/intel/mkl/8.1
MKL_LIBS_DIR = $(MKL_BASE_DIR)/lib/32
MKL_LIBS = -lmkl_lapack -lmkl_ia32

IMSL_BASE_DIR = /opt/vni/CTT6.0

G2C_BASE_DIR = /usr/lib/gcc-lib/i386-redhat-linux/3.2.3
endif

#################################################################################
VPATH = $(OUT_DIR)
INCLUDE_DIR = 
LIBS_DIR = 
LIBS = 
OBJS =
#################################################################################

### GLS #########################################################################
# GSL_LIBS_DIR and GSL_INCLUDE_DIR muste be defined
ifdef USE_GSL
  INCLUDE_DIR := $(INCLUDE_DIR) -I$(GSL_INCLUDE_DIR)
  LIBS_DIR := $(LIBS_DIR) -L$(GSL_LIBS_DIR)
  LIBS := $(LIBS) -lgsl
endif
#################################################################################

### GLS CBLAS ###################################################################
# GSL_LIBS_DIR and GSL_INCLUDE_DIR muste be defined
ifdef USE_GSL_CBLAS
  ifndef USE_GSL
    INCLUDE_DIR := $(INCLUDE_DIR) -I$(GSL_INCLUDE_DIR)
    LIBS_DIR := $(LIBS_DIR) -L$(GSL_LIBS_DIR)
  endif
  LIBS := $(LIBS) -lgslcblas
endif
#################################################################################

### MKL #########################################################################
# MKL_BASE_DIR and MKL_LIBS must be defined
ifdef USE_MKL
  USE_PTHREAD = USE_PTHREAD 
  INCLUDE_DIR := $(INCLUDE_DIR) -I$(MKL_BASE_DIR)/include
  LIBS_DIR := $(LIBS_DIR) -L$(MKL_LIBS_DIR)
  LIBS := $(LIBS) $(MKL_LIBS)
endif
#################################################################################

### ATLAS #######################################################################
# ATLAS_LIBS_BASE and ATLAS_LIBS must be defined
ifdef USE_ATLAS
  USE_PTHREAD = USE_PTHREAD 
  USE_FORTRAN = USE_FORTRAN
  LIBS_DIR := $(LIBS_DIR) -L$(ATLAS_LIBS_BASE)/lib
  LIBS := $(LIBS) $(ATLAS_LIBS)
endif
#################################################################################

### BLAS / LAPACK LIBRARIES #####################################################
ifdef USE_LAPACK
  ifndef USE_MKL
    ifndef USE_ATLAS
      USE_FORTRAN = USE_FORTRAN
      ifdef LAPACK_LIBS_DIR
        LIBS_DIR := $(LIBS_DIR) -L$(LAPACK_LIBS_DIR)
      endif
      ifdef LAPACK_LIBS
        LIBS := $(LIBS) $(LAPACK_LIBS)
      else
        LIBS := $(LIBS) -llapack -lblas
      endif
    endif
  endif
endif
#################################################################################

### FORTRAN #####################################################################
# FORTRAN_LIBS should be defined
ifdef USE_FORTRAN
  ifdef FORTRAN_LIBS_DIR
    LIBS_DIR := $(LIBS_DIR) -L$(FORTRAN_LIBS_DIR)
  endif
  LIBS := $(LIBS) $(FORTRAN_LIBS)
endif
#################################################################################

### PTHREAD #####################################################################
ifdef USE_PTHREAD
  LIBS := $(LIBS) -lpthread
endif
#################################################################################

### MATH LIBRARY ################################################################
ifdef USE_MATH
  LIBS := $(LIBS) -lm
endif
#################################################################################

### DW FILES ####################################################################
MATRIX_DIR = $(WORK_DIR)/matrix
ERROR_DIR = $(WORK_DIR)/error
ARRAY_DIR = $(WORK_DIR)/arrays
STAT_DIR = $(WORK_DIR)/stat
ASCII_DIR = $(WORK_DIR)/ascii
MATH_DIR = $(WORK_DIR)/math
#################################################################################

# DW  FILES
INCLUDE_DIR := $(INCLUDE_DIR) -I$(ERROR_DIR) -I$(MATRIX_DIR) -I$(STAT_DIR) -I$(ASCII_DIR) -I$(ARRAY_DIR) -I$(MATH_DIR)
VPATH := $(VPATH) $(ERROR_DIR) $(MATRIX_DIR) $(STAT_DIR) $(ASCII_DIR) $(ARRAY_DIR) $(MATH_DIR)
OBJS := $(OBJS) dw_error.o bmatrix_blas_lapack.o matrix.o dw_rand_gsl.o dw_matrix_rand.o dw_parse_cmd.o dw_ascii.o dw_array.o dw_math.o

# PROJECT FILE
INCLUDE_DIR := $(INCLUDE_DIR)
VPATH := $(VPATH)
OBJS := $(OBJS) matrix_test_main.o matrix_test.o matrix_test_instances.o

# OUTPUT
EFILE = $(OUT_DIR)/matrix_test


#################################################################################
$(EFILE): $(OBJS)
	$(CC) $(CFLAGS) $^ $(LIBS_DIR) $(LIBS) -o $(EFILE)

%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $(OUT_DIR)/$@

%.o : %.cpp
	$(CC) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $(OUT_DIR)/$@
#
#################################################################################
clean:
	rm -f $(OUT_DIR)/*.o
#
#################################################################################
#test:
#	echo '$(OUT_DIR)'
#$(EFILE): $(OBJS)
#	$(CC) $(CFLAGS) $^ $(LIBS_DIR) $(LIBS) -o $(EFILE)
#
#%.o : %.c %.h
#	echo '-c $< -o $(OUT_DIR)/$@'