-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
127 lines (90 loc) · 2.93 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
CC = ./clang
CFLAGS = -g -fsanitize=address,array-bounds,null,return,shift -fsanitize-coverage=trace-pc-guard -I.
CXX = ./clang++
CXXFLAGS = $(CFLAGS) -std=c++11
LDFLAGS = -L.
LDLIBS = -lwolfssl -lFuzzer
PYTHON = python2
prefix = ./out
libFuzzer = libFuzzer.a
fuzzer_dir = Fuzzer
fuzzer_src = https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer
new_clang = new_clang
clang_tool_src = https://chromium.googlesource.com/chromium/src/tools/clang
clang_dir = $(new_clang)/clang/clang
clang_tool = $(clang_dir)/scripts/update.py
clang_bin = $(new_clang)/third_party/llvm-build/Release+Asserts/bin/
src = $(wildcard ./*/target.c)
opt = $(wildcard ./*/target.options)
trg = $(notdir $(src:/target.c=))
trg_opt = $(notdir $(opt:/target.options=))
obj = $(src:.c=.o)
out = $(src:.c=)
targets = $(patsubst %,$(prefix)/%, $(trg))
corpora = $(patsubst %,$(prefix)/%_seed_corpus.zip,$(trg))
optionses = $(patsubst %,$(prefix)/%.options, $(trg_opt))
found_dictionaries = $(wildcard ./*.dict)
dictionaries = $(addprefix $(prefix)/,$(notdir $(found_dictionaries)))
exports = $(targets) $(corpora) $(optionses) $(dictionaries)
all: $(out) # make all
export: $(prefix) $(exports) # not quite install, but close
deps: $(CC) $(CXX) $(libFuzzer) # dependencies
dependencies: deps # deps alias
%: %.c # cancel the implicit rule
%: %.cc # cancel the implicit rule
.PHONY: clean spotless export unexport
.INTERMEDIATE: $(obj)
# libFuzzer
$(fuzzer_dir):
@echo -e "\nRetrieving libFuzzer...\n"
@git clone $(fuzzer_src) $@ --depth 1
$(libFuzzer): $(fuzzer_dir)
@bash $</build.sh
@echo -e "\nlibFuzzer retrieved!\n"
# clang
$(clang_tool):
@echo -e "\nRetrieving new clang binaries...\n"
@git clone $(clang_tool_src) $(clang_dir) --depth 1
$(clang_bin): $(clang_tool)
@$(PYTHON) $<
@touch $@ #to prevent make from always running this rule
@echo -e "\nClang retrieved!\n"
$(clang_bin)/$(CC): $(clang_bin)
$(clang_bin)/$(CXX): $(clang_bin)
$(CC): $(clang_bin)/$(CC)
@ln -s $< $@
$(CXX): $(clang_bin)/$(CXX)
@ln -s $< $@
# actual source code
$(obj): %.o: %.c
@echo "CC $< -o $@"
@$(CC) -c $< $(CFLAGS) -o $@
$(out): %: %.o
@echo "C++ $< -o $@"
@$(CXX) $< $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@
# export
$(prefix):
@mkdir -p $(prefix)
$(corpora): $(prefix)/%_seed_corpus.zip: ./%
@find $</* -maxdepth 0 -type d \
-printf "zip\t$@\t%f\n" \
-exec zip -q -r $@ {} +
$(optionses): $(prefix)/%.options: ./%/target.options
@echo "cp $< $@"
@cp $< $@
$(targets): $(prefix)/%: ./%/target
@echo "cp $< $@"
@cp $< $@
$(dictionaries): $(prefix)/%: ./%
@echo "cp $< $@"
@cp $< $@
# cleanup
clean:
@rm -f $(out)
@echo "Cleaned!"
spotless:
@rm -rf $(fuzzer_dir) $(libFuzzer) $(new_clang) $(CC) $(CXX) $(out)
@echo "Cleaned harder!"
unexport:
@rm -rf $(prefix)/*
@echo "Un-exported!"