.PHONY
타겟과의 전투에서 나는 다음과 같이 썼다.Makefile : tar 파일을 만들 때 디렉토리 내용에 대한 의존성
# Makefile v0
tar:
tar -cf tarfile.tar dir
.PHONY: tar
:
# Makefile v1
tar: tarfile.tar
tarfile.tar: $(shell find dir)
tar -cf [email protected] dir
.PHONY: tar
장난감 예제에서 작동하는 것처럼 보입니다.
그러나 $(shell find dir)
가 평가되는 시간에 따라 이것이 잘못된 것을 할 수 있음을 알 수 있습니다. Makefile이 파싱 된 후 dir
에서 파일을 만들거나 삭제하는 규칙이있는 경우이 문제가 발생할 수 있습니다.
업데이트
@ user562374의 답을 바탕으로 더 나은 해결책이있는 것 같습니다.이 경우를 고려해보십시오.
# Makefile v2
tar: tarfile.tar
tarfile.tar: dir/.dirstamp
tar --create --exclude $< --file [email protected] $(<D)
dir/.dirstamp: .FORCE
[ ! -e [email protected] -o "$(find $(@D) -newer [email protected] -print -quit)" ] && touch [email protected]
dir/a: src/a
cp $< [email protected]
.FORCE:
.PHONY: .FORCE tar
이제 src/a
이 변경되었다고 가정합니다. tarfile.tar
와 dir/a
(직접 또는 간접이 아님)간에 종속성이 없으므로 tarfile.tar:
대상은 dir/a:
이전에 평가 될 수 있으므로 tarfile.tar
은 최신이 아닙니다.
그럼, 내 질문은 : 이러한 경우를 다루는 가장 좋은 방법은 무엇입니까? dir
에있는 파일 목록을 별도로 유지해야합니까? 그렇다면 가장 쉬운 방법은 무엇입니까?
니스. 이 답변을 바탕으로 collègue는'dirstamp' 대상에 대한 최적화 된 제조법을 제시했습니다. -e $ @ -o "$ (find subdir/-newer $ @ -print -quit)"] && touch $ @' –