0

我正在为一个网站编写一个makefile。

我有一个名为src/andbuild/

基本上,我想获取这样的文件:

src/index.html
src/blog/title1/index.html
src/blog/title2/index.html

并将它们复制到这样的build/目录中:

build/index.html
build/blog/title1/index.html
build/blog/title2/index.html

我尝试编写规则,但我不确定如何调试:

src_html := src/**/*.html
build_html := $(shell find src -name '*.html' | sed 's/src/build/')

$(src_html): $(build_html)
    @cp $< $@
4

3 回答 3

2

如果你安装了 rsync,你可以使用它。

default:
        rsync -r --include '*/' --include='*.html' --exclude='*' src/ build/
于 2015-01-14T04:37:12.170 回答
1

尝试这样的事情:

#! /bin/bash

# get htm files
find . -name '*html' > files

# manipulate file location
sed 's/src/build/' files | paste files - > mapping

# handle spaces in the file names
sed 's/ /\\ /' mapping > files

# output mapping to be sure.
cat files
echo "Apply mapping?[Y/n]"
read reply
[[ $reply =~ [Yy].* ]] || exit 1
# copy files from column one to column two
awk '{ system("cp "$1" "$2)}' files

exit 0

编辑

不用等我有一个班轮:

$ find -name '*html' -exec bash -c 'file=$(echo {}); file=$(echo $file | sed "s:\/:\\\/:g"); cp "{}" $(echo ${file/src/build} | sed "s:\\\/:\/:g")' \;
于 2015-01-14T01:57:18.990 回答
1

为了完整起见,make可以使用静态模式规则处理这个问题:

src := src/index.html src/blog/title1/index.html src/blog/title2/index.html
# or src := $(shell find …) etc., but hopefully the makefile already has a list

dst := $(patsubst src/%,build/%,${src})
${dst}: build/%: src/% ; cp $< $@

.PHONY: all
all: ${dst}

这也是-j安全的,并且不会复制尚未更新的文件。

于 2015-01-15T13:48:20.853 回答