# Copyright 2017 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE.  If not, see <http://www.gnu.org/licenses/>.

CPP=g++
CC=gcc
AR=ar
CFLAGS=-fPIC -Ofast
CPPFLAGS=-fPIC --std=c++11 -Ofast -Irestclient-cpp/include `pkg-config --cflags lasso`
LDFLAGS=--shared
LIBS=-lrestclient-cpp -lcurl `pkg-config --libs lasso` -lgobject-2.0 -lgumbo -lgq
SONAME=_occi.so
SOURCES=compute.cpp entity.cpp network.cpp occisession.cpp resource.cpp storage.cpp template.cpp link.cpp saml2_ecp.cpp

SWIG=swig
SWIG_INTERFACES=occilib.i
WRAPPER_SOURCES=occilib_wrap.cpp
WRAPPER_INCLUDES=`pkg-config python --cflags`

RESTCLIENT_CPP_URL=https://github.com/fuximo/restclient-cpp.git
RESTCLIENT_CPP_TAG=master


default: python

python:
	python setup.py build

lib: deps
	$(CPP) $(CPPFLAGS) -c $(SOURCES)
	$(AR) rcs libocci.a *.o

restclient-cpp:
	git clone --depth=1 $(RESTCLIENT_CPP_URL) -b $(RESTCLIENT_CPP_TAG)
	bash gen_restclient-cpp_version.sh $(RESTCLIENT_CPP_TAG)

build-restclient-cpp: restclient-cpp
	cd restclient-cpp ; \
	$(CPP) $(CPPFLAGS) -c source/*.cc -Iinclude
	$(AR) rcs librestclient-cpp.a restclient-cpp/*.o

deps: build-restclient-cpp

clean:
	rm -f *.o
	rm -f $(WRAPPER_SOURCES)
	rm -f $(SONAME)
	rm -f occi.py
	rm -f occi.pyc
	rm -Rf build

mrproper: clean clean_deps
	rm -Rf dist libocci.egg-info

clean_deps:
	rm -Rf restclient-cpp
	rm -f librestclient-cpp.a
