Description: jlink: Hash of module differs to expected hash recorded in java.base
 The cause is the use of dh_strip_nondeterminism late in the build
 process.  This reorganises the jmod files, which in turn changes their
 SHA256 checksums.  This would not be a problem, except that the
 checksums are saved in java.base.jmod *before* the use of
 dh_strip_nondeterminism.  Performing this stripping immediately after
 each jmod file is created results in the checksums being consistent
 throughout.
Author: Julian Gilbey <jdg@debian.org>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=944738
Forwarded: not-needed

--- a/make/CreateJmods.gmk
+++ b/make/CreateJmods.gmk
@@ -218,6 +218,15 @@
 
 # Create jmods in a temp dir and then move them into place to keep the
 # module path in $(IMAGES_OUTPUTDIR)/jmods valid at all times.
+# strip-nondeterminism requires the same timestamp as
+# dh_strip_nondeterminism uses, so we determine this first.
+# Fall back to the original behavior if the tools are missing for backports
+DSN_TIMESTAMP := $(shell perl -MDebian::Debhelper::Dh_Lib -e 'print get_source_date_epoch()' 2>/dev/null)
+ifneq (,$(DSN_TIMESTAMP))
+  ifneq (,$(wildcard /bin/strip-nondeterminism /usr/bin/strip-nondeterminism))
+    use_snt = yes
+  endif
+endif
 $(JMODS_DIR)/$(MODULE).jmod: $(DEPS)
 	$(call LogWarn, Creating $(patsubst $(OUTPUTDIR)/%, %, $@))
 	$(call MakeDir, $(JMODS_DIR) $(JMODS_TEMPDIR))
@@ -229,7 +238,11 @@
 	        --module-path $(JMODS_DIR) \
 	        $(JMOD_FLAGS) $(JMODS_TEMPDIR)/$(notdir $@) \
 	)
+ifeq ($(use_snt),yes)
+	strip-nondeterminism --timestamp $(DSN_TIMESTAMP) $(JMODS_TEMPDIR)/$(notdir $@) && $(MV) $(JMODS_TEMPDIR)/$(notdir $@) $@
+else
 	$(MV) $(JMODS_TEMPDIR)/$(notdir $@) $@
+endif
 
 TARGETS += $(JMODS_DIR)/$(MODULE).jmod
 
