1# 2# american fuzzy lop - makefile 3# ----------------------------- 4# 5# Written and maintained by Michal Zalewski <lcamtuf@google.com> 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# http://www.apache.org/licenses/LICENSE-2.0 14# 15 16PROGNAME = afl 17VERSION = $(shell grep '^\#define VERSION ' config.h | cut -d '"' -f2) 18 19PREFIX ?= /usr/local 20BIN_PATH = $(PREFIX)/bin 21HELPER_PATH = $(PREFIX)/lib/afl 22DOC_PATH = $(PREFIX)/share/doc/afl 23MISC_PATH = $(PREFIX)/share/afl 24 25# PROGS intentionally omit afl-as, which gets installed elsewhere. 26 27PROGS = afl-gcc afl-fuzz afl-showmap afl-tmin afl-gotcpu afl-analyze 28SH_PROGS = afl-plot afl-cmin afl-whatsup 29 30CFLAGS ?= -O3 -funroll-loops 31CFLAGS += -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign \ 32 -DAFL_PATH=\"$(HELPER_PATH)\" -DDOC_PATH=\"$(DOC_PATH)\" \ 33 -DBIN_PATH=\"$(BIN_PATH)\" 34 35ifneq "$(filter Linux GNU%,$(shell uname))" "" 36 LDFLAGS += -ldl 37endif 38 39ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" "" 40 TEST_CC = afl-gcc 41else 42 TEST_CC = afl-clang 43endif 44 45COMM_HDR = alloc-inl.h config.h debug.h types.h 46 47all: test_x86 $(PROGS) afl-as all_done 48 49ifndef AFL_NO_X86 50 51test_x86: 52 @echo "[*] Checking for the ability to compile x86 code..." 53 @echo 'main() { __asm__("xorb %al, %al"); }' | $(CC) -w -x c - -o .test || ( 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 ) 54 @rm -f .test 55 @echo "[+] Everything seems to be working, ready to compile." 56 57else 58 59test_x86: 60 @echo "[!] Note: skipping x86 compilation checks (AFL_NO_X86 set)." 61 62endif 63 64afl-gcc: afl-gcc.c $(COMM_HDR) | test_x86 65 $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) 66 set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $$i; done 67 68afl-as: afl-as.c afl-as.h $(COMM_HDR) | test_x86 69 $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) 70 ln -sf afl-as as 71 72afl-fuzz: afl-fuzz.c $(COMM_HDR) | test_x86 73 $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) 74 75afl-showmap: afl-showmap.c $(COMM_HDR) | test_x86 76 $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) 77 78afl-tmin: afl-tmin.c $(COMM_HDR) | test_x86 79 $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) 80 81afl-analyze: afl-analyze.c $(COMM_HDR) | test_x86 82 $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) 83 84afl-gotcpu: afl-gotcpu.c $(COMM_HDR) | test_x86 85 $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) 86 87ifndef AFL_NO_X86 88 89test_build: afl-gcc afl-as afl-showmap 90 @echo "[*] Testing the CC wrapper and instrumentation output..." 91 unset AFL_USE_ASAN AFL_USE_MSAN; AFL_QUIET=1 AFL_INST_RATIO=100 AFL_PATH=. ./$(TEST_CC) $(CFLAGS) test-instr.c -o test-instr $(LDFLAGS) 92 echo 0 | ./afl-showmap -m none -q -o .test-instr0 ./test-instr 93 echo 1 | ./afl-showmap -m none -q -o .test-instr1 ./test-instr 94 @rm -f test-instr 95 @cmp -s .test-instr0 .test-instr1; DR="$$?"; rm -f .test-instr0 .test-instr1; if [ "$$DR" = "0" ]; then echo; echo "Oops, the instrumentation does not seem to be behaving correctly!"; echo; echo "Please ping <lcamtuf@google.com> to troubleshoot the issue."; echo; exit 1; fi 96 @echo "[+] All right, the instrumentation seems to be working!" 97 98else 99 100test_build: afl-gcc afl-as afl-showmap 101 @echo "[!] Note: skipping build tests (you may need to use LLVM or QEMU mode)." 102 103endif 104 105all_done: 106 @if [ ! "`which clang 2>/dev/null`" = "" ]; then echo "[+] LLVM users: see llvm_mode/README.llvm for a faster alternative to afl-gcc."; fi 107 @echo "[+] All done! Be sure to review README - it's pretty short and useful." 108 @if [ "`uname`" = "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. You can also use VirtualBox\n(virtualbox.org) to put AFL inside a Linux or *BSD VM.\n\n"; fi 109 @! 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.txt for advice.\033[0m\n" 2>/dev/null 110 111.NOTPARALLEL: clean 112 113clean: 114 rm -f $(PROGS) afl-as as afl-g++ afl-clang afl-clang++ *.o *~ a.out core core.[1-9][0-9]* *.stackdump test .test test-instr .test-instr0 .test-instr1 qemu_mode/qemu-2.10.0.tar.bz2 afl-qemu-trace 115 rm -rf out_dir qemu_mode/qemu-2.10.0 116 $(MAKE) -C llvm_mode clean 117 $(MAKE) -C libdislocator clean 118 $(MAKE) -C libtokencap clean 119 120install: all 121 mkdir -p -m 755 $${DESTDIR}$(BIN_PATH) $${DESTDIR}$(HELPER_PATH) $${DESTDIR}$(DOC_PATH) $${DESTDIR}$(MISC_PATH) 122 rm -f $${DESTDIR}$(BIN_PATH)/afl-plot.sh 123 install -m 755 $(PROGS) $(SH_PROGS) $${DESTDIR}$(BIN_PATH) 124 rm -f $${DESTDIR}$(BIN_PATH)/afl-as 125 if [ -f afl-qemu-trace ]; then install -m 755 afl-qemu-trace $${DESTDIR}$(BIN_PATH); fi 126ifndef AFL_TRACE_PC 127 if [ -f afl-clang-fast -a -f afl-llvm-pass.so -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-pass.so afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi 128else 129 if [ -f afl-clang-fast -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi 130endif 131 if [ -f afl-llvm-rt-32.o ]; then set -e; install -m 755 afl-llvm-rt-32.o $${DESTDIR}$(HELPER_PATH); fi 132 if [ -f afl-llvm-rt-64.o ]; then set -e; install -m 755 afl-llvm-rt-64.o $${DESTDIR}$(HELPER_PATH); fi 133 set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $${DESTDIR}$(BIN_PATH)/$$i; done 134 install -m 755 afl-as $${DESTDIR}$(HELPER_PATH) 135 ln -sf afl-as $${DESTDIR}$(HELPER_PATH)/as 136 install -m 644 docs/README docs/ChangeLog docs/*.txt $${DESTDIR}$(DOC_PATH) 137 cp -r testcases/ $${DESTDIR}$(MISC_PATH) 138 cp -r dictionaries/ $${DESTDIR}$(MISC_PATH) 139 140publish: clean 141 test "`basename $$PWD`" = "afl" || exit 1 142 test -f ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz; if [ "$$?" = "0" ]; then echo; echo "Change program version in config.h, mmkay?"; echo; exit 1; fi 143 cd ..; rm -rf $(PROGNAME)-$(VERSION); cp -pr $(PROGNAME) $(PROGNAME)-$(VERSION); \ 144 tar -cvz -f ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz $(PROGNAME)-$(VERSION) 145 chmod 644 ~/www/afl/releases/$(PROGNAME)-$(VERSION).tgz 146 ( cd ~/www/afl/releases/; ln -s -f $(PROGNAME)-$(VERSION).tgz $(PROGNAME)-latest.tgz ) 147 cat docs/README >~/www/afl/README.txt 148 cat docs/status_screen.txt >~/www/afl/status_screen.txt 149 cat docs/historical_notes.txt >~/www/afl/historical_notes.txt 150 cat docs/technical_details.txt >~/www/afl/technical_details.txt 151 cat docs/ChangeLog >~/www/afl/ChangeLog.txt 152 cat docs/QuickStartGuide.txt >~/www/afl/QuickStartGuide.txt 153 echo -n "$(VERSION)" >~/www/afl/version.txt 154.PHONY: libdislocator llvm_mode test_llvm_mode 155 156libdislocator: 157 $(MAKE) -C libdislocator 158 159llvm_mode: 160 $(MAKE) -C llvm_mode 161 162test_llvm_mode: 163 $(MAKE) -C llvm_mode test_build 164