Change Makefile to invoke g++ -MM for dependencies
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 25 Oct 2024 11:00:04 +0000 (13:00 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 25 Oct 2024 11:00:04 +0000 (13:00 +0200)
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++.

ex01/Makefile

index ca73b439eae44ad181140cc909c13387799dd7d1..6b8715560353629fad495d48331da89cce9214cd 100644 (file)
@@ -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