# Install path:
# ------------
# Header wil go to $(PREFIX)/include, libraries to $(PREFIX)/lib,
# binaries to $(PREFIX)/tools.
PREFIX       = /usr/local

# C++ compiler:
# ------------
#CXX          = g++
CXX          = g++

# Yorick interpreter:
# ------------------
YORICK       = yorick

# Version of the library:
# ----------------------
# This should normally be changed only be the developpers, but can
# sometimes be overriden by distributors:
SOVERS_MAJOR = 0
SOVERS       = $(SOVERS_MAJOR).0.0

# Options for using POSIX threads:
# -------------------------------
GYOTO_FLAGS += -DHAVE_PTHREADS
ifneq (,$(findstring -DHAVE_PTHREADS,$(GYOTO_FLAGS)))
LIB_CXX += -lpthread
endif


# Options for using Xerces:
# -------------------------
# Xerces-c 3 is used to read/write scenery descriptions in XML format.
# It is recommended to enable it, required for building the gyoto executable.
# 
# Comment next line to disable Xerces:
GYOTO_FLAGS += -DGYOTO_USE_XERCES
#           Where are Xerces include files:
XERCES_INC = -I/opt/local/include
#           Where is libxercesc.so/.dylib/.a:
XERCES_LDFLAGS = -L/opt/local/lib

# Options for using cfisio:
# -------------------------
# cfitsio is used to save images as fits files.
# It is required for building the gyoto executable.
# Parts of the library will not be built if GYOTO_USE_CFITSIO is not set.
GYOTO_FLAGS += -DGYOTO_USE_CFITSIO
CFITSIO_INC = -I/opt/local/include
CFITSIO_LDFLAGS = -L/opt/local/lib

# ________________________________________________________________
# It shouldn't be necessary to change anything below this line


# Options for the C++ compiler
# ----------------------------
ifndef CXXFLAGS
CXXFLAGS = -g -O2 -pedantic -Wall -W -Wundef -Wshadow -Wcast-qual \
  -Wcast-align -Wconversion -Winline \
  -Wabi -Woverloaded-virtual  -Wno-long-long \
# security hardening, also catches some memory overflows:
  -Wformat -Wformat-security -Werror=format-security \
  -D_FORTIFY_SOURCE=2 \
  -fstack-protector --param ssp-buffer-size=4
endif
ifneq (,$(findstring -DHAVE_PTHREADS,$(GYOTO_FLAGS)))
CXXFLAGS += -pthread
endif
CXXFLAGS += -fPIC



# Path for the include files 
# --------------------------------------------
GYOTO_INC        = $(CFITSIO_INC)
ifneq (,$(findstring -DGYOTO_USE_XERCES,$(GYOTO_FLAGS)))
GYOTO_INC += $(XERCES_INC)
endif

# C, C++ library, mathematical library
# -------------------------------------
LIB_CXX += -lstdc++ -lm
ifneq (,$(findstring -DGYOTO_USE_XERCES,$(GYOTO_FLAGS)))
LIB_CXX +=  -lxerces-c
GYOTO_LDFLAGS += $(XERCES_LDFLAGS)
endif
ifneq (,$(findstring -DGYOTO_USE_CFITSIO,$(GYOTO_FLAGS)))
LIB_CXX +=  -lcfitsio
GYOTO_LDFLAGS += $(CFITSIO_LDFLAGS)
endif

SYS=$(shell uname -s)
ifeq ($(SYS),Darwin)
DYLIB_SFX=dylib
DYLIB_FLAG=-dynamiclib
LIBGYOTO_FILE=libgyoto.$(DYLIB_SFX)
STLIB_CMD=libtool -static -o
PLUG_FLAGS=-flat_namespace -bundle -bundle_loader $(LIBGYOTO_PATH)$(LIBGYOTO_FILE)
DYLIB_VAR=DYLD_LIBRARY_PATH
else
DYLIB_SFX=so
DYLIB_FLAG=-shared -Wl,-soname,libgyoto.$(DYLIB_SFX).$(SOVERS_MAJOR)
LIBGYOTO_FILE=libgyoto.$(DYLIB_SFX).$(SOVERS)
GYOTO_FLAGS += -rdynamic
STLIB_CMD=ar qc
PLUG_FLAGS=-shared
DYLIB_VAR=LD_LIBRARY_PATH
endif

GYOTO_FLAGS += -DGYOTO_PLUGIN_SFX=\"$(DYLIB_SFX)\"
GYOTO_FLAGS += -DGYOTO_PREFIX=\"$(PREFIX)\"
GYOTO_FLAGS += -DGYOTO_SOVERS=\"$(SOVERS)\"

CPPFLAGS += $(CFITSIO_INC) $(XERCES_INC)
LDFLAGS  += $(GYOTO_LDFLAGS)
LDLIBS   = $(LIB_CXX)
