forked from TrenchBoot/secure-kernel-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (76 loc) · 2.55 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
# Start with empty flags
CFLAGS :=
LDFLAGS :=
ifeq ($(DEBUG),y)
CFLAGS += -DDEBUG
endif
ifeq ($(LTO),y)
CFLAGS += -flto
LDFLAGS += -flto
endif
ifeq ($(M32),y)
CFLAGS += -m32 -mregparm=3 -fno-plt -freg-struct-return
LDFLAGS += -m32
else
CFLAGS += -m64
LDFLAGS += -m64
endif
# There is a 64k total limit, so optimise for size. The binary may be loaded
# at an arbitray location, so build it as position independent, but link as
# non-pie as all relocations are internal and there is no dynamic loader to
# help.
CFLAGS += -Os -g -MMD -MP -march=btver2 -mno-sse -mno-mmx -fpie -fomit-frame-pointer
CFLAGS += -Iinclude -ffreestanding -fno-common -Wall -Werror
LDFLAGS += -nostdlib -no-pie -Wl,--build-id=none
CFLAGS_TPMLIB := -include boot.h -include errno-base.h -include byteswap.h -DEBADRQC=EINVAL
# Derive AFLAGS from CFLAGS
AFLAGS := -D__ASSEMBLY__ $(filter-out -std=%,$(CFLAGS))
ALL_SRC := $(wildcard *.c) $(wildcard tpmlib/*.c)
TESTS := $(filter test-%,$(ALL_SRC:.c=))
# Collect objects for building. For simplicity, we take all ASM/C files except tests
ASM := $(wildcard *.S)
SRC := $(filter-out test-%,$(ALL_SRC))
OBJ := $(ASM:.S=.o) $(SRC:.c=.o)
.PHONY: all
all: skl.bin
-include Makefile.local
# Generate a flat binary
#
# As a sanity check, look for the SKL UUID at its expected offset in the binary
# image. One reason this might fail is if the linker decides to put an
# unreferenced section ahead of .text, in which case link.lds needs adjusting.
skl.bin: skl Makefile
objcopy -O binary -S $< $@
@./sanity_check.sh
skl: link.lds $(OBJ) Makefile
$(CC) -Wl,-T,link.lds $(LDFLAGS) $(OBJ) -o $@
tpmlib/%.o: tpmlib/%.c Makefile
$(CC) $(CFLAGS) $(CFLAGS_TPMLIB) -o $@ -c $<
%.o: %.c Makefile
$(CC) $(CFLAGS) -o $@ -c $<
%.o: %.S Makefile
$(CC) $(AFLAGS) -c $< -o $@
# Helpers for debugging. Preprocess and/or compile only.
%.E: %.c Makefile
$(CC) $(CFLAGS) -E $< -o $@
%.S: %.c Makefile
$(CC) $(CFLAGS) -S $< -o $@
# Helpers for building and running tests on the current host
test-%: test-%.c Makefile
$(CC) $(filter-out -ffreestanding -march%,$(CFLAGS)) $(if $(COV),-fprofile-arcs -ftest-coverage) $< -o $@
.PHONY: run-test-%
.SECONDARY:
run-test-%: test-% Makefile
./$<
# Wrapper for building and running every test-*.c we find.
.PHONY: tests
tests: $(addprefix run-,$(TESTS))
.PHONY: cscope
cscope:
find . -name "*.[hcsS]" > cscope.files
cscope -b -q -k
.PHONY: clean
clean:
rm -f skl.bin skl $(TESTS) *.d *.o *.gcov *.gcda *.gcno tpmlib/*.d tpmlib/*.o cscope.*
# Compiler-generated header dependencies. Should be last.
-include $(OBJ:.o=.d) $(TESTS:=.d)