@matheusbsbs / matheus-bagliano / commits / fc36f6a6c9
Fork 0

Don't write directly to a make target ($@).

Otherwise, if make is suspended, or killed with prejudice, or if the system crashes, you could be left with an up-to-date, yet corrupt, generated file. I left off the `clean' addition, because I believe "make clean" should not remove wildcard patterns like "*+", on the off-chance that someone uses names like that for files they care about. Besides, in practice, those temporary files are left behind so rarely that they're not a bother, and they're removed again as part of the next build. [jc: sign-off?] Signed-off-by: Junio C Hamano <junkio@cox.net>

Jim Meyering committed May 25, 2006 at 18:52 UTC fc36f6a6c9e6d428dafee47f140f943b3e520240
1 file changed +20 -14
Makefile
+20 -14
@@ -496,37 +496,43 @@ $(BUILT_INS): git$X
496 rm -f $@ && ln git$X $@
497
498 common-cmds.h: Documentation/git-*.txt
499 - ./generate-cmdlist.sh > $@
499 + ./generate-cmdlist.sh > $@+
500 + mv $@+ $@
501
502 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
502 - rm -f $@
503 + rm -f $@ $@+
504 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
505 -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
506 -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
507 -e 's/@@NO_PYTHON@@/$(NO_PYTHON)/g' \
507 - $@.sh >$@
508 - chmod +x $@
508 + $@.sh >$@+
509 + chmod +x $@+
510 + mv $@+ $@
511
512 $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl
511 - rm -f $@
513 + rm -f $@ $@+
514 sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \
515 -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
514 - $@.perl >$@
515 - chmod +x $@
516 + $@.perl >$@+
517 + chmod +x $@+
518 + mv $@+ $@
519
520 $(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py
518 - rm -f $@
521 + rm -f $@ $@+
522 sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
523 -e 's|@@GIT_PYTHON_PATH@@|$(GIT_PYTHON_DIR_SQ)|g' \
524 -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
522 - $@.py >$@
523 - chmod +x $@
525 + $@.py >$@+
526 + chmod +x $@+
527 + mv $@+ $@
528
529 git-cherry-pick: git-revert
526 - cp $< $@
530 + cp $< $@+
531 + mv $@+ $@
532
533 git-status: git-commit
529 - cp $< $@
534 + cp $< $@+
535 + mv $@+ $@
536
537 # These can record GIT_VERSION
538 git$X git.spec \
@@ -653,7 +659,8 @@ install-doc:
659 ### Maintainer's dist rules
660
661 git.spec: git.spec.in
656 - sed -e 's/@@VERSION@@/$(GIT_VERSION)/g' < $< > $@
662 + sed -e 's/@@VERSION@@/$(GIT_VERSION)/g' < $< > $@+
663 + mv $@+ $@
664
665 GIT_TARNAME=git-$(GIT_VERSION)
666 dist: git.spec git-tar-tree
@@ -724,4 +731,3 @@ check-docs::
731 *) echo "no link: $$v";; \
732 esac ; \
733 done | sort
727 -