diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c4b17d7 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_flake diff --git a/.gitignore b/.gitignore index cd531cf..d96c101 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# ---> Nix +.direnv + # ---> C # Prerequisites *.d diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a77ad75 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +SHELL = bash + +NAME = ft_ping + +CC = clang + +OBJSDIR = obj/ + +SRCS = $(shell find . -name '*.cpp') + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o)) + +FLAGS = -Wall -Werror -Wextra -MMD -MP -g + +RED = \033[0;31m +GREEN = \033[0;32m +YELLOW = \033[1;33m +PURPLE = \e[0;35m +NC = \033[0m +DELETE = \x1B[2K\r + +ifeq ($(VERBOSE),true) + FLAGS += -D VERBOSE +endif + +all: $(NAME) + +$(NAME): $(OBJS) + @$(CC) $(FLAGS) -I . $(OBJS) -o $(NAME) + @printf "$(YELLOW)「✨」($(NAME)) Program compiled\n" + +$(OBJSDIR)%.o: %.cpp + @mkdir -p $(@D) + @$(CC) $(FLAGS) -I . -c $< -o $@ + @printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n" + +clean: + @rm -f $(OBJS) + @printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n" + +fclean: clean + @rm -f $(NAME) + @rm -Rf $(OBJSDIR) + @printf "$(RED)「🗑️」($(NAME)) Program deleted\n" + +re: fclean all + +.PHONY: clean fclean all re diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0a71b4e --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1754725699, + "narHash": "sha256-iAcj9T/Y+3DBy2J0N+yF9XQQQ8IEb5swLFzs23CdP88=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "85dbfc7aaf52ecb755f87e577ddbe6dbbdbc1054", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8622411 --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + description = "A devshell flake for my ft_ping project"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + + outputs = + { + nixpkgs, + self, + }: + let + supportedSystems = [ "x86_64-linux" ]; + + forEachSupportedSystem = + f: + nixpkgs.lib.genAttrs supportedSystems ( + system: + f { + pkgs = import nixpkgs { inherit system; }; + } + ); + in + { + devShells = forEachSupportedSystem ( + { pkgs }: + { + default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + gcc + clang + ]; + hardeningDisable = [ "all" ]; + packages = with pkgs; [ + gdb + valgrind + compiledb + inetutils + + nixfmt-rfc-style + ]; + }; + } + ); + }; +}