-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
103 lines (76 loc) · 1.89 KB
/
Makefile
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
# Vulcalien's Library Makefile
# version 0.3.3
#
# Adapted for GBA libraries
# === Detect OS ===
ifeq ($(OS),Windows_NT)
CURRENT_OS := WINDOWS
else
CURRENT_OS := UNIX
endif
# === Basic Info ===
OUT_FILENAME := libsimplegba
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
SRC_SUBDIRS := math memory backup debug
# === Variable Implementations ===
AUDIO_DRIVER := basic
SRC_SUBDIRS += audio/$(AUDIO_DRIVER)
# === Compilation ===
CPPFLAGS := -MMD -MP -Iinclude
CFLAGS := -O3 -fomit-frame-pointer -marm -mcpu=arm7tdmi\
-Wall -pedantic
ASFLAGS := -mcpu=arm7tdmi -I$(SRC_DIR)
ifeq ($(CURRENT_OS),UNIX)
CC := arm-none-eabi-gcc
AS := arm-none-eabi-as
else ifeq ($(CURRENT_OS),WINDOWS)
CC :=
AS :=
endif
# === Extensions & Commands ===
OBJ_EXT := o
LIB_EXT := a
ifeq ($(CURRENT_OS),UNIX)
MKDIR := mkdir -p
RM := rm -rfv
else ifeq ($(CURRENT_OS),WINDOWS)
MKDIR := mkdir
RM := rmdir /Q /S
endif
# === Resources ===
# list of source file extensions
SRC_EXT := s c
# list of source directories
SRC_DIRS := $(SRC_DIR)\
$(foreach SUBDIR,$(SRC_SUBDIRS),$(SRC_DIR)/$(SUBDIR))
# list of source files
SRC := $(foreach DIR,$(SRC_DIRS),\
$(foreach EXT,$(SRC_EXT),\
$(wildcard $(DIR)/*.$(EXT))))
# list of object directories
OBJ_DIRS := $(SRC_DIRS:%=$(OBJ_DIR)/%)
# list of object files
OBJ := $(SRC:%=$(OBJ_DIR)/%.$(OBJ_EXT))
# output file
OUT := $(BIN_DIR)/$(OUT_FILENAME).$(LIB_EXT)
# === Targets ===
.PHONY: all build clean
all: build
build: $(OUT)
clean:
@$(RM) $(BIN_DIR) $(OBJ_DIR)
# generate library file
$(OUT): $(OBJ) | $(BIN_DIR)
$(AR) rcs $@ $^
# compile .s files
$(OBJ_DIR)/%.s.$(OBJ_EXT): %.s | $(OBJ_DIRS)
$(AS) $(ASFLAGS) -o $@ $<
# compile .c files
$(OBJ_DIR)/%.c.$(OBJ_EXT): %.c | $(OBJ_DIRS)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# create directories
$(BIN_DIR) $(OBJ_DIRS):
$(MKDIR) "$@"
-include $(OBJ:.$(OBJ_EXT)=.d)