我的c ++项目具有以下通用Makefile。我最近将编译器从GNU转换为PGI编译器,发现依赖文件不再存储在BUILD_PATH中,而是存储在SRC_PATH中。无论如何,我可以将它们全部保存到BUILD_PATH以保持src文件夹清洁吗?
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
DEP = $(OBJECTS:.o=.d)
CPP_FLAGS = -std=c++11 -g -Wall -MD
.PHONY: default_target
default_target: release
.PHONY: release
release: dirs
@$(MAKE) all
.PHONY: dirs
dirs:
@echo "Creating directories"
@mkdir -p $(dir $(OBJECTS))
@mkdir -p $(BIN_PATH)
.PHONY: clean
clean:
@echo "Deleting $(BIN_NAME) symlink"
@$(RM) $(BIN_NAME)
@echo "Deleting directories"
@$(RM) -r $(BUILD_PATH)
@$(RM) -r $(BIN_PATH)
@$(RM) $(DEPS)
# checks the executable and symlinks to the output
.PHONY: all
all: $(BIN_PATH)/$(BIN_NAME)
@echo "Making symlink: $(BIN_NAME) -> $<"
@$(RM) $(BIN_NAME)
@ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
# Creation of the executable
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
@echo "Linking: $@"
$(CXX) $(CPPFLAGS) $(LFLAGS) -o $@ $(OBJECTS) $(LIBS)
# Add dependency files, if they exist
-include $(DEPS)
# Source file rules
# After the first compilation they will be joined with the rules from the
# dependency files to provide header dependencies
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compiling: $< -> $@"
$(CXX) $(CPP_FLAGS) $(LFLAGS) -c $< -o $@ $(LIBS)
[PGI
编译器描述'-MD':
-MD生成make依赖项列表,并将它们打印到文件file.d,其中file是正在编译的文件的根名称。
它不提供任何控制位置的选项。同样,GCC
:
-MD -MD等效于-M -MF文件,除了未隐含-E以外。驱动程序确定文件根据是否指定了-o选项。如果是,则驱动程序使用其参数,但带有.d的后缀,否则使用输入文件的名称,删除所有目录组件和后缀,并应用.d后缀。
在表面上,两个选项:
我认为#1更容易:
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compiling: $< -> $@"
$(CXX) $(CPP_FLAGS) $(LFLAGS) -c $< -o $@ $(LIBS)
[ -f "${^D}/$*.d" ] && mv -f "${^D}/${*}.d" "${@D}/" || true
无法使用PGI编译器进行测试(对我来说没有PGI编译器,所以我希望它可以实际使用。)>