Skip to content

Commit

Permalink
some improvements on makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcheel committed Jul 2, 2024
1 parent 9a7d1bf commit a3b8cb9
Showing 1 changed file with 60 additions and 66 deletions.
126 changes: 60 additions & 66 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,97 +1,91 @@

RESET := \033[1;97m
RED := \033[1;91m
GREEN := \033[1;92m
YELLOW := \033[1;93m
BLUE := \033[1;94m
PINK := \033[1;95m
CYAN := \033[1;96m
CLEAN_CAR = \033[2K\r

NAME := Webserv

# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jcheel-n <[email protected]. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/07/02 23:56:57 by jcheel-n #+# #+# #
# Updated: 2024/07/02 23:57:01 by jcheel-n ### ########.fr #
# #
# **************************************************************************** #

# Color codes
COLOR_RESET := \033[1;97m
COLOR_RED := \033[1;91m
COLOR_GREEN := \033[1;92m
COLOR_YELLOW := \033[1;93m
COLOR_BLUE := \033[1;94m
COLOR_PINK := \033[1;95m
COLOR_CYAN := \033[1;96m
CLEAN_CAR := \033[2K\r

# Program name
NAME := webserv

# Directories
DIRSRC := ./mandatory/src/

DIRINC := ./mandatory/inc/
OBJDST_DIR := ./mandatory/obj/

OBJDST_DIR := ./mandatory/obj/

SRCS := $(wildcard $(DIRSRC)*.cpp)
# Source and Header Files
SRC_WEBSERV = Attributes.cpp ListDir.cpp Server.cpp WebServerMAC.cpp \
CGI.cpp ListeningSocket.cpp ServerGetters.cpp WebservParser.cpp \
Environment.cpp Location.cpp ServerSetters.cpp filetype.cpp \
ExtendedString.cpp LocationParser.cpp StatusCode.cpp main.cpp \
FileContent.cpp Parser.cpp WebServer.cpp utils.cpp \
Header.cpp Recieve.cpp WebServerLNX.cpp \

INCS := $(wildcard $(DIRINC)*.hpp)
SRCS += $(addprefix $(DIRSRC), $(SRC_WEBSERV))

OBJS = $(SRCS:$(DIRSRC)%.cpp=$(OBJDST_DIR)%.o)
DSTS := $(SRCS:$(DIRSRC)%.cpp=$(OBJDST_DIR)%.d)
INC = $(DIRINC)
INCLUDE += $(addprefix -I , $(INC))
OBJS = $(SRCS:$(DIRSRC)%.cpp=$(OBJDST_DIR)%.o)
DEPS = $(OBJS:.o=.d)

# Commands
RM := rm -rfd
CC := c++

CC:= c++

# Compiler Flags
FLAGS := -Wall -Werror -Wextra -std=c++98 $(SYSTEM) -g #-fsanitize=address #-pedantic

ifeq (,$(findstring "Linux",$(shell uname -s)))
# System Detection
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
SYSTEM := -DLNX
endif
ifeq (,$(findstring "Darwin",$(shell uname -s)))
ifeq ($(UNAME_S), Darwin)
SYSTEM := -DMAC
endif

FLAGS := -Wall -Werror -Wextra -std=c++98 $(SYSTEM) -g #-fsanitize=address #-pedantic

all: print_system $(NAME)
all: print_system $(NAME)

print_system:
@printf "$(YELLOW)$(CLEAN_CAR)System compiles $(NAME) with $(shell uname -s)$(RESET)\n"
@printf "$(COLOR_YELLOW)$(CLEAN_CAR)System compiles $(NAME) with $(SYSTEM) $(COLOR_RESET)\n"

$(NAME): $(DSTS) $(OBJS)
$(NAME): $(OBJS)
@printf "$(CLEAN_CAR)Linking: $(NAME)\n"
@$(CC) $(FLAGS) -I $(DIRINC) $(OBJS) -o $(NAME)

$(OBJDST_DIR)%.o: $(DIRSRC)%.cpp $(OBJDST_DIR)%.d Makefile
$(OBJDST_DIR)%.o: $(DIRSRC)%.cpp Makefile
@mkdir -p $(OBJDST_DIR)
@printf "$(GREEN)$(CLEAN_CAR)Compiling $*.o: $(notdir $<) $(RESET)"
@$(CC) $(FLAGS) -c $(DIRSRC)$*.cpp -o $(OBJDST_DIR)$*.o

$(OBJDST_DIR)%.d: $(DIRSRC)%.cpp
@mkdir -p $(OBJDST_DIR)
@printf "$(BLUE)$(CLEAN_CAR)Creating Dependencies $*.d: $(notdir $<). with flag $(SYSTEM)$(RESET)"
@set -e; rm -f $@; \
$(CC) -M $(FLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$

print:
@echo "$(RESET)NAME: $(NAME)"
@echo "FLAGS: $(YELLOW)$(FLAGS)$(RESET)"
@echo "SRCS: $(YELLOW)$(SRCS)$(RESET)"
@echo "INCS: $(YELLOW)$(INCS)$(RESET)"
@echo OBJS: $(OBJS)
@echo DSTS: $(DSTS)
@echo OBJDST_DIR: $(OBJDST_DIR)
@echo DIRSRC: $(DIRSRC)
@echo DIRINC: $(DIRINC)
@echo FLAG SISTEMA: $(SYSTEM)
@printf "$(COLOR_GREEN)$(CLEAN_CAR)Compiling $*.o: $(notdir $<) $(COLOR_RESET)"
@$(CC) $(FLAGS) -MMD -MP -c $(INCLUDE) $< -o $@

clean:
@printf "$(RED)$(CLEAN_CAR)Removing objects folder $(OBJDST_DIR)$(RESET)\n"
$(RM) $(OBJDST_DIR)
@printf "$(COLOR_RED)$(CLEAN_CAR)Removing objects folder $(OBJDST_DIR)$(COLOR_RESET)\n"
@$(RM) $(OBJDST_DIR)

fclean: clean
@printf "$(RED)$(CLEAN_CAR)Removing executable object $(NAME)$(RESET)\n"
$(RM) $(NAME)
@printf "$(COLOR_RED)$(CLEAN_CAR)Removing executable object $(NAME)$(COLOR_RESET)\n"
@$(RM) $(NAME)

re: fclean all



PHONY: all clean fclean re print lnx print_system

.SILENT:

ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring re,$(MAKECMDGOALS)))
-include $(DSTS)
endif
endif


.SILENT: $(DEPS) $(OBJS) $(NAME)

-include $(DEPS)

0 comments on commit a3b8cb9

Please sign in to comment.