Skip to content

Instantly share code, notes, and snippets.

@SealtielFreak
Last active July 9, 2025 00:34
Show Gist options
  • Save SealtielFreak/ee03581e6112167942c63e2c426c0aeb to your computer and use it in GitHub Desktop.
Save SealtielFreak/ee03581e6112167942c63e2c426c0aeb to your computer and use it in GitHub Desktop.
Makefile for NES development
# ===== Basic Configuration =====
CC = mos-nes-mmc1-clang
TARGET = main.nes
EMULATOR = fceux
# ===== Directories =====
SRC_DIR = src
INCLUDE_DIR = include
OBJ_DIR = obj
# ===== Customizable Flags =====
# - Language standard: c89, c99, c11, etc.
STD = -std=c99
# - Optimization level: -O0 (none), -O1, -O2, -O3, -Os (small size)
OPTIMIZE = -Os
# - Additional flags for the compiler (e.g., -Wall, -Wextra, -pedantic)
EXTRA_CFLAGS = -Wall -Wextra -Wpedantic
# - Flags for the linker (e.g., additional libraries)
EXTRA_LDFLAGS =
# ===== Automatic Flags =====
CFLAGS = $(STD) $(OPTIMIZE) $(EXTRA_CFLAGS) -I$(INCLUDE_DIR)
LDFLAGS = chr-rom.s -lneslib -lnesdoug $(EXTRA_LDFLAGS)
# ===== File Search =====
SRCS = $(shell find $(SRC_DIR) -type f -name '*.c')
HDRS = $(shell find $(INCLUDE_DIR) -type f -name '*.h')
OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
# ===== Rules =====
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(HDRS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
run: $(TARGET)
$(EMULATOR) $(TARGET)
install: $(TARGET)
sudo cp $(TARGET) /bin/$(TARGET)
clean:
rm -rf $(OBJ_DIR) $(TARGET)
.PHONY: all run install clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment