-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
58 lines (46 loc) · 2.01 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
# Example usage:
# If you have testbench/my_test.c, you can execute the following to create a MIPS binary
# make testbench/my_test.mips.bin
# For simulator
CC = g++
CPPFLAGS = -W -Wall -std=c++11
# For MIPS binaries. Turn on all warnings, enable all optimisations and link everything statically
MIPS_CC = mips-linux-gnu-gcc
MIPS_OBJCOPY = mips-linux-gnu-objcopy
MIPS_OBJDUMP = mips-linux-gnu-objdump
MIPS_CPPFLAGS = -W -Wall -fno-builtin -march=mips1 -mfp32 -fno-stack-protector
MIPS_LDFLAGS = -nostdlib -Wl,-melf32btsmip -march=mips1 -nostartfiles -mno-check-zero-division -Wl,--gpsize=0 -static -Wl,-Bstatic -Wl,--build-id=none
# Compile C file (.c) into MIPS object file (.o)
%.mips.o: test/src/%.c
$(MIPS_CC) $(MIPS_CPPFLAGS) -c $< -o $@
# Assemble MIPS assembly file (.s) into MIPS object file (.o)
%.mips.o: test/src/%.s
$(MIPS_CC) $(MIPS_CPPFLAGS) -c $< -o $@
# Link MIPS object file (.o), producing .elf, using memory locations specified in spec
%.mips.elf: %.mips.o
$(MIPS_CC) $(MIPS_CPPFLAGS) $(MIPS_LDFLAGS) -T linker.ld $< -o $@
# Extract binary instructions only from linked object file (.elf)
test/bin/%.mips.bin: %.mips.elf
$(MIPS_OBJCOPY) -O binary --only-section=.text $< $@
# Disassemble linked object file (.elf), pulling out instructions as MIPS assembly file (.s)
%.mips.s : %.mips.elf
$(MIPS_OBJDUMP) -j .text -D $< > $@
# Build simulator
bin/mips_simulator: src/Simulator.cpp src/Instruction.cpp src/Instruction.h src/System.cpp src/System.h src/Errors.h
mkdir -p bin
$(CC) $(CPPFLAGS) src/Simulator.cpp src/Instruction.cpp src/Instruction.h src/System.cpp src/System.h src/Errors.h -o bin/mips_simulator
# Dummy for build simulator to conform to spec
simulator: bin/mips_simulator
testbench-build:
cd test && pyinstaller --onefile mips_testbench.py
mv test/dist/mips_testbench test/
testbench:
@echo "Moving pre-built testbench to bin/"
@echo "To rebuild the testbench, run make testbench-build"
mkdir -p bin/
cp test/mips_testbench bin/
clean:
rm -rf bin
rm -rf test/bin
rm -rf test/dist
rm -rf test/build