-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
50 lines (37 loc) · 897 Bytes
/
Copy pathmakefile
File metadata and controls
50 lines (37 loc) · 897 Bytes
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
# --- Variables ---
# Compiler
CC = gcc
# Compiler Flags
CFLAGS = -Wall -Wextra -g -Iinclude -MMD -MP
# Linker Libraries
LDLIBS = -pthread
# Directories
SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin
# Executable Name
TARGET_EXEC = mar1server
TARGET = $(BIN_DIR)/$(TARGET_EXEC)
# --- Files ---
SOURCES = $(shell find $(SRC_DIR) -name '*.c')
OBJECTS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SOURCES))
DEPS = $(OBJECTS:.o=.d)
# --- Rules ---
.PHONY: all
all: $(TARGET)
# Rule to link the final executable
$(TARGET): $(OBJECTS)
@echo "Linking $(TARGET)..."
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LDLIBS)
@echo "Build complete: $(TARGET)"
# Pattern rule to compile .c files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@echo "Compiling $<..."
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
.PHONY: clean
clean:
@echo "Cleaning..."
rm -rf $(OBJ_DIR) $(BIN_DIR)
-include $(DEPS)