Update toolchain to use GCC 8.1.
[n64chain.git] / libn64 / Makefile
1 #
2 # libn64/Makefile: Makefile for libn64.
3 #
4 # n64chain: A (free) open-source N64 development toolchain.
5 # Copyright 2014-16 Tyler J. Stachecki <stachecki.tyler@gmail.com>
6 #
7 # This file is subject to the terms and conditions defined in
8 # 'LICENSE', which is part of this source code package.
9 #
10
11 ifdef SystemRoot
12 FIXPATH = $(subst /,\,$1)
13 RM = del /Q
14 else
15 FIXPATH = $1
16 RM = rm -f
17 endif
18
19 AS = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-as)
20 AR = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-gcc-ar)
21 CC = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-gcc)
22 CPP = $(call FIXPATH,$(CURDIR)/../tools/bin/mips64-elf-cpp)
23
24 RSPASM = $(call FIXPATH,$(CURDIR)/../tools/bin/rspasm)
25
26 CFLAGS = -Wall -Wextra -pedantic -std=c99 -I. -Iinclude -Ipriv_include
27 OPTFLAGS = -Os -march=vr4300 -mtune=vr4300 -mabi=eabi -mgp32 -mlong32 \
28 -flto -ffat-lto-objects -ffunction-sections -fdata-sections \
29 -G4 -mno-extern-sdata -mgpopt -mfix4300 -mbranch-likely \
30 -mno-check-zero-division
31
32 ASMFILES = $(call FIXPATH,\
33 os/asm/boot.s \
34 os/asm/context.s \
35 os/asm/exception.s \
36 os/asm/idle_thread.s \
37 os/asm/message.s \
38 os/asm/syscall.s \
39 )
40
41 CFILES = $(call FIXPATH,\
42 io/init.c \
43 io/filesystem.c \
44 io/pi_thread.c \
45 io/si_thread.c \
46 os/fbtext.c \
47 os/main.c \
48 os/mm.c \
49 os/panic.c \
50 os/thread.c \
51 os/time.c \
52 rcp/vi.c \
53 sp/init.c \
54 sp/sp_thread.c \
55 )
56
57 UCODES = $(call FIXPATH,\
58 ucodes/init.rsp \
59 )
60
61 OBJFILES = \
62 $(CFILES:.c=.o) \
63 $(ASMFILES:.s=.o) \
64 $(UCODES:.rsp=.o)
65
66 DEPFILES = $(OBJFILES:.o=.d)
67
68 #
69 # Primary targets.
70 #
71 libn64.a: $(OBJFILES)
72 @echo $(call FIXPATH,"Building: libn64/$@")
73 @$(AR) rcs $@ $^
74
75 #
76 # Generic compilation/assembly targets.
77 #
78 %.o: %.s
79 @echo $(call FIXPATH,"Assembling: libn64/$<")
80 @$(CC) -x assembler-with-cpp $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
81
82 %.o: %.c include/syscall.h
83 @echo $(call FIXPATH,"Compiling: libn64/$<")
84 @$(CC) $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
85
86 %.o: %.rsp %.rsps
87 @echo $(call FIXPATH,"Assembling: $(ROM_NAME)/$@")
88 @$(CPP) -E -Iucodes $< > $(<:.rsp=.rsppch)
89 @$(RSPASM) $(<:.rsp=.rsppch) -o $(<:.rsp=.bin)
90 @$(CC) -x assembler-with-cpp $(CFLAGS) $(OPTFLAGS) -MMD -c $(<:.rsp=.rsps) -o $@
91
92 #
93 # Clean project target.
94 #
95 .PHONY: clean
96 clean:
97 @echo "Cleaning libn64..."
98 @$(RM) libn64.a $(DEPFILES) $(OBJFILES)
99