From 51cdeeb245b27ea4125bdf17fed3ec0762460059 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 2 Aug 2024 15:50:14 +0200 Subject: [PATCH] Improve the make system Change the Makefile similarly to the last update of Libft. Make now "remembers" the build settings and builds accordingly. --- .gitignore | 2 ++ Makefile | 48 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index f4332b4..f0432f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ minishell *.[ao] tags +.debug +.noleaks diff --git a/Makefile b/Makefile index 56d6170..0d8d3ef 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,19 @@ CC := gcc CFLAGS = -std=c99 -Wall -Wextra -Werror -Wpedantic +ifneq ("$(wildcard .debug)","") + CFLAGS += -g +endif + +ifneq ("$(wildcard .noleaks)","") + CFLAGS += -DNOLEAKS +else + EXT_LIBS := readline + LINKS := $(addprefix -l, $(EXT_LIBS)) +endif + RM := rm -f -EXT_LIBS := readline -LINKS := $(addprefix -l, $(EXT_LIBS)) SUBPROJECTS := Libft @@ -31,21 +40,33 @@ NAME := minishell all : $(NAME) -debug : CFLAGS += -g -debug : $(NAME) +.PHONY : Libft/libft.a -noleaks : CFLAGS += -DNOLEAKS -noleaks : debug +debug : .debug + $(MAKE) -C Libft debug + $(MAKE) all + +nodebug : + $(MAKE) -C Libft nodebug + $(RM) .debug + $(MAKE) shallow_re + +noleaks : .noleaks + $(MAKE) all + +readline : + $(RM) .noleaks + $(MAKE) shallow_re + +.% : + $(MAKE) shallow_fclean + touch $@ $(NAME) : $(OBJECTS) Libft/libft.a $(CC) $(CFLAGS) -o $@ $^ $(LINKS) Libft/libft.a : | Libft/Makefile -ifneq (,$(findstring debug, $(MAKECMDGOALS))) - $(MAKE) -C Libft debug -else $(MAKE) -C Libft -endif %.o : %.c | Libft/Makefile $(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE) @@ -58,6 +79,13 @@ clean : fclean : clean $(RM) $(NAME) + $(MAKE) -C Libft fclean re : fclean $(MAKE) all + +shallow_fclean : clean + $(RM) $(NAME) + +shallow_re : shallow_fclean + $(MAKE) all -- 2.30.2