diff --git a/Makefile b/Makefile index ae060556..443db222 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,16 @@ else endif # Occlum major version -MAJOR_VER_NUM = $(shell grep '\#define OCCLUM_MAJOR_VERSION' ./src/pal/include/occlum_version.h | awk '{print $$3}') +MAJOR_VER_NUM = $(shell grep '\#define OCCLUM_MAJOR_VERSION' ./src/pal/include/occlum_version.h | awk '{print $$3}') +MINOR_VER_NUM = $(shell grep '\#define OCCLUM_MINOR_VERSION' ./src/pal/include/occlum_version.h | awk '{print $$3}') +PATCH_VER_NUM = $(shell grep '\#define OCCLUM_PATCH_VERSION' ./src/pal/include/occlum_version.h | awk '{print $$3}') +VERSION_NUM = $(MAJOR_VER_NUM).$(MINOR_VER_NUM).$(PATCH_VER_NUM) # Exclude files when install EXCLUDE_FILES = "libocclum-libos.so.$(MAJOR_VER_NUM)\$$|libocclum-pal.so.$(MAJOR_VER_NUM)\$$|libocclum-pal.so\$$|.a\$$|occlum-protect-integrity.so.*" +SHELL := bash + submodule: githooks git submodule init git submodule update $(OCCLUM_GIT_OPTIONS) @@ -47,7 +52,7 @@ test: @$(MAKE) --no-print-directory -C test test OCCLUM_PREFIX ?= /opt/occlum -install: +install: $(OCCLUM_PREFIX)/sgxsdk-tools/lib64/libsgx_uae_service_sim.so @# Install both libraries for HW mode and SIM mode @$(MAKE) SGX_MODE=HW --no-print-directory -C src @$(MAKE) SGX_MODE=SIM --no-print-directory -C src @@ -58,6 +63,9 @@ install: @mkdir -p $(OCCLUM_PREFIX)/build/lib/ @# Don't copy libos library and pal library symbolic files to install dir @cd build/lib && cp --no-dereference `ls | grep -Ev $(EXCLUDE_FILES)` $(OCCLUM_PREFIX)/build/lib/ && cd - + @# Create symbolic for pal library of hardware mode + @cd $(OCCLUM_PREFIX)/build/lib && ln -sf libocclum-pal.so.$(VERSION_NUM) libocclum-pal.so.$(MAJOR_VER_NUM) && \ + ln -sf libocclum-pal.so.$(MAJOR_VER_NUM) libocclum-pal.so @echo "Install headers and miscs ..." @mkdir -p $(OCCLUM_PREFIX)/include/ @@ -66,8 +74,21 @@ install: @mkdir -p $(OCCLUM_PREFIX)/etc/template/ @cp etc/template/* $(OCCLUM_PREFIX)/etc/template @chmod 444 $(OCCLUM_PREFIX)/etc/template/* + @echo "Installation is done." +# Install minimum sgx-sdk set to support Occlum cmd execution in non-customized sgx-sdk environment +$(OCCLUM_PREFIX)/sgxsdk-tools/lib64/libsgx_uae_service_sim.so: /opt/intel/sgxsdk/lib64/libsgx_uae_service_sim.so + @echo "Install needed sgx-sdk tools ..." + @mkdir -p $(OCCLUM_PREFIX)/sgxsdk-tools/lib64 + @cp /opt/intel/sgxsdk/lib64/{libsgx_ptrace.so,libsgx_uae_service_sim.so} $(OCCLUM_PREFIX)/sgxsdk-tools/lib64 + @mkdir -p $(OCCLUM_PREFIX)/sgxsdk-tools/lib64/gdb-sgx-plugin + @cd /opt/intel/sgxsdk/lib64/gdb-sgx-plugin/ && cp $$(ls -A | grep -v __pycache__) $(OCCLUM_PREFIX)/sgxsdk-tools/lib64/gdb-sgx-plugin + @cd /opt/intel/sgxsdk && cp --parents {bin/sgx-gdb,bin/x64/sgx_sign,sdk_libs/libsgx_uae_service_sim.so} $(OCCLUM_PREFIX)/sgxsdk-tools/ + @# Delete SGX_LIBRARY_PATH env in sgx-gdb which are defined in etc/environment + @sed -i '/^SGX_LIBRARY_PATH=/d' $(OCCLUM_PREFIX)/sgxsdk-tools/bin/sgx-gdb + @cp etc/environment $(OCCLUM_PREFIX)/sgxsdk-tools/ + format: @$(MAKE) --no-print-directory -C test format @$(MAKE) --no-print-directory -C tools format diff --git a/etc/environment b/etc/environment new file mode 100644 index 00000000..e4b31ccf --- /dev/null +++ b/etc/environment @@ -0,0 +1,13 @@ +if [ -d "/opt/occlum/sgxsdk-tools" ]; then + export SGX_SDK=/opt/occlum/sgxsdk-tools +else + export SGX_SDK=/opt/intel/sgxsdk +fi +export SGX_LIBRARY_PATH=$SGX_SDK/lib64 +export PATH=$SGX_SDK/bin:$SGX_SDK/bin/x64:$PATH +export PKG_CONFIG_PATH=$SGX_SDK/pkgconfig:$PKG_CONFIG_PATH +if [ -z "$LD_LIBRARY_PATH" ]; then + export LD_LIBRARY_PATH=$SGX_SDK/sdk_libs +else + export LD_LIBRARY_PATH=$SGX_SDK/sdk_libs:$LD_LIBRARY_PATH +fi diff --git a/tools/occlum b/tools/occlum index 81a81d94..5ea9dccc 100755 --- a/tools/occlum +++ b/tools/occlum @@ -6,8 +6,10 @@ build_makefile=$occlum_dir/build/bin/occlum_build.mk if [[ "$occlum_dir" == "/opt/occlum" ]]; then version_header=$occlum_dir/include/occlum_version.h + occlum_sgx_env=$occlum_dir/sgxsdk-tools/environment else version_header=$occlum_dir/src/pal/include/occlum_version.h + occlum_sgx_env=$occlum_dir/etc/environment fi major_ver=`grep '\#define OCCLUM_MAJOR_VERSION' $version_header | awk '{print $3}'` @@ -19,7 +21,7 @@ instance_dir=`pwd` status_file=$instance_dir/.__occlum_status -SGX_SDK="${SGX_SDK:-/opt/intel/sgxsdk}" +source $occlum_sgx_env SGX_GDB="$SGX_SDK/bin/sgx-gdb" ENCLAVE_SIGN_TOOL="$SGX_SDK/bin/x64/sgx_sign" ENCLAVE_SIGN_KEY="$occlum_dir/etc/template/Enclave.pem" diff --git a/tools/occlum_build.mk b/tools/occlum_build.mk index acd7c699..fdc516ba 100644 --- a/tools/occlum_build.mk +++ b/tools/occlum_build.mk @@ -1,4 +1,4 @@ -SGX_SDK ?= /opt/intel/sgxsdk +SGX_SDK ?= /opt/occlum/sgxsdk-tools IMAGE := $(instance_dir)/image SECURE_IMAGE := $(instance_dir)/build/mount/__ROOT/metadata