xref: /aosp_15_r20/external/AFLplusplus/GNUmakefile (revision 08b48e0b10e97b33e7b60c5b6e2243bd915777f2)
1#
2# american fuzzy lop++ - makefile
3# -----------------------------
4#
5# Originally written by Michal Zalewski
6#
7# Copyright 2013, 2014, 2015, 2016, 2017 Google Inc. All rights reserved.
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at:
12#
13#   https://www.apache.org/licenses/LICENSE-2.0
14#
15
16# For Heiko:
17#TEST_MMAP=1
18# the hash character is treated differently in different make versions
19# so use a variable for '#'
20HASH=\#
21
22PREFIX     ?= /usr/local
23BIN_PATH    = $(PREFIX)/bin
24HELPER_PATH = $(PREFIX)/lib/afl
25DOC_PATH    = $(PREFIX)/share/doc/afl
26MISC_PATH   = $(PREFIX)/share/afl
27MAN_PATH    = $(PREFIX)/share/man/man8
28
29PROGNAME    = afl
30VERSION     = $(shell grep '^$(HASH)define VERSION ' ../config.h | cut -d '"' -f2)
31
32# PROGS intentionally omit afl-as, which gets installed elsewhere.
33
34PROGS       = afl-fuzz afl-showmap afl-tmin afl-gotcpu afl-analyze
35SH_PROGS    = afl-plot afl-cmin afl-cmin.bash afl-whatsup afl-addseeds afl-system-config afl-persistent-config afl-cc
36MANPAGES=$(foreach p, $(PROGS) $(SH_PROGS), $(p).8) afl-as.8
37ASAN_OPTIONS=detect_leaks=0
38
39SYS = $(shell uname -s)
40ARCH = $(shell uname -m)
41
42$(info [*] Compiling AFL++ for OS $(SYS) on ARCH $(ARCH))
43
44ifdef NO_SPLICING
45  override CFLAGS_OPT += -DNO_SPLICING
46endif
47
48ifdef NO_UTF
49  override CFLAGS_OPT += -DFANCY_BOXES_NO_UTF
50endif
51
52ifdef ASAN_BUILD
53  $(info Compiling ASAN version of binaries)
54  override CFLAGS += $(ASAN_CFLAGS)
55  LDFLAGS += $(ASAN_LDFLAGS)
56endif
57ifdef UBSAN_BUILD
58  $(info Compiling UBSAN version of binaries)
59  override CFLAGS += -fsanitize=undefined -fno-omit-frame-pointer
60  override LDFLAGS += -fsanitize=undefined
61endif
62ifdef MSAN_BUILD
63  $(info Compiling MSAN version of binaries)
64  CC := clang
65  override CFLAGS += -fsanitize=memory -fno-omit-frame-pointer
66  override LDFLAGS += -fsanitize=memory
67endif
68
69ifdef CODE_COVERAGE
70  override CFLAGS += -D__AFL_CODE_COVERAGE=1
71endif
72
73ifeq "$(findstring android, $(shell $(CC) --version 2>/dev/null))" ""
74ifeq "$(shell echo 'int main() {return 0; }' | $(CC) $(CFLAGS) -Werror -x c - -flto=full -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
75	CFLAGS_FLTO ?= -flto=full
76else
77 ifeq "$(shell echo 'int main() {return 0; }' | $(CC) $(CFLAGS) -Werror -x c - -flto=thin -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
78	CFLAGS_FLTO ?= -flto=thin
79 else
80  ifeq "$(shell echo 'int main() {return 0; }' | $(CC) $(CFLAGS) -Werror -x c - -flto -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
81	CFLAGS_FLTO ?= -flto
82  endif
83 endif
84endif
85endif
86
87#ifeq "$(shell echo 'int main() {return 0; }' | $(CC) -fno-move-loop-invariants -fdisable-tree-cunrolli -x c - -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
88#	SPECIAL_PERFORMANCE += -fno-move-loop-invariants -fdisable-tree-cunrolli
89#endif
90
91#ifeq "$(shell echo 'int main() {return 0; }' | $(CC) $(CFLAGS) -Werror -x c - -march=native -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
92#  ifndef SOURCE_DATE_EPOCH
93#    HAVE_MARCHNATIVE = 1
94#    CFLAGS_OPT += -march=native
95#  endif
96#endif
97
98ifneq "$(SYS)" "Darwin"
99  #ifeq "$(HAVE_MARCHNATIVE)" "1"
100  #  SPECIAL_PERFORMANCE += -march=native
101  #endif
102 #ifndef DEBUG
103 #  CFLAGS_OPT += -D_FORTIFY_SOURCE=1
104 #endif
105else
106  # On some odd MacOS system configurations, the Xcode sdk path is not set correctly
107  SDK_LD = -L$(shell xcrun --show-sdk-path)/usr/lib
108  LDFLAGS += $(SDK_LD)
109endif
110
111COMPILER_TYPE=$(shell $(CC) --version|grep "Free Software Foundation")
112ifneq "$(COMPILER_TYPE)" ""
113  #$(info gcc is being used)
114  CFLAGS_OPT += -Wno-error=format-truncation -Wno-format-truncation
115endif
116
117ifeq "$(SYS)" "SunOS"
118  LDFLAGS = -lkstat -lrt -lsocket -lnsl
119endif
120
121ifdef STATIC
122  $(info Compiling static version of binaries, disabling python though)
123  # Disable python for static compilation to simplify things
124  PYTHON_OK = 0
125  PYFLAGS=
126  PYTHON_INCLUDE = /
127
128  CFLAGS_OPT += -static
129  LDFLAGS += -lm -lpthread -lz -lutil
130endif
131
132ifdef PROFILING
133  $(info Compiling with profiling information, for analysis: gprof ./afl-fuzz gmon.out > prof.txt)
134  override CFLAGS_OPT += -pg -DPROFILING=1
135  override LDFLAGS += -pg
136endif
137
138ifdef INTROSPECTION
139  $(info Compiling with introspection documentation)
140  override CFLAGS_OPT += -DINTROSPECTION=1
141endif
142
143ifneq "$(ARCH)" "x86_64"
144 ifneq "$(patsubst i%86,i386,$(ARCH))" "i386"
145  ifneq "$(ARCH)" "amd64"
146   ifneq "$(ARCH)" "i86pc"
147	AFL_NO_X86=1
148   endif
149  endif
150 endif
151endif
152
153ifdef DEBUG
154  $(info Compiling DEBUG version of binaries)
155  override CFLAGS += -ggdb3 -O0 -Wall -Wextra -Werror $(CFLAGS_OPT)
156else
157  CFLAGS ?= -O2 $(CFLAGS_OPT) # -funroll-loops is slower on modern compilers
158endif
159
160override CFLAGS += -g -Wno-pointer-sign -Wno-variadic-macros -Wall -Wextra -Wno-pointer-arith \
161			-fPIC -I include/ -DAFL_PATH=\"$(HELPER_PATH)\"  \
162			-DBIN_PATH=\"$(BIN_PATH)\" -DDOC_PATH=\"$(DOC_PATH)\"
163# -fstack-protector
164
165ifeq "$(SYS)" "FreeBSD"
166  override CFLAGS  += -I /usr/local/include/
167  override LDFLAGS += -L /usr/local/lib/
168endif
169
170ifeq "$(SYS)" "DragonFly"
171  override CFLAGS  += -I /usr/local/include/
172  override LDFLAGS += -L /usr/local/lib/
173endif
174
175ifeq "$(SYS)" "OpenBSD"
176  override CFLAGS  += -I /usr/local/include/ -mno-retpoline
177  override LDFLAGS += -Wl,-z,notext -L /usr/local/lib/
178endif
179
180ifeq "$(SYS)" "NetBSD"
181  override CFLAGS  += -I /usr/pkg/include/
182  override LDFLAGS += -L /usr/pkg/lib/
183endif
184
185ifeq "$(SYS)" "Haiku"
186  SHMAT_OK=0
187  override CFLAGS  += -DUSEMMAP=1 -Wno-error=format
188  override LDFLAGS += -Wno-deprecated-declarations -lgnu -lnetwork
189  #SPECIAL_PERFORMANCE += -DUSEMMAP=1
190endif
191
192AFL_FUZZ_FILES = $(wildcard src/afl-fuzz*.c)
193
194ifneq "$(shell command -v python3m 2>/dev/null)" ""
195  ifneq "$(shell command -v python3m-config 2>/dev/null)" ""
196    PYTHON_INCLUDE  := $(shell python3m-config --includes)
197    PYTHON_VERSION  := $(strip $(shell python3m --version 2>&1))
198    # Starting with python3.8, we need to pass the `embed` flag. Earlier versions didn't know this flag.
199    ifeq "$(shell python3m-config --embed --libs 2>/dev/null | grep -q lpython && echo 1 )" "1"
200      PYTHON_LIB      := $(shell python3m-config --libs --embed --ldflags)
201    else
202      PYTHON_LIB      := $(shell python3m-config --ldflags)
203    endif
204  endif
205endif
206
207ifeq "$(PYTHON_INCLUDE)" ""
208  ifneq "$(shell command -v python3 2>/dev/null)" ""
209    ifneq "$(shell command -v python3-config 2>/dev/null)" ""
210      PYTHON_INCLUDE  := $(shell python3-config --includes)
211      PYTHON_VERSION  := $(strip $(shell python3 --version 2>&1))
212      # Starting with python3.8, we need to pass the `embed` flag. Earlier versions didn't know this flag.
213      ifeq "$(shell python3-config --embed --libs 2>/dev/null | grep -q lpython && echo 1 )" "1"
214        PYTHON_LIB      := $(shell python3-config --libs --embed --ldflags)
215      else
216        PYTHON_LIB      := $(shell python3-config --ldflags)
217      endif
218    endif
219  endif
220endif
221
222ifeq "$(PYTHON_INCLUDE)" ""
223  ifneq "$(shell command -v python 2>/dev/null)" ""
224    ifneq "$(shell command -v python-config 2>/dev/null)" ""
225      PYTHON_INCLUDE  := $(shell python-config --includes)
226      PYTHON_LIB      := $(shell python-config --ldflags)
227      PYTHON_VERSION  := $(strip $(shell python --version 2>&1))
228    endif
229  endif
230endif
231
232# Old Ubuntu and others dont have python/python3-config so we hardcode 3.7
233ifeq "$(PYTHON_INCLUDE)" ""
234  ifneq "$(shell command -v python3.7 2>/dev/null)" ""
235    ifneq "$(shell command -v python3.7-config 2>/dev/null)" ""
236      PYTHON_INCLUDE  := $(shell python3.7-config --includes)
237      PYTHON_LIB      := $(shell python3.7-config --ldflags)
238      PYTHON_VERSION  := $(strip $(shell python3.7 --version 2>&1))
239    endif
240  endif
241endif
242
243# Old Ubuntu and others dont have python/python2-config so we hardcode 2.7
244ifeq "$(PYTHON_INCLUDE)" ""
245  ifneq "$(shell command -v python2.7 2>/dev/null)" ""
246    ifneq "$(shell command -v python2.7-config 2>/dev/null)" ""
247      PYTHON_INCLUDE  := $(shell python2.7-config --includes)
248      PYTHON_LIB      := $(shell python2.7-config --ldflags)
249      PYTHON_VERSION  := $(strip $(shell python2.7 --version 2>&1))
250    endif
251  endif
252endif
253
254ifdef SOURCE_DATE_EPOCH
255    BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+%Y-%m-%d" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+%Y-%m-%d" 2>/dev/null || date -u "+%Y-%m-%d")
256else
257    BUILD_DATE ?= $(shell date "+%Y-%m-%d")
258endif
259
260ifneq "$(filter Linux GNU%,$(SYS))" ""
261  override LDFLAGS += -ldl -lrt -lm
262endif
263
264ifneq "$(findstring FreeBSD, $(SYS))" ""
265  override CFLAGS  += -pthread
266  override LDFLAGS += -lpthread -lm
267endif
268
269ifneq "$(findstring NetBSD, $(SYS))" ""
270  override CFLAGS  += -pthread
271  override LDFLAGS += -lpthread -lm
272endif
273
274ifneq "$(findstring OpenBSD, $(SYS))" ""
275  override CFLAGS  += -pthread
276  override LDFLAGS += -lpthread -lm
277endif
278
279COMM_HDR    = include/alloc-inl.h include/config.h include/debug.h include/types.h
280
281ifeq "$(shell echo '$(HASH)include <Python.h>@int main() {return 0; }' | tr @ '\n' | $(CC) $(CFLAGS) -x c - -o .test $(PYTHON_INCLUDE) $(LDFLAGS) $(PYTHON_LIB) 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
282	PYTHON_OK=1
283	PYFLAGS=-DUSE_PYTHON $(PYTHON_INCLUDE) $(LDFLAGS) $(PYTHON_LIB) -DPYTHON_VERSION="\"$(PYTHON_VERSION)\""
284else
285	PYTHON_OK=0
286	PYFLAGS=
287endif
288
289ifdef NO_PYTHON
290	PYTHON_OK=0
291	PYFLAGS=
292endif
293
294IN_REPO=0
295ifeq "$(shell command -v git >/dev/null && git status >/dev/null 2>&1 && echo 1 || echo 0)" "1"
296  IN_REPO=1
297endif
298ifeq "$(shell command -v svn >/dev/null && svn proplist . 2>/dev/null && echo 1 || echo 0)" "1"
299  IN_REPO=1
300endif
301
302ifeq "$(shell echo 'int main() { return 0;}' | $(CC) $(CFLAGS) -fsanitize=address -x c - -o .test2 2>/dev/null && echo 1 || echo 0 ; rm -f .test2 )" "1"
303	ASAN_CFLAGS=-fsanitize=address -fstack-protector-all -fno-omit-frame-pointer -DASAN_BUILD
304	ASAN_LDFLAGS=-fsanitize=address -fstack-protector-all -fno-omit-frame-pointer
305endif
306
307ifeq "$(shell echo '$(HASH)include <sys/ipc.h>@$(HASH)include <sys/shm.h>@int main() { int _id = shmget(IPC_PRIVATE, 65536, IPC_CREAT | IPC_EXCL | 0600); shmctl(_id, IPC_RMID, 0); return 0;}' | tr @ '\n' | $(CC) $(CFLAGS) -x c - -o .test2 2>/dev/null && echo 1 || echo 0 ; rm -f .test2 )" "1"
308	SHMAT_OK=1
309else
310	SHMAT_OK=0
311	override CFLAGS+=-DUSEMMAP=1
312	LDFLAGS += -Wno-deprecated-declarations
313endif
314
315ifdef TEST_MMAP
316	SHMAT_OK=0
317	override CFLAGS += -DUSEMMAP=1
318	LDFLAGS += -Wno-deprecated-declarations
319endif
320
321.PHONY: all
322all:	test_x86 test_shm test_python ready $(PROGS) afl-as llvm gcc_plugin test_build all_done
323	-$(MAKE) -C utils/aflpp_driver
324	@echo
325	@echo
326	@echo Build Summary:
327	@test -e afl-fuzz && echo "[+] afl-fuzz and supporting tools successfully built" || echo "[-] afl-fuzz could not be built, please set CC to a working compiler"
328	@test -e afl-llvm-pass.so && echo "[+] LLVM basic mode successfully built" || echo "[-] LLVM mode could not be built, please install at least llvm-11 and clang-11 or newer, see docs/INSTALL.md"
329	@test -e SanitizerCoveragePCGUARD.so && echo "[+] LLVM mode successfully built" || echo "[-] LLVM mode could not be built, please install at least llvm-13 and clang-13 or newer, see docs/INSTALL.md"
330	@test -e SanitizerCoverageLTO.so && echo "[+] LLVM LTO mode successfully built" || echo "[-] LLVM LTO mode could not be built, it is optional, if you want it, please install LLVM and LLD 11+. More information at instrumentation/README.lto.md on how to build it"
331ifneq "$(SYS)" "Darwin"
332	@test -e afl-gcc-pass.so && echo "[+] gcc_mode successfully built" || echo "[-] gcc_mode could not be built, it is optional, install gcc-VERSION-plugin-dev to enable this"
333endif
334	@echo
335
336.PHONY: llvm
337llvm:
338	-$(MAKE) -j$(nproc) -f GNUmakefile.llvm
339	@test -e afl-cc || { echo "[-] Compiling afl-cc failed. You seem not to have a working compiler." ; exit 1; }
340
341.PHONY: gcc_plugin
342gcc_plugin:
343ifneq "$(SYS)" "Darwin"
344	-$(MAKE) -f GNUmakefile.gcc_plugin
345endif
346
347.PHONY: man
348man:    $(MANPAGES)
349
350.PHONY: test
351test:	tests
352
353.PHONY: tests
354tests:	source-only
355	@cd test ; ./test-all.sh
356	@rm -f test/errors
357
358.PHONY: performance-tests
359performance-tests:	performance-test
360.PHONY: test-performance
361test-performance:	performance-test
362
363.PHONY: performance-test
364performance-test:	source-only
365	@cd test ; ./test-performance.sh
366
367
368# hint: make targets are also listed in the top level README.md
369.PHONY: help
370help:
371	@echo "HELP --- the following make targets exist:"
372	@echo "=========================================="
373	@echo "all: the main AFL++ binaries and llvm/gcc instrumentation"
374	@echo "binary-only: everything for binary-only fuzzing: frida_mode, nyx_mode, qemu_mode, frida_mode, unicorn_mode, coresight_mode, libdislocator, libtokencap"
375	@echo "source-only: everything for source code fuzzing: nyx_mode, libdislocator, libtokencap"
376	@echo "distrib: everything (for both binary-only and source code fuzzing)"
377	@echo "man: creates simple man pages from the help option of the programs"
378	@echo "install: installs everything you have compiled with the build option above"
379	@echo "clean: cleans everything compiled (not downloads when on a checkout)"
380	@echo "deepclean: cleans everything including downloads"
381	@echo "uninstall: uninstall AFL++ from the system"
382	@echo "code-format: format the code, do this before you commit and send a PR please!"
383	@echo "tests: this runs the test framework. It is more catered for the developers, but if you run into problems this helps pinpointing the problem"
384	@echo "unit: perform unit tests (based on cmocka and GNU linker)"
385	@echo "document: creates afl-fuzz-document which will only do one run and save all manipulated inputs into out/queue/mutations"
386	@echo "help: shows these build options :-)"
387	@echo "=========================================="
388	@echo "Recommended: \"distrib\" or \"source-only\", then \"install\""
389	@echo
390	@echo Known build environment options:
391	@echo "=========================================="
392	@echo STATIC - compile AFL++ static
393	@echo "CODE_COVERAGE - compile the target for code coverage (see docs/instrumentation/README.llvm.md)"
394	@echo ASAN_BUILD - compiles AFL++ with memory sanitizer for debug purposes
395	@echo UBSAN_BUILD - compiles AFL++ tools with undefined behaviour sanitizer for debug purposes
396	@echo DEBUG - no optimization, -ggdb3, all warnings and -Werror
397	@echo LLVM_DEBUG - shows llvm deprecation warnings
398	@echo PROFILING - compile afl-fuzz with profiling information
399	@echo INTROSPECTION - compile afl-fuzz with mutation introspection
400	@echo NO_PYTHON - disable python support
401	@echo NO_SPLICING - disables splicing mutation in afl-fuzz, not recommended for normal fuzzing
402	@echo "NO_UTF - do not use UTF-8 for line rendering in status screen (fallback to G1 box drawing, of vanilla AFL)"
403	@echo NO_NYX - disable building nyx mode dependencies
404	@echo "NO_CORESIGHT - disable building coresight (arm64 only)"
405	@echo NO_UNICORN_ARM64 - disable building unicorn on arm64
406	@echo "WAFL_MODE - enable for WASM fuzzing with https://github.com/fgsect/WAFL"
407	@echo AFL_NO_X86 - if compiling on non-intel/amd platforms
408	@echo "LLVM_CONFIG - if your distro doesn't use the standard name for llvm-config (e.g., Debian)"
409	@echo "=========================================="
410	@echo e.g.: make LLVM_CONFIG=llvm-config-16
411
412.PHONY: test_x86
413ifndef AFL_NO_X86
414test_x86:
415	@echo "[*] Checking for the default compiler cc..."
416	@type $(CC) >/dev/null || ( echo; echo "Oops, looks like there is no compiler '"$(CC)"' in your path."; echo; echo "Don't panic! You can restart with '"$(_)" CC=<yourCcompiler>'."; echo; exit 1 )
417	@echo "[*] Testing the PATH environment variable..."
418	@test "$${PATH}" != "$${PATH#.:}" && { echo "Please remove current directory '.' from PATH to avoid recursion of 'as', thanks!"; echo; exit 1; } || :
419	@echo "[*] Checking for the ability to compile x86 code..."
420	@echo 'int main() { __asm__("xorb %al, %al"); }' | $(CC) $(CFLAGS) $(LDFLAGS) -w -x c - -o .test1 || ( echo; echo "Oops, looks like your compiler can't generate x86 code."; echo; echo "Don't panic! You can use the LLVM or QEMU mode, but see docs/INSTALL first."; echo "(To ignore this error, set AFL_NO_X86=1 and try again.)"; echo; exit 1 )
421	@rm -f .test1
422else
423test_x86:
424	@echo "[!] Note: skipping x86 compilation checks (AFL_NO_X86 set)."
425endif
426
427.PHONY: test_shm
428ifeq "$(SHMAT_OK)" "1"
429test_shm:
430	@echo "[+] shmat seems to be working."
431	@rm -f .test2
432else
433test_shm:
434	@echo "[-] shmat seems not to be working, switching to mmap implementation"
435endif
436
437.PHONY: test_python
438ifeq "$(PYTHON_OK)" "1"
439test_python:
440	@rm -f .test 2> /dev/null
441	@echo "[+] $(PYTHON_VERSION) support seems to be working."
442else
443test_python:
444	@echo "[-] You seem to need to install the package python3-dev or python-dev (and perhaps python[3]-apt), but it is optional so we continue"
445endif
446
447.PHONY: ready
448ready:
449	@echo "[+] Everything seems to be working, ready to compile. ($(shell $(CC) --version 2>&1|head -n 1))"
450
451afl-as: src/afl-as.c include/afl-as.h $(COMM_HDR) | test_x86
452	$(CC) $(CFLAGS) src/$@.c -o $@ $(LDFLAGS)
453	@ln -sf afl-as as
454
455src/afl-performance.o : $(COMM_HDR) src/afl-performance.c include/hash.h
456	$(CC) $(CFLAGS) $(CFLAGS_OPT) -Iinclude -c src/afl-performance.c -o src/afl-performance.o
457
458src/afl-common.o : $(COMM_HDR) src/afl-common.c include/common.h
459	$(CC) $(CFLAGS) $(CFLAGS_FLTO) -c src/afl-common.c -o src/afl-common.o
460
461src/afl-forkserver.o : $(COMM_HDR) src/afl-forkserver.c include/forkserver.h
462	$(CC) $(CFLAGS) $(CFLAGS_FLTO) -c src/afl-forkserver.c -o src/afl-forkserver.o
463
464src/afl-sharedmem.o : $(COMM_HDR) src/afl-sharedmem.c include/sharedmem.h
465	$(CC) $(CFLAGS) $(CFLAGS_FLTO) -c src/afl-sharedmem.c -o src/afl-sharedmem.o
466
467afl-fuzz: $(COMM_HDR) include/afl-fuzz.h $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o | test_x86
468	$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o -o $@ $(PYFLAGS) $(LDFLAGS) -lm
469
470afl-showmap: src/afl-showmap.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o $(COMM_HDR) | test_x86
471	$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) src/$@.c src/afl-fuzz-mutators.c src/afl-fuzz-python.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o -o $@ $(PYFLAGS) $(LDFLAGS)
472
473afl-tmin: src/afl-tmin.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o $(COMM_HDR) | test_x86
474	$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) src/$@.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o -o $@ $(LDFLAGS)
475
476afl-analyze: src/afl-analyze.c src/afl-common.o src/afl-sharedmem.o src/afl-performance.o src/afl-forkserver.o $(COMM_HDR) | test_x86
477	$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) src/$@.c src/afl-common.o src/afl-sharedmem.o src/afl-performance.o src/afl-forkserver.o -o $@ $(LDFLAGS)
478
479afl-gotcpu: src/afl-gotcpu.c src/afl-common.o $(COMM_HDR) | test_x86
480	$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) src/$@.c src/afl-common.o -o $@ $(LDFLAGS)
481
482.PHONY: document
483document:	afl-fuzz-document
484
485# document all mutations and only do one run (use with only one input file!)
486afl-fuzz-document: $(COMM_HDR) include/afl-fuzz.h $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-performance.o | test_x86
487	$(CC) -D_DEBUG=\"1\" -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS) $(CFLAGS_FLTO) $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.c src/afl-performance.o -o afl-fuzz-document $(PYFLAGS) $(LDFLAGS)
488
489test/unittests/unit_maybe_alloc.o : $(COMM_HDR) include/alloc-inl.h test/unittests/unit_maybe_alloc.c $(AFL_FUZZ_FILES)
490	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -c test/unittests/unit_maybe_alloc.c -o test/unittests/unit_maybe_alloc.o
491
492unit_maybe_alloc: test/unittests/unit_maybe_alloc.o
493	@$(CC) $(CFLAGS) -Wl,--wrap=exit -Wl,--wrap=printf test/unittests/unit_maybe_alloc.o -o test/unittests/unit_maybe_alloc $(LDFLAGS) $(ASAN_LDFLAGS) -lcmocka
494	./test/unittests/unit_maybe_alloc
495
496test/unittests/unit_hash.o : $(COMM_HDR) include/alloc-inl.h test/unittests/unit_hash.c $(AFL_FUZZ_FILES) src/afl-performance.o
497	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -c test/unittests/unit_hash.c -o test/unittests/unit_hash.o
498
499unit_hash: test/unittests/unit_hash.o src/afl-performance.o
500	@$(CC) $(CFLAGS) -Wl,--wrap=exit -Wl,--wrap=printf $^ -o test/unittests/unit_hash $(LDFLAGS) $(ASAN_LDFLAGS) -lcmocka
501	./test/unittests/unit_hash
502
503test/unittests/unit_rand.o : $(COMM_HDR) include/alloc-inl.h test/unittests/unit_rand.c $(AFL_FUZZ_FILES) src/afl-performance.o
504	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -c test/unittests/unit_rand.c -o test/unittests/unit_rand.o
505
506unit_rand: test/unittests/unit_rand.o src/afl-common.o src/afl-performance.o
507	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -Wl,--wrap=exit -Wl,--wrap=printf $^ -o test/unittests/unit_rand  $(LDFLAGS) $(ASAN_LDFLAGS) -lcmocka
508	./test/unittests/unit_rand
509
510test/unittests/unit_list.o : $(COMM_HDR) include/list.h test/unittests/unit_list.c $(AFL_FUZZ_FILES)
511	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -c test/unittests/unit_list.c -o test/unittests/unit_list.o
512
513unit_list: test/unittests/unit_list.o
514	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -Wl,--wrap=exit -Wl,--wrap=printf test/unittests/unit_list.o -o test/unittests/unit_list  $(LDFLAGS) $(ASAN_LDFLAGS) -lcmocka
515	./test/unittests/unit_list
516
517test/unittests/unit_preallocable.o : $(COMM_HDR) include/alloc-inl.h test/unittests/unit_preallocable.c $(AFL_FUZZ_FILES)
518	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -c test/unittests/unit_preallocable.c -o test/unittests/unit_preallocable.o
519
520unit_preallocable: test/unittests/unit_preallocable.o
521	@$(CC) $(CFLAGS) $(ASAN_CFLAGS) -Wl,--wrap=exit -Wl,--wrap=printf test/unittests/unit_preallocable.o -o test/unittests/unit_preallocable $(LDFLAGS) $(ASAN_LDFLAGS) -lcmocka
522	./test/unittests/unit_preallocable
523
524.PHONY: unit_clean
525unit_clean:
526	@rm -f ./test/unittests/unit_preallocable ./test/unittests/unit_list ./test/unittests/unit_maybe_alloc test/unittests/*.o
527
528.PHONY: unit
529ifneq "$(SYS)" "Darwin"
530unit:	unit_maybe_alloc unit_preallocable unit_list unit_clean unit_rand unit_hash
531else
532unit:
533	@echo [-] unit tests are skipped on Darwin \(lacks GNU linker feature --wrap\)
534endif
535
536.PHONY: code-format
537code-format:
538	./.custom-format.py -i src/*.c
539	./.custom-format.py -i include/*.h
540	./.custom-format.py -i instrumentation/*.h
541	./.custom-format.py -i instrumentation/*.cc
542	./.custom-format.py -i instrumentation/*.c
543	./.custom-format.py -i *.h
544	./.custom-format.py -i *.c
545	@#./.custom-format.py -i custom_mutators/*/*.c* # destroys libfuzzer :-(
546	@#./.custom-format.py -i custom_mutators/*/*.h # destroys honggfuzz :-(
547	./.custom-format.py -i utils/*/*.c*
548	./.custom-format.py -i utils/*/*.h
549	./.custom-format.py -i test/*.c
550	./.custom-format.py -i frida_mode/src/*.c
551	./.custom-format.py -i frida_mode/include/*.h
552	-./.custom-format.py -i frida_mode/src/*/*.c
553	./.custom-format.py -i qemu_mode/libcompcov/*.c
554	./.custom-format.py -i qemu_mode/libcompcov/*.cc
555	./.custom-format.py -i qemu_mode/libcompcov/*.h
556	./.custom-format.py -i qemu_mode/libqasan/*.c
557	./.custom-format.py -i qemu_mode/libqasan/*.h
558
559
560.PHONY: test_build
561ifndef AFL_NO_X86
562test_build: afl-cc afl-gcc afl-as afl-showmap
563	@echo "[*] Testing the CC wrapper afl-cc and its instrumentation output..."
564	@unset AFL_MAP_SIZE AFL_USE_UBSAN AFL_USE_CFISAN AFL_USE_LSAN AFL_USE_ASAN AFL_USE_MSAN; ASAN_OPTIONS=detect_leaks=0 AFL_INST_RATIO=100 AFL_PATH=. ./afl-cc test-instr.c $(LDFLAGS) -o test-instr 2>&1 || (echo "Oops, afl-cc failed"; exit 1 )
565	-ASAN_OPTIONS=detect_leaks=0 ./afl-showmap -q -m none -o .test-instr0 ./test-instr < /dev/null
566	-echo 1 | ASAN_OPTIONS=detect_leaks=0 ./afl-showmap -m none -q -o .test-instr1 ./test-instr
567	@rm -f test-instr
568	@cmp -s .test-instr0 .test-instr1; DR="$$?"; rm -f .test-instr0 .test-instr1; if [ "$$DR" = "0" ]; then echo; echo "Oops, the instrumentation of afl-cc does not seem to be behaving correctly!"; echo; echo "Please post to https://github.com/AFLplusplus/AFLplusplus/issues to troubleshoot the issue."; echo; exit 1; fi
569	@echo
570	@echo "[+] All right, the instrumentation of afl-cc seems to be working!"
571#	@echo "[*] Testing the CC wrapper afl-gcc and its instrumentation output..."
572#	@unset AFL_MAP_SIZE AFL_USE_UBSAN AFL_USE_CFISAN AFL_USE_LSAN AFL_USE_ASAN AFL_USE_MSAN; AFL_CC=$(CC) ASAN_OPTIONS=detect_leaks=0 AFL_INST_RATIO=100 AFL_PATH=. ./afl-gcc test-instr.c -o test-instr 2>&1 || (echo "Oops, afl-gcc failed"; exit 1 )
573#	ASAN_OPTIONS=detect_leaks=0 ./afl-showmap -m none -q -o .test-instr0 ./test-instr < /dev/null
574#	echo 1 | ASAN_OPTIONS=detect_leaks=0 ./afl-showmap -m none -q -o .test-instr1 ./test-instr
575#	@rm -f test-instr
576#	@cmp -s .test-instr0 .test-instr1; DR="$$?"; rm -f .test-instr0 .test-instr1; if [ "$$DR" = "0" ]; then echo; echo "Oops, the instrumentation of afl-gcc does not seem to be behaving correctly!"; \
577#		gcc -v 2>&1 | grep -q -- --with-as= && ( echo; echo "Gcc is configured not to use an external assembler with the -B option." ) || \
578#		( echo; echo "Please post to https://github.com/AFLplusplus/AFLplusplus/issues to troubleshoot the issue." ); echo; exit 0; fi
579#	@echo
580#	@echo "[+] All right, the instrumentation of afl-gcc seems to be working!"
581else
582test_build: afl-cc afl-as afl-showmap
583	@echo "[!] Note: skipping build tests (you may need to use LLVM or QEMU mode)."
584endif
585
586.PHONY: all_done
587all_done: test_build
588	@test -e afl-cc && echo "[+] Main compiler 'afl-cc' successfully built!" || { echo "[-] Main compiler 'afl-cc' failed to build, set up a working build environment first!" ; exit 1 ; }
589	@test -e cmplog-instructions-pass.so && echo "[+] LLVM mode for 'afl-cc' successfully built!" || echo "[-] LLVM mode for 'afl-cc'  failed to build, likely you either don't have llvm installed, or you need to set LLVM_CONFIG, to point to e.g. llvm-config-11. See instrumentation/README.llvm.md how to do this. Highly recommended!"
590	@test -e SanitizerCoverageLTO.so && echo "[+] LLVM LTO mode for 'afl-cc' successfully built!" || echo "[-] LLVM LTO mode for 'afl-cc'  failed to build, this would need LLVM 11+, see instrumentation/README.lto.md how to build it"
591	@test -e afl-gcc-pass.so && echo "[+] gcc_plugin for 'afl-cc' successfully built!" || echo "[-] gcc_plugin for 'afl-cc'  failed to build, unless you really need it that is fine - or read instrumentation/README.gcc_plugin.md how to build it"
592	@echo "[+] All done! Be sure to review the README.md - it's pretty short and useful."
593	@if [ "$(SYS)" = "Darwin" ]; then printf "\nWARNING: Fuzzing on MacOS X is slow because of the unusually high overhead of\nfork() on this OS. Consider using Linux or *BSD for fuzzing software not\nspecifically for MacOS.\n\n"; fi
594	@! tty <&1 >/dev/null || printf "\033[0;30mNOTE: If you can read this, your terminal probably uses white background.\nThis will make the UI hard to read. See docs/status_screen.md for advice.\033[0m\n" 2>/dev/null
595
596.NOTPARALLEL: clean all
597
598.PHONY: clean
599clean:
600	rm -rf $(PROGS) afl-fuzz-document afl-as as afl-g++ afl-clang afl-clang++ *.o src/*.o *~ a.out core core.[1-9][0-9]* *.stackdump .test .test1 .test2 test-instr .test-instr0 .test-instr1 afl-cs-proxy afl-qemu-trace afl-gcc-fast afl-g++-fast ld *.so *.8 test/unittests/*.o test/unittests/unit_maybe_alloc test/unittests/preallocable .afl-* afl-gcc afl-g++ afl-clang afl-clang++ test/unittests/unit_hash test/unittests/unit_rand *.dSYM lib*.a
601	-$(MAKE) -f GNUmakefile.llvm clean
602	-$(MAKE) -f GNUmakefile.gcc_plugin clean
603	-$(MAKE) -C utils/libdislocator clean
604	-$(MAKE) -C utils/libtokencap clean
605	-$(MAKE) -C utils/aflpp_driver clean
606	-$(MAKE) -C utils/afl_network_proxy clean
607	-$(MAKE) -C utils/socket_fuzzing clean
608	-$(MAKE) -C utils/argv_fuzzing clean
609	-$(MAKE) -C utils/plot_ui clean
610	-$(MAKE) -C qemu_mode/unsigaction clean
611	-$(MAKE) -C qemu_mode/fastexit clean
612	-$(MAKE) -C qemu_mode/libcompcov clean
613	-$(MAKE) -C qemu_mode/libqasan clean
614	-$(MAKE) -C frida_mode clean
615	rm -rf nyx_mode/packer/linux_initramfs/init.cpio.gz nyx_mode/libnyx/libnyx/target/release/* nyx_mode/QEMU-Nyx/x86_64-softmmu/qemu-system-x86_64
616ifeq "$(IN_REPO)" "1"
617	-test -e coresight_mode/coresight-trace/Makefile && $(MAKE) -C coresight_mode/coresight-trace clean || true
618	-test -e qemu_mode/qemuafl/Makefile && $(MAKE) -C qemu_mode/qemuafl clean || true
619	-test -e unicorn_mode/unicornafl/Makefile && $(MAKE) -C unicorn_mode/unicornafl clean || true
620	-test -e nyx_mode/QEMU-Nyx/Makefile && $(MAKE) -C nyx_mode/QEMU-Nyx clean || true
621else
622	rm -rf coresight_mode/coresight_trace
623	rm -rf qemu_mode/qemuafl
624	rm -rf unicorn_mode/unicornafl
625endif
626
627.PHONY: deepclean
628deepclean:	clean
629	rm -rf coresight_mode/coresight-trace
630	rm -rf unicorn_mode/unicornafl
631	rm -rf qemu_mode/qemuafl
632	rm -rf nyx_mode/libnyx nyx_mode/packer nyx_mode/QEMU-Nyx
633ifeq "$(IN_REPO)" "1"
634	git checkout coresight_mode/coresight-trace
635	git checkout unicorn_mode/unicornafl
636	git checkout qemu_mode/qemuafl
637	git checkout nyx_mode/libnyx
638	git checkout nyx_mode/packer
639	git checkout nyx_mode/QEMU-Nyx
640endif
641
642.PHONY: distrib
643distrib: all
644	-$(MAKE) -j$(nproc) -f GNUmakefile.llvm
645ifneq "$(SYS)" "Darwin"
646	-$(MAKE) -f GNUmakefile.gcc_plugin
647	-$(MAKE) -C utils/libdislocator
648	-$(MAKE) -C utils/libtokencap
649endif
650	-$(MAKE) -C utils/afl_network_proxy
651	-$(MAKE) -C utils/socket_fuzzing
652	-$(MAKE) -C utils/argv_fuzzing
653	# -$(MAKE) -C utils/plot_ui
654	-$(MAKE) -C frida_mode
655ifneq "$(SYS)" "Darwin"
656ifeq "$(ARCH)" "aarch64"
657  ifndef NO_CORESIGHT
658	-$(MAKE) -C coresight_mode
659  endif
660endif
661ifeq "$(SYS)" "Linux"
662ifndef NO_NYX
663	-cd nyx_mode && ./build_nyx_support.sh
664endif
665endif
666	-cd qemu_mode && sh ./build_qemu_support.sh
667  ifeq "$(ARCH)" "aarch64"
668    ifndef NO_UNICORN_ARM64
669	-cd unicorn_mode && unset CFLAGS && sh ./build_unicorn_support.sh
670    endif
671  else
672	-cd unicorn_mode && unset CFLAGS && sh ./build_unicorn_support.sh
673  endif
674endif
675
676.PHONY: binary-only
677binary-only: test_shm test_python ready $(PROGS)
678ifneq "$(SYS)" "Darwin"
679	-$(MAKE) -C utils/libdislocator
680	-$(MAKE) -C utils/libtokencap
681endif
682	-$(MAKE) -C utils/afl_network_proxy
683	-$(MAKE) -C utils/socket_fuzzing
684	-$(MAKE) -C utils/argv_fuzzing
685	# -$(MAKE) -C utils/plot_ui
686	-$(MAKE) -C frida_mode
687ifneq "$(SYS)" "Darwin"
688ifeq "$(ARCH)" "aarch64"
689  ifndef NO_CORESIGHT
690	-$(MAKE) -C coresight_mode
691  endif
692endif
693ifeq "$(SYS)" "Linux"
694ifndef NO_NYX
695	-cd nyx_mode && ./build_nyx_support.sh
696endif
697endif
698	-cd qemu_mode && sh ./build_qemu_support.sh
699  ifeq "$(ARCH)" "aarch64"
700    ifndef NO_UNICORN_ARM64
701	-cd unicorn_mode && unset CFLAGS && sh ./build_unicorn_support.sh
702    endif
703  else
704	-cd unicorn_mode && unset CFLAGS && sh ./build_unicorn_support.sh
705  endif
706endif
707	@echo
708	@echo
709	@echo Build Summary:
710	@test -e afl-fuzz && echo "[+] afl-fuzz and supporting tools successfully built" || echo "[-] afl-fuzz could not be built, please set CC to a working compiler"
711ifneq "$(SYS)" "Darwin"
712ifeq "$(ARCH)" "aarch64"
713  ifndef NO_CORESIGHT
714	@test -e afl-cs-proxy && echo "[+] coresight_mode successfully built" || echo "[-] coresight_mode could not be built, it is optional and experimental, see coresight_mode/README.md for what is needed"
715  endif
716endif
717ifeq "$(SYS)" "Linux"
718ifndef NO_NYX
719	@test -e libnyx.so && echo "[+] nyx_mode successfully built" || echo "[-] nyx_mode could not be built, it is optional, see nyx_mode/README.md for what is needed"
720endif
721endif
722	@test -e afl-qemu-trace && echo "[+] qemu_mode successfully built" || echo "[-] qemu_mode could not be built, see docs/INSTALL.md for what is needed"
723  ifeq "$(ARCH)" "aarch64"
724    ifndef NO_UNICORN_ARM64
725	@test -e unicorn_mode/unicornafl/build_python/libunicornafl.so && echo "[+] unicorn_mode successfully built" || echo "[-] unicorn_mode could not be built, it is optional, see unicorn_mode/README.md for what is needed"
726    endif
727  else
728	@test -e unicorn_mode/unicornafl/build_python/libunicornafl.so && echo "[+] unicorn_mode successfully built" || echo "[-] unicorn_mode could not be built, it is optional, see unicorn_mode/README.md for what is needed"
729  endif
730endif
731	@echo
732
733.PHONY: source-only
734source-only: all
735	-$(MAKE) -j$(nproc) -f GNUmakefile.llvm
736ifneq "$(SYS)" "Darwin"
737	-$(MAKE) -f GNUmakefile.gcc_plugin
738	-$(MAKE) -C utils/libdislocator
739	-$(MAKE) -C utils/libtokencap
740endif
741	# -$(MAKE) -C utils/plot_ui
742ifeq "$(SYS)" "Linux"
743ifndef NO_NYX
744	-cd nyx_mode && ./build_nyx_support.sh
745endif
746endif
747	@echo
748	@echo
749	@echo Build Summary:
750	@test -e afl-fuzz && echo "[+] afl-fuzz and supporting tools successfully built" || echo "[-] afl-fuzz could not be built, please set CC to a working compiler"
751	@test -e afl-llvm-pass.so && echo "[+] LLVM basic mode successfully built" || echo "[-] LLVM mode could not be built, please install at least llvm-11 and clang-11 or newer, see docs/INSTALL.md"
752	@test -e SanitizerCoveragePCGUARD.so && echo "[+] LLVM mode successfully built" || echo "[-] LLVM mode could not be built, please install at least llvm-13 and clang-13 or newer, see docs/INSTALL.md"
753	@test -e SanitizerCoverageLTO.so && echo "[+] LLVM LTO mode successfully built" || echo "[-] LLVM LTO mode could not be built, it is optional, if you want it, please install LLVM 11-14. More information at instrumentation/README.lto.md on how to build it"
754ifneq "$(SYS)" "Darwin"
755	test -e afl-gcc-pass.so && echo "[+] gcc_mode successfully built" || echo "[-] gcc_mode could not be built, it is optional, install gcc-VERSION-plugin-dev to enable this"
756endif
757ifeq "$(SYS)" "Linux"
758ifndef NO_NYX
759	@test -e libnyx.so && echo "[+] nyx_mode successfully built" || echo "[-] nyx_mode could not be built, it is optional, see nyx_mode/README.md for what is needed"
760endif
761endif
762	@echo
763
764%.8:	%
765	@echo .TH $* 8 $(BUILD_DATE) "AFL++" > $@
766	@echo .SH NAME >> $@
767	@echo .B $* >> $@
768	@echo >> $@
769	@echo .SH SYNOPSIS >> $@
770	@./$* -h 2>&1 | head -n 3 | tail -n 1 | sed 's/^\.\///' >> $@
771	@echo >> $@
772	@echo .SH OPTIONS >> $@
773	@echo .nf >> $@
774	@./$* -hh 2>&1 | tail -n +4 >> $@
775	@echo >> $@
776	@echo .SH AUTHOR >> $@
777	@echo "AFL++ was written by Michal \"lcamtuf\" Zalewski and is maintained by Marc \"van Hauser\" Heuse <[email protected]>, Dominik Maier <[email protected]>, Andrea Fioraldi <[email protected]> and Heiko \"hexcoder-\" Eissfeldt <[email protected]>" >> $@
778	@echo  The homepage of AFL++ is: https://github.com/AFLplusplus/AFLplusplus >> $@
779	@echo >> $@
780	@echo .SH LICENSE >> $@
781	@echo Apache License Version 2.0, January 2004 >> $@
782
783.PHONY: install
784install: all $(MANPAGES)
785	@install -d -m 755 $${DESTDIR}$(BIN_PATH) $${DESTDIR}$(HELPER_PATH) $${DESTDIR}$(DOC_PATH) $${DESTDIR}$(MISC_PATH)
786	@rm -f $${DESTDIR}$(BIN_PATH)/afl-plot.sh
787	@rm -f $${DESTDIR}$(BIN_PATH)/afl-as
788	@rm -f $${DESTDIR}$(HELPER_PATH)/afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH)/afl-llvm-rt-32.o $${DESTDIR}$(HELPER_PATH)/afl-llvm-rt-64.o $${DESTDIR}$(HELPER_PATH)/afl-gcc-rt.o
789	@for i in afl-llvm-dict2file.so afl-llvm-lto-instrumentlist.so afl-llvm-pass.so cmplog-instructions-pass.so cmplog-routines-pass.so cmplog-switches-pass.so compare-transform-pass.so libcompcov.so libdislocator.so libnyx.so libqasan.so libtokencap.so SanitizerCoverageLTO.so SanitizerCoveragePCGUARD.so split-compares-pass.so split-switches-pass.so injection-pass.so; do echo rm -fv $${DESTDIR}$(HELPER_PATH)/$${i}; done
790	install -m 755 $(PROGS) $(SH_PROGS) $${DESTDIR}$(BIN_PATH)
791	@if [ -f afl-qemu-trace ]; then install -m 755 afl-qemu-trace $${DESTDIR}$(BIN_PATH); fi
792	@if [ -f utils/plot_ui/afl-plot-ui ]; then install -m 755 utils/plot_ui/afl-plot-ui $${DESTDIR}$(BIN_PATH); fi
793	@if [ -f libdislocator.so ]; then set -e; install -m 755 libdislocator.so $${DESTDIR}$(HELPER_PATH); fi
794	@if [ -f libtokencap.so ]; then set -e; install -m 755 libtokencap.so $${DESTDIR}$(HELPER_PATH); fi
795	@if [ -f libcompcov.so ]; then set -e; install -m 755 libcompcov.so $${DESTDIR}$(HELPER_PATH); fi
796	@if [ -f libqasan.so ]; then set -e; install -m 755 libqasan.so $${DESTDIR}$(HELPER_PATH); fi
797	@if [ -f afl-fuzz-document ]; then set -e; install -m 755 afl-fuzz-document $${DESTDIR}$(BIN_PATH); fi
798	@if [ -f socketfuzz32.so -o -f socketfuzz64.so ]; then $(MAKE) -C utils/socket_fuzzing install; fi
799	@if [ -f argvfuzz32.so -o -f argvfuzz64.so ]; then $(MAKE) -C utils/argv_fuzzing install; fi
800	@if [ -f afl-frida-trace.so ]; then install -m 755 afl-frida-trace.so $${DESTDIR}$(HELPER_PATH); fi
801	@if [ -f libnyx.so ]; then install -m 755 libnyx.so $${DESTDIR}$(HELPER_PATH); fi
802	@if [ -f utils/afl_network_proxy/afl-network-server ]; then $(MAKE) -C utils/afl_network_proxy install; fi
803	@if [ -f utils/aflpp_driver/libAFLDriver.a ]; then set -e; install -m 644 utils/aflpp_driver/libAFLDriver.a $${DESTDIR}$(HELPER_PATH); fi
804	@if [ -f utils/aflpp_driver/libAFLQemuDriver.a ]; then set -e; install -m 644 utils/aflpp_driver/libAFLQemuDriver.a $${DESTDIR}$(HELPER_PATH); fi
805	-$(MAKE) -f GNUmakefile.llvm install
806ifneq "$(SYS)" "Darwin"
807	-$(MAKE) -f GNUmakefile.gcc_plugin install
808endif
809	ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-gcc
810	ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-g++
811	ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-clang
812	ln -sf afl-cc $${DESTDIR}$(BIN_PATH)/afl-clang++
813	@mkdir -m 0755 -p ${DESTDIR}$(MAN_PATH)
814	install -m0644 *.8 ${DESTDIR}$(MAN_PATH)
815	install -m 755 afl-as $${DESTDIR}$(HELPER_PATH)
816	ln -sf afl-as $${DESTDIR}$(HELPER_PATH)/as
817	install -m 644 docs/*.md $${DESTDIR}$(DOC_PATH)
818	cp -r testcases/ $${DESTDIR}$(MISC_PATH)
819	cp -r dictionaries/ $${DESTDIR}$(MISC_PATH)
820	cp injections.dic $${DESTDIR}$(MISC_PATH)
821
822.PHONY: uninstall
823uninstall:
824	-cd $${DESTDIR}$(BIN_PATH) && rm -f $(PROGS) $(SH_PROGS) afl-cs-proxy afl-qemu-trace afl-plot-ui afl-fuzz-document afl-network-client afl-network-server afl-g* afl-plot.sh afl-as afl-ld-lto afl-c* afl-lto*
825	-cd $${DESTDIR}$(HELPER_PATH) && rm -f afl-g*.*o afl-llvm-*.*o afl-compiler-*.*o libdislocator.so libtokencap.so libcompcov.so libqasan.so afl-frida-trace.so libnyx.so socketfuzz*.so argvfuzz*.so libAFLDriver.a libAFLQemuDriver.a as afl-as SanitizerCoverage*.so compare-transform-pass.so cmplog-*-pass.so split-*-pass.so dynamic_list.txt injections.dic
826	-rm -rf $${DESTDIR}$(MISC_PATH)/testcases $${DESTDIR}$(MISC_PATH)/dictionaries
827	-sh -c "ls docs/*.md | sed 's|^docs/|$${DESTDIR}$(DOC_PATH)/|' | xargs rm -f"
828	-cd $${DESTDIR}$(MAN_PATH) && rm -f $(MANPAGES)
829	-rmdir $${DESTDIR}$(BIN_PATH) 2>/dev/null
830	-rmdir $${DESTDIR}$(HELPER_PATH) 2>/dev/null
831	-rmdir $${DESTDIR}$(MISC_PATH) 2>/dev/null
832	-rmdir $${DESTDIR}$(DOC_PATH) 2>/dev/null
833	-rmdir $${DESTDIR}$(MAN_PATH) 2>/dev/null
834