-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
53 lines (40 loc) · 1.15 KB
/
Copy pathMakefile
File metadata and controls
53 lines (40 loc) · 1.15 KB
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
CC = gcc
CFLAGS = -Wall -Wextra -std=c11 -DVERSION=\"$(VERSION)\"
VERSION = 0.2.0
SRC_DIR = src
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
BIN_DIR = $(BUILD_DIR)/bin
# Get all .c files from src directory and its subdirectories
SRCS = $(wildcard $(SRC_DIR)/*.c) \
$(wildcard $(SRC_DIR)/container/*.c) \
$(wildcard $(SRC_DIR)/cgroup/*.c) \
$(wildcard $(SRC_DIR)/cli/*.c) \
$(wildcard $(SRC_DIR)/utils/*.c)
# Convert source files to object files
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
# Main binary name with version
BIN_NAME = tinydocker-$(VERSION)
.PHONY: all clean debug release
all: debug
# Debug build (default)
debug: CFLAGS += -g -DDEBUG
debug: $(BIN_DIR)/tinydocker
# Release build
release: CFLAGS += -O2
release: $(BIN_DIR)/$(BIN_NAME)
# Create necessary directories
$(OBJ_DIR) $(BIN_DIR):
mkdir -p $@
# Compile source files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# Link debug binary
$(BIN_DIR)/tinydocker: $(OBJS) | $(BIN_DIR)
$(CC) $(OBJS) -o $@
# Link release binary
$(BIN_DIR)/$(BIN_NAME): $(OBJS) | $(BIN_DIR)
$(CC) $(OBJS) -o $@
clean:
rm -rf $(BUILD_DIR)