Improve Makefile debug functionality
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 2 Aug 2024 13:09:59 +0000 (15:09 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 2 Aug 2024 13:09:59 +0000 (15:09 +0200)
Makefile now creates .debug file when "make debug" is executed.
This make Makefile able to remember the debug mode for futher builds
and rebuilds. The debug mode can be disabled by removing the .debug file
or by executing "make nodebug" which will also build the project.

.gitignore
Makefile

index e41909e9aaa0c46172213f546f9e99add467a1aa..8350638d131c4466a45df617206ca0d86f5416f2 100644 (file)
@@ -2,3 +2,4 @@
 *.swp
 .libtemp
 tags
+.debug
index 5199275f6e7399d14772f076c08d1fb9db2f4d31..537e92de4a4f384da0365229b1e19c717631d7de 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,10 @@
 CC := cc
 CFLAGS := -std=c99 -Wall -Wextra -Werror -Wpedantic
+
+ifneq ("$(wildcard .debug)","")
+       CFLAGS += -g
+endif
+
 AR := ar
 
 RM := rm -f
@@ -149,8 +154,16 @@ NAME = libft.a
 
 all : $(NAME)
 
-debug : CFLAGS += -g
-debug : $(NAME)
+.debug :
+       $(MAKE) fclean
+       touch $@
+
+debug : .debug
+       $(MAKE) all
+
+nodebug :
+       $(RM) .debug
+       $(MAKE) re
 
 $(NAME) : $(OBJECTS)
        $(AR) rcs $@ $^