makefile

Posted howld

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了makefile相关的知识,希望对你有一定的参考价值。

SRC_DIR  := src/
INC_DIR  := include/
OBJ_DIR  := build/
DEP_DIR  := build/
EXE_DIR  := build/
SRC      := $(notdir $(shell ls $(SRC_DIR)*.cpp))
OBJ      := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(notdir $(SRC)))
DEP      := $(patsubst %.cpp,$(DEP_DIR)%.d,$(notdir $(SRC)))
LIBFLAGS :=
CXXFLAGS := -Wall -std=c++11 -DWIN32
INCFLAGS := -I$(INC_DIR) 
EXE      := $(EXE_DIR)main.exe

vpath %.cpp $(SRC_DIR)

.PHONY: run clean

$(EXE): $(OBJ)
    $(CXX) -o $(EXE) $(OBJ) $(LIBFLAGS)

run:
    ./$(EXE)

clean:
    rm -f $(OBJ_DIR)*.o $(DEP_DIR)*.d $(EXE)

$(OBJ_DIR)%.o: %.cpp
    $(CXX) -c $< -o [email protected] $(INCFLAGS) $(CXXFLAGS)

$(DEP_DIR)%.d: %.cpp
    @$(CXX) $< -MP -MM [email protected] [email protected]     -MT$(patsubst %.d,$(OBJ_DIR)%.o,$(notdir [email protected]))     $(INCFLAGS) $(CXXFLAGS)

ifneq ($(MAKECMDGOALS),clean)
include $(DEP)
endif

 资料:

https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Preprocessor-Options.html#Preprocessor-Options

 

以上是关于makefile的主要内容,如果未能解决你的问题,请参考以下文章

Makefile文件语法

使用带有 NMake 样式 Makefile 的 clang-cl 无法回显

如何使用 makefile 使用 Visual Studio 编译代码

重建后的Makefile重新编译代码需要很多时间

Makefile

Makefile步步为营