Finished makefile

This commit is contained in:
Kyler Olsen 2025-11-02 22:15:16 -07:00
parent 6d5e0fd99d
commit ef18ff2bc0
1 changed files with 7 additions and 5 deletions

View File

@ -1,7 +1,7 @@
# Makefile for SLS project
# Makefile for SLS project with automatic header dependencies
CC ?= gcc
CFLAGS ?= -std=c11 -Wall -Wextra -g -Iinclude
CFLAGS ?= -std=c11 -Wall -Wextra -g -Iinclude -MMD -MP
LDFLAGS ?=
SRCDIR := src
@ -18,7 +18,10 @@ OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
TEST_SOURCES := $(wildcard $(TESTDIR)/*.c)
TEST_OBJECTS := $(patsubst $(TESTDIR)/%.c,$(OBJDIR)/%.o,$(TEST_SOURCES))
.PHONY: all compile run test clean
# Include dependency files if they exist
-include $(OBJECTS:.o=.d) $(TEST_OBJECTS:.o=.d)
.PHONY: all build run test clean
# Default: build main program
all: $(TARGET)
@ -26,11 +29,10 @@ all: $(TARGET)
# Compile object files
build: $(OBJECTS)
# Rule to compile .c -> .o
# Rule to compile .c -> .o (handles both src and tests)
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Rule to compile test .c -> .o
$(OBJDIR)/%.o: $(TESTDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@