xref: /linux/tools/testing/selftests/sgx/Makefile (revision 1553a1c48281243359a9529a10ddb551f3b967ab)
1top_srcdir = ../../../..
2
3include ../lib.mk
4
5.PHONY: all clean
6
7CAN_BUILD_X86_64 := $(shell ../x86/check_cc.sh "$(CC)" \
8			    ../x86/trivial_64bit_program.c)
9
10ifndef OBJCOPY
11OBJCOPY := $(CROSS_COMPILE)objcopy
12endif
13
14INCLUDES := -I$(top_srcdir)/tools/include
15HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC
16HOST_LDFLAGS := -z noexecstack -lcrypto
17ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \
18	       -fno-stack-protector -mrdrnd $(INCLUDES)
19ENCL_LDFLAGS := -Wl,-T,test_encl.lds,--build-id=none
20
21ifeq ($(CAN_BUILD_X86_64), 1)
22TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx
23TEST_FILES := $(OUTPUT)/test_encl.elf
24
25all: $(TEST_CUSTOM_PROGS) $(OUTPUT)/test_encl.elf
26endif
27
28$(OUTPUT)/test_sgx: $(OUTPUT)/main.o \
29		    $(OUTPUT)/load.o \
30		    $(OUTPUT)/sigstruct.o \
31		    $(OUTPUT)/call.o \
32		    $(OUTPUT)/sign_key.o
33	$(CC) $(HOST_CFLAGS) -o $@ $^ $(HOST_LDFLAGS)
34
35$(OUTPUT)/main.o: main.c
36	$(CC) $(HOST_CFLAGS) -c $< -o $@
37
38$(OUTPUT)/load.o: load.c
39	$(CC) $(HOST_CFLAGS) -c $< -o $@
40
41$(OUTPUT)/sigstruct.o: sigstruct.c
42	$(CC) $(HOST_CFLAGS) -c $< -o $@
43
44$(OUTPUT)/call.o: call.S
45	$(CC) $(HOST_CFLAGS) -c $< -o $@
46
47$(OUTPUT)/sign_key.o: sign_key.S
48	$(CC) $(HOST_CFLAGS) -c $< -o $@
49
50$(OUTPUT)/test_encl.elf: test_encl.c test_encl_bootstrap.S
51	$(CC) $(ENCL_CFLAGS) $^ -o $@ $(ENCL_LDFLAGS)
52
53EXTRA_CLEAN := \
54	$(OUTPUT)/test_encl.elf \
55	$(OUTPUT)/load.o \
56	$(OUTPUT)/call.o \
57	$(OUTPUT)/main.o \
58	$(OUTPUT)/sigstruct.o \
59	$(OUTPUT)/test_sgx \
60	$(OUTPUT)/test_sgx.o \
61