# Require a SRCBASE directory variable
ifeq ("${SRCBASE}","")
$(error "SRCBASE not defined")
endif

# Determine the operating system, R home directory, and include directories
OS=$(shell uname -s | cut -c "1 2 3 4 5")
RHOME=$(shell R RHOME)
INCLUDEDIRS=-I$(RHOME) -I$(SRCBASE)/threads -I$(SRCBASE)/cluster -I/Library/Frameworks/R.framework/Resources/include -I$(SRCBASE)

# Get version number of EDGE library
ifeq ("${VERSION}", "")
VERSION=1.0.$(shell ${SRCBASE}/getversion)
endif

EDGELIBVERSION=-DEDGE_LIBRARY_VERSION=\"$(VERSION)\"

# Debug flags
ifneq ("${DEBUG}", "")
DEBUG=-DEDGE_DEBUG
else
DEBUG=
endif

# Operating system-specific compiler/linker flags

ifeq ("${OS}","Darwi")
OS_FLAGS=-DMAC_OS_X -Dassert\(expr\)= -fPIC
PKG_KNNLIBS=-L/sw/lib
SOEXT=.so
RCMD=R
RCMD_CMD=CMD
endif

ifeq ("${OS}", "MINGW")
OS_FLAGS=-DWIN32
SOEXT=.dll
RCMD=RCMD
RCMD_CMD=
# MinGW and pdflatex don't get along
IGNORE_PDFLATEX_ERRORS=-
endif

ifeq ("${OS}", "Linux")
OS_FLAGS=-DLINUX -Dassert\(expr\)= -fPIC
SOEXT=.so
RCMD=R
RCMD_CMD=CMD
THREAD_LIB=-lpthread
endif

ifeq ("${RCMD}", "")
#error
endif

# All compiler flags

PKG_CXXFLAGS=$(OS_FLAGS) $(INCLUDEDIRS) $(EDGELIBVERSION) $(DEBUG) -D__STDC_LIMIT_MACROS -Wall
PKG_CFLAGS=$(OS_FLAGS) $(INCLUDEDIRS) $(EDGELIBVERSION) $(DEBUG) -D__STDC_LIMIT_MACROS -Wall

CC=gcc 
CCOPTS=-c -g 
CXX=g++ 
CXXOPTS=-c -g 

