Change hcompta-jcc to hcompta-lcc.
[comptalang.git] / GNUmakefile
index 2c8180f4012c16652604ee6f46f361fce2e7298c..128b88bc199d37f92a8e8cbb7e674a7feee60450 100644 (file)
@@ -15,9 +15,10 @@ GHC_PROF_CPUS:=
 GHC_PROF_PS_WIDTH:=11in
 GHC_PROF_RATE:=0.1
 GHC_PROF_CC_LENGTH:=50
-HCOMPTA_CLI_PROF:=$(CABAL_SANDBOX)/bin/hcompta-cli-prof
-HCOMPTA_COMMANDS:=balance
-# gl journal
+HCOMPTA_CLI_PROF:=$(CABAL_SANDBOX)/bin/hcompta-prof
+HCOMPTA_COMMANDS:=balance gl journal
+HCOMPTA_PACKAGES:=lib jcc ledger cli web
+HCOMPTA_IN_FORMATS:=jcc ledger
 commit:=$(shell if which git >/dev/null; then git describe --long; else echo COMMIT; fi)
 
 #
@@ -30,25 +31,53 @@ rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
 #
 ##  install
 ###
-install: cabal/install lib/install cli/install web/install
+install: cabal/install $(HCOMPTA_PACKAGES:=/install)
 cabal/install:
-       cabal update $(CABAL_FLAGS) $(CABAL_UPDATE_FLAGS)
-       cabal install -v $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) cabal
-.PHONY: lib cli web
-lib lib/install:
-       cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./lib
+       cabal $(CABAL_FLAGS) update $(CABAL_UPDATE_FLAGS)
+       cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) cabal
+.PHONY: $(HCOMPTA_PACKAGES)
+lib lib/install: \
+ cli/unregister \
+ web/unregister \
+ ledger/unregister \
+ jcc/unregister \
+ cli/unregister/sandbox \
+ web/unregister/sandbox \
+ ledger/unregister/sandbox \
+ jcc/unregister/sandbox
+       cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./lib
+jcc jcc/install: \
+ cli/unregister \
+ web/unregister \
+ cli/unregister/sandbox \
+ web/unregister/sandbox
+       cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./jcc
+ledger ledger/install: \
+ cli/unregister \
+ web/unregister \
+ cli/unregister/sandbox \
+ web/unregister/sandbox
+       cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./ledger
 cli cli/install:
-       cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./cli
+       cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./cli
 web web/install:
-       cabal install -v                    $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) alex happy
-       cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./web
+       cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) alex happy
+       cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./web
+
+%/recomp: CABAL_INSTALL_FLAGS+=--ghc-options -fforce-recomp
+%/recomp: %
+       
 
 #
 ##  clean
 ###
-clean: lib/clean cli/clean web/clean doc/clean
+clean: lib/clean $(HCOMPTA_PACKAGES:=/clean)
 lib/clean:
        (cd lib && cabal clean)
+jcc/clean:
+       (cd jcc && cabal clean)
+ledger/clean:
+       (cd ledger && cabal clean)
 cli/clean:
        (cd cli && cabal clean)
 web/clean:
@@ -57,13 +86,17 @@ web/clean:
 #
 ##  test
 ###
-test: lib/test cli/test web/test
+test: $(HCOMPTA_PACKAGES:=/test)
 lib/test:
-       (cd lib && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
+       (cd lib && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
+jcc/test:
+       (cd jcc && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
+ledger/test:
+       (cd ledger && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
 cli/test:
-       (cd cli && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
+       (cd cli && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
 web/test:
-       (cd web && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
+       (cd web && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
 %/install/test: CABAL_INSTALL_FLAGS+=--enable-tests
 %/install/test: %/install
        
@@ -72,17 +105,28 @@ web/test:
 ##  doc
 ###
 .PHONY: doc
-doc: doc/xhtml lib/doc cli/doc web/doc
-%/prof: CABAL_INSTALL_FLAGS+=-fprof --ghc-options -fforce-recomp --enable-library-profiling --enable-executable-profiling
-%/prof: $(CABAL_SANDBOX) %
-       
+doc: doc/xhtml $(HCOMPTA_PACKAGES:=/doc)
 
 lib/doc:
-       (cd lib && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
+       (cd lib && \
+       cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
+       cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
+jcc/doc:
+       (cd jcc && \
+       cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
+       cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
+ledger/doc:
+       (cd ledger && \
+       cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
+       cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
 cli/doc:
-       (cd cli && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
+       (cd cli && \
+       cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
+       cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
 web/doc:
-       (cd web && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
+       (cd web && \
+       cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
+       cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
 doc/%: .
        $(MAKE) -C doc $*
 
@@ -93,100 +137,151 @@ doc/%: .
 %/dev: %
        
 
+#
+##  dump
+###
+%/dump: CABAL_INSTALL_FLAGS+=-fdump
+%/dump: %
+       
+
+#
+##  hlint
+###
+hlint: $(HCOMPTA_PACKAGES:=/hlint.html)
+%/hlint: %/hlint.html
+       
+%/hlint.html: .
+       if hlint \
+        -i 'Redundant $$' \
+        -i 'Redundant bracket' \
+        -i 'Redundant do' \
+        -i 'Redundant lambda' \
+        -i "Use camelCase" \
+        -i 'Use if' \
+        -i 'Use String' \
+        -i 'Use string literal' \
+        --quiet --report="$@" \
+        "$*"/Hcompta; \
+       then rm -f "$@"; \
+       else echo; echo "BROWSE REPORT AT: file://$(abspath $@)"; fi
+
 #
 ##  prof
 ###
 .PHONY: prof
-prof: $(foreach command,$(HCOMPTA_COMMANDS),prof/$(command))
+prof: $(addprefix prof/,$(HCOMPTA_COMMANDS))
 
 prof/commit/$(commit):
        mkdir -p "$@"
 
-lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --ghc-options -fforce-recomp --enable-library-profiling
+lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
        
 
-cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --ghc-options -fforce-recomp --enable-library-profiling --enable-executable-profiling
+jcc/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
+jcc/install/prof: cli/unregister/sandbox web/unregister/sandbox jcc/install | $(CABAL_SANDBOX)
+       
+
+ledger/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
+ledger/install/prof: cli/unregister/sandbox web/unregister/sandbox ledger/install | $(CABAL_SANDBOX)
+       
+
+cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
 cli/install/prof: cli/install | $(CABAL_SANDBOX)
        mv \
-        $(CABAL_SANDBOX)/bin/hcompta-cli \
-        $(CABAL_SANDBOX)/bin/hcompta-cli-prof
+        $(CABAL_SANDBOX)/bin/hcompta \
+        $(HCOMPTA_CLI_PROF)
 
 define prof/command
-
 prof/clean: prof/$(command)/clean
 
-prof/%.ledger/$(command)/clean: \
+endef
+
+define prof/in
+prof/%.$(in)/clean: \
+ $(foreach command,$(HCOMPTA_COMMANDS), \
+  $(foreach journal,$(HCOMPTA_IN_FORMATS), \
+  prof/%.$(in)/$(command)/clean ))
+       
+
+endef
+
+define prof/command/in
+
+prof/%.$(in)/$(command)/clean: \
  $(foreach hC,$(GHC_PROF_CATEGORIES), \
- prof/%.ledger/$(command)/$(hC)/clean \
+ prof/%.$(in)/$(command)/$(hC)/clean \
  )
        $$(call rmw, \
-        prof/$$*.ledger.$(command) \
+        prof/$$*.$(in).$(command) \
         )
 
 endef
 
 define prof/command/hC
+prof/$(command):                      prof/$(command)/$(hC)
+prof/$(command)/clean:                prof/$(command)/$(hC)/clean
+prof/$(command)/$(hC): \
+ $(addsuffix /$(command)/$(hC),$(wildcard prof/*.$(in)))
+prof/$(command)/$(hC)/clean:
+       $$(call rmw, \
+        prof/commit/$$(commit)/*.$(in).$(command).$(hC).aux \
+        prof/commit/$$(commit)/*.$(in).$(command).$(hC).hp \
+        prof/commit/$$(commit)/*.$(in).$(command).$(hC).prof \
+        prof/commit/$$(commit)/*.$(in).$(command).$(hC).ps \
+        prof/commit/$$(commit)/*.$(in).$(command).$(hC).stats \
+        )
 
-prof/$(command):                prof/$(command)/$(hC)
-prof/$(command)/clean:          prof/$(command)/$(hC)/clean
-prof/%.ledger/$(command):       prof/%.ledger.$(command)/$(hC)
-prof/%.ledger/$(command)/$(hC): prof/commit/$$(commit)/%.ledger.$(command).$(hC).ps
+endef
+
+define prof/command/in/hC
+prof/%.$(in)/$(command):       prof/%.$(in).$(command)/$(hC)
+prof/%.$(in)/$(command)/$(hC): prof/commit/$$(commit)/%.$(in).$(command).$(hC).ps
        
 
-prof/%.ledger.$(command): \
- prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
+prof/%.$(in).$(command): \
+ prof/commit/$$(commit)/%.$(in).$(command).$(hC).hs
 
-prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
-prof/%.ledger.$(command): \
+prof/commit/$$(commit)/%.$(in).$(command).$(hC).hp \
+prof/%.$(in).$(command): \
  $$(HCOMPTA_CLI_PROF) \
- prof/%.ledger \
+ prof/%.$(in) \
  | prof/commit/$$(commit)
        GHCRTS=' \
         -$(hC)$$(GHC_PROF_$(hC)) \
         -i$$(GHC_PROF_RATE) \
         -L$$(GHC_PROF_CC_LENGTH) \
         -N$$(GHC_PROF_CPUS) \
-        -tprof/commit/$(commit)/$$*.ledger.$(command).$(hC).stats \
+        -tprof/commit/$(commit)/$$*.$(in).$(command).$(hC).stats \
         -p \
         $$(GHCRTS)' \
        $$(HCOMPTA_CLI_PROF) $$(HCOMPTA_FLAGS) \
-        $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.ledger,$$^) \
-        >prof/$$*.ledger.$(command)
-       mv hcompta-cli-prof.hp   prof/commit/$(commit)/$$*.ledger.$(command).$(hC).hp
-       mv hcompta-cli-prof.prof prof/commit/$(commit)/$$*.ledger.$(command).$(hC).prof
+        $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.$(in),$$^) \
+        >prof/$$*.$(in).$(command)
+       mv $(notdir $(HCOMPTA_CLI_PROF)).hp   prof/commit/$(commit)/$$*.$(in).$(command).$(hC).hp
+       mv $(notdir $(HCOMPTA_CLI_PROF)).prof prof/commit/$(commit)/$$*.$(in).$(command).$(hC).prof
 
-prof/$(command)/$(hC): \
- $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
-prof/$(command)/$(hC)/clean:
+prof/%.$(in)/$(command)/$(hC)/clean:
        $$(call rmw, \
-        prof/commit/$$(commit)/*.ledger.$(command).$(hC).aux \
-        prof/commit/$$(commit)/*.ledger.$(command).$(hC).hp \
-        prof/commit/$$(commit)/*.ledger.$(command).$(hC).prof \
-        prof/commit/$$(commit)/*.ledger.$(command).$(hC).ps \
-        prof/commit/$$(commit)/*.ledger.$(command).$(hC).stats \
-        )
-prof/%.ledger/$(command)/$(hC)/clean:
-       $$(call rmw, \
-        prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).aux \
-        prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).hp \
-        prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).prof \
-        prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).ps \
-        prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).stats \
+        prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).aux \
+        prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).hp \
+        prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).prof \
+        prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).ps \
+        prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).stats \
         )
 
 endef
 
-prof/%.ledger/clean: \
- $(foreach command,$(HCOMPTA_COMMANDS), \
- prof/%.ledger/$(command)/clean \
- )
-       
-
+$(foreach in,$(HCOMPTA_IN_FORMATS), \
+ $(eval $(call prof/in)) )
 $(foreach command,$(HCOMPTA_COMMANDS), \
  $(eval $(call prof/command)) \
  $(foreach hC,$(GHC_PROF_CATEGORIES), \
-  $(eval $(call prof/command/hC)) ))
+  $(eval $(call prof/command/hC)) ) \
+ $(foreach in,$(HCOMPTA_IN_FORMATS), \
+  $(eval $(call prof/command/in)) \
+  $(foreach hC,$(GHC_PROF_CATEGORIES), \
+   $(eval $(call prof/command/in/hC)) )))
 
 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
        
@@ -195,19 +290,6 @@ $(foreach command,$(HCOMPTA_COMMANDS), \
 %.ps: %.hp
        (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
 
-#prof/%.ledger/clean:
-#      $(call rmw, \
-#       $(foreach command,$(HCOMPTA_COMMANDS), \
-#               prof/$*.ledger.$(command) \
-#               $(foreach hC,$(GHC_PROF_CATEGORIES),\
-#                       prof/commit/$(commit)/$*.ledger.$(command).$(hC).aux \
-#                       prof/commit/$(commit)/$*.ledger.$(command).$(hC).hp \
-#                       prof/commit/$(commit)/$*.ledger.$(command).$(hC).prof \
-#                       prof/commit/$(commit)/$*.ledger.$(command).$(hC).ps \
-#                       prof/commit/$(commit)/$*.ledger.$(command).$(hC).stats \
-#                        )))
-#      $(call rmdirw,prof/commit/$(commit))
-
 #
 ##  not-threaded
 ###
@@ -215,23 +297,35 @@ $(foreach command,$(HCOMPTA_COMMANDS), \
 %/not-threaded: %
        
 
+#
+##  ghc-pkg
+###
+unregister: $(HCOMPTA_PACKAGES:=/unregister)
+
+%/unregister: .
+       if    $(GHC_PKG) list       hcompta-$* | grep -q '^ * hcompta-$*-' ; \
+        then $(GHC_PKG) unregister hcompta-$* ; \
+        fi
+
+%/unregister/sandbox: GHC_PKG:=cabal sandbox hc-pkg
+%/unregister/sandbox: .
+       if    $(GHC_PKG) list       hcompta-$* | grep -q '^ * hcompta-$*-' ; \
+        then $(GHC_PKG) unregister hcompta-$* ; \
+        fi
+
 #
 ##  sandbox
 ###
 $(CABAL_SANDBOX):
-       cabal sandbox --sandbox="$@" init $(CABAL_FLAGS) $(CABAL_SANDBOX_FLAGS)
+       cabal $(CABAL_FLAGS) sandbox --sandbox="$@" $(CABAL_SANDBOX_FLAGS) init
 
 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg
 %/sandbox: %
        
 
 #
-##  ghc-pkg
+##  stats
 ###
-
-unregister: $(addsuffix /unregister,web cli lib)
-
-%/unregister:
-       if    $(GHC_PKG) list       hcompta-$* | grep -q '^ * hcompta-$*-' ; \
-        then $(GHC_PKG) unregister hcompta-$* ; \
-        fi
+.PHONY: stats
+stats:
+       gitstats . $@