set version with CPP instead of cabal-file-th; make building more robust

hledger and hledger-web were reading their version number (and program
name) from their cabal files at compile time using cabal-file-th,
which allowed the version number be maintained in one place (per
package).

This meant you had to be in same directory as the cabal file when
building, which made life more complicated, eg emacs compilation mode
could not jump to errors. Also, it slowed down building slightly, and
is a factor in hledger Debian packages being unavailable on a number
of platforms (we also use TH for report templates).

Now, the build version is set with a CPP VERSION flag, which seems
simpler overall. For cabal builds, this needs to be configured
manually in a few more places in each cabal file. For makefile builds,
it is set it to the name of the most recent darcs tag (which should be
more useful than the old behaviour). If not set, it defaults to the
blank string, useful eg for haddock. And, all makefile builds now run
from the top directory.
This commit is contained in:
Simon Michael 2012-10-13 19:21:17 +00:00
parent 7fec954cbf
commit f03b020e2f
5 changed files with 36 additions and 41 deletions

View File

@ -78,12 +78,14 @@ WEBFILES:= \
DOCFILES:= \
*.md
LASTTAG:=$(shell darcs show tags | head -1)
PATCHLEVEL:=$(shell expr `darcs changes --count --from-tag=\\\\\.` - 1)
WARNINGS:=-W -fwarn-tabs -fno-warn-name-shadowing #-fwarn-orphans -fwarn-simple-patterns -fwarn-monomorphism-restriction
DEFINEFLAGS:=
PREFERMACUSRLIBFLAGS=-L/usr/lib
GHCMEMFLAGS= #+RTS -M200m -RTS
BUILDFLAGS:=-rtsopts -DMAKE $(WARNINGS) $(INCLUDEPATHS) $(PREFERMACUSRLIBFLAGS) -DPATCHLEVEL=$(PATCHLEVEL) $(GHCMEMFLAGS) $(HCFLAGS)
BUILDFLAGS1:=-rtsopts -DMAKE -DPATCHLEVEL=$(PATCHLEVEL) $(WARNINGS) $(INCLUDEPATHS) $(PREFERMACUSRLIBFLAGS) $(GHCMEMFLAGS) $(HCFLAGS)
BUILDFLAGS:=$(BUILDFLAGS1) -DVERSION='"$(LASTTAG)"'
AUTOBUILDFLAGS:=$(BUILDFLAGS1) -DVERSION='\"$(LASTTAG)\"' # different quoting for sp
PROFBUILDFLAGS:=-prof -osuf hs_p #-prof-auto
LINUXRELEASEBUILDFLAGS:=-DMAKE $(WARNINGS) $(INCLUDEPATHS) -O2 -static -optl-static -optl-pthread
MACRELEASEBUILDFLAGS:=-DMAKE $(WARNINGS) $(INCLUDEPATHS) $(PREFERMACUSRLIBFLAGS) -O2 # -optl-L/usr/lib
@ -140,22 +142,22 @@ allcabal%:
# auto-recompile and run (something, eg --help or unit tests) whenever a module changes
auto: sp
cd hledger; $(AUTOBUILD) $(MAIN) -o ../bin/hledger $(BUILDFLAGS) --run --version
$(AUTOBUILD) $(MAIN) -o bin/hledger $(AUTOBUILDFLAGS) --run --version
autotest: sp
cd hledger; $(AUTOBUILD) $(MAIN) -o ../bin/hledger $(BUILDFLAGS) --run test
$(AUTOBUILD) $(MAIN) -o bin/hledger $(AUTOBUILDFLAGS) --run test
autotest-%: sp
cd hledger; $(AUTOBUILD) $(MAIN) -o ../bin/hledger $(BUILDFLAGS) --run test $*
$(AUTOBUILD) $(MAIN) -o bin/hledger $(AUTOBUILDFLAGS) --run test $*
autoweb: sp
cd hledger-web; $(AUTOBUILD) hledger-web.hs -o ../bin/hledger-web $(BUILDFLAGS) -DDEVELOPMENT --run -B --port 5001 --base-url http://localhost:5001 -f test.journal
cd hledger-web; $(AUTOBUILD) hledger-web.hs -o bin/hledger-web $(AUTOBUILDFLAGS) -DDEVELOPMENT --run -B --port 5001 --base-url http://localhost:5001 -f test.journal
autovty: sp
cd hledger-vty; $(AUTOBUILD) hledger-vty.hs -o ../bin/hledger-vty $(BUILDFLAGS) --run --help
cd hledger-vty; $(AUTOBUILD) hledger-vty.hs -o bin/hledger-vty $(AUTOBUILDFLAGS) --run --help
autochart: sp
cd hledger-chart; $(AUTOBUILD) hledger-chart.hs -o ../bin/hledger-chart $(BUILDFLAGS) --run --help
cd hledger-chart; $(AUTOBUILD) hledger-chart.hs -o bin/hledger-chart $(AUTOBUILDFLAGS) --run --help
# check for sp and explain how to get it if not found.
sp:
@ -169,11 +171,11 @@ hledgerall: bin/hledger hledger-web hledger-vty hledger-chart
# build hledger binary as quickly as possible
bin/hledger:
cd hledger; ghc --make $(MAIN) -o ../bin/hledger $(BUILDFLAGS)
ghc --make $(MAIN) -o bin/hledger $(BUILDFLAGS)
# build a GHC-version-specific hledger binary without disturbing with other GHC version builds
bin/hledger.ghc-%: $(SOURCEFILES)
cd hledger; ghc-$* --make $(MAIN) -o ../$@ $(BUILDFLAGS) -outputdir .ghc-$*
ghc-$* --make $(MAIN) -o $@ $(BUILDFLAGS) -outputdir .ghc-$*
# build hledger with the main supported GHC versions
bin/hledger.ghcall: \
@ -185,30 +187,30 @@ bin/hledger.ghcall: \
# build the fastest binary we can
bin/hledgeropt:
cd hledger; ghc --make $(MAIN) -o ../$@ $(BUILDFLAGS) -O2 # -fvia-C # -fexcess-precision -optc-O3 -optc-ffast-math
ghc --make $(MAIN) -o $@ $(BUILDFLAGS) -O2 # -fvia-C # -fexcess-precision -optc-O3 -optc-ffast-math
# build the time profiling binary. cabal install --reinstall -p some libs may be required.
bin/hledgerp:
cd hledger; ghc --make $(MAIN) -o ../$@ $(BUILDFLAGS) $(PROFBUILDFLAGS)
ghc --make $(MAIN) -o $@ $(BUILDFLAGS) $(PROFBUILDFLAGS)
# build the heap profiling binary for coverage reports and heap profiles.
# Keep these .o files separate from the regular ones.
hledgerhpc:
cd hledger; ghc --make $(MAIN) -fhpc -o ../bin/hledgerhpc -outputdir .hledgerhpcobjs $(BUILDFLAGS)
ghc --make $(MAIN) -fhpc -o bin/hledgerhpc -outputdir .hledgerhpcobjs $(BUILDFLAGS)
# build other executables quickly
bin/hledger-web:
cd hledger-web; ghc --make hledger-web.hs -o ../bin/hledger-web $(BUILDFLAGS)
cd hledger-web; ghc --make hledger-web.hs -o bin/hledger-web $(BUILDFLAGS)
bin/hledger-web-production:
cd hledger-web; ghc --make hledger-web.hs -o ../$@ $(BUILDFLAGS)
cd hledger-web; ghc --make hledger-web.hs -o $@ $(BUILDFLAGS)
bin/hledger-vty:
cd hledger-vty; ghc --make hledger-vty.hs -o ../bin/hledger-vty $(BUILDFLAGS)
cd hledger-vty; ghc --make hledger-vty.hs -o bin/hledger-vty $(BUILDFLAGS)
bin/hledger-chart:
cd hledger-chart; ghc --make hledger-chart.hs -o ../bin/hledger-chart $(BUILDFLAGS)
cd hledger-chart; ghc --make hledger-chart.hs -o bin/hledger-chart $(BUILDFLAGS)
# build portable releaseable binaries for gnu/linux
linuxbinaries: linuxbinary-hledger \
@ -238,7 +240,7 @@ macbinaries: macbinary-hledger \
# Clunky, does the link twice.
macbinary-%:
BINARY=`echo $(BINARYFILENAME) | sed -e 's/hledger/$*/'` ; \
LINKCMD=`cd $* && ghc -v --make $*.hs $(MACRELEASEBUILDFLAGS) -o ../bin/$$BINARY 2>&1 | egrep "bin/gcc.*bin/$$BINARY"` ; \
LINKCMD=`cd $* && ghc -v --make $*.hs $(MACRELEASEBUILDFLAGS) -o bin/$$BINARY 2>&1 | egrep "bin/gcc.*bin/$$BINARY"` ; \
PORTABLELINKCMD=`echo $$LINKCMD | sed -e 's/ -framework GMP//'` ; \
echo $$PORTABLELINKCMD; $$PORTABLELINKCMD
@ -481,7 +483,7 @@ viewcoverage:
# get a debug prompt
ghci:
cd hledger; ghci $(INCLUDEPATHS) $(MAIN)
ghci $(INCLUDEPATHS) $(MAIN)
ghci-vty:
ghci $(INCLUDEPATHS) hledger-vty/Hledger/Vty/Main.hs
@ -600,7 +602,6 @@ HADDOCK=haddock --no-warnings --prologue .haddockprologue #--optghc='-hide-packa
# we define HADDOCK to disable cabal-file-th code which requires a cabal file in the current dir
haddock: .haddockprologue
$(HADDOCK) --title "hledger-* API docs" \
--optghc '-DHADDOCK' \
-o site/api \
--html \
--source-module=src/%{MODULE/./-}.html \

View File

@ -7,7 +7,6 @@ module Hledger.Web.Options
where
import Prelude
import Data.Maybe
import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pkgVersion)
import System.Console.CmdArgs
import System.Console.CmdArgs.Explicit
@ -15,12 +14,11 @@ import Hledger.Cli hiding (progname,version,prognameandversion)
import Hledger.Web.Settings
progname, version :: String
#if HADDOCK
progname = ""
version = ""
progname = "hledger-web"
#ifdef VERSION
version = VERSION
#else
progname = $(packageVariable (pkgName . package))
version = $(packageVariable (pkgVersion . package))
version = ""
#endif
prognameandversion :: String
prognameandversion = progname ++ " " ++ version :: String

View File

@ -1,4 +1,5 @@
name: hledger-web
-- also in cpp-options below
version: 0.18.2
category: Finance
synopsis: A web interface for the hledger accounting tool.
@ -77,7 +78,7 @@ library
Hledger.Web.Handlers
ghc-options: -Wall -O0 -fno-warn-unused-do-bind
cpp-options: -DDEVELOPMENT
cpp-options: -DVERSION="0.18.2" -DDEVELOPMENT
extensions: TemplateHaskell
QuasiQuotes
@ -93,7 +94,7 @@ executable hledger-web
Buildable: False
if flag(dev)
cpp-options: -DDEVELOPMENT
cpp-options: -DVERSION="0.18.2" -DDEVELOPMENT
ghc-options: -Wall -O0 -fno-warn-unused-do-bind
else
ghc-options: -Wall -O2 -fno-warn-unused-do-bind
@ -126,7 +127,6 @@ executable hledger-web
hledger == 0.18.2
, hledger-lib == 0.18.2
, base >= 4.3 && < 5
, cabal-file-th
, cmdargs >= 0.10 && < 0.11
, directory
, filepath

