Makefileの修正
[YACASL2.git] / Makefile
index d85cacc..29e29f1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,44 +1,56 @@
-.PHONY: all build gtags \
-        check \
+.PHONY: all srcall gtags \
+        check valgrind \
         doc alldoc doc_inner \
         install uninstall \
         version gittag \
         clean src-clean gtags-clean \
         test-clean doc-clean doc_inner-clean
 
-CMD := casl2 comet2 dumpword
-
 CAT := cat
-CP := cp
-ECHO := echo
-GITTAG := git tag
+CP := cp -v
+ECHO := /bin/echo
+EXPR := expr
+GIT := git
+GREP := grep
 GTAGS := gtags
 INSTALL := install
 SED := sed
+WC := wc
 WHICH := which
+XARGS := xargs
 
 prefix ?= ~
 bindir ?= $(prefix)/bin
+libdir ?= $(prefix)/share
+
+VERSION := $(shell $(CAT) VERSION)
+
+VERSIONGITREF := $(shell $(GIT) show-ref -s --tags $(VERSION))
 
-VERSION = $(shell $(CAT) VERSION)
-VERSIONFILES = include/package.h test/system/casl2/opt_v/0.txt test/system/comet2/opt_v/0.txt test/system/dumpword/opt_v/0.txt
+MASTERGITREF := $(shell $(GIT) show-ref -s refs/heads/master)
 
-all: build doc gtags
+VERSIONFILES := include/version.h \
+        test/system/casl2_opt/opt_v/0.txt \
+        test/system/comet2_opt/opt_v/0.txt \
+        test/system/dumpword/opt_v/0.txt
 
-build: version
+CMDFILES := casl2 comet2 dumpword casl2rev
+
+all: build INSTALL gtags
+
+build:
        $(MAKE) -C src all
-       $(CP) $(addprefix src/,$(CMD)) ./
+       @(for f in $(CMDFILES); do if test src/$$f -nt $$f; then $(CP) src/$$f $$f; fi; done)
 
 gtags:
        $(if $(strip $(shell $(WHICH) $(GTAGS))),$(GTAGS),@$(ECHO) '$(GTAGS): not found')
 
-doc:
-       $(MAKE) -C doc base
-       $(MAKE) INSTALL
-
 INSTALL: doc/install.txt
        $(CP) $< $@
 
+doc/install.txt:
+       $(MAKE) -C doc base
+
 alldoc:
        $(MAKE) -C doc all
 
@@ -48,11 +60,17 @@ doc_inner:
 check:
        $(MAKE) -sC test/system
 
-install: casl2 comet2 dumpword install-info install-casl2lib
+valgrind:
+       $(MAKE) -sC test/system valgrind
+
+install: casl2 comet2 dumpword install-info
        $(INSTALL) -d $(bindir)
        $(INSTALL) $(CMD) $(bindir)/
 
-uninstall: uninstall-info uninstall-casl2lib
+install-info:
+       $(MAKE) -C doc install-info
+
+uninstall: uninstall-info
        $(RM) $(prefix $(bindir)/,$(CMD))
 
 version: $(VERSIONFILES)
@@ -61,8 +79,8 @@ version: $(VERSIONFILES)
 $(VERSIONFILES): VERSION
        @$(SED) -e "s/@@VERSION@@/$(VERSION)/g" $@.version >$@
 
-gittag: VERSION
-       $(GITTAG) $(VERSION)
+gittag:
+       if test `$(GIT) status -s | $(WC) -l` -gt 0; then $(ECHO) "Error: commit, first."; exit 1; fi; if test "$(VERSIONGITREF)" != "$(MASTERGITREF)"; then $(GIT) tag $(VERSION); fi
 
 distclean: cmd-clean src-distclean gtags-clean version-clean clean