Improve the make system
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 2 Aug 2024 13:50:14 +0000 (15:50 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 2 Aug 2024 13:50:14 +0000 (15:50 +0200)
Change the Makefile similarly to the last update of Libft.
Make now "remembers" the build settings and builds accordingly.

.gitignore
Makefile

index f4332b436df098e6830c2599e653c796f586d284..f0432f969ca2de44ecf7c7c1ff1e8ef9597eb88a 100644 (file)
@@ -1,3 +1,5 @@
 minishell
 *.[ao]
 tags
+.debug
+.noleaks
index 56d61706814defdd75343af30b68be0a997a79a9..0d8d3ef4d89f2f3600449a599d6cf26bb17bc272 100644 (file)
--- 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