diff --git a/.version b/.version new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/Makefile b/Makefile index 8f48c83..9649427 100644 --- a/Makefile +++ b/Makefile @@ -53,15 +53,24 @@ MANPAGES = $(addprefix $(SHAREDIR)/,gray.1 gray-convert.1 gray.ini.5 \ profiles.txt.5 beamdata.txt.5 magneticdata.txt.5) ## -## Git information (used in the version string) +## Version information ## +ifneq ($(wildcard .git/*),) +# We are building from a git checkout + # Short hash of the latest commit -GIT_REV ?= $(shell git rev-parse --short HEAD) +GIT_REV ?= $(shell git rev-parse --short HEAD) # Whether the worktree and the latest commit differs GIT_DIRTY ?= $(shell test -n "$$(git status --porcelain)" && echo "-dirty") +REVISION ?= $(GIT_REV)$(GIT_DIRTY) +else +# We are building from a release archive, use the version +REVISION ?= v$(file < .version) +endif + # Source date ifndef SOURCE_DATE_EPOCH # Use current date @@ -76,7 +85,7 @@ DATE=$(shell LC_TIME=C date -d @$(SOURCE_DATE_EPOCH) '+%B %Y') LD = $(FC) FFLAGS += -I$(INCDIR) -fpic LDFLAGS += -L$(LIBDIR) -CPPFLAGS += -DREVISION=\"$(GIT_REV)$(GIT_DIRTY)\" -DPREFIX=\"$(PREFIX)\" +CPPFLAGS += -DREVISION=\"$(REVISION)\" -DPREFIX=\"$(PREFIX)\" # Compiler-specific flags ifdef GNU diff --git a/default.nix b/default.nix index 98b8a01..cca5ff0 100644 --- a/default.nix +++ b/default.nix @@ -14,18 +14,19 @@ let sha256 = "007nv11r0z9fz593iwzn55nc0p0wj5lpgf0k2brhs1ynmikq9gjr"; }; - # Exclude this file and build artifacts + # Exclude this file, build artifacts and git source = builtins.filterSource (path: type: !builtins.elem path [ "configure.mk" "default.nix" "result" ] - && baseNameOf path != "build") ./.; + && baseNameOf path != "build" + && baseNameOf path != ".git") ./.; inherit (import nixpkgs {}) lib pkgs; in pkgs.stdenv.mkDerivation rec { pname = "gray"; - version = "0.1"; + version = builtins.readFile ./.version; src = source; doCheck = true; @@ -72,8 +73,6 @@ in (lib.enableFeature static "static") "--with-katex=${katex}" "--enable-deterministic" - "GIT_REV=${version}" - "GIT_DIRTY=" ]; meta = {