-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
89 lines (68 loc) · 1.91 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
88
89
#Directories and File Names
NAME := webserv
SRC_DIR := src
CGI_DIR := cgi_src
CGI_BIN_DIR := html/cgi-bin
BUILD_DIR := obj
MAIN := main.cpp
RM := rm -rf
HEADERS := inc/Webserv.hpp
CC := c++ --std=c++20
# Include Paths
INCLUDES := $(shell find inc -type d -exec echo -I {} \;)
#Compiler Flags
CFLAGS := -Wall -Wextra -Werror -Wunreachable-code
#Debug Flags
ifdef DEBUG
CFLAGS += -g -Og#-D DEBUG #-fsanitize=address,undefined #-D DEBUG
endif
ifdef FAST
CFLAGS += -Ofast -march=native -flto
endif
#Source files
SRC := $(wildcard $(SRC_DIR)/**/*.cpp)
CGI_SRC := $(wildcard $(CGI_DIR)/*.cpp)
# Object files
MAIN_OBJ := $(addprefix $(BUILD_DIR)/, $(MAIN:%.cpp=%.o))
OBJS := $(addprefix $(BUILD_DIR)/, $(SRC:$(SRC_DIR)/%.cpp=%.o))
CGI_OBJS := $(addprefix $(BUILD_DIR)/, $(CGI_SRC:$(CGI_DIR)/%.cpp=%.o))
# CGI targets
CGI_TARGETS := $(patsubst $(CGI_DIR)/%.cpp,$(CGI_BIN_DIR)/%.cgi,$(CGI_SRC))
# Colors
RED := \033[31m
BLUE := \033[34m
YELLOW := \033[33m
GREEN := \033[32m
RESET_COLOR := \033[0m
# Targets
all: $(NAME) $(CGI_TARGETS)
debug:
$(MAKE) DEBUG=1
rebug: fclean debug
fast:
$(MAKE) FAST=1
refast: fclean fast
cgi:
$(MAKE) $(CGI_TARGETS)
$(NAME): $(OBJS) $(MAIN_OBJ)
$(CC) $(CFLAGS) $(INCLUDES) $^ -o $(NAME)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(CGI_BIN_DIR)/%.cgi: $(CGI_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
@echo "$(GREEN)CGI script $@ created$(RESET_COLOR)"
@echo "$(GREEN)./$(NAME) executable created$(RESET_COLOR)"
# Cleaning Targets
clean:
@$(RM) ./obj
@$(RM) ./logDir/*
@echo "$(YELLOW)Object files deleted$(RESET_COLOR)"
@echo "$(YELLOW)Log deleted$(RESET_COLOR)"
fclean: clean
@$(RM) $(NAME)
@$(RM) $(CGI_BIN_DIR)/*.cgi
@echo "$(YELLOW)./$(NAME) executable deleted$(RESET_COLOR)"
re: fclean all
.PHONY: all clean fclean re debug cgi