CC       = gcc
MPICC    = gcc #mpicc
RM_F_V   = rm -f -v
PWD      = $(shell pwd)
export CC
export MPICC
export RM_F_V
export PWD

OBJS_DIR := $(PWD)/objs

SVN_REV := $(shell svnversion -n .)
DATE_REV := $(shell date '+%F %T')

NUM_CORES:=$(shell cat /proc/cpuinfo | grep processor | wc -l)

# Check for libraries and export cflags/linker variables
NETTLE_FOUND    := $(shell if pkg-config --exists nettle; then echo "1" ; else echo "0"; fi)
ifeq ($(NETTLE_FOUND), 1)
NETTLE_LIBS     := $(shell pkg-config --libs nettle)
#else 
#@echo "package nettle not installed"
endif

OPENSSL_FOUND   := $(shell if pkg-config --exists openssl; then echo "1" ; else echo "0"; fi)
ifeq ($(OPENSSL_FOUND), 1)
OPENSSL_LIBS    := $(shell pkg-config --libs openssl)
#else 
#@echo "package openssl not installed"
endif

PGM_FOUND       := $(shell if pkg-config --exists openpgm-5.1; then echo "1" ; else echo "0"; fi)
ifeq ($(PGM_FOUND), 1)
PGM_CFLAGS  := $(shell pkg-config --cflags openpgm-5.1)
PGM_LIBS    := $(shell pkg-config --libs openpgm-5.1)
#else 
#@echo "package pgm not installed"
endif

LIBXML2_FOUND   := $(shell if pkg-config --exists libxml-2.0; then echo "1" ; else echo "0"; fi)
ifeq ($(LIBXML2_FOUND), 1)
LIBXML2_CFLAGS  := $(shell pkg-config --cflags libxml-2.0)
LIBXML2_LIBS    := $(shell pkg-config --libs libxml-2.0)
#else 
#@echo "package libxml2 not installed"
endif

XPM_FOUND       := $(shell if pkg-config --exists xpm; then echo "1" ; else echo "0"; fi)
ifeq ($(XPM_FOUND), 1)
XPM_LIBS        := $(shell pkg-config --libs xpm)
#else 
#@echo "package xmp not installed"
endif

LIBBLAS_FOUND   := $(shell if [ -f /usr/include/cblas.h ]; then echo "1"; else echo "0"; fi)
ifeq ($(LIBBLAS_FOUND), 1)
LIBBLAS_LIBS    := -lblas
else
$(error "libblas not found, please install it")
endif

#Export common libs
LIBS =  \
    -lm                 \
    $(LIBBLAS_LIBS)     \
    $(LIBXML2_LIBS)     \
    $(XPM_LIBS)
