Last active
January 20, 2025 06:19
-
-
Save Aragami1408/5f7e3d1f9c231dfdcdaf5e6f6702b256 to your computer and use it in GitHub Desktop.
Higanbana's Makefile template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = clang | |
CFLAGS = -Wall -Wextra -Isrc | |
LDFLAGS = -lm | |
DEBUG_FLAGS = -g -O0 -fsanitize=address $(CFLAGS) | |
RELEASE_FLAGS = -O2 $(CFLAGS) | |
TARGET = # insert program name here | |
TARGET_DEBUG = $(TARGET)_debug | |
OBJ_DIR = obj | |
BIN_DIR = bin | |
SRC_DIR = src | |
SRC_FILES = $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/**/*.c) | |
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES)) | |
.PHONY: all clean | |
all: $(OBJ_DIR) $(BIN_DIR) $(BIN_DIR)/$(TARGET) $(BIN_DIR)/$(TARGET_DEBUG) | |
$(OBJ_DIR): | |
mkdir -p $(OBJ_DIR) | |
$(BIN_DIR): | |
mkdir -p $(BIN_DIR) | |
# Build the main executable | |
$(BIN_DIR)/$(TARGET): $(OBJ_FILES) | |
$(CC) $(RELEASE_FLAGS) $^ -o $@ $(LDFLAGS) | |
$(BIN_DIR)/$(TARGET_DEBUG): $(OBJ_FILES) | |
$(CC) $(DEBUG_FLAGS) $^ -o $@ $(LDFLAGS) | |
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | |
$(CC) $(CFLAGS) -c $< -o $@ | |
clean: | |
rm -rf $(BIN_DIR) $(OBJ_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment