synix/templates/dev/c-hello/Makefile
sid 95a533c876
All checks were successful
Deploy docs / build-and-deploy (push) Successful in 3s
initial commit
2026-02-23 20:34:35 +01:00

51 lines
1.1 KiB
Makefile

PNAME = hello-world
BUILD_DIR = build
INCLUDE_DIR = include
SRC_DIR = src
CC = gcc
CFLAGS = -I$(INCLUDE_DIR) -Wall -Wextra -g
TARGET = $(BUILD_DIR)/$(PNAME)
SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
# Default target
all: $(TARGET)
# Build the executable
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $@
# Compile source files into object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Create the build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Run the executable
run: $(TARGET)
@$(TARGET)
# Clean built files
clean:
rm -rf $(BUILD_DIR)
# Clean then build
rebuild: clean all
# Display help information
help:
@echo "Makefile Usage:"
@echo ""
@echo " make - Builds the executable (default)"
@echo " make all - Same as 'make'"
@echo " make run - Builds the executable if needed and then runs it"
@echo " make clean - Removes the build directory and all built files"
@echo " make rebuild - Performs a clean first, then builds the project"
@echo " make help - Displays this help message"
.PHONY: all clean run rebuild help