Makefile 2.8 KB
Newer Older
1 2 3 4 5 6
ifndef OBJCOPY
OBJCOPY := $(CROSS_COMPILE)objcopy
endif

OUTPUT ?= ./
HOST_CFLAGS := -Wall -Werror -g -fPIC -z noexecstack \
7
	       -Wno-unused-const-variable -std=gnu11
8
ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \
9
	       -fno-stack-protector -mrdrnd -std=gnu11
10
HOST_LDFLAGS := -fPIC -shared -Wl,-Bsymbolic
11

12
IS_OOT_DRIVER := $(shell [ ! -e /dev/isgx ])
13
IS_SGX_FLC := $(shell lscpu | grep -q sgx_lc)
14

15 16
PRODUCT_ENCLAVE ?=

17
TEST_CUSTOM_PROGS := $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss $(OUTPUT)/liberpal-skeleton-v1.so $(OUTPUT)/liberpal-skeleton-v2.so $(OUTPUT)/liberpal-skeleton-v3.so $(OUTPUT)/signing_key.pem
18 19 20

ifeq ($(IS_OOT_DRIVER),1)
    TEST_CUSTOM_PROGS += $(OUTPUT)/encl.token
21 22
else ifeq ($(IS_SGX_FLC),)
    TEST_CUSTOM_PROGS += $(OUTPUT)/encl.token
23
endif
24 25 26

all: $(TEST_CUSTOM_PROGS)

27
$(OUTPUT)/liberpal-skeleton-v1.so: $(OUTPUT)/sgx_call.o $(OUTPUT)/liberpal-skeleton-v1.o $(OUTPUT)/liberpal-skeleton.o
28 29
	$(CC) $(HOST_LDFLAGS) -o $@ $^

30
$(OUTPUT)/liberpal-skeleton-v1.o: liberpal-skeleton-v1.c liberpal-skeleton.c
31 32 33 34 35 36
	$(CC) $(HOST_CFLAGS) -c $< -o $@

$(OUTPUT)/liberpal-skeleton-v2.so: $(OUTPUT)/sgx_call.o $(OUTPUT)/liberpal-skeleton-v2.o $(OUTPUT)/liberpal-skeleton.o
	$(CC) $(HOST_LDFLAGS) -o $@ $^

$(OUTPUT)/liberpal-skeleton-v2.o: liberpal-skeleton-v2.c liberpal-skeleton.c
37 38
	$(CC) $(HOST_CFLAGS) -c $< -o $@

39 40 41
$(OUTPUT)/liberpal-skeleton.o: liberpal-skeleton.c
	$(CC) $(HOST_CFLAGS) -c $< -o $@

42 43 44 45 46 47
$(OUTPUT)/liberpal-skeleton-v3.so: $(OUTPUT)/sgx_call.o $(OUTPUT)/liberpal-skeleton-v3.o $(OUTPUT)/liberpal-skeleton.o
	$(CC) $(HOST_LDFLAGS) -o $@ $^

$(OUTPUT)/liberpal-skeleton-v3.o: liberpal-skeleton-v3.c liberpal-skeleton.c
	$(CC) $(HOST_CFLAGS) -c $< -o $@

48 49 50 51 52 53 54 55 56
$(OUTPUT)/sgx_call.o: sgx_call.S
	$(CC) $(HOST_CFLAGS) -c $< -o $@

$(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign
	$(OBJCOPY) -O binary $< $@

$(OUTPUT)/encl.elf: encl.lds encl.c encl_bootstrap.S
	$(CC) $(ENCL_CFLAGS) -T $^ -o $@

57
# If you want to sign a production encalve, you need add '-p' args in sgxsign. In addition, for Intel SGX1 without FLC, please replace signing_key with the product signature key applied to Intel.
58 59 60
$(OUTPUT)/signing_key.pem:
	openssl genrsa -3 -out $@ 3072

61 62 63 64 65 66
ifeq ($(PRODUCT_ENCLAVE),1)
    PRODUCT_OPT := -p
else
    PRODUCT_OPT :=
endif

67
$(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin $(OUTPUT)/signing_key.pem
68
	$(OUTPUT)/sgxsign $(PRODUCT_OPT) signing_key.pem $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
69 70

$(OUTPUT)/encl.token: $(OUTPUT)/encl.ss
71
	sgx-tools gen-token --signature encl.ss --token $@
72 73 74 75 76 77 78 79 80 81

$(OUTPUT)/sgxsign: sgxsign.c
	$(CC) -I../include -o $@ $< -lcrypto

EXTRA_CLEAN := \
	$(OUTPUT)/encl.bin \
	$(OUTPUT)/encl.elf \
	$(OUTPUT)/encl.ss \
	$(OUTPUT)/sgx_call.o \
	$(OUTPUT)/sgxsign \
82 83
	$(OUTPUT)/liberpal-skeleton*.o \
	$(OUTPUT)/liberpal-skeleton*.so \
84 85 86 87 88 89 90
	$(OUTPUT)/signing_key.pem \
	$(OUTPUT)/encl.token

clean:
	rm -f ${EXTRA_CLEAN}

.PHONY: clean all