-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (45 loc) · 1.32 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
# # Compiler flags
CXXFLAGS := -std=c++11 -fno-rtti -fno-exceptions -fno-unwind-tables -Wall -Wextra -I $(CURDIR) -I $(CURDIR)/include -g -Os
# Source files directory
SRC_DIR := src
# Build directory
BUILD_DIR := build
# Source files (add more as needed)
SRCS := $(shell find $(SRC_DIR) -type f -name '*.cpp')
# Object files
OBJS := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS))
PNG_SUPPORT ?= 1
# Add PNG support flag if PNG_SUPPORT is set to 1
ifeq ($(PNG_SUPPORT),1)
CXXFLAGS += -DPNG_SUPPORT
MAKEOVERRIDES := PNG_SUPPORT=1
endif
# Ensure necessary directories exist
# This function ensures the directory for the target exists
define make_directory
@mkdir -p $(dir $@)
endef
# Target executable
TARGET := libpokemegb.a
# Phony targets
.PHONY: all clean
# Default target
all: $(TARGET) examples
examples: $(TARGET)
$(MAKE) -C examples $(MAKECMDGOALS) $(MAKEOVERRIDES)
# Rule to build the target executable
$(TARGET): $(OBJS)
@echo "Creating static library $(TARGET)"
ar rcs $@ $(OBJS)
ranlib $(TARGET)
# Rule to compile source files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR) $(C_FILE)
$(make_directory)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Create the build directory if it doesn't exist
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Clean rule
clean:
make -C examples clean $(MAKEOVERRIDES)
rm -rf $(BUILD_DIR) $(TARGET)