-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (48 loc) · 1.59 KB
/
Makefile
File metadata and controls
60 lines (48 loc) · 1.59 KB
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
# Makefile for the Tetris project
# This Makefile is designed for GCC/Clang and works on Linux, macOS,
# and on Windows with a build environment like MinGW-w64.
# Compiler and flags
CC = gcc
# CFLAGS: -Wall (warn all) -Wextra (extra warnings) -std=c99 (C standard) -g (debug symbols)
CFLAGS = -Wall -Wextra -std=c99 -g
# --- Cross-platform setup ---
# Default to Unix-like commands and executable names.
EXEC = tetris
RM = rm -f
# If on Windows, override the commands and add .exe suffix.
# Note: This requires 'make' from a shell that defines OS=Windows_NT, like Git Bash or MSYS2.
ifeq ($(OS),Windows_NT)
EXEC := $(EXEC).exe
RM = del /Q
endif
# Directories
APP_DIR = app
CORE_DIR = core
PLATFORM_DIR = platform
# Source files
# We list all the .c files we plan to have in the project.
SRCS = $(APP_DIR)/main.c \
$(CORE_DIR)/game.c \
$(CORE_DIR)/board.c \
$(CORE_DIR)/tetromino.c \
$(PLATFORM_DIR)/renderer.c \
$(PLATFORM_DIR)/input.c
# Object files are derived from source files
OBJS = $(SRCS:.c=.o)
# Default target: build the executable
all: $(EXEC)
# Rule to link the executable
$(EXEC): $(OBJS)
$(CC) $(CFLAGS) -o $(EXEC) $(OBJS)
# Rule to compile .c files into .o files
# This is a generic rule that works for all our source directories.
# $< is the source file (e.g., app/main.c)
# $@ is the target file (e.g., app/main.o)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Target to clean up the project directory
# The '-' prefix tells make to ignore errors (e.g., if files don't exist).
clean:
-$(RM) $(OBJS) $(EXEC)
# Phony targets are not actual files
.PHONY: all clean