Added automatic dependency system to Makefile.

This commit is contained in:
Jérôme 2019-03-30 10:02:18 +01:00
parent 38b9a872f1
commit 8803ac9921
4 changed files with 24 additions and 14 deletions

View file

@ -1,8 +1,9 @@
# Declaration of variables
C = clang
C_FLAGS = -Wall
COMMON_FLAGS = -Wall -MMD
C_FLAGS = $(COMMON_FLAGS)
CC = clang++
CC_FLAGS = -Wall -std=c++17
CC_FLAGS = $(COMMON_FLAGS) -std=c++17
LD_FLAGS =
INCLUDES =
@ -15,7 +16,7 @@ OBJECTS = $(SOURCES:.cpp=.o)
# Main target
$(EXEC): $(COBJECTS) $(OBJECTS)
$(CC) $(LD_FLAGS) $(COBJECTS) $(OBJECTS) -o $(EXEC)
$(CC) $(COBJECTS) $(OBJECTS) -o $(EXEC) $(LD_FLAGS)
# To obtain object files
%.o: %.cpp
@ -25,9 +26,12 @@ $(EXEC): $(COBJECTS) $(OBJECTS)
%.o: %.c
$(C) $(INCLUDES) $(C_FLAGS) -o $@ -c $<
-include $(SOURCES:%.cpp=%.d)
-include $(CSOURCES:%.c=%.d)
# To remove generated files
clean:
rm -f $(COBJECTS) $(OBJECTS)
rm -f $(COBJECTS) $(OBJECTS) $(SOURCES:%.cpp=%.d) $(CSOURCES:%.c=%.d)
cleaner:
rm -f $(EXEC) $(COBJECTS) $(OBJECTS)
cleaner: clean
rm -f $(EXEC)

View file

@ -12,4 +12,3 @@ int main()
return 0;
}

1
test_c_lib.c Normal file
View file

@ -0,0 +1 @@
#include "test_c_lib.h"

6
test_c_lib.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef DEF_test_c_lib
#define DEF_test_c_lib
#endif