xref: /aosp_15_r20/external/AFLplusplus/utils/aflpp_driver/GNUmakefile (revision 08b48e0b10e97b33e7b60c5b6e2243bd915777f2)
1*08b48e0bSAndroid Build Coastguard Workerifeq "" "$(LLVM_CONFIG)"
2*08b48e0bSAndroid Build Coastguard Worker  LLVM_CONFIG=llvm-config
3*08b48e0bSAndroid Build Coastguard Workerendif
4*08b48e0bSAndroid Build Coastguard Worker
5*08b48e0bSAndroid Build Coastguard Workerifeq "$(shell uname -s)" "Darwin"
6*08b48e0bSAndroid Build Coastguard Worker  # On some odd MacOS system configurations, the Xcode sdk path is not set correctly
7*08b48e0bSAndroid Build Coastguard Worker  SDK_LD = -L$(shell xcrun --show-sdk-path)/usr/lib
8*08b48e0bSAndroid Build Coastguard Worker  LDFLAGS += $(SDK_LD)
9*08b48e0bSAndroid Build Coastguard Workerendif
10*08b48e0bSAndroid Build Coastguard Worker
11*08b48e0bSAndroid Build Coastguard Workerifeq "" "$(LLVM_CONFIG)"
12*08b48e0bSAndroid Build Coastguard Worker  LLVM_CONFIG := llvm-config
13*08b48e0bSAndroid Build Coastguard Workerendif
14*08b48e0bSAndroid Build Coastguard WorkerLLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir 2>/dev/null)
15*08b48e0bSAndroid Build Coastguard Workerifneq "" "$(LLVM_BINDIR)"
16*08b48e0bSAndroid Build Coastguard Worker  ifeq "$(shell test -x $(LLVM_BINDIR)/clang && echo 1)" "1"
17*08b48e0bSAndroid Build Coastguard Worker    CC := $(LLVM_BINDIR)/clang
18*08b48e0bSAndroid Build Coastguard Worker  endif
19*08b48e0bSAndroid Build Coastguard Workerendif
20*08b48e0bSAndroid Build Coastguard Worker
21*08b48e0bSAndroid Build Coastguard WorkerCFLAGS := -O3 -funroll-loops -g -fPIC
22*08b48e0bSAndroid Build Coastguard Worker
23*08b48e0bSAndroid Build Coastguard Workerall:	libAFLDriver.a libAFLQemuDriver.a aflpp_qemu_driver_hook.so
24*08b48e0bSAndroid Build Coastguard Worker
25*08b48e0bSAndroid Build Coastguard Workeraflpp_driver.o:	aflpp_driver.c
26*08b48e0bSAndroid Build Coastguard Worker	-$(CC) -I. -I../../include $(CFLAGS) -c aflpp_driver.c
27*08b48e0bSAndroid Build Coastguard Worker
28*08b48e0bSAndroid Build Coastguard WorkerlibAFLDriver.a:	aflpp_driver.o
29*08b48e0bSAndroid Build Coastguard Worker	@ar rc libAFLDriver.a aflpp_driver.o
30*08b48e0bSAndroid Build Coastguard Worker	@cp -vf libAFLDriver.a ../../
31*08b48e0bSAndroid Build Coastguard Worker
32*08b48e0bSAndroid Build Coastguard Workerdebug:
33*08b48e0bSAndroid Build Coastguard Worker	$(CC) -Wno-deprecated -I../../include $(CFLAGS) -D_DEBUG=\"1\" -c -o afl-performance.o ../../src/afl-performance.c
34*08b48e0bSAndroid Build Coastguard Worker	$(CC) -I../../include -D_DEBUG=\"1\" -g -funroll-loops -c aflpp_driver.c
35*08b48e0bSAndroid Build Coastguard Worker	#$(CC) -S -emit-llvm -Wno-deprecated -I../../include $(CFLAGS) -D_DEBUG=\"1\" -c -o afl-performance.ll ../../src/afl-performance.c
36*08b48e0bSAndroid Build Coastguard Worker	#$(CC) -S -emit-llvm -I../../include -D_DEBUG=\"1\" -g -funroll-loops -c aflpp_driver.c
37*08b48e0bSAndroid Build Coastguard Worker	ar rc libAFLDriver.a afl-performance.o aflpp_driver.o
38*08b48e0bSAndroid Build Coastguard Worker
39*08b48e0bSAndroid Build Coastguard Workeraflpp_qemu_driver.o:	aflpp_qemu_driver.c
40*08b48e0bSAndroid Build Coastguard Worker	-$(CC) $(CFLAGS) -O0 -funroll-loops -c aflpp_qemu_driver.c
41*08b48e0bSAndroid Build Coastguard Worker
42*08b48e0bSAndroid Build Coastguard WorkerlibAFLQemuDriver.a:	aflpp_qemu_driver.o
43*08b48e0bSAndroid Build Coastguard Worker	@-ar rc libAFLQemuDriver.a aflpp_qemu_driver.o
44*08b48e0bSAndroid Build Coastguard Worker	@-cp -vf libAFLQemuDriver.a ../../
45*08b48e0bSAndroid Build Coastguard Worker
46*08b48e0bSAndroid Build Coastguard Workeraflpp_qemu_driver_hook.so:	aflpp_qemu_driver_hook.o
47*08b48e0bSAndroid Build Coastguard Worker	@-test -e aflpp_qemu_driver_hook.o && $(CC) $(LDFLAGS) -shared aflpp_qemu_driver_hook.o -o aflpp_qemu_driver_hook.so || echo "Note: Optional aflpp_qemu_driver_hook.so not built."
48*08b48e0bSAndroid Build Coastguard Worker
49*08b48e0bSAndroid Build Coastguard Workeraflpp_qemu_driver_hook.o:	aflpp_qemu_driver_hook.c
50*08b48e0bSAndroid Build Coastguard Worker	@-test -e ../../qemu_mode/qemuafl/qemuafl/api.h && $(CC) $(CFLAGS) -funroll-loops -c aflpp_qemu_driver_hook.c || echo "Note: Optional aflpp_qemu_driver_hook.o not built."
51*08b48e0bSAndroid Build Coastguard Worker
52*08b48e0bSAndroid Build Coastguard Workertest:	debug
53*08b48e0bSAndroid Build Coastguard Worker	#clang -S -emit-llvm -D_DEBUG=\"1\" -I../../include -Wl,--allow-multiple-definition -funroll-loops -o aflpp_driver_test.ll aflpp_driver_test.c
54*08b48e0bSAndroid Build Coastguard Worker	afl-clang-fast -D_DEBUG=\"1\" -I../../include -Wl,--allow-multiple-definition -funroll-loops -o aflpp_driver_test aflpp_driver_test.c libAFLDriver.a afl-performance.o
55*08b48e0bSAndroid Build Coastguard Worker
56*08b48e0bSAndroid Build Coastguard Workerclean:
57*08b48e0bSAndroid Build Coastguard Worker	rm -f *.o libAFLDriver*.a libAFLQemuDriver.a aflpp_qemu_driver_hook.so *~ core aflpp_driver_test
58