summary refs log tree commit diff
path: root/Makefile
blob: 9c7135cef826e92163da7fec09fc3e1b8b77d261 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Build recipe
#
# SPDX-FileCopyrightText: 2016 Aleksandar Nikolic <anikolich@sourcefire.com>
# SPDX-FileCopyrightText: 2018-2020 Marc "van Hauser" Heuse <vh@thc.org>
# SPDX-License-Identifier: Apache-2.0
#
# SPDX-FileCopyrightText: 2024 Nguyễn Gia Phong <cnx@loang.net>
# SPDX-License-Identifier: AGPL-3.0-or-later

.POSIX:
.PHONY: all clean install uninstall

VERSION ::= 1.0.0
PREFIX ?= /usr/local
BINDIR ::= $(DESTDIR)$(PREFIX)/bin
LIBDIR ::= $(DESTDIR)$(PREFIX)/lib
MANDIR ::= $(DESTDIR)$(PREFIX)/share/man

# Override on non-FHS environments
DYNINST_LIB ?= $(LIBDIR)
# Override to . for local development
AFL_DYNINST_LIB ?= $(LIBDIR)

CPPFLAGS = -DVERSION=\"$(VERSION)\"\
	-DAFL_DYNINST_LIB=\"$(AFL_DYNINST_LIB)/libafldyninst.so\"\
	-DDYNINSTAPI_RT_LIB=\"$(DYNINST_LIB)/libdyninstAPI_RT.so\"
CXXFLAGS += -std=c++11 -Wextra -Werror
LDFLAGS ?= -fPIC
LDLIBS += -ldyninstAPI

BIN ::= afl-dyninst afl-dyninst-env
LIB ::= libafldyninst.so
MAN ::= afl-dyninst.1

all: $(BIN) $(LIB) $(MAN)

afl-dyninst: afl-dyninst.cc

afl-dyninst-env: afl-dyninst-env.m4
	m4 -D AFL_DYNINST_LIB=$(AFL_DYNINST_LIB)\
		-D DYNINST_LIB=$(DYNINST_LIB) $< > $@

%.so: %.cc
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $< -o $@

%.1: %
	help2man --no-info --output=$@ `realpath $<`

clean:
	rm -f $(BIN) $(LIB) $(MAN)

install: $(BIN:%=$(BINDIR)/%) $(LIB:%=$(LIBDIR)/%) $(MAN:%.1:$(MANDIR)/man1/%.1)

$(BINDIR)/%: %
	install -Dm 755 $< $@

$(LIBDIR)/%: %
	install -Dm 644 $< $@

$(MANDIR)/man1/%.1 : %.1
	install -Dm 644 $< $@

uninstall:
	rm -f $(BIN:%=$(BINDIR)/%)
	rm -f $(LIB:%=$(LIBDIR)/%)
	rm -f $(MAN:%.1:$(MANDIR)/man1/%.1)