Makefile: make script-related rules usable from subdirectories

Git's Makefile provides a few nice features for script build and installation (substitute the first line with the right path, hardcode the path to Git library, ...). The Makefile already knows how to process files outside the toplevel directory with e.g. make SCRIPT_PERL=path/to/file.perl path/to/file but we can make it simpler for callers by exposing build, install and clean rules as .PHONY targets. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Feb 8, 2013 at 18:31 UTC 4c06b41888ab827b91e7ad7b7067889916847233
1 file changed +32 -3
Makefile
+32 -3
@@ -480,9 +480,38 @@ SCRIPT_PERL += git-svn.perl
480 SCRIPT_PYTHON += git-remote-testpy.py
481 SCRIPT_PYTHON += git-p4.py
482
483 -SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
484 - $(patsubst %.perl,%,$(SCRIPT_PERL)) \
485 - $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
483 +# Generated files for scripts
484 +SCRIPT_SH_GEN = $(patsubst %.sh,%,$(SCRIPT_SH))
485 +SCRIPT_PERL_GEN = $(patsubst %.perl,%,$(SCRIPT_PERL))
486 +SCRIPT_PYTHON_GEN = $(patsubst %.py,%,$(SCRIPT_PYTHON))
487 +
488 +# Individual rules to allow e.g.
489 +# "make -C ../.. SCRIPT_PERL=contrib/foo/bar.perl build-perl-script"
490 +# from subdirectories like contrib/*/
491 +.PHONY: build-perl-script build-sh-script build-python-script
492 +build-perl-script: $(SCRIPT_PERL_GEN)
493 +build-sh-script: $(SCRIPT_SH_GEN)
494 +build-python-script: $(SCRIPT_PYTHON_GEN)
495 +
496 +.PHONY: install-perl-script install-sh-script install-python-script
497 +install-sh-script: $(SCRIPT_SH_GEN)
498 + $(INSTALL) $(SCRIPT_SH_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
499 +install-perl-script: $(SCRIPT_PERL_GEN)
500 + $(INSTALL) $(SCRIPT_PERL_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
501 +install-python-script: $(SCRIPT_PYTHON_GEN)
502 + $(INSTALL) $(SCRIPT_PYTHON_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
503 +
504 +.PHONY: clean-perl-script clean-sh-script clean-python-script
505 +clean-sh-script:
506 + $(RM) $(SCRIPT_SH_GEN)
507 +clean-perl-script:
508 + $(RM) $(SCRIPT_PERL_GEN)
509 +clean-python-script:
510 + $(RM) $(SCRIPT_PYTHON_GEN)
511 +
512 +SCRIPTS = $(SCRIPT_SH_GEN) \
513 + $(SCRIPT_PERL_GEN) \
514 + $(SCRIPT_PYTHON_GEN) \
515 git-instaweb
516
517 ETAGS_TARGET = TAGS