#
# platform_specific_includes.mk.x86_64-linux
#
# This file is included in other Makefiles and defines
# platform specific macros

	GKS_INCLUDES	= -I../../ppl/include/xgks \
			  -I../../xgks/src/lib \
			  -Ipplinc/xgks \
			  -I../../xgks/port 

	INCLUDES        = -I. \
			  -I../fmt/cmn/ \
			  -I$(NETCDF4_DIR)/include \
			  -I$(READLINE_DIR)/include \
			  -I../common \
			  -I../../fmt/cmn \
			  -I../../ppl/include \
			  -I../../fer/common \
			  $(GKS_INCLUDES) \
			  -I/usr/local/include

	FINCLUDES	= -I../../ppl/tmap_inc \
			  -I../include \
			  -I../../fmt/cmn \
			  -I../common \
			  -I../../ppl/include \
			  -I../../fer/common

	PLATFORM = $(shell uname -s -r) 64-bit

	CC              = gcc
	CXX		= c++
	FC		= gfortran
	F77		= gfortran

	RANLIB          = /usr/bin/ranlib

	CPP		= /lib/cpp

	CPP_FLAGS       = $(INCLUDES) \
			  -m64 \
			  -fPIC -Dunix -Dgfortran   \
			  -DNO_OPEN_SHARED \
			  -DNO_OPEN_RECORDTYPE \
			  -DX_REFRESH -Dreclen_in_bytes  \
			  -DNO_OPEN_READONLY -DMANDATORY_FORMAT_WIDTHS\
			  -DNO_OPEN_CARRIAGECONTROL -Dxgks -DSTAR_1_SUPPORTED \
			  -DFULL_GUI_VERSION -DX_REFRESH \
			  -DXT_CODE  -DLINUX -DNO_PASSED_CONCAT \
			  -Dcrptd_cat_argument \
			  -DG77_SIGNAL -DG77 \
			  -DNEED_IAND -DINTERNAL_READ_FORMAT_BUG \
			  -DNO_PREPEND_STRING -DNO_DOUBLE_ESCAPE_SLASH \
			  -Ddouble_p 

# Flags for compiling all C code
# -DusingDODSf2cUnderscore needed if using netcdf library...
# also consider -ffloat-store.
	CFLAGS		= $(CPP_FLAGS) \
			  -Dlint -D_SSIZE_T -DVOID_SIGHANDLER -D_POSIX_VERSION -DLINUX \
			  -DFULL_GUI_VERSION -DX_REFRESH -DXT_CODE -Dsun4 
# Flags for compiling the PlotPlus FORTRAN code (ppl subdirectory)
	PPLUS_FFLAGS	= $(CPP_FLAGS) \
			  -fno-automatic -fno-second-underscore \
			  -fdollar-ok -ffixed-line-length-132 $(FINCLUDES)
# Flags for compiling non-PlotPlus FORTRAN code
	FFLAGS		= $(CPP_FLAGS) \
			  -fno-automatic -fno-second-underscore \
			  -fdollar-ok -ffixed-line-length-132 -ffpe-trap=overflow \
			  -fimplicit-none \
			  -fdefault-real-8 -fdefault-double-8 $(FINCLUDES)

        # PROF_FLAGS	= -pg

	# Below this line are macro definitions used only for the final linking of the executable
	#

	LD		= gcc
	LDFLAGS		= -v --verbose -m64 -fPIC -export-dynamic

	SYSLIB		= -lX11 \
			  -lcurl \
			  -ldl \
			  $(LIBZ_DIR)/lib64/libz.a \
			  -Wl,-Bstatic -lgfortran -Wl,-Bdynamic \
			  -lm

# -static-libgfortran can be used with gfortran 4.4 but not 4.1
# /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgfortran.a

	GKSLIB		= ../xgks/src/lib/libxgks.a

# For netCDF4 using new hdf5 and new zlib

	CDFLIB		= $(NETCDF4_DIR)/lib64/libnetcdff.a \
			  $(NETCDF4_DIR)/lib64/libnetcdf.a \
			  $(HDF5_DIR)/lib64/libhdf5_hl.a \
			  $(HDF5_DIR)/lib64/libhdf5.a \
			  $(LIBZ_DIR)/lib64/libz.a

	LINUX_OBJS	= special/linux_routines.o \
			  dat/*.o \
			  ../fmt/src/x*.o \
			  ../ppl/plot/ppldata.o

# Use the home-built libncurses.so to build so
# libtinfo.so is not a requirement from RHEL6
# builds.
# (But use the system ncurses.so.5 for running.)

	TERMCAPLIB	= -L/usr/local/lib64 -lncurses

# For statically linking in the readline and history libraries
#	READLINELIB = -L$(READLINE_DIR)/lib64 -Wl,-Bstatic -lreadline -lhistory -Wl,-Bdynamic
# For linking against the shared-object libraries (if they exist)
	READLINELIB = -L$(READLINE_DIR)/lib64 -lreadline -lhistory

## cancel the default rule for .f -> .o to prevent objects from being built
## from .f files that are out-of-date with respect to their corresponding .F file
#%.o : %.f
#
## use cpp to preprocess the .F files to .f files and then compile the .f files
#%.o : %.F
#	rm -f $*.f
#	$(CPP) -P -traditional $(CPP_FLAGS) $(<F) | sed -e 's/de    /de /g' | sed -e 's/de         /de /g' > $*.f
#	$(F77) $(FFLAGS) -c $*.f	 

# Directly compile the .F source files to the .o object files
# since gfortran can handle the C compiler directives in Fortran code
%.o : %.F
	$(FC) $(FFLAGS) -c $*.F -o $*.o

#
# End of platform_specific_includes.mk.x86_64-linux
#
