• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Capstone Disassembler Engine
2# By Philippe Antoine <contact@catenacyber.fr>, 2018
3
4include ../../config.mk
5include ../../functions.mk
6
7ifneq ($(CAPSTONE_STATIC),yes)
8$(error Needs static capstone.)
9endif
10
11# Verbose output?
12V ?= 0
13
14INCDIR = ../../include
15ifndef BUILDDIR
16TESTDIR = .
17OBJDIR = .
18LIBDIR = ../..
19else
20TESTDIR = $(BUILDDIR)/tests
21OBJDIR = $(BUILDDIR)/obj/tests
22LIBDIR = $(BUILDDIR)
23endif
24
25CFLAGS += -Wall -I$(INCDIR)
26LDFLAGS += -L$(LIBDIR)
27
28CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
29LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
30
31LIBNAME = capstone
32
33BIN_EXT =
34AR_EXT = a
35
36
37ARCHIVE = $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
38
39.PHONY: all clean
40
41SOURCES = fuzz_disasm.c drivermc.c fuzz_harness.c driverbin.c
42OBJS = $(addprefix $(OBJDIR)/,$(SOURCES:.c=.o))
43BINARY = $(addprefix $(TESTDIR)/,fuzz_disasm$(BIN_EXT))
44BINARYBIN = $(addprefix $(TESTDIR)/,fuzz_bindisasm$(BIN_EXT))
45
46all: $(BINARY) $(BINARYBIN)
47
48clean:
49	rm -rf fuzz_harness $(OBJS) $(BINARY) $(BINARYBIN) $(OBJDIR)/lib$(LIBNAME).* $(OBJDIR)/$(LIBNAME).*
50
51$(BINARY): fuzz_disasm.o drivermc.o
52	@mkdir -p $(@D)
53ifeq ($(V),0)
54	$(call log,LINK,$(notdir $@))
55	@$(link-static)
56else
57	$(link-static)
58endif
59
60$(BINARYBIN): fuzz_disasm.o driverbin.o
61	@mkdir -p $(@D)
62ifeq ($(V),0)
63	$(call log,LINK,$(notdir $@))
64	@$(link-static)
65else
66	$(link-static)
67endif
68
69$(OBJDIR)/%.o: %.c
70	@mkdir -p $(@D)
71ifeq ($(V),0)
72	$(call log,CC,$(@:$(OBJDIR)/%=%))
73	@$(compile)
74else
75	$(compile)
76endif
77
78
79
80define link-static
81	$(CC) $(LDFLAGS) $^ $(ARCHIVE) -o $@
82endef
83
84fuzz_harness: fuzz_harness.o
85	${CC} $< -O3 -Wall -l$(LIBNAME) -o $@
86