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