# -*- makefile -*-
# make fragment included in each subdir/Makefile which
# must have $(TOP) set to top level directory

# CXX = g++
# CDF = 1
# CXX = KCC

ifndef ELFIO_DIR
ELFIO_DIR = /usr/local
endif

ifdef CDF
NO_EXCEPT = --no_exceptions
NO_EXCEPT_DEF = -DNO_EXCEPT
endif

# Install into MINOS SRT areas if SRT is turned on
ifdef SRT_DIST
ifeq ("$(SRT_PRIVATE_CONTEXT)",".")
base = $(SRT_PUBLIC_CONTEXT)
else
base = $(SRT_PRIVATE_CONTEXT)
endif
LIBDEST = $(base)/lib/$(SRT_SUBDIR)
BINDEST = $(base)/bin/$(SRT_SUBDIR)
endif

# DEB = -DDEBUG_ME

ifndef LIBDEST
LIBDEST = $(TOP)/lib
endif

ifndef BINDEST
BINDEST = $(TOP)/bin
endif

LDFLAGS = -L. -L$(ELFIO_DIR)/lib -L$(LIBDEST)
COM_INCS = -I$(ELFIO_DIR)/include -I$(TOP)/include
COM_FLAGS = -g $(NO_EXCEPT_DEF) -DLINUX $(DEB) -D_POSIX_C_SOURCE=199506L $(COM_INCS)

KAI_CXX = KCC
KAI_FLAGS = -D_GNU_SOURCE $(COM_FLAGS) --one_instantiation_per_object $(NO_EXCEPT) -DKAI
KAI_AR = $(KAI_CXX) $(KAI_FLAGS) -o
KAI_COMPILE = $(KAI_CXX) $(KAI_FLAGS)
KAI_LD = $(KAI_CXX)  --one_instantiation_per_object $(LDFLAGS) $(NO_EXCEPT)

GCC_CXX = g++
GCC_FLAGS = $(COM_FLAGS)
GCC_AR = ar r
GCC_COMPILE = $(GCC_CXX) $(GCC_FLAGS)
GCC_LD = $(GCC_CXX) $(LDFLAGS) -shared 

LD_LIB_FLAGS = # -shared

# example
# LDLIBS = -lMemLoggerUtil -lz -lELFIO

ifeq ("$(CXX)","g++")
buildtype = gnu
endif
ifdef SRT_DIST
buildtype = gnu
endif

ifeq ("$(buildtype)","gnu")
AR = $(GCC_AR)
CXXFLAGS = $(GCC_FLAGS)
MAKE_LIB = $(GCC_LD)
else
AR = $(KAI_AR)
CXXFLAGS = $(KAI_FLAGS)
MAKE_LIB = $(KAI_LD)
endif

# explicitly state implicit rules to work around make inconsistencies

%.o:: %.cpp
	$(CXX) $(CXXFLAGS) -o $@ -c $<