1XEN_ROOT=$(CURDIR)/../../..
2include $(XEN_ROOT)/tools/Rules.mk
3
4.PHONY: x86-insn-fuzz-all
5ifeq ($(CONFIG_X86_64),y)
6x86-insn-fuzz-all: x86-insn-fuzzer.a fuzz-emul.o afl
7else
8x86-insn-fuzz-all:
9endif
10
11# Add libx86 to the build
12vpath %.c $(XEN_ROOT)/xen/lib/x86
13
14x86_emulate:
15	[ -L $@ ] || ln -sf $(XEN_ROOT)/xen/arch/x86/$@
16
17x86_emulate/%: x86_emulate ;
18
19x86-emulate.c x86-emulate.h wrappers.c: %:
20	[ -L $* ] || ln -sf $(XEN_ROOT)/tools/tests/x86_emulator/$*
21
22CFLAGS += $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -I.
23
24GCOV_FLAGS := --coverage
25%-cov.o: %.c
26	$(CC) -c $(CFLAGS) $(GCOV_FLAGS) $< -o $@
27
28x86.h := $(addprefix $(XEN_ROOT)/tools/include/xen/asm/,\
29                     x86-vendors.h x86-defns.h msr-index.h) \
30         $(addprefix $(XEN_ROOT)/tools/include/xen/lib/x86/, \
31                     cpuid.h cpuid-autogen.h)
32x86_emulate.h := x86-emulate.h x86_emulate/x86_emulate.h $(x86.h)
33
34# x86-emulate.c will be implicit for both
35x86-emulate.o x86-emulate-cov.o: x86_emulate/x86_emulate.c $(x86_emulate.h)
36
37fuzz-emul.o fuzz-emulate-cov.o cpuid.o wrappers.o: $(x86_emulate.h)
38
39x86-insn-fuzzer.a: fuzz-emul.o x86-emulate.o cpuid.o
40	$(AR) rc $@ $^
41
42afl-harness: afl-harness.o fuzz-emul.o x86-emulate.o cpuid.o wrappers.o
43	$(CC) $(CFLAGS) $^ -o $@
44
45afl-harness-cov: afl-harness-cov.o fuzz-emul-cov.o x86-emulate-cov.o cpuid.o wrappers.o
46	$(CC) $(CFLAGS) $(GCOV_FLAGS) $^ -o $@
47
48# Common targets
49.PHONY: all
50all: x86-insn-fuzz-all
51
52.PHONY: distclean
53distclean: clean
54	rm -f x86_emulate x86-emulate.c x86-emulate.h
55
56.PHONY: clean
57clean:
58	rm -f *.a *.o .*.d afl-harness afl-harness-cov *.gcda *.gcno *.gcov
59
60.PHONY: install
61install: all
62
63.PHONY: uninstall
64
65.PHONY: afl
66afl: afl-harness
67
68.PHONY: afl-cov
69afl-cov: afl-harness-cov
70