forked from smartcontractkit/chainlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (95 loc) · 4.1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#
# Makefile settings -----
#
ENVIRONMENT ?= release
#
# SGX SDK settings ------
#
SGX_SDK ?= /opt/sgxsdk
SGX_SIMULATION ?= no
SGX_RUST_SDK ?= /opt/rust-sgx-sdk
#
# Flags -----------------
#
CARGO ?= cargo
SGX_BIN := $(SGX_SDK)/bin/x64
SGX_EDGER8R := $(SGX_BIN)/sgx_edger8r
SGX_ENCLAVE_SIGNER := $(SGX_BIN)/sgx_sign
SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
SGX_COMMON_CFLAGS := -m64
ifneq (,$(filter release,$(ENVIRONMENT)))
SGX_COMMON_CFLAGS += -O2
RUST_FLAGS := --release
else
SGX_COMMON_CFLAGS += -O0 -g
endif
TRTS_LIB := sgx_trts
SERVICE_LIB := sgx_tservice
ifneq (,$(filter yes true,$(SGX_SIMULATION)))
TRTS_LIB := sgx_trts_sim
SERVICE_LIB := sgx_tservice_sim
endif
INCLUDES := -I$(SGX_SDK)/include -I$(SGX_RUST_SDK)/edl
CC_FLAGS := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(INCLUDES)
ENCLAVE_RS_INCLUDE := -I$(SGX_RUST_SDK)/common/inc -I$(SGX_RUST_SDK)/edl -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I$(SGX_SDK)/include/epid
ENCLAVE_RS_LIBS := -L./target/$(ENVIRONMENT) -lenclave
ENCLAVE_RS_FLAGS := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(ENCLAVE_RS_INCLUDE)
ENCLAVE_RS_LD_FLAGS := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
-Wl,--whole-archive -l$(TRTS_LIB) -l$(SERVICE_LIB) -Wl,--no-whole-archive \
-Wl,--start-group -lsgx_tstdc -lsgx_tcxx -lsgx_tcrypto $(ENCLAVE_RS_LIBS) -Wl,--end-group \
-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
-Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
-Wl,--defsym,__ImageBase=0 \
-Wl,--gc-sections \
-Wl,--version-script=enclave/enclave.lds
#
# Target aliases --------
#
ENCLAVE := ./target/$(ENVIRONMENT)/libenclave.a
PATCHED_ENCLAVE := ./target/$(ENVIRONMENT)/enclave.patched.so
SIGNED_ENCLAVE := ./target/$(ENVIRONMENT)/enclave.signed.so
ENCLAVE_STUB := target/$(ENVIRONMENT)/libenclave_u.a
LIBADAPTERS := target/$(ENVIRONMENT)/libadapters.so
UNTRUSTED_EDL_FILES := target/$(ENVIRONMENT)/enclave_u.c target/$(ENVIRONMENT)/enclave_u.h
TRUSTED_EDL_FILES := target/$(ENVIRONMENT)/enclave_t.c target/$(ENVIRONMENT)/enclave_t.h
#
# Targets ---------------
#
.PHONY: all
all: $(LIBADAPTERS) $(SIGNED_ENCLAVE)
# Lib Adapters ----------
.PHONY: $(UNTRUSTED_EDL_FILES)
$(UNTRUSTED_EDL_FILES): $(SGX_EDGER8R) enclave/enclave.edl
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
$(SGX_EDGER8R) --untrusted enclave/enclave.edl --search-path $(SGX_SDK)/include --search-path $(SGX_RUST_SDK)/edl --untrusted-dir $(@D)
target/$(ENVIRONMENT)/enclave_u.o: $(UNTRUSTED_EDL_FILES)
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
$(CC) $(CC_FLAGS) -c $< -o $@
$(ENCLAVE_STUB): target/$(ENVIRONMENT)/enclave_u.o
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
$(AR) rcsD $@ $^
$(LIBADAPTERS): libadapters/Cargo.toml $(wildcard libadapters/src/*.rs) $(ENCLAVE_STUB)
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
SGX_SIMULATION=$(SGX_SIMULATION) ENVIRONMENT=$(ENVIRONMENT) SGX_SDK=$(SGX_SDK) $(CARGO) build $(RUST_FLAGS) --manifest-path $<
# Enclave ---------------
$(ENCLAVE): enclave/Cargo.toml $(wildcard enclave/src/*.rs)
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
SGX_SIMULATION=$(SGX_SIMULATION) ENVIRONMENT=$(ENVIRONMENT) SGX_SDK=$(SGX_SDK) $(CARGO) build $(RUST_FLAGS) --manifest-path $<
$(TRUSTED_EDL_FILES): $(SGX_EDGER8R) enclave/enclave.edl
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
$(SGX_EDGER8R) --trusted enclave/enclave.edl --search-path $(SGX_SDK)/include --search-path $(SGX_RUST_SDK)/edl --trusted-dir $(@D)
target/$(ENVIRONMENT)/enclave_t.o: $(TRUSTED_EDL_FILES) $(ENCLAVE)
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
$(CC) $(ENCLAVE_RS_FLAGS) -c $< -o $@
$(PATCHED_ENCLAVE): target/$(ENVIRONMENT)/enclave_t.o
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
@printf -- 'Linking against simulation libraries: \e[1;91m$(SGX_SIMULATION)\e[0m\n\n'
$(CXX) $< -o $@ $(ENCLAVE_RS_LD_FLAGS)
$(SIGNED_ENCLAVE): $(PATCHED_ENCLAVE)
@printf -- '\nBuilding \e[1;36m$@\e[0m\n\n'
$(SGX_ENCLAVE_SIGNER) sign -key enclave/key.pem -enclave $< -out $@ -config enclave/enclave.config.xml
# Clean -----------------
clean:
cd libadapters && $(CARGO) clean
cd enclave && $(CARGO) clean
rm -rf target