diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index b51efab..3e55e4e 100644 --- a/.gitignore +++ b/.gitignore @@ -34,5 +34,7 @@ # Nix files flake.lock .direnv/ + +# Editor files .clangd .vscode/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1f2b015 --- /dev/null +++ b/Makefile @@ -0,0 +1,138 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2025/05/02 15:40:00 by rparodi ### ########.fr # +# # +# **************************************************************************** # + +# Variables + +# Name +NAME = ircserv + +# Commands +CXX = c++ +RM = rm -rf + +# Flags +# Mandatory flags for 42 +CXXFLAGS = -Werror -Wextra -Wall -std=c++98 +# Flags to have the dependences (can be removed for correction) +# Flags to have the debug (can be removed for correction) +DEBUG = -g3 +# DEBUG += -fsanitize=address +CXXFLAGS += $(DEBUG) + +# Sources +SRC = main.cpp + +INC_DIR = + +CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP + +# Flags to have the dependences (can be removed for correction) +# DEBUG = -g3 +# CPPFLAGS += $(DEBUG) + +# Objects +OBJDIRNAME = ./build +OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o)) + +# Colors +GREEN = \033[32m +GREY = \033[0;90m +RED = \033[0;31m +GOLD = \033[38;5;220m +END = \033[0m + +# Rules + +# All (make all) +all: header $(NAME) footer + +# Clean (make clean) +clean: + @printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n' + @printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n' + @$(RM) $(OBJDIRNAME) + +# Clean (make fclean) +fclean: clean + @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' + @$(RM) $(NAME) + @echo "" + +# Restart (make re) +re: header fclean all + +# Dependences for all +$(NAME): $(OBJ) + @mkdir -p $(OBJDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(NAME) $(OBJ) + +# Creating the objects +$(OBJDIRNAME)/%.o: %.cpp + @mkdir -p $(dir $@) + @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' + @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $< + +debug: CPPFLAGS += -D DEBUG=1 +debug: re + +test: debug + @printf '$(GREY) now running with\n\t- Port:\t$(GREEN)4243$(GREY)\n\t-Password:\t$(GREEN)irc$(END)\n' + @./$(NAME) 4243 irc + +# Header +header: + @clear + @printf '\n\n' + @printf '$(GOLD) ******* ****** ******* $(END)\n' + @printf '$(GOLD) ****** *** ******* $(END)\n' + @printf '$(GOLD) ******* * ******* $(END)\n' + @printf '$(GOLD) ****** ******* $(END)\n' + @printf '$(GOLD) ******* ******* $(END)\n' + @printf '$(GOLD) ******************* ******* * $(END)\n' + @printf '$(GOLD) ******************* ******* *** $(END)\n' + @printf '$(GOLD) ****** ******* ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GREY) Made by rparodi$(END)\n\n' + +# Footer +footer: + @printf "\n" + @printf "$(GOLD) ,_ _,$(END)\n" + @printf "$(GOLD) | \\___//|$(END)\n" + @printf "$(GOLD) |=6 6=|$(END)\n" + @printf "$(GOLD) \\=._Y_.=/$(END)\n" + @printf "$(GOLD) ) \` ( ,$(END)\n" + @printf "$(GOLD) / \\ (('$(END)\n" + @printf "$(GOLD) | | ))$(END)\n" + @printf "$(GOLD) /| | | |\\_//$(END)\n" + @printf "$(GOLD) \\| |._.| |/-\`$(END)\n" + @printf "$(GOLD) '\"' '\"'$(END)\n" + @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' + +clangd: + @printf "CompileFlags:\n" > ./.clangd + @printf " Add:\n" >> ./.clangd + @printf " - \"-xc++\"\n" >> ./.clangd + @for FLAG in $(CXXFLAGS); do \ + printf " - \"$$FLAG\"\n" >> ./.clangd; \ + done + @printf " - \"-I"$(shell pwd)"/\"\n" >> .clangd; + @for file in $(INC_DIR); do \ + printf " - \"-I"$(shell pwd)"/"$$file"\"" >> .clangd; \ + done + @printf "\n" >> ./.clangd + @printf '$(GREY) Now parsing settings is set in $(END)$(GREEN)./.clangd$(END)\n' + +# Phony +.PHONY: all clean fclean re clangd debug test +-include ${OBJ:.o=.d} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8544b58 --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "Shell for ft_irc 42 project"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in { + devShells.default = pkgs.mkShell { + name = "cpp-42"; + buildInputs = with pkgs; [ + clang + clang-tools + irssi + ] ++ ( + if pkgs.stdenv.isLinux then [ + valgrind + ] else [] + ); + + shellHook = '' + export NIX_SHOW_STATS=0 + export NIX_HIDE_STATS=1 + export CXX=clang++ + export CXXFLAGS="-std=cpp98 -Wall -Werror -Wextra" + printf "\n\033[0;90mCPP env loaded for: \033[38;5;220m${system}\033[0m\n" + ''; + }; + } + ); +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..1f5b6a4 --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include + +int main(int argc, char *argv[]) { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return 1; + } + std::cout << "Port:" << argv[1] << std::endl; + std::cout << "Password:" << argv[2] << std::endl; + return 0; +}