【问题标题】:How to copy files and retain the structure in gnu makefiles?如何复制文件并保留 gnu makefile 中的结构?
【发布时间】:2014-04-07 08:48:26
【问题描述】:

例如,给定当前目录中的文件列表,如何将文件复制到另一个目录。

dest_dir := /usr/bin/test

.PHONY: install
install: $(dest_dir)

#there files are in current directory
xpi_built := install.rdf \
             chrome.manifest \
             $(wildcard content/*.js) \
             $(wildcard content/*.xul) \
             $(wildcard content/*.xml) \
             $(wildcard content/*.css) \
             $(wildcard skin/*.css) \
             $(wildcard skin/*.png) \
             $(wildcard locale/*/*.dtd) \
             $(wildcard locale/*/*.properties)

#how to copy there files to another directory
$(dest_dir)/% : $(xpi_built)
    @mkdir -p $(dest_dir)
    @cp $< $@

如何将文件列表复制到目标目录中?

【问题讨论】:

    标签: makefile


    【解决方案1】:
    .PHONY: copy_files
    
    copy_files: $(xpi_built)
        @mkdir -p $(dest_dir)
        @cp $^ $(dest_dir)
    

    【讨论】:

    • cp -R 无法保留目录结构。
    • @Jichao:你是对的,我的错误,我会编辑。我还在研究一种变体,仅在确实需要复制文件时才复制文件(也就是说,如果它们尚未被复制,或者已经过时),但这很难简单。
    • 您可以添加一个虚拟目标/文件来跟踪它。也就是说,使用$(dest_dir)/.copyfiles: $(xpi_built),其中最后一条规则是touch $@$(dest_dir)/.copyfiles 文件上会有一个日期,因此只有在其中一个构建文件更新时才会更新它。另外,如果你核对 $(dest_dir),它会重新运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 2013-10-08
    • 1970-01-01
    • 2010-12-11
    相关资源
    最近更新 更多