diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4002b05 --- /dev/null +++ b/Makefile @@ -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