Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
98 lines (78 loc) · 3.47 KB
/
Copy pathMakefile
File metadata and controls
98 lines (78 loc) · 3.47 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Bare `make` builds both shipped artifacts. Without this the first
# target below (lib) would be the default, which builds libarmlint.a
# and silently leaves a stale armlint executable behind -- the driver
# in main.c is not part of the library.
.DEFAULT_GOAL := build
CFLAGS = -g -Wall -Wextra -fPIC -std=c11
CAPSTONE_CFLAGS_RAW := $(shell pkg-config --cflags capstone 2>/dev/null)
# Homebrew's capstone.pc sets includedir to .../include/capstone, which
# makes <capstone/capstone.h> unresolvable. Append a stripped form so the
# header resolves under either packaging convention.
CAPSTONE_CFLAGS := $(CAPSTONE_CFLAGS_RAW) $(patsubst %/capstone,%,$(CAPSTONE_CFLAGS_RAW))
CAPSTONE_LIBS := $(shell pkg-config --libs capstone 2>/dev/null)
ifeq ($(strip $(CAPSTONE_LIBS)),)
CAPSTONE_LIBS := -lcapstone
endif
%.o: %.c
$(CC) $(CFLAGS) $(CAPSTONE_CFLAGS) -c $< -o $@
# The pattern rule above sees only the .c file, so a change to the
# shared header would otherwise not rebuild anything. Every object in
# the project includes armlint.h; the tools/ programs do not.
armlint.o main.o armlint_test.o: armlint.h
# The real file is the target so make can date-stamp it; `lib` stays
# as the phony alias the other targets and the docs refer to.
libarmlint.a: armlint.o
ar -crs $@ $<
lib: libarmlint.a
armlint: armlint.o main.o
$(CC) $(CFLAGS) armlint.o main.o $(CAPSTONE_LIBS) -o armlint
test: armlint.o armlint_test.o
$(CC) $(CFLAGS) armlint.o armlint_test.o $(CAPSTONE_LIBS) -pthread -o armlint_test
./armlint_test
# Snapshot-based integration suite under fixtures/. Each .s is
# assembled with clang -arch arm64 and diffed against the matching
# .expected. Requires a clang that can assemble AArch64 and fails
# (exit 2) without one, rather than passing having tested nothing.
integration-test: armlint
./scripts/run_fixtures.sh
./scripts/json_test.sh
./scripts/driver_test.sh
# Regenerate fixtures/*.expected from current armlint output -- use
# after an intentional behavior change, then review the diff before
# committing.
integration-test-regen: armlint
./scripts/run_fixtures.sh regen
# Runs armlint's advice on random programs and compares the results
# (tools/rwfuzz, scripts/rwfuzz_test.sh). The programs run natively, so
# it needs an AArch64 host, and it takes longer than the suites above.
rwfuzz-test: tools/rwfuzz
./scripts/rwfuzz_test.sh
# Corpus-mining research utilities (see "Mining tools" in README.md);
# not part of the default build or test targets.
tools: tools/pairscan tools/defuse tools/rwfuzz tools/tblgen_probe
tools/pairscan: tools/pairscan.c
$(CC) $(CFLAGS) $(CAPSTONE_CFLAGS) $< $(CAPSTONE_LIBS) -o $@
tools/defuse: tools/defuse.c
$(CC) $(CFLAGS) $(CAPSTONE_CFLAGS) $< $(CAPSTONE_LIBS) -o $@
# Drives the check registry itself, so it links the library.
tools/rwfuzz: tools/rwfuzz.c libarmlint.a armlint.h
$(CC) $(CFLAGS) $(CAPSTONE_CFLAGS) -I. $< libarmlint.a $(CAPSTONE_LIBS) -lm -o $@
# Prints armlint's classifiers next to Capstone's model for
# tools/tblgen_audit.py, so it links the library too.
tools/tblgen_probe: tools/tblgen_probe.c libarmlint.a armlint.h
$(CC) $(CFLAGS) $(CAPSTONE_CFLAGS) -I. $< libarmlint.a $(CAPSTONE_LIBS) -o $@
# The default goal: everything that ships, without running the suites.
build: lib armlint
all: lib armlint test
clean:
rm -f \
armlint \
armlint_test \
libarmlint.a \
tools/pairscan \
tools/defuse \
tools/rwfuzz \
tools/tblgen_probe \
*.o
.PHONY: all build clean lib test integration-test integration-test-regen \
rwfuzz-test tools