59 lines
1.5 KiB
Makefile
59 lines
1.5 KiB
Makefile
# Recursive Directory Digesting Makefile V1.0
|
|
# === Project Settings ===
|
|
PROJECT := soundThing # Change this to your project name
|
|
CC := gcc
|
|
CFLAGS := -Wall -Wextra -std=c11 -O2
|
|
# Preprocessor flags (deps only here)
|
|
CPPFLAGS := -MMD -MP
|
|
# Add linker flags
|
|
LDFLAGS = -lraylib -lm -ldl -lpthread -lGL -lrt -lX11 -lasound #here (e.g. -lm)
|
|
|
|
# === Directory Structure ===
|
|
SRC_DIR := source
|
|
OBJ_DIR := build
|
|
BIN_DIR := bin
|
|
INC_DIR := include
|
|
|
|
# === Discover headers recursively ===
|
|
INC_SUBDIRS := $(shell find $(INC_DIR) -type d)
|
|
CPPFLAGS += $(addprefix -I,$(INC_SUBDIRS))
|
|
|
|
# === Discover sources recursively ===
|
|
SRC := $(shell find $(SRC_DIR) -type f -name '*.c')
|
|
# Map source paths to object paths (mirror folders under build/)
|
|
OBJ := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
|
|
DEP := $(OBJ:.o=.d)
|
|
BIN := $(BIN_DIR)/$(PROJECT)
|
|
|
|
# === Rules ===
|
|
.PHONY: all clean run dirs
|
|
|
|
all: dirs $(BIN)
|
|
|
|
dirs:
|
|
@mkdir -p $(BIN_DIR)
|
|
@mkdir -p $(sort $(dir $(OBJ))) # create object subdirs that mirror source/
|
|
|
|
# Link objects into final executable
|
|
$(BIN): $(OBJ)
|
|
$(CC) $(OBJ) -o $@ $(LDFLAGS)
|
|
@echo "Linked -> $@"
|
|
|
|
# Compile each .c into a .o, with auto header deps
|
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
|
@echo "Compiled -> $@"
|
|
|
|
# Run the program
|
|
run: all
|
|
@echo "Running $(BIN)..."
|
|
@$(BIN)
|
|
|
|
# Clean build artifacts
|
|
clean:
|
|
@rm -rf $(OBJ_DIR) $(BIN)
|
|
@echo "Clean complete."
|
|
|
|
# Include auto-generated dependency files (if present)
|
|
-include $(DEP)
|