Add makefile

This commit is contained in:
Lily 2025-05-22 17:14:17 +10:00
parent 2ef7de5617
commit 3717c5f020

55
Makefile Normal file
View file

@ -0,0 +1,55 @@
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -O3 -flto
DEBUG_FLAGS = -g -DDEBUG
# Directories
SRCDIR = src
OBJDIR = obj
BINDIR = bin
# Source files
SOURCES = $(SRCDIR)/agg.c
OBJECTS = $(OBJDIR)/agg.o
TARGET = $(BINDIR)/agg
# Default target
all: $(TARGET)
# Create directories if they don't exist
$(OBJDIR):
mkdir -p $(OBJDIR)
$(BINDIR):
mkdir -p $(BINDIR)
# Compile object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Link executable
$(TARGET): $(OBJECTS) | $(BINDIR)
$(CC) $(OBJECTS) -o $@
# Debug build
debug: CFLAGS += $(DEBUG_FLAGS)
debug: $(TARGET)
# Clean build artifacts
clean:
rm -rf $(OBJDIR) $(BINDIR)
# Run the program
run: $(TARGET)
./$(TARGET)
# Install (copy to /usr/local/bin)
install: $(TARGET)
cp $(TARGET) /usr/local/bin/
# Uninstall
uninstall:
rm -f /usr/local/bin/agg
# Phony targets
.PHONY: all debug clean run install uninstall