make install rule copy the right things to the right places
[riscv-tests.git] / benchmarks / Makefile
1 #=======================================================================
2 # UCB VLSI FLOW: Makefile for riscv-bmarks
3 #-----------------------------------------------------------------------
4 # Yunsup Lee (yunsup@cs.berkeley.edu)
5 #
6
7 default: all
8
9 bmarkdir = .
10
11 instname = riscv-bmarks
12 instbasedir = $(UCB_VLSI_HOME)/install
13
14 #--------------------------------------------------------------------
15 # Sources
16 #--------------------------------------------------------------------
17
18 bmarks = \
19 median \
20 qsort \
21 rsort \
22 towers \
23 vvadd \
24 multiply \
25 mm \
26 dhrystone \
27 spmv \
28 mt-vvadd \
29 mt-matmul \
30
31 bmarks_host = \
32 median \
33 qsort \
34 towers \
35 vvadd \
36 multiply \
37 spmv \
38 vec-vvadd \
39 vec-cmplxmult \
40 vec-matmul \
41
42 #--------------------------------------------------------------------
43 # Build rules
44 #--------------------------------------------------------------------
45
46 HOST_OPTS = -std=gnu99 -DPREALLOCATE=0 -DHOST_DEBUG=1
47 HOST_COMP = gcc $(HOST_OPTS)
48
49 RISCV_PREFIX=riscv64-unknown-elf-
50 RISCV_GCC = $(RISCV_PREFIX)gcc
51 RISCV_GCC_OPTS = -static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf
52 RISCV_LINK = $(RISCV_GCC) -T $(bmarkdir)/common/test.ld $(incs)
53 RISCV_LINK_MT = $(RISCV_GCC) -T $(bmarkdir)/common/test-mt.ld
54 RISCV_LINK_OPTS = -nostdlib -nostartfiles -ffast-math -lc -lgcc
55 RISCV_OBJDUMP = $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
56 RISCV_SIM = spike
57
58 VPATH += $(addprefix $(bmarkdir)/, $(bmarks))
59 VPATH += $(bmarkdir)/common
60
61 incs += -I$(bmarkdir)/../env -I$(bmarkdir)/common $(addprefix -I$(bmarkdir)/, $(bmarks))
62 objs :=
63
64 include $(patsubst %, $(bmarkdir)/%/bmark.mk, $(bmarks))
65
66 #------------------------------------------------------------
67 # Build and run benchmarks on riscv simulator
68
69 bmarks_riscv_bin = $(addsuffix .riscv, $(bmarks))
70 bmarks_riscv_dump = $(addsuffix .riscv.dump, $(bmarks))
71 bmarks_riscv_hex = $(addsuffix .riscv.hex, $(bmarks))
72 bmarks_riscv_out = $(addsuffix .riscv.out, $(bmarks))
73
74 bmarks_defs = -DPREALLOCATE=1 -DHOST_DEBUG=0
75 bmarks_cycles = 80000
76
77 %.hex: %
78 elf2hex 16 32768 $< > $@
79
80 $(bmarks_riscv_dump): %.riscv.dump: %.riscv
81 $(RISCV_OBJDUMP) $< > $@
82
83 $(bmarks_riscv_out): %.riscv.out: %.riscv
84 $(RISCV_SIM) $< > $@
85
86 %.o: %.c
87 $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) \
88 -c $(incs) $< -o $@
89
90 %.o: %.S
91 $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) -D__ASSEMBLY__=1 \
92 -c $(incs) $< -o $@
93
94 riscv: $(bmarks_riscv_dump) $(bmarks_riscv_hex)
95 run-riscv: $(bmarks_riscv_out)
96 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
97 $(bmarks_riscv_out); echo;
98
99 junk += $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(bmarks_riscv_hex) $(bmarks_riscv_out)
100
101 #------------------------------------------------------------
102 # Build and run benchmarks on host machine
103
104 bmarks_host_bin = $(addsuffix .host, $(bmarks_host))
105 bmarks_host_out = $(addsuffix .host.out, $(bmarks_host))
106
107 $(bmarks_host_out): %.host.out: %.host
108 ./$< > $@
109
110 host: $(bmarks_host_bin)
111 run-host: $(bmarks_host_out)
112 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
113 $(bmarks_host_out); echo;
114
115 junk += $(bmarks_host_bin) $(bmarks_host_out)
116
117 #------------------------------------------------------------
118 # Default
119
120 all: riscv
121
122 #------------------------------------------------------------
123 # Install
124
125 date_suffix = $(shell date +%Y-%m-%d_%H-%M)
126 install_dir = $(instbasedir)/$(instname)-$(date_suffix)
127 latest_install = $(shell ls -1 -d $(instbasedir)/$(instname)* | tail -n 1)
128
129 install:
130 mkdir $(install_dir)
131 cp -r $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(install_dir)
132
133 install-link:
134 rm -rf $(instbasedir)/$(instname)
135 ln -s $(latest_install) $(instbasedir)/$(instname)
136
137 #------------------------------------------------------------
138 # Clean up
139
140 clean:
141 rm -rf $(objs) $(junk)