-
Notifications
You must be signed in to change notification settings - Fork 6
/
makefile_lib
123 lines (90 loc) · 2.65 KB
/
makefile_lib
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Build SGDK library to be referenced in projects
# specify SGDK root dir
SGDK?=/opt/sgdk
# specify your M68k GNU toolchain prefix
M68K_PREFIX?=m68k-elf-
###################################################
# fancy colors cause we're fancy
CLEAR=\033[0m
RED=\033[1;31m
YELLOW=\033[1;33m
GREEN=\033[1;32m
# library source directories
SRC_DIR:=$(SGDK)/src
RES_DIR:=$(SGDK)/res
INC_DIR:=$(SGDK)/inc
# m68k toolset
CC:=$(M68K_PREFIX)gcc
OBJCPY:=$(M68K_PREFIX)objcopy
# z80 toolset
ASM_Z80=sjasmplus
# SGDK toolset
RESCOMP:=java -jar $(SGDK)/bin/rescomp.jar
BINTOS:=$(SGDK)/bin/bintos
# gather code & resources
SRC_C:=$(wildcard $(SRC_DIR)/*.c)
SRC_S:=$(wildcard $(SRC_DIR)/*.s)
SRC_S80:=$(wildcard $(SRC_DIR)/*.s80)
RES:=$(wildcard $(RES_DIR)/*.res)
# setup output objects
OBJ:=$(RES:.res=.o)
OBJ+=$(SRC_S80:.s80=.o)
OBJ+=$(SRC_S:.s=.o)
OBJ+=$(SRC_C:.c=.o)
LST:=$(SRC_C:.c=.lst)
# setup includes
INC:=-I$(INC_DIR) -I$(SRC_DIR) -I$(RES_DIR)
# default flags
DEF_FLAGS_M68K:=-m68000 -Wall -Wextra -Wno-shift-negative-value -fno-builtin $(INC)
DEF_FLAGS_Z80:=-i$(SRC_DIR) -i$(INC_DIR)
release: envcheck
release: FLAGS:=$(DEF_FLAGS_M68K) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -flto
release: $(SGDK)/lib/libmd.a
debug: envcheck
debug: FLAGS:=$(DEF_FLAGS_M68K) -O1 -ggdb -DDEBUG=1
debug: $(SGDK)/lib/libmd_debug.a
asm: envcheck
asm: FLAGS:=$(DEF_FLAGS_M68K) -O3 -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -S
asm: $(LST)
all: release
default: release
Default: release
Release: release
.PHONY: clean
envcheck:
@if [ ! -d $(SGDK) ]; then echo -e "${RED}*** SGDK directory not found!${CLEAR}"; exit -1; fi
@command -v $(CC) >/dev/null || { echo -e "${RED}*** '$(CC)' not found!${CLEAR}"; exit -1; }
@command -v $(OBJCOPY) >/dev/null || { echo -e "${RED}*** '$(OBJCOPY)' not found!${CLEAR}"; exit -1; }
cleanobj:
@rm -f $(OBJ)
cleanrelease: cleanobj
@rm -f $(SGDK)/lib/libmd.a
cleandebug: cleanobj
@rm -f $(SGDK)/lib/libmd_debug.a
clean: cleanobj
@rm -f $(SGDK)/lib/libmd.a $(SGDK)/lib/libmd_debug.a $(OBJ)
cleanall: clean
cleanAll: clean
cleandefault: clean
cleanDefault: clean
cleanRelease: cleanrelease
cleanDebug: cleandebug
cleanAsm: cleanasm
$(SGDK)/lib/libmd.a: $(OBJ)
ar rs $(SGDK)/lib/libmd.a $(OBJ)
$(SGDK)/lib/libmd_debug.a: $(OBJ)
ar rs $(SGDK)/lib/libmd_debug.a $(OBJ)
%.lst: %.c
$(CC) $(FLAGS) -c $< -o $@
%.o: %.c
$(CC) $(FLAGS) -MMD -c $< -o $@
%.o: %.s
$(CC) -x assembler-with-cpp $(FLAGS) -c $< -o $@
%.o: %.rs
$(CC) -x assembler-with-cpp $(FLAGS) -c $< -o $@
%.rs: %.res
$(RESCOMP) $*.res $*.rs -dep $*.o
%.o80: %.s80
$(ASM_Z80) $(DEF_FLAGS_Z80) --raw=$@ $<
%.s: %.o80
$(BINTOS) $<