#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
# National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
# Operator of Los Alamos National Laboratory.
# This file is distributed subject to a Software License Agreement found
# in the file LICENSE that is included with this distribution. 
#*************************************************************************
#
# $Log: not supported by cvs2svn $
# Revision 1.18  2010/03/09 21:45:24  oag
# Updated so that it can build 32bit version on 64bit linux.
#
# Revision 1.17  2009/11/24 15:49:59  soliday
# Added purify support on linux.
#
# Revision 1.16  2009/11/24 05:05:09  lemery
# Added file local.64bits.macros and other statements that adds integer-8
# as default for 64-bit machines.
#
# Revision 1.15  2009/06/02 21:11:30  soliday
# Fixed an issue that popped up on Fedora 8 when building statically.
#
# Revision 1.14  2008/02/26 22:59:35  soliday
# Updated to work with gfortran on Darwin.
#
# Revision 1.13  2008/02/26 21:16:27  soliday
# Updated for darwin-ppc
#
# Revision 1.12  2007/11/12 19:09:40  soliday
# Updated to build a static version of shower on Linux.
#
# Revision 1.11  2007/11/09 22:19:23  soliday
# Changed link library order.
#
# Revision 1.10  2007/02/12 20:53:26  soliday
# Updated so that Windows builds will no longer need a fortran compiler.
#
# Revision 1.9  2006/08/24 15:11:21  soliday
# Updated to work on Windows using Intel Visual Fortran Compiler. This compiler
# is required if using Microsoft Visual Studio 2003 or 2005.
#
# Revision 1.8  2005/11/10 22:06:10  soliday
# Added support for building with 64bit compiler.
#
# Revision 1.7  2004/04/30 19:03:21  soliday
# Fixed build rules to build on MacOSX
#
# Revision 1.6  2004/04/21 18:36:01  soliday
# Fixed issue with newer WIN32 compiler
#
# Revision 1.5  2004/04/08 17:12:26  soliday
# Fixed some issues on solaris
#
# Revision 1.4  2004/04/08 17:09:05  soliday
# Build rules are now compatible with Base 3.14
#
# Revision 1.3  2002/08/14 20:34:34  soliday
# Added Open License
#
# Revision 1.2  2000/02/21 16:49:58  soliday
# Changed to point to Makefile.Host
#
# Revision 1.1  1996/02/07 19:05:50  emery
# Generic Makefile
#

TOP=../..
include $(TOP)/configure/CONFIG
include $(TOP)/src/shower/Makefile.OAG
include $(TOP)/configure/RULES

ifeq ($(OS_CLASS),Darwin)
F77 = gfortran-mp-14
M77 = gfortran-mp-14 -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
FLDFLAGS = -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
endif
ifeq ($(OS_CLASS),Linux)
#DO NOT USE -fno-align-commons
#F77 = gfortran -fno-align-commons
F77 = gfortran
endif
ifeq ($(EPICS_HOST_ARCH),linux-x86_64)
FFLAGS = -O4 -m64 -fno-align-commons
FLDFLAGS = -m64
endif
ifeq ($(EPICS_HOST_ARCH),linux-x86)
FFLAGS = -O4 -m32
FLDFLAGS = -m32
endif
CAT = cat
MORTRAN = ./mortran
SED = sed
ifeq ($(EPICS_HOST_ARCH),win32-x86-mingw)
F77 = gfortran -fno-align-commons
FFLAGS = -O4 -m32
FLDFLAGS = -m32
CAT = c:\cygwin\bin\cat.exe
SED = c:\cygwin\bin\sed.exe
CAT = cat.exe
SED = sed.exe
MORTRAN = ./mortran.exe
endif
ifeq ($(EPICS_HOST_ARCH),windows-x64-mingw)
F77 = gfortran -fno-align-commons
FFLAGS = -O4 -m64
FLDFLAGS = -m64
CAT = c:\cygwin\bin\cat.exe
SED = c:\cygwin\bin\sed.exe
CAT = cat.exe
SED = sed.exe
MORTRAN = ./mortran.exe
endif

ifdef RATIONAL
  F77 := $(RATIONAL) $(F77)
endif

ifneq  ($(OS_CLASS),Darwin)
M77 = $(F77)
endif

shower$(OBJ): shower.h

shower.h: ../shower.nl
	$(EPICS_EXTENSIONS_BIN)/nlpp ../shower.nl shower.h


ifdef WIN32
else
mortran$(EXE) : ../mortran3.f
	$(M77) ../mortran3.f -o mortran$(EXE)
endif


ifdef USE_PRESTA
	PRESTAMACRO = ../presta.macros
	PRESTAMORTRAN = ../presta.mortran
endif

ifeq ($(EPICS_HOST_ARCH),linux-x86_64)
 USE_64BITS = yes
endif

ifdef USE_64BITS
	SIXTY4BITMACRO = ../local.64bit.macros
	FFLAGS += -fdefault-integer-8
endif

egs4.f: ../egs4mac.mortran ../nrcc4mac.mortran $(PRESTAMACRO) ../machine.mortran ../local.mortran $(SIXTY4BITMACRO) ../nrccaux.mortran $(PRESTAMORTRAN) ../egs4blok.mortran ../egs4.mortran mortran$(EXE)  
	$(RM) fort.1
	$(RM) fort.7
	$(RM) .mortlst
	$(CP) ../sparc.mortran.dat fort.1
	$(CAT) ../egs4mac.mortran ../nrcc4mac.mortran $(PRESTAMACRO) ../machine.mortran ../local.mortran $(SIXTY4BITMACRO) ../nrccaux.mortran $(PRESTAMORTRAN) ../egs4blok.mortran  ../egs4.mortran | $(MORTRAN) > .mortlst
# Strip trailing blanks to save space. The $$ is replaced with one $ by gnumake.
	$(MV) fort.7 egs4.f.temp
	-$(SED) -e 's/ *$$//' < egs4.f.temp > egs4.f
	$(RM) egs4.f.temp
#	$(RM) fort.*

ifdef WIN32
else
egs4$(OBJ) : egs4.f
	$(F77) egs4.f -c -o egs4$(OBJ) $(FFLAGS)

endif


ifdef WIN32
else

ifeq ($(HOST_ARCH),solaris)
solaris_libs = -lrt
endif
ifeq ($(HOST_ARCH),solaris-sparc)
solaris_libs = -lrt
endif
ifeq ($(EPICS_HOST_ARCH),solaris-sparc)
solaris_libs = -lrt
endif
ifeq ($(EPICS_HOST_ARCH),solaris-sparc)
solaris_libs = -lrt
endif
ifeq ($(OS_CLASS),Darwin)
darwin_libs = -L/opt/local/lib -L/sw/lib
endif
ifeq ($(OS_CLASS),Linux)
ifeq ($(STATIC_BUILD),YES)
static_flags = -Wl,-Bstatic -static-libgcc
linux_libs = -lc
endif
endif

shower$(EXE): $(OBJNAMES)
	$(F77) $(FLDFLAGS) -o $@ $(OBJNAMES) $(static_flags) -I$(INSTALL_LIB) -L$(EPICS_EXTENSIONS_LIB) -lmdbcommon -lmatlib -lfftpack -lSDDS1 -lnamelist -lrpnlib -lgsl -lmdbmth -lmdblib -llzma -lz $(solaris_libs) $(darwin_libs) $(linux_libs)

endif