View File

@ -10,7 +10,6 @@ module Hledger.Cli.Version (
binaryfilename
)
where
import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pkgVersion)
import System.Info (os, arch)
import Text.Printf
@ -19,12 +18,11 @@ import Hledger.Utils
-- package name and version from the cabal file
progname, version, prognameandversion :: String
#if HADDOCK
progname = ""
version = ""
progname = "hledger"
#ifdef VERSION
version = VERSION
#else
progname = $(packageVariable (pkgName . package))
version = $(packageVariable (pkgVersion . package))
version = ""
#endif
prognameandversion = progname ++ " " ++ version

View File

@ -1,4 +1,5 @@
name: hledger
-- also in cpp-options below
version: 0.18.2
category: Finance
synopsis: The main command-line interface for the hledger accounting tool.
@ -40,8 +41,7 @@ flag threaded
Default: True
library
-- XXX should set patchlevel here as in Makefile
cpp-options: -DPATCHLEVEL=0
cpp-options: -DVERSION="0.18.2"
ghc-options: -W
-- should be the same as below
exposed-modules:
@ -64,7 +64,7 @@ library
build-depends:
hledger-lib == 0.18.2
,base >= 4.3 && < 5
,cabal-file-th
-- ,cabal-file-th
,containers
,cmdargs >= 0.10 && < 0.11
,directory
@ -110,8 +110,7 @@ executable hledger
Hledger.Cli.Print
Hledger.Cli.Register
Hledger.Cli.Stats
-- XXX should set patchlevel here as in Makefile
cpp-options: -DPATCHLEVEL=0
cpp-options: -DVERSION="0.18.2"
ghc-options: -W
if flag(threaded)
ghc-options: -threaded
@ -119,7 +118,6 @@ executable hledger
build-depends:
hledger-lib == 0.18.2
,base >= 4.3 && < 5
,cabal-file-th
,containers
,cmdargs >= 0.10 && < 0.11
,directory