Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (80 loc) · 2.75 KB
/
Copy pathMakefile
File metadata and controls
101 lines (80 loc) · 2.75 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
NAME = webserv
CXX = c++
# CXXFLAGS = -Wall -Wextra -Werror
# CXXFLAGS += -pedantic-errors
CXXFLAGS += -std=c++98
CXXFLAGS += -Wconversion -Wunreachable-code
ifeq ($(CXX), clang++)
CXXFLAGS += -fno-limit-debug-info
endif
CXXFLAGS += -g
CXXFLAGS += -O0
# CXXFLAGS += -g3
# CXXFLAGS += -DNDEBUG
OBJ_DIR = obj/
SRC_DIR = src/
INCLUDE_DIR = include/
CPPFLAGS += -I$(INCLUDE_DIR)
CPPFLAGS += -I$(SRC_DIR) # Add src include path here
SRCS = $(addprefix $(SRC_DIR), main.cpp)
SRCS += $(addprefix $(SRC_DIR), SocketUtils.cpp)
SRCS += $(addprefix $(SRC_DIR), HTTPConnxData.cpp)
SRCS += $(addprefix $(SRC_DIR), Config.cpp)
SRCS += $(addprefix $(SRC_DIR), CGI.cpp)
SRCS += $(addprefix $(SRC_DIR), HTTPServer.cpp)
SRCS += $(addprefix $(SRC_DIR), Constants.cpp)
SRCS += $(addprefix $(SRC_DIR), URLMatcher.cpp)
SRCS += $(addprefix $(SRC_DIR), Responses.cpp)
SRCS += $(addprefix $(SRC_DIR), Parser.cpp)
SRCS += $(addprefix $(SRC_DIR), Utils.cpp)
SRCS += $(addprefix $(SRC_DIR), ParserUtils.cpp)
OBJS = $(patsubst $(SRC_DIR)%.cpp,$(OBJ_DIR)%.o,$(SRCS))
HDRS = $(addprefix $(INCLUDE_DIR), debug.h )
HDRS += $(addprefix $(SRC_DIR), )
all: $(NAME) test
$(NAME): $(OBJS) $(HDRS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OBJS) $(LDFLAGS) -o $(NAME)
$(OBJ_DIR)%.o: $(SRC_DIR)%.cpp
mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
clean:
rm -f $(OBJS)
rm -rf $(OBJ_DIR)
fclean: clean
@rm -f $(NAME)
@rm -rf $(VENV_DIR)
@echo "Cleaned project and virtual environment"
re: clean all
# The idea is for this project to use run for production with extra flags to speed it up
# and optimize the binary size
ARGS = config/default.conf
run: all
@echo
@PATH=".$${PATH:+:$${PATH}}" && ./$(NAME) $(ARGS)
valrun: all
@echo
@PATH=".$${PATH:+:$${PATH}}" && valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt ./$(NAME) $(ARGS)
# Check if venv exists, create if not
# Makefile for webserver with automatic venv setup
# Makefiles always run commands in a subshell so activate is not possible
VENV_DIR = venv
PYTHON = python3
PIP = $(VENV_DIR)/bin/pip
PYTEST = $(VENV_DIR)/bin/pytest
# Virtual environment setup
venv:
@echo "Setting up virtual environment..."
@if [ ! -d "$(VENV_DIR)" ]; then \
$(PYTHON) -m venv $(VENV_DIR) || $(PYTHON) -m virtualenv $(VENV_DIR); \
$(PIP) install --upgrade pip; \
$(PIP) install pytest; \
if [ -f "tests/requirements.txt" ]; then $(PIP) install -r tests/requirements.txt; fi; \
echo "Virtual environment ready"; \
else \
echo "Virtual environment already exists"; \
fi
# Run tests in the venv
test: $(NAME) venv
@echo "Running tests..."
@$(PYTEST) tests/
.PHONY: all venv test clean fclean re run valrun