FFLAGS += -I$(CERN)/$(CERN_LEVEL)/include
CFLAGS += -I$(CERN)/$(CERN_LEVEL)/include
CXXFLAGS += -I$(CERN)/$(CERN_LEVEL)/include
CERNLIBS = -L$(CERN)/$(CERN_LEVEL)/lib $(shell cernlib geant321 pawlib graflib grafX11 packlib mathlib kernlib)

FFLAGS += -I/usr/include/cernlib/$(CERN_LEVEL)
CFLAGS += -I/usr/include/cernlib/$(CERN_LEVEL)
CXXFLAGS += -I/usr/include/cernlib/$(CERN_LEVEL)

MISC_LIBS += $(CERNLIBS) $(EXTRA_LIBS)

# This seems to be needed to get it to link and run without errors 
# on 64-bit CentOS 5.3 
ifeq "$(ARCH)" "x86_64"
  MISC_LIBS += -lmathlib -lblas
  FFLAGS += -fno-automatic
endif

# The tricky part here is choosing which program to link with. It seems
# that more modern systems use gcc4 and gfortran in which case you
# want to use g++ to link and add the -lgfortran library (which is
# currently added automatically in Makefile.CERNLIB).
#
# For legacy gcc3 systems using g77, you want to use g77 to
# link and explicitly add the the libstdc++ library.
#
# Other systems may mix gcc3 with gfortran or gcc4 with
# g77. For these, you'll just need to play around since
# it is just too difficult to make (and keep!) this working
# for all possible combinations.
#
# We do at least make an attempt to do the right thing based
# on whether you are running gcc3 or gcc4.
GCCVERSION = $(shell $(HALLD_HOME)/src/BMS/gcc_version.csh majoronly)

ifeq ($(strip $(GCCVERSION)), 3)
	# Using gcc3
	LD = $(FC)
	MISC_LIBS += -lstdc++
else
	# Using gcc4
	LD = $(CXX)
	MISC_LIBS += -lgfortran
endif