-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
78 lines (61 loc) · 2.63 KB
/
Copy pathMakefile
File metadata and controls
78 lines (61 loc) · 2.63 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
# 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
# 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
# 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/pairscan: tools/pairscan.c
$(CC) $(CFLAGS) $(CAPSTONE_CFLAGS) $< $(CAPSTONE_LIBS) -o $@
tools/defuse: tools/defuse.c
$(CC) $(CFLAGS) $(CAPSTONE_CFLAGS) $< $(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 \
*.o
.PHONY: all build clean lib test integration-test integration-test-regen tools