我目前正在尝试建立一个适当的马克图案。
我想的是完全控制所发生的事情,因此我不想使用第三方软件。
我目前的尝试看来是逻辑的,但由于依赖性一代不是有效的,我不喜欢。
读写能力越好,全书就破碎。 如果有任何改进之处,我将不胜感激。
首先,我有以下固定定义:
CXX = g++
CXXFLAGS = -Wall
-Wextra
-Wuninitialized
-Wmissing-declarations
-pedantic
-O3
-p -g -pg
LDFLAGS = -p -g -pg
DEPFLAGS = -MM
Afaik 这应当罚款。 最好使貌相标志成为选择性的标志,但这并非重要。
SRC_DIR = ./src
OBJ_DIR = ./obj
SRC_EXT = .cpp
OBJ_EXT = .o
TARGET = ./bin/my_target
SRCS = $(wildcard $(SRC_DIR)/*$(SRC_EXT))
OBJS = $(subst $(SRC_DIR), $(OBJ_DIR), $(SRCS:$(SRC_EXT)=$(OBJ_EXT)))
DEP = depend.main
基本上,这应当只是从以下各分册中提取所有<代码>*.cpp的文档,并再以<代码>取代<代码>/src。
.PHONY: clean all depend
all: $(TARGET)
$(TARGET): $(OBJS)
@echo "-> linking $@"
@$(CXX) $^ $(LDFLAGS) -o $@
$(OBJ_DIR)/%.$(EXT_OBJ):
@echo "-> compiling $@"
@$(CXX) $(CXXFLAGS) -c $< -o $@
Afaik,这个区块——只要有有效的附属档案,就应当进行一切必要的汇编和连接。
clean:
@echo "removing objects and main file"
@rm -f $(OBJS) $(TARGET)
难道应该自我解释和正确,或者我在这里没有东西?
$(SRC_DIR)/%.$(SRC_EXT):
$(CXX) $(DEPFLAGS) -MT
"$(subst $(SRC_DIR),$(OBJ_DIR),$(subst $(SRC_EXT),$(OBJ_EXT),$@))"
$(addprefix ,$@) >> $(DEP);
clear_dependencies:
@echo "-> (re-)building dependencies";
@$(RM) $(DEP)
depend: clear_dependencies $(SRCS)
This is the non-functional part. What I intend to do is using the g++
Compiler flag -MM
to auto-create dependencies and using -MT
to use a different path than the default one.
The resulting dependency should look like
./obj/main.o: ./src/main.cpp ./src/some_header_file.h
Unfortunately, this will never be called and I lack the knowledge why this is the case.
In a similar question, user Beta gladly provided a temporary solution by adding a .Phony
but this has the side effect on rebuilding every object without any change.
最后,只有一个线。
-include $(DEP)
包括扶养档案,一旦建立。
Any answer providing some hints about any part are very welcome. So my question is: What can I do better or maybe "cleaner" and why doesn t the dependency generation work?