-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
89 lines (71 loc) · 2.2 KB
/
Makefile
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
#
# Copyright © 2017 Samuel Holland <[email protected]>
# See LICENSE in the project directory for license terms.
#
ARCH_arisc = or1k
ARCH_nbrom = arm
ARCH_rvbrom = riscv64
ARCH_sbrom = arm
CROSS_aarch64 = aarch64-linux-musl-
CROSS_arm = arm-linux-musleabi-
CROSS_or1k = or1k-linux-musl-
CROSS_riscv64 = riscv64-linux-musl-
BLOB ?= */*
BLOBS = $(sort $(wildcard $(BLOB)/blob.hex))
CHECKS = $(addsuffix .checked,$(DIRS))
COMMENTS = $(addsuffix comments,$(DIRS))
DIRS = $(dir $(BLOBS))
OUTPUT = $(foreach d,$(DIRS),$(d)annotated.s $(d)blob.s $(d)callgraph.svg)
SECTIONS = $(addsuffix sections,$(DIRS))
SYMBOLS = $(addsuffix symbols,$(DIRS))
arch = $(ARCH_$(firstword $(subst _, ,$(notdir $1))))
cross_compile = $(CROSS_$(call arch,$(1)))
env = env ARCH=$(call arch,$(1)) CROSS_COMPILE=$(call cross_compile,$(1))
M := @printf ' %-7s %s\n'
Q := @
ifneq ($(V),)
M := @\#
Q :=
endif
all: $(OUTPUT)
check: $(CHECKS)
clean:
$(M) CLEAN "$(BLOB)"
$(Q) rm -f $(BLOB)/.checked $(BLOB)/annotated.s $(BLOB)/blob.bin $(BLOB)/blob.elf $(BLOB)/blob.s
$(Q) rm -f $(BLOB)/callgraph.dot $(BLOB)/callgraph.svg
save: $(COMMENTS)
%/.checked: %/sections %/symbols
$(M) CHECK $*
$(Q) sort -cu $*/sections
$(Q) test -z "$$(uniq -df1 $*/sections)" || \
(echo "error: Consecutive sections of the same type!"; false)
$(Q) sort -cu $*/symbols
$(Q) test -z "$$(sort -k2 $*/symbols | grep -Fv '$$' | uniq -df1)" || \
(echo "error: Duplicate symbol name!"; false)
%/annotated.s: %/blob.s %/comments
$(M) PASTE $@
$(Q) paste $^ > [email protected] && expand -t88,90 [email protected] > $@
$(Q) rm -f [email protected]
%/blob.bin: %/blob.hex
$(M) XXD $@
$(Q) xxd -r $^ $@
%/blob.elf: %/blob.bin %/sections %/symbols
$(M) BIN2ELF $@
$(Q) $(call env,$*) scripts/bin2elf $^ $@
%/blob.s: %/blob.elf
$(M) OBJDUMP $@
$(Q) $(call cross_compile,$*)objdump -d $^ | expand -t11,12 > [email protected] \
&& cut -c-86 [email protected] > $@
$(Q) rm -f [email protected]
%/callgraph.dot: %/blob.s
$(M) CGRAPH $@
$(Q) $(call env,$*) scripts/callgraph $^ $@
%/callgraph.svg: %/callgraph.dot
$(M) DOT $@
$(Q) dot -T svg $^ > $@
%/comments: %
$(M) SAVE $@
$(Q) { test $*/annotated.s -nt $@ && cut -c89- $*/annotated.s > $@; } || touch $@
.PHONY: all check clean save
.SECONDARY:
.SUFFIXES: