-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
87 lines (63 loc) · 1.94 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
CC = gcc
CFLAGS = -Wall -Werror -Wextra -Wpedantic -pedantic-errors \
-Wformat -Wformat-security -Wuninitialized -Wshadow \
-Wsign-compare -Wmissing-field-initializers -Iinclude
SRC_DIR = src
BUILD_DIR = build
DATA_DIR = data
APP_DIR = $(SRC_DIR)/app
DB_DIR = $(SRC_DIR)/database
SRCS = $(APP_DIR)/app.c $(APP_DIR)/utilities.c $(DB_DIR)/db.c $(SRC_DIR)/main.c
OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(notdir $(SRCS)))
TARGET = $(BUILD_DIR)/phonebook
all: setup $(TARGET)
setup:
@mkdir -p $(BUILD_DIR) $(DATA_DIR)
$(BUILD_DIR)/%.o: $(APP_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: $(DB_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/main.o: $(SRC_DIR)/main.c
$(CC) $(CFLAGS) -c $< -o $@
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $(TARGET)
run: all
@$(TARGET)
clean:
rm -rf $(BUILD_DIR) $(DATA_DIR)
.PHONY: all setup run clean
# CC = gcc
# CFLAGS = -Wall -Werror -Wextra -Wpedantic -pedantic-errors \
# -Wformat -Wformat-security -Wuninitialized -Wshadow \
# -Wsign-compare -Wmissing-field-initializers
# # Directories
# SRC_DIR = src
# BUILD_DIR = build
# DATA_DIR = data
# APP_DIR = $(SRC_DIR)/app
# DB_DIR = $(SRC_DIR)/database
# # Source and object files
# SRCS = $(APP_DIR)/app.c $(APP_DIR)/utilities.c $(DB_DIR)/db.c $(SRC_DIR)/main.c
# OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(notdir $(SRCS)))
# # Target executable
# TARGET = $(BUILD_DIR)/phonebook
# # Default rule
# all: setup $(TARGET)
# # Create necessary directories
# setup:
# @mkdir -p $(BUILD_DIR) $(DATA_DIR)
# # Build object files
# $(BUILD_DIR)/%.o: $(APP_DIR)/%.c
# $(CC) $(CFLAGS) -c $< -o $@
# $(BUILD_DIR)/%.o: $(DB_DIR)/%.c
# $(CC) $(CFLAGS) -c $< -o $@
# $(BUILD_DIR)/main.o: $(SRC_DIR)/main.c
# $(CC) $(CFLAGS) -c $< -o $@
# # Link the target executable
# $(TARGET): $(OBJS)
# $(CC) $(OBJS) -o $(TARGET)
# # Clean up build and data folders
# clean:
# rm -rf $(BUILD_DIR) $(DATA_DIR)
# # Phony targets
# .PHONY: all setup run clean