是否可以同时将一个规则依赖于两个文件,并在其中一个文件发生更改时仅执行一次规则?
我正在将 SASS 源文件的编译添加到我的 Makefile 中。我用 Compass 编译它们,但它有自己的配置,其中指定了源文件夹和目标文件夹。Compass 不带任何参数执行,并将所有更改的 SASS 文件编译成相应的 CSS 文件。
假设我有两个 SASS 文件:
folder1/file1.scss
folder2/file2.scss
如果两个文件都改变了,只执行一次 compass 编译两个文件,不需要执行两次 Compass。我可以创建一个 Makefile,如果其中一个或两个文件都被更改,我只能在其中执行一次编译吗?说这样的话:
folder_out1/file1.css folder_out2/file2.css: folder1/file1.scss folder2/file2.scss
compass compile
编辑- 适用于 FreeBSD 的修正脚本(有一些小的改动):
#!/usr/bin/env bash
# Start fresh: delete all files and folders
rm -rf folder folder_out Makefile.mock mock_compass
# Create the input folder and files
mkdir folder
echo 1 > folder/file1.scss
echo 2 > folder/file2.scss
# Create mock compass command that creates output directories and copies
# input files to output files without transforming them
echo '
#!/usr/bin/env bash
if ! [ -d folder_out ]; then
mkdir folder_out
fi
cp folder/file1.scss folder_out/file1.css
cp folder/file2.scss folder_out/file2.css' > ./mock_compass
chmod +x mock_compass
# Create the Makefile
echo -e '
# Disable implicit rules to simplify debugging output
.SUFFIXES:
%: %,v
%: RCS/%
%: RCS/%,v
%: s.%
%: SCCS/s.%
folder_out/file1.css folder_out/file2.css: folder/file1.scss folder/file2.scss
\t@echo Running compass
\t./mock_compass
' > Makefile.mock
# Test it!
echo 'Initial build:'
gmake -f Makefile.mock
echo
echo 'Changing only file1'
touch folder/file1.scss
gmake -f Makefile.mock
echo
echo 'Changing only file2'
touch folder/file2.scss
gmake -f Makefile.mock
echo
echo 'Changing both'
touch folder/file1.scss folder/file2.scss
gmake -f Makefile.mock
echo