-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
43 lines (31 loc) · 813 Bytes
/
Copy pathMakefile
File metadata and controls
43 lines (31 loc) · 813 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
CC = gcc
CFLAGS = -Wall -Wextra -Werror -Iinclude
SRC_DIR = src
APP_DIR = app
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/objects
TARGET = $(BUILD_DIR)/db
# All .c files inside src/
SRCS = $(wildcard $(SRC_DIR)/*.c)
# All .o files from src/
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
# Main file
MAIN = $(APP_DIR)/main.c
MAIN_OBJ = $(OBJ_DIR)/main.o
# Default target
all: $(TARGET)
# Link everything
$(TARGET): $(OBJ_DIR) $(OBJS) $(MAIN_OBJ)
$(CC) $(CFLAGS) $(OBJS) $(MAIN_OBJ) -o $(TARGET)
# Compile .c files inside src/
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Compile main.c separately
$(OBJ_DIR)/main.o: $(MAIN) | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Ensure build/objects exists
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
clean:
rm -rf $(BUILD_DIR)
.PHONY: all clean