-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
66 lines (48 loc) · 1.76 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
BIN = bin
SRC = src
EXAMPLE_DIR = example
DOCKER = docker run --rm -v $(shell pwd):/workdir multiarch/crossbuild
CROSS_ENV_DIR = /usr/mipsel-linux-gnu/bin
CC = $(DOCKER) $(CROSS_ENV_DIR)/gcc
AS = $(DOCKER) $(CROSS_ENV_DIR)/as
LD = $(DOCKER) $(CROSS_ENV_DIR)/ld
COPY = $(DOCKER) $(CROSS_ENV_DIR)/objcopy
DUMP = $(DOCKER) $(CROSS_ENV_DIR)/objdump
.PHONY: build ex_plus ex_mult ex_as build_ex dump_elf dump_bin
all: build
build:
$(shell which go) build -o $(BIN)/emu ./cmd/emu/
ex_plus:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/plus.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_mult:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/mult.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_sub:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/sub.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_div:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/div.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_for:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/for.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_while:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/for.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_struct:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/struct.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_fib:
$(CC) -ffreestanding -nostdlib -mips1 -O0 -c $(EXAMPLE_DIR)/fib.c -o $(EXAMPLE_DIR)/main.o
@make build_ex
ex_as:
$(AS) -mips1 -O0 -o $(EXAMPLE_DIR)/main.o $(EXAMPLE_DIR)/main.S
@make build_ex
build_ex: $(EXAMPLE_DIR)/main.o
$(LD) -T $(EXAMPLE_DIR)/linker.ld -o $(BIN)/main.elf $^
$(COPY) -O binary --only-section=.text --only-section=.data $(BIN)/main.elf $(BIN)/main
dump_elf:
$(DUMP) -D $(BIN)/main.elf
dump_bin:
$(DUMP) -m mips -b binary --endian=little -D $(BIN)/main