libgfx: Merge in very early release.
[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/pi_thread.c \
44 os/fbtext.c \
45 os/main.c \
46 os/mm.c \
47 os/panic.c \
48 os/thread.c \
49 os/time.c \
50 rcp/vi.c \
51 sp/init.c \
52 )
53
54 UCODES = $(call FIXPATH,\
55 ucodes/init.rsp \
56 )
57
58 OBJFILES = \
59 $(CFILES:.c=.o) \
60 $(ASMFILES:.s=.o) \
61 $(UCODES:.rsp=.o)
62
63 DEPFILES = $(OBJFILES:.o=.d)
64
65 #
66 # Primary targets.
67 #
68 libn64.a: $(OBJFILES)
69 @echo $(call FIXPATH,"Building: libn64/$@")
70 @$(AR) rcs $@ $^
71
72 #
73 # Generic compilation/assembly targets.
74 #
75 %.o: %.s
76 @echo $(call FIXPATH,"Assembling: libn64/$<")
77 @$(CC) -x assembler-with-cpp $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
78
79 %.o: %.c include/syscall.h
80 @echo $(call FIXPATH,"Compiling: libn64/$<")
81 @$(CC) $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
82
83 %.o: %.rsp %.rsps
84 @echo $(call FIXPATH,"Assembling: $(ROM_NAME)/$@")
85 @$(CPP) -E -Iucodes $< > $(<:.rsp=.rsppch)
86 @$(RSPASM) $(<:.rsp=.rsppch) -o $(<:.rsp=.bin)
87 @$(CC) -x assembler-with-cpp $(CFLAGS) $(OPTFLAGS) -MMD -c $(<:.rsp=.rsps) -o $@
88
89 #
90 # Clean project target.
91 #
92 .PHONY: clean
93 clean:
94 @echo "Cleaning libn64..."
95 @$(RM) libn64.a $(DEPFILES) $(OBJFILES)
96