Initial commit.
[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
23 CFLAGS = -Wall -Wextra -pedantic -std=c99 -I. -Iinclude
24 OPTFLAGS = -Os -march=vr4300 -mabi=eabi -mgp32 -mlong32 \
25 -flto -ffat-lto-objects -ffunction-sections -fdata-sections \
26 -G4 -mno-extern-sdata -mgpopt
27
28 ASMFILES = $(call FIXPATH,\
29 os/asm/boot.s \
30 os/asm/exception.s \
31 os/asm/syscall.s \
32 os/asm/thread.s \
33 )
34
35 CFILES = $(call FIXPATH,\
36 os/fbtext.c \
37 os/kthread.c \
38 os/main.c \
39 os/panic.c \
40 os/thread.c \
41 rcp/vi.c \
42 )
43
44 OBJFILES = \
45 $(CFILES:.c=.o) \
46 $(ASMFILES:.s=.o)
47
48 DEPFILES = $(OBJFILES:.o=.d)
49
50 #
51 # Primary targets.
52 #
53 libn64.a: $(OBJFILES)
54 @echo $(call FIXPATH,"Building: libn64/$@")
55 @$(AR) rcs $@ $^
56
57 #
58 # Generic compilation/assembly targets.
59 #
60 %.o: %.s
61 @echo $(call FIXPATH,"Assembling: libn64/$<")
62 @$(CC) -x assembler-with-cpp $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
63
64 %.o: %.c
65 @echo $(call FIXPATH,"Compiling: libn64/$<")
66 @$(CC) $(CFLAGS) $(OPTFLAGS) -MMD -c $< -o $@
67
68 #
69 # Clean project target.
70 #
71 .PHONY: clean
72 clean:
73 @echo "Cleaning libn64..."
74 @$(RM) libn64.a $(DEPFILES) $(OBJFILES)
75