如何使用make保持文件同步?

时间:2019-04-28 01:07:17

标签: file recursion makefile synchronization

如果这样做:

ECHOCMD:=/bin/echo -e
SHELL := /bin/bash

GITIGNORE_SOURCE_PATH := ../.gitignore
GITIGNORE_DESTINE_PATH := ./setup/.gitignore

start_syncing: "${GITIGNORE_DESTINE_PATH}"
    printf '\n'

"${GITIGNORE_DESTINE_PATH}":
    cp -vr "${GITIGNORE_SOURCE_PATH}" ./setup/

每次调用"${GITIGNORE_DESTINE_PATH}"时,Make都会继续运行规则make,但是只有在修改源文件../.gitignore时,它才应调用它。

更新3

这是我建议在评论中使用的Make文件:

ECHOCMD:=/bin/echo -e
SHELL := /bin/bash

GITIGNORE_SOURCE_PATH := ../.gitignore
GITIGNORE_DESTINE_PATH := ./setup/.gitignore

start_syncing: "${GITIGNORE_DESTINE_PATH}"
    printf '\n'

${GITIGNORE_DESTINE_PATH}: ${GITIGNORE_SOURCE_PATH}
    cp -vr "${GITIGNORE_SOURCE_PATH}" ./setup/

运行它,它说:

$ ls -l ../.gitignore
-rwx---r-x+ 1 User None 488 Apr 27 23:23 ../.gitignore
$ ls -l ./setup/.gitignore
-rwx---r-x+ 1 User None 488 Apr 28 07:41 ./setup/.gitignore
$ make
make: *** No rule to make target '"./setup/.gitignore"', needed by 'start_syncing'.  Stop.

1 个答案:

答案 0 :(得分:0)

解决方案是从目标规则中删除双引号。如果名称上有空格,除了使用\

手动转义空格的值外,make不能做任何其他事情
ECHOCMD:=/bin/echo -e
SHELL := /bin/bash

GITIGNORE_SOURCE_PATH := ../.gitignore
GITIGNORE_DESTINE_PATH := ./setup/.gitignore

start_syncing: ${GITIGNORE_DESTINE_PATH}
    printf '\n'

${GITIGNORE_DESTINE_PATH}: ${GITIGNORE_SOURCE_PATH}
    cp -vr "${GITIGNORE_SOURCE_PATH}" ./setup/