scl/Makefile

56 lines
1.9 KiB
Makefile
Raw Normal View History

2024-09-28 09:31:23 -04:00
NAME = scl
TARGET = $(NAME).out
2024-09-28 09:31:23 -04:00
SRC_DIR = src
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
TEST_DIR = test
TEST_BUILD_DIR = $(BUILD_DIR)/test
TEST_OBJ_DIR = $(TEST_BUILD_DIR)/obj
CC = clang
LINK = clang
CFLAGS = -Wall
LDFLAGS =
2024-09-28 09:31:23 -04:00
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES))
OBJ_FILES_NOMAIN = $(filter-out $(OBJ_DIR)/main.o, $(OBJ_FILES)) # Object files without main.c.
UNITY_C = $(TEST_DIR)/unity/unity.c
TEST_SRC_FILES = $(wildcard $(TEST_DIR)/*.c)
TEST_OBJ_FILES = $(patsubst $(TEST_DIR)/%.c, $(TEST_OBJ_DIR)/%.o, $(TEST_SRC_FILES))
2024-09-28 09:31:23 -04:00
2024-09-28 09:38:01 -04:00
all: $(TARGET)
2024-09-28 09:31:23 -04:00
# Link to final binary.
2024-09-28 09:38:01 -04:00
$(TARGET): $(OBJ_FILES)
@ echo -e "\x1b[37;1mLinking \x1b[0m\x1b[37m$(TARGET)\x1b[37;1m...\x1b[0m\x1b[37m $(CC) -o $(TARGET) $(OBJ_FILES) $(LDFLAGS)\x1b[0m"
@ $(LINK) -o $(TARGET) $(OBJ_FILES) $(LDFLAGS)
2024-09-28 09:31:23 -04:00
# Compile project sources.
2024-09-28 09:38:01 -04:00
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(SRC_DIR)/include/%.h
2024-09-28 09:31:23 -04:00
@ mkdir -p $(OBJ_DIR)
@ echo -e "\x1b[37;1mCompiling \x1b[0m\x1b[37m$<\x1b[37;1m... \x1b[0m\x1b[37m$(CC) $(CFLAGS) -c $< -o $@\x1b[0m"
2024-09-28 09:38:01 -04:00
@ $(CC) $(CFLAGS) -c $< -o $@
2024-09-28 09:31:23 -04:00
# Compile test sources.
$(TEST_OBJ_DIR)/%.o: $(TEST_DIR)/%.c
@ mkdir -p $(TEST_OBJ_DIR)
@ echo -e "\x1b[37;1mCompiling Test \x1b[0m\x1b[37m$<\x1b[37;1m... \x1b[0m\x1b[37m$(CC) $(CFLAGS) -I$(SRC_DIR)/include -c $< -o $@\x1b[0m"
@ $(CC) $(CFLAGS) -I$(SRC_DIR)/include -c $< -o $@
# Link the test executable.
test: $(TEST_OBJ_FILES) $(OBJ_FILES_NOMAIN) $(UNITY_C)
@ echo -e "\x1b[37;1mLinking test binary\x1b[0m\x1b[37m...\x1b[0m"
@ $(LINK) $(TEST_OBJ_FILES) $(OBJ_FILES_NOMAIN) $(UNITY_C) -o $(TEST_BUILD_DIR)/test.out
@ echo -e "\x1b[37;1mRunning tests\x1b[0m\x1b[37m...\x1b[0m"
@ ./$(TEST_BUILD_DIR)/test.out
2024-09-28 09:38:01 -04:00
clean:
@ echo -e "\x1b[37;1mCleaning up...\x1b[0m\x1b[37m $(OBJ_DIR)/*.o $(TEST_OBJ_DIR)/*.o $(TEST_BUILD_DIR)/test.out $(TARGET)\x1b[0m"
@ rm -rf $(OBJ_DIR)/*.o $(TEST_OBJ_DIR)/*.o $(TEST_BUILD_DIR)/test.out $(TARGET)
.PHONY: all clean test
2024-09-28 09:31:23 -04:00