CXX             = g++
RM              = rm -f
PYTHON_CFLAGS = -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7  -Wdate-time #-fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv 
PYTHON_LDFLAGS = -L/usr/lib/python2.7/config-x86_64-linux-gnu  -lpython2.7   -lutil #-ldl -lm  #-Wl,-export-dynamic -Wl,-Bsymbolic-functions
CXX_FLAGS       = -Wall  -O2 -std=c++11 -fpic -fdata-sections -ffunction-sections

LD              = ${CXX} -v
LD_FLAGS        = -Wall #${PYTHON_LDFLAGS}

all_non_sgx_obj := $(system_obj) $(protobuf_obj) #$(patsubst %.cpp,%.o,$(all_non_sgx_cpp)}

all_non_sgx_cpp := $(patsubst %.o,%.cpp,$(all_non_sgx_obj))
sgx_protobuf_obj := $(patsubst %.cpp,%.o,$(wildcard SgxProtobuf*))
sgx_obj := $(patsubst %.cpp,%.o,$(wildcard Sgx*))

protobuf_obj := $(patsubst %.cpp,%.o,$(wildcard Protobuf*))
system_obj := $(patsubst %.cpp,%.o,$(wildcard system*))
OBJECTS := systemMain.o systemSealerWrapper.o SgxSealer.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o 

SGX_COMMON_CFLAGS := -m64
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
SgxC_Library_Name := sgx_tstdc
Trts_Library_Name := sgx_trts
Service_Library_Name := sgx_tservice
Crypto_Library_Name := sgx_tcrypto
SGX_INCLUDE_PATHS := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/libcxx

Uae_Library_Name := sgx_uae_service

all:	verifier #${OBJECTS}

clean:
	${RM} *.obj *~* systemMain.o DeploymentStageLogic.o LAInitiator/LA.o LAInitiator/Transforms.o PostLA/PostLAMessaging.o ProtobufAutogenerated/ProtobufLAMessages.pb.o ProtobufMessageRW.o crypto.o

LAInitiator/%.o: LAInitiator/%.cpp
	${CXX} -I./include -I$(SGX_SDK)/include ${CXX_FLAGS} -c $^ -o $@

PostLA/%.o: PostLA/%.cpp
	${CXX} -I./include -I$(SGX_SDK)/include ${CXX_FLAGS} -c $^ -o $@

ProtobufAutogenerated/%.o: ProtobufAutogenerated/%.cpp
	${CXX} -I./include ${CXX_FLAGS} -c $^ -o $@

%.o: %.cpp
	${CXX} -I./include ${CXX_FLAGS} -c $^ -o $@
	#-I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/

crypto.o: crypto.cpp 
	${CXX} ${CXX_FLAGS} -c $^ -o $@

verifier:  systemMain.o DeploymentStageLogic.o LAInitiator/LA.o LAInitiator/Transforms.o PostLA/PostLAMessaging.o ProtobufAutogenerated/ProtobufLAMessages.pb.o ProtobufMessageRW.o crypto.o
	${CXX} systemMain.o DeploymentStageLogic.o LAInitiator/LA.o LAInitiator/Transforms.o PostLA/PostLAMessaging.o ProtobufAutogenerated/ProtobufLAMessages.pb.o ProtobufMessageRW.o crypto.o -Wl,--no-undefined ${LD_FLAGS} -lcrypto -lssl -L$(SGX_LIBRARY_PATH) -l$(Service_Library_Name) -l$(Crypto_Library_Name) -l$(Trts_Library_Name) -l$(SgxC_Library_Name) -lprotobuf  -o $@
#-L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm  
#-L~/linux-sgx-trts-modified/build/linux -lsgx_tstdc -lsgx_trts ${LD_FLAGS} -o $@

#-Wl,-rpath,$(SGX_SDK)/lib64  systemMain.o  ${LD_FLAGS} -o $@
#systemSealerWrapper.o SgxSealer.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o
#${LD_FLAGS} 
#-L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -L$(SGX_LIBRARY_PATH) -l$(Service_Library_Name) -l$(Crypto_Library_Name) -lsgx_tstdc 
# -lprotobuf 
# -L${Openssl_Path}/lib -lssl -lcrypto 
# -o $@
# -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm 

