From: Lukas Jiriste Date: Fri, 25 Oct 2024 11:00:04 +0000 (+0200) Subject: Change Makefile to invoke g++ -MM for dependencies X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=83d1541b491bcf46b4347d01671685578ef372fc;p=42%2FCPP_Module_04 Change Makefile to invoke g++ -MM for dependencies The g++ -MM $(SOURCES) creates dependency list (without system deps) for all the sources in a format suitable for Makefile. I don't like using g++ just after making use of clang++ explicit as I don't know whether both of those are usually present on PCs. The solution would probably be to provide the g++ incompatible flag conditionally when c++ == clang++. --- diff --git a/ex01/Makefile b/ex01/Makefile index ca73b43..6b87155 100644 --- a/ex01/Makefile +++ b/ex01/Makefile @@ -1,6 +1,8 @@ CC := clang++ CFLAGS = -std=c++98 -Wall -Wextra -Werror -Wpedantic +DEP_GEN = g++ -MM + ifneq ("$(wildcard .debug)","") CFLAGS += -g -fno-limit-debug-info endif @@ -56,3 +58,11 @@ fclean : clean re : fclean $(MAKE) all + +depend: .depend + +.depend: $(SOURCES) + rm -f $@ + $(DEP_GEN) $^ > $@ + +include .depend