CXX             = g++
RM              = rm -f
CXX_FLAGS       = -Wall  -O2 -std=c++11 -fpic -fdata-sections -ffunction-sections
LD              = ${CXX} -v
LD_FLAGS        = -Wall -O2

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_SDK := /home/m2mazmud/sgx2.1_installation/sgxsdk
SGX_COMMON_CFLAGS := -m64
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
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
Openssl_Path := /home/m2mazmud/plain-openssl

Uae_Library_Name := sgx_uae_service

all:	verifier ${OBJECTS}

clean:
	${RM} *.obj *~* ${OBJECTS} verifier #${LocalAttestationCode_objects} ${LocalAttestationCode_ipc_objects} ${LocalAttestationCode_serialization_objects}

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

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

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

crypto.o: crypto.cpp 
	gcc -I${Openssl_Path}/include ${CXX_FLAGS} -c $^ -o $@

verifier:  systemMain.o systemSealerWrapper.o SgxSealer.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o
#	echo $(system_obj)
	${CXX} ${CXX_FLAGS} -Wl,--no-undefined  -Wl,-rpath,$(SGX_SDK)/lib64  systemMain.o systemSealerWrapper.o SgxSealer.o ProtobufLAInitiator.o SgxProtobufLAInitiator.o SgxProtobufLAInitiator_Transforms.o ProtobufLAMessages.pb.o crypto.o -L./ -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive  -L$(SGX_LIBRARY_PATH) -l$(Service_Library_Name) -l$(Crypto_Library_Name) -l$(Uae_Library_Name) -lsgx_tstdc -lsgx_urts -lprotobuf -lsgx_tstdcxx  -L${Openssl_Path}/lib -lssl -lcrypto   -Wl,--verbose -o $@
