-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
62 lines (46 loc) · 1.24 KB
/
Makefile
File metadata and controls
62 lines (46 loc) · 1.24 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
# Isle.Computer - Assembler Makefile (Chapter 5)
# Copyright Will Green and Isle Contributors
# SPDX-License-Identifier: MIT
MAKEFLAGS += --no-builtin-rules --no-builtin-variables
# BIN_PREFIX needs adjusting on some platforms
# e.g. riscv64-elf on Arch Linux and riscv64-linux-gnu on Fedora
BIN_PREFIX := riscv64-unknown-elf
# arch settings
MARCH := rv32i # RV32I for chapter 5
MABI := ilp32
# linker script
LDSCRIPT := isle16.ld
# tool names
AS := $(BIN_PREFIX)-as
LD := $(BIN_PREFIX)-ld
OBJDUMP := $(BIN_PREFIX)-objdump
OBJCOPY := $(BIN_PREFIX)-objcopy
HEXDUMP := hexdump
# find sources and derive program names and .mem targets
SRCS := $(wildcard *.s)
NAMES := $(SRCS:.s=)
MEMS := $(SRCS:.s=.mem)
all: $(MEMS)
#
# targets
#
# allow 'make hello' to build hello.mem
$(NAMES): %: %.mem
# assemble
%.o: %.s
$(AS) -march=$(MARCH) -mabi=$(MABI) $< -o $@
# link
%.out: %.o
$(LD) $< -o $@ -T $(LDSCRIPT) -m elf32lriscv -nostdlib
# generate raw binary
%.bin: %.out
$(OBJCOPY) -O binary $< $@
# convert binary to Verilog $readmemh format
%.mem: %.bin
$(HEXDUMP) -ve '"%08X\n"' $< > $@
# disassemble linked binary to aid with debugging
%.dis: %.out
$(OBJDUMP) -d $< > $@
clean:
rm -f *.o *.out *.bin *.mem *.dis
.PHONY: all clean $(NAMES)