-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (55 loc) · 1.96 KB
/
Copy pathMakefile
File metadata and controls
68 lines (55 loc) · 1.96 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g
# Paths
SRC_DIR = src
OBJ_DIR = build
# Object files
OBJS = $(OBJ_DIR)/main.o \
$(OBJ_DIR)/input_buffer.o \
$(OBJ_DIR)/statement.o \
$(OBJ_DIR)/meta_command.o \
$(OBJ_DIR)/execute.o \
$(OBJ_DIR)/table.o \
$(OBJ_DIR)/cursor.o \
$(OBJ_DIR)/node.o
TARGET = db
.PHONY: all clean run test format
# Default target
all: $(TARGET)
# Final binary
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
# Recompile .o files if .c or .h files they depend on change
$(OBJ_DIR)/main.o: $(SRC_DIR)/main.c \
$(SRC_DIR)/input_buffer.h \
$(SRC_DIR)/statement.h \
$(SRC_DIR)/meta_command.h \
$(SRC_DIR)/execute.h \
$(SRC_DIR)/table.h \
$(SRC_DIR)/common.h \
$(SRC_DIR)/cursor.h \
$(SRC_DIR)/node.h
$(OBJ_DIR)/input_buffer.o: $(SRC_DIR)/input_buffer.c $(SRC_DIR)/input_buffer.h
$(OBJ_DIR)/statement.o: $(SRC_DIR)/statement.c $(SRC_DIR)/statement.h $(SRC_DIR)/common.h
$(OBJ_DIR)/meta_command.o: $(SRC_DIR)/meta_command.c $(SRC_DIR)/meta_command.h $(SRC_DIR)/input_buffer.h
$(OBJ_DIR)/execute.o: $(SRC_DIR)/execute.c $(SRC_DIR)/execute.h $(SRC_DIR)/common.h $(SRC_DIR)/table.h
$(OBJ_DIR)/table.o: $(SRC_DIR)/table.c $(SRC_DIR)/table.h $(SRC_DIR)/common.h
$(OBJ_DIR)/cursor.o: $(SRC_DIR)/cursor.c $(SRC_DIR)/cursor.h $(SRC_DIR)/table.h
$(OBJ_DIR)/node.o: $(SRC_DIR)/node.c $(SRC_DIR)/node.h $(SRC_DIR)/table.h $(SRC_DIR)/cursor.h
# Generic compilation rule
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Run the compiled binary with a test db
run: $(TARGET)
./$(TARGET) mydb.db
# Clean build artifacts
clean:
rm -rf $(OBJ_DIR) $(TARGET) *.db
# Run tests (RSpec)
test: $(TARGET)
bundle exec rspec
# Format source files
format:
clang-format -style=Google -i $(SRC_DIR)/*.c $(SRC_DIR)/*.h