-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
141 lines (111 loc) · 3.2 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#
# Copyright © 2017-2019 The Crust Firmware Authors.
# SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only
#
SRC = .
OBJ = build
HOST =
CROSS_COMPILE ?= or1k-linux-musl-
AR = $(CROSS_COMPILE)gcc-ar
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)cpp
OBJCOPY = $(CROSS_COMPILE)objcopy
HOSTAR = ar
HOSTCC = cc
PYTHON = python3
COMMON_CFLAGS = -g -O1 -pipe -std=c11 \
-fdata-sections \
-ffunction-sections \
-fno-builtin \
-fno-common \
-fvar-tracking-assignments \
-Wall -Wextra -Wformat=2 -Wno-pedantic -Wshadow \
-Werror=implicit-function-declaration \
-Werror=implicit-int \
-Werror=pointer-arith \
-Werror=pointer-sign \
-Werror=strict-prototypes \
-Werror=vla \
-Wno-missing-field-initializers
COMMON_CPPFLAGS = -I$(SRC)/include \
-I$(SRC)/include/soc/a64
AFLAGS = -Wa,--fatal-warnings
CFLAGS = $(COMMON_CFLAGS) \
-ffixed-r2 \
-ffreestanding \
-flto \
-fno-asynchronous-unwind-tables \
-fno-pie \
-fomit-frame-pointer \
-funsigned-char \
-msoft-div -msoft-mul \
-static
CPPFLAGS = $(COMMON_CPPFLAGS) \
-I$(SRC)/include/stdlib \
-nostdinc \
-Werror=missing-include-dirs
LDFLAGS = -nostdlib \
-Wl,-O1 \
-Wl,--build-id=none \
-Wl,--fatal-warnings \
-Wl,--gc-sections \
-Wl,--no-dynamic-linker \
-Wl,--no-undefined
HOSTCFLAGS = $(COMMON_CFLAGS)
HOSTCPPFLAGS = $(COMMON_CPPFLAGS) \
-D_XOPEN_SOURCE=700
HOSTLDFLAGS =
HOSTLDLIBS =
###############################################################################
fuzzer = $(OBJ)/fuzzer.bin
loader = $(OBJ)/loader
objects = $(OBJ)/console.o \
$(OBJ)/start.o \
$(OBJ)/main.o \
$(OBJ)/runtime.o \
$(OBJ)/string.o
###############################################################################
M := @$(if $(filter-out 0,$(V)),:,exec printf ' %-7s %s\n')
Q := $(if $(filter-out 0,$(V)),,@)exec
all: fuzzer tools
check: run
clean:
$(Q) rm -fr $(OBJ)
fuzzer: $(fuzzer)
run: $(fuzzer) $(loader)
@scp $(fuzzer) root@$(HOST):/tmp/$(notdir $(fuzzer))
@scp $(loader) root@$(HOST):/tmp/$(notdir $(loader))
@ssh root@$(HOST) /tmp/$(notdir $(loader)) /tmp/$(notdir $(fuzzer))
tools: $(loader)
$(OBJ)/%.bin: $(OBJ)/%.elf
$(M) OBJCOPY $@
$(Q) $(OBJCOPY) -O binary -S --reverse-bytes 4 $< $@
$(OBJ)/%.elf $(OBJ)/%.map: $(OBJ)/%.ld $(objects)
$(M) LD $@
$(Q) $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$(OBJ)/$*.map -o $@ -T $^
$(OBJ)/%.ld: $(SRC)/src/%.ld.S | $(OBJ)/.
$(M) CPP $@
$(Q) $(CPP) $(CPPFLAGS) -MMD -MF [email protected] -MT $@ -P -o $@ $<
$(OBJ)/%.o: $(SRC)/src/%.S | $(OBJ)/.
$(M) AS $@
$(Q) $(CC) $(CPPFLAGS) $(AFLAGS) -MMD -c -o $@ $<
$(OBJ)/%.o: $(SRC)/src/%.c | $(OBJ)/.
$(M) CC $@
$(Q) $(CC) $(CPPFLAGS) $(CFLAGS) $(AFLAGS) -MMD -c -o $@ $<
$(OBJ)/%: $(OBJ)/%.o
$(M) HOSTLD $@
$(Q) $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^ $(HOSTLDLIBS)
$(OBJ)/%.o: $(SRC)/tools/%.c | $(OBJ)/.
$(M) HOSTCC $@
$(Q) $(HOSTCC) $(HOSTCPPFLAGS) $(HOSTCFLAGS) -MMD -c -o $@ $<
$(SRC)/%.c: $(SRC)/%.py
$(M) GEN $@
$(Q) $(PYTHON) $< $@
%/.:
$(Q) mkdir -p $*
%.d:;
$(SRC)/Makefile:;
-include $(fuzzer:.bin=.ld.d) $(objects:.o=.d)
.PHONY: all check clean fuzzer run tools
.SECONDARY:
.SUFFIXES: