From e9c28e42e476933208437cdaaea5dc84404029d8 Mon Sep 17 00:00:00 2001 From: Edi De Candido Date: Mon, 17 Apr 2023 19:05:52 +0200 Subject: [PATCH] add Makefile's comment --- Makefile | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 7a13253..b7b0fb4 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,50 @@ -# VARIABLES -CXX = g++ -SRC_DIR = src -OBJ_DIR = .obj -INC_DIR = inc -WFLAGS = -Wall -OFLAG = -o -TARGET = main -EXEC = ./$(TARGET) -INCLUDE = -I $(INC_DIR) +# [--------------------DIRECTORIES--------------------] +# SRC_DIR is the source directory +# OBJ_DIR is the object directory +# INC_DIR is the header directory +SRC_DIR := src +OBJ_DIR := obj +INC_DIR := inc + +# [--------------------COMPILE & RUN--------------------] +# CXX is the keyword to compile .cpp src files +# WFLAG is a flag to detect all the warnings +# OFLAG is the flag to rename the output of the compiler +# TARGET is the name of the output +# INCLUDE add to g++ path the custom include path +CXX := g++ +WFLAGS := -Wall +OFLAG := -o +TARGET := main +INCLUDE := -I $(INC_DIR) -# FUNCTION: -SRCS := $(shell find $(SRC_DIR) -name "*.cpp") # extract all file in src/ -FILES := $(notdir $(basename $(SRCS))) # extract the name of the file -OBJS := $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(FILES))) # concat obj/ + FILES + .o +# [--------------------FUNCTION--------------------] +# SRCS extract all file in src/ +# FILES extract the name of the file +# OBJS concat obj/ + FILES + .o +SRCS := $(shell find $(SRC_DIR) -name "*.cpp") +FILES := $(notdir $(basename $(SRCS))) +OBJS := $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(FILES))) + all: execute execute: linking @ echo execute... - @ $(EXEC) + @ ./$(TARGET) @ echo ...terminate linking: $(OBJS) @ echo linking @ $(CXX) $(WFLAGS) $(OFLAG) $(TARGET) $(OBJS) -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR) @ echo compile $< @ $(CXX) $(WFLAGS) -c $< $(OFLAG) $@ $(INCLUDE) +$(OBJ_DIR): + mkdir -p $(OBJ_DIR) + clean: - @ -rm -f $(OBJS) \ No newline at end of file + @ rm -rf $(OBJ) \ No newline at end of file