-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
64 lines (50 loc) · 1.33 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Compiler settings
CC := gcc
CFLAGS := -Wall -Wextra -pedantic -std=gnu99 -O2 -fopenmp
CPPFLAGS := -MMD -MP -D_GNU_SOURCE
LDFLAGS := -fopenmp
# Directories
SRC_DIR := .
OBJ_DIR := obj
BIN_DIR := bin
# Source files and object files
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
# Target executable
TARGET := $(BIN_DIR)/spellcast_solver
SYMLINK := spellcast_solver
# Test executable
TEST_TARGET := $(BIN_DIR)/run_tests
# Phony targets
.PHONY: all clean test
# Default target
all: $(TARGET) $(SYMLINK)
# Linking the target executable
$(TARGET): $(filter-out $(OBJ_DIR)/tests.o, $(OBJS)) | $(BIN_DIR)
@echo "Linking $@..."
@$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
# Creating symlink
$(SYMLINK): $(TARGET)
@echo "Creating symlink $@..."
@ln -sf $< $@
# Compiling source files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
@echo "Compiling $<..."
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# Creating necessary directories
$(BIN_DIR) $(OBJ_DIR):
@mkdir -p $@
# Clean up
clean:
@echo "Cleaning up..."
@rm -rf $(OBJ_DIR) $(BIN_DIR) $(SYMLINK)
# Test target
test: $(TEST_TARGET)
@echo "Running tests..."
@./$(TEST_TARGET)
$(TEST_TARGET): $(filter-out $(OBJ_DIR)/main.o, $(OBJS)) | $(BIN_DIR)
@echo "Linking $@..."
@$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
# Include dependency files
-include $(DEPS)