#######################
#### Start of File ####
#######################
# --------------------------------------------------------------- 
# Makefile Contents: make settings to build datareel library
# C/C++ Compiler Used: GUN, Intel, Cray
# --------------------------------------------------------------- 
# Define file extensions and path variables
OBJ_EXT = .o
EXE_EXT = 
LIB_EXT = .a
DLIB_EXT = .so
PATHSEP = /
SHAREDLIB_VERSION = 5.0
SHAREDLIB_EXT = $(DLIB_EXT).$(SHAREDLIB_VERSION)

# Installation directory for the library files
LIB_INSTALL_DIR = ../lib

# Setup include paths
ADD_INC_PATHS = -I$(GCODE_LIB_DIR)$(PATHSEP)include

ifeq ($(FINAL),1)
     	DEBUG_DEFMACS = -D__NO_DEBUG_OPTIONS__
else
	DEBUG_DEFMACS = -D__DEBUG__
endif

# Our NODETYPE and BUILD must be set in our ENV
BUILD := $(BUILD)
NODETYPE := $(NODETYPE)
USE_IOBUF := $(USE_IOBUF)

ifeq ($(BUILD),cray)
     COMPILER_DEFMACS = -DCRAYCE
     LIBCOMPILE_FLAGS = -fPIC 
else ifeq ($(BUILD),intel)
     COMPILER_DEFMACS = -DINTEL
     LIBCOMPILE_FLAGS = -fPIC
else ifeq ($(BUILD),gnu)
     COMPILER_DEFMACS = -DGNU
     LIBCOMPILE_FLAGS = -fPIC
else
     COMPILER_DEFMACS = -DGNU
     BUILD = gnu
     COMPILER = gnu
     LIBCOMPILE_FLAGS = -fPIC
endif

ifeq ($(NODETYPE),COMPUTE)
ifeq ($(USE_IOBUF),YES)
      COMPILER_DEFMACS := $(COMPILER_DEFMACS) -DUSE_IOBUF_MACROS -D_USE_DIRECT_IO_ 
endif
endif

ifeq ($(NODETYPE),LOGIN)
ifeq ($(USE_IOBUF),YES)
      COMPILER_DEFMACS := $(COMPILER_DEFMACS) -DUSE_IOBUF_MACROS -D_USE_DIRECT_IO_  	
endif
endif

# Define large file settings, files over 2.1GB
ifeq ($(LARGEFILES),1)
	LARGEFILE_DEFMACS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__64_BIT_DATABASE_ENGINE__ -D__ENABLE_64_BIT_INTEGERS__
else
	LARGEFILE_DEFMACS = 
endif

TYPES_DEFMACS = -D__USE_NATIVE_INT_TYPES__ -D__USE_NATIVE_FLOAT_TYPES__ 
ANSI_DEFMACS = -D__USE_ANSI_CPP__
CPP_DEFMACS = -D__USE_CPP_IOSTREAM__ #-D__CPP_EXCEPTIONS__
DISPLAY_DEFMACS = -D__CONSOLE__
IO_DEFMACS = -D__USE_SIGNAL_IO__
THREAD_DEFMACS = -D__REENTRANT__ -D_REENTRANT #-D__GUI_THREAD_SAFE__
POSIX_DEFMACS = -D__POSIX__ -D_POSIX_PTHREAD_SEMANTICS
UNICODE_DEMACS = -D__HAS_UNICODE__
PS_DEFMACS = -D__USE_POSTSCRIPT_PRINTING__ 
HTM_DEFMACS = -D__USE_HTM_PRINTING__ 
TXT_DEFMACS = -D__USE_TEXT_PRINTING__
DATABASE_DEFMACS = -D__USE_DATABASE_CACHE__ -D__USE_BTREE_CACHE__
SERIAL_COMM_DEFMACS = -D__LINUX_BAUD_RATE_38400_SUPPORT__ \
-D__LINUX_BAUD_RATE_57600_SUPPORT__ -D__LINUX_BAUD_RATE_115200_SUPPORT__ \
-D__LINUX_BAUD_RATE_230400_SUPPORT__ -D__LINUX_BAUD_RATE_460800_SUPPORT__
TERMIO_DEFMACS = # -D__USE_TERMINAL_IO__
DEVCACHE_DEFMACS = -D__VMEMORY_BUFFER__ # -D__SMEMORY_BLOCK__
BTREE_DEFMACS = -D__USE_BINARY_SEARCH__ -D__USE_SINGLE_COMPARE__

ifeq ($(USE_OPEN_SSL),YES)
SSL_DEFMACS = -D__USE_GX_SSL_EXTENSIONS__
else
SSL_DEFMACS =
endif

# Setup define macros
DEFMACS = $(COMPILER_DEFMACS) -D__UNIX__ -D__LINUX__ -D__X86__ \
$(LARGEFILE_DEFMACS) $(TYPES_DEFMACS) $(ANSI_DEFMACS) $(CPP_DEFMACS) \
$(DEBUG_DEFMACS) $(DISPLAY_DEFMACS) $(IO_DEFMACS) $(UNICODE_DEMACS) \
$(THREAD_DEFMACS) $(POSIX_DEFMACS) $(PS_DEFMACS) $(HTM_DEFMACS) \
$(TXT_DEFMACS) $(DATABASE_DEFMACS) $(SERIAL_COMM_DEFMACS) \
$(TERMIO_DEFMACS) $(DEVCACHE_DEFMACS) $(BTREE_DEFMACS) \
$(SSL_DEFMACS)

# Define macros for compiler and linker
LINKER = ld
LIBUTIL = ar
RANLIB_UTIL = ranlib
SHARED_LIBUTIL = $(CC) -shared
LN_S = ln -s
LIBUTIL_FLAGS = ruv
SHAREDLIBUTIL_FLAGS =

# Define compiler and linker flags macros
DEBUG_FLAGS = $(CXXFLAGS) $(ADD_INC_PATHS) $(DEFMACS)
RELEASE_FLAGS = $(CXXFLAGS) $(ADD_INC_PATHS) $(DEFMACS)

ifeq ($(FINAL),1)
	COMPILE_FLAGS = $(RELEASE_FLAGS)
else
	COMPILE_FLAGS = $(DEBUG_FLAGS)
endif

COMPILE_ONLY = -c
OUTPUT = -o

# Set link libraries here
LINK_LIBRARIES = -lpthread

ifeq ($(USE_OPEN_SSL),YES)
LINK_LIBRARIES := $(LINK_LIBRARIES) -ldl -lssl -lcrypto
endif

LINKER_FLAGS = 

# --------------------------------------------------------------- 
#####################
#### End of File ####
#####################
