Files
ASCIIRenderer/Makefile
2025-12-17 21:31:12 +00:00

126 lines
3.0 KiB
Makefile

SRCDIR := src
INCDIR := include
OBJDIR := obj
BINDIR := bin
# Compiler and flags
CC := clang
CFLAGS := -std=c11 -Wall -Wextra -Wpedantic -Werror
CFLAGS += -Wshadow -Wconversion -Wdouble-promotion
CFLAGS += -Wformat=2 -Wundef -fno-common
CFLAGS += -I$(INCDIR)
# Target
TARGET := $(BINDIR)/ascii3d
# Source files
SRCS := $(wildcard $(SRCDIR)/*.c)
OBJS := $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DEPS := $(OBJS:.o=.d)
# Libraries
LDFLAGS := -lm
# Build modes
.PHONY: all debug release clean install uninstall help
# Default target
all: release
# Release build (optimized)
release: CFLAGS += -O3 -DNDEBUG -march=native -flto
release: LDFLAGS += -flto
release: $(TARGET)
# Debug build (with symbols and sanitizers)
debug: CFLAGS += -O0 -g3 -DDEBUG
debug: CFLAGS += -fsanitize=address,undefined
debug: LDFLAGS += -fsanitize=address,undefined
debug: $(TARGET)
# Profile build (optimized with debug symbols)
profile: CFLAGS += -O2 -g -pg
profile: LDFLAGS += -pg
profile: $(TARGET)
# Create directories
$(OBJDIR) $(BINDIR):
@mkdir -p $@
# Link
$(TARGET): $(OBJS) | $(BINDIR)
@echo "Linking $@..."
@$(CC) $(OBJS) -o $@ $(LDFLAGS)
@echo "Build complete: $@"
# Compile
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
@echo "Compiling $<..."
@$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
# Include dependencies
-include $(DEPS)
# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(OBJDIR) $(BINDIR)
@echo "Clean complete."
# Install to system
PREFIX ?= /usr/local
install: release
@echo "Installing to $(PREFIX)/bin..."
@install -d $(PREFIX)/bin
@install -m 755 $(TARGET) $(PREFIX)/bin/
@echo "Installation complete."
# Uninstall from system
uninstall:
@echo "Uninstalling from $(PREFIX)/bin..."
@rm -f $(PREFIX)/bin/ascii3d
@echo "Uninstallation complete."
# Run the program
run: release
@./$(TARGET)
# Run with demo text
demo: release
@./$(TARGET) -a HELLO
# Static analysis
analyze:
@echo "Running static analysis..."
@cppcheck --enable=all --std=c11 -I$(INCDIR) $(SRCDIR)/*.c
# Format code
format:
@echo "Formatting code..."
@clang-format -i $(SRCDIR)/*.c $(INCDIR)/*.h
# Help
help:
@echo "ASCII 3D Renderer - Build System"
@echo "================================"
@echo ""
@echo "Targets:"
@echo " all - Build release version (default)"
@echo " release - Build optimized release version"
@echo " debug - Build debug version with sanitizers"
@echo " profile - Build with profiling support"
@echo " clean - Remove build artifacts"
@echo " install - Install to system (PREFIX=/usr/local)"
@echo " uninstall - Remove from system"
@echo " run - Build and run"
@echo " demo - Build and run demo"
@echo " analyze - Run static analysis (requires cppcheck)"
@echo " format - Format source code (requires clang-format)"
@echo " help - Show this help"
@echo ""
@echo "Examples:"
@echo " make # Build release"
@echo " make debug # Build debug"
@echo " make run # Build and run"
@echo " make install PREFIX=~ # Install to home directory"