-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
72 lines (52 loc) · 1.9 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
# File: Makefile
# Author: Matthew Toohey
# Date: 15/11/2020
# Definitions.
CC = gcc
CFLAGS = -std=c99 -Wall -Wstrict-prototypes -Wextra -g -Isrc/common
CLEAN_CMD = rm build/obj/* && rm build/bin/*
SRC_DIR = src
COMMON_DIR = $(SRC_DIR)/common
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
BIN_DIR = $(BUILD_DIR)/bin
MAIN = main
MAIN_DIR = $(SRC_DIR)
MAIN_DEPS = $(COMMON_DIR)/gameboy.h $(COMMON_DIR)/cpu.h
EXECUTABLE = gbc
COPY_BTLDR_CMD = cp DMG_ROM.bin build/bin
# Windows
ifeq ($(OS),Windows_NT)
EXECUTABLE = gbc.exe
MAIN = winmain
MAIN_DIR = $(SRC_DIR)/windows
MAIN_DEPS = $(COMMON_DIR)/gameboy.h $(COMMON_DIR)/cpu.h
CFLAGS += -mwindows
CLEAN_CMD = del /Q build\obj\* && del /Q build\bin\*
COPY_BTLDR_CMD = copy DMG_ROM.bin build\bin
endif
# Default target.
all: $(BIN_DIR)/$(EXECUTABLE) $(BIN_DIR)/DMG_ROM.bin
# Compile: create object files from C source files.
$(OBJ_DIR)/$(MAIN).o: $(MAIN_DIR)/$(MAIN).c $(MAIN_DEPS)
$(CC) -c $(CFLAGS) $< -o $@
# winmain.o: winmain.c gameboy.h cpu.h
# $(CC) -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/gameboy.o: $(COMMON_DIR)/gameboy.c $(COMMON_DIR)/gameboy.h $(COMMON_DIR)/cpu.h $(COMMON_DIR)/instructions.h $(COMMON_DIR)/logging.h $(COMMON_DIR)/memory.h $(COMMON_DIR)/screen.h
$(CC) -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/cpu.o: $(COMMON_DIR)/cpu.c $(COMMON_DIR)/cpu.h
$(CC) -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/memory.o: $(COMMON_DIR)/memory.c $(COMMON_DIR)/memory.h $(COMMON_DIR)/gameboy.h
$(CC) -c $(CFLAGS) $< -o $@
$(OBJ_DIR)/screen.o: $(COMMON_DIR)/screen.c $(COMMON_DIR)/screen.h
$(CC) -c $(CFLAGS) $< -o $@
# Link
$(BIN_DIR)/$(EXECUTABLE): $(OBJ_DIR)/$(MAIN).o $(OBJ_DIR)/gameboy.o $(OBJ_DIR)/cpu.o $(OBJ_DIR)/memory.o $(OBJ_DIR)/screen.o
$(CC) $(CFLAGS) $^ -o $@ -lm
# Copy bootloader rom.
$(BIN_DIR)/DMG_ROM.bin: DMG_ROM.bin
$(COPY_BTLDR_CMD)
# Target: clean project.
.PHONY: clean
clean:
$(CLEAN_CMD)