mm/Makefile

95 lines
2.7 KiB
Makefile
Raw Normal View History

2018-10-26 02:29:41 +00:00
# TODO think about how to split this up
MIPS_BINUTILS := mips-linux-gnu-
AS := $(MIPS_BINUTILS)as
LD := $(MIPS_BINUTILS)ld
#QEMU_IRIX := ~/irixemu/mips-linux-user/qemu-mips
QEMU_IRIX := ~/qemu-irix
IRIX_ROOT := ./ido/62/
2018-10-26 02:29:41 +00:00
CC := $(QEMU_IRIX) -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
CFLAGS := -G 0 -non_shared -Xfullwarn -Xcpluscomm
ASFLAGS := -march=vr4300 -32
2018-10-26 02:29:41 +00:00
MIPS_VERSION := -mips2
OPTIMIZATION := -O2 -g3
build/src/libultra/os/%: OPTIMIZATION := -O1
build/src/libultra/io/%: OPTIMIZATION := -O2
build/src/libultra/libc/%: OPTIMIZATION := -O2
build/src/boot_O1/%: OPTIMIZATION := -O1
build/src/boot_O2_g3/%: OPTIMIZATION := -O2 -g3
2018-10-30 04:52:02 +00:00
test.txt: OPTIMIZATION := -O2 -g3
2018-10-26 02:29:41 +00:00
test.txt: MIPS_VERSION := -mips2
test.txt: CC := python3 preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/boot_O2_g3/%: CC := python3 preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
2018-10-26 02:29:41 +00:00
BASEROM_FILES := $(wildcard baserom/*)
BASEROM_O_FILES := $(BASEROM_FILES:baserom/%=build/baserom/%.o)
S_FILES := $(wildcard asm/*)
S_O_FILES = $(S_FILES:asm/%.asm=build/asm/%.o)
C_FILES := $(wildcard src/libultra/*) \
$(wildcard src/libultra/os/*) \
$(wildcard src/libultra/io/*) \
$(wildcard src/libultra/libc/*) \
$(wildcard src/code/*) \
$(wildcard src/boot_O2_g3/*) \
$(wildcard src/boot_O1/*)
2018-10-26 02:29:41 +00:00
C_O_FILES = $(C_FILES:src/%.c=build/src/%.o)
O_FILES := $(BASEROM_O_FILES) $(S_O_FILES)
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
ROM := rom.z64
ELF := build/rom.elf
# make build directories
$(shell mkdir -p build/asm)
$(shell mkdir -p build/baserom)
$(shell mkdir -p build/src)
$(shell mkdir -p build/src/libultra)
$(shell mkdir -p build/src/libultra/os)
$(shell mkdir -p build/src/libultra/io)
$(shell mkdir -p build/src/libultra/libc)
$(shell mkdir -p build/src/code)
$(shell mkdir -p build/src/boot_O2_g3)
$(shell mkdir -p build/src/boot_O1)
2018-10-26 02:29:41 +00:00
check: $(ROM) code.bin boot.bin
@md5sum -c checksum.md5
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
$(ROM): $(ELF)
@python3 elf2rom.py
$(ELF): $(O_FILES) ldscript.txt
$(LD) -T ldscript.txt --no-check-sections --accept-unknown-input-arch -o $@
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
boot.bin: code.elf
$(MIPS_BINUTILS)objcopy --dump-section boot=$@ $<
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
code.bin: code.elf
$(MIPS_BINUTILS)objcopy --dump-section code=$@ $<
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
code.elf: $(S_O_FILES) $(C_O_FILES) codescript.txt undef.txt
$(LD) -T codescript.txt -T undef.txt --no-check-sections --accept-unknown-input-arch -o $@
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
test.txt: build/src/test.o
$(MIPS_BINUTILS)objdump -d -z --adjust-vma=0x80080790 $< > test.txt
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
clean:
rm $(ROM) $(ELF) code.elf code.bin boot.bin -r build
# Recipes
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
build/baserom/%.o: baserom/%
$(MIPS_BINUTILS)objcopy -I binary -O elf32-big $< $@
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
build/asm/%.o: asm/%.asm
$(AS) $(ASFLAGS) $^ -o $@
2018-10-28 08:32:16 +00:00
2018-10-26 02:29:41 +00:00
build/src/%.o: src/%.c include/*
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
2018-10-28 08:32:16 +00:00