Skip to content

Instantly share code, notes, and snippets.

@hardfalcon
Last active April 23, 2022 21:44
Show Gist options
  • Save hardfalcon/6009404f2d52fcfcdb73d4daaf8c830a to your computer and use it in GitHub Desktop.
Save hardfalcon/6009404f2d52fcfcdb73d4daaf8c830a to your computer and use it in GitHub Desktop.
Build openjdk-lts 11.0.15+10 and openjdk-17 17.0.3+7 for Ubuntu 20.04, derived from existing packages openjdk-lts 11.0.14.1+1-0ubuntu1~20.04 and openjdk-17 17-17.0.2+8-0ubuntu1~20.04
#!/bin/bash
set -euo pipefail
export UBUMAIL="Pascal Ernster <pascal.ernster@localhost>"
# obtained timestamp from https://github.com/openjdk/jdk17u/releases/tag/jdk-17.0.3%2B7
export SOURCE_DATE_EPOCH=1650398209
pkgname="openjdk-17"
# openjdk-17 17.0.2+8-0ubuntu1~20.04
oldpkgver="17.0.2+8"
oldpkgversuffix1="-0ubuntu"
oldpkgversuffix2="1~20.04"
# openjdk-17 17.0.3+7-0ubuntu0~20.04
newpkgver="17.0.3+7"
newpkgversuffix1="-0ubuntu"
newpkgversuffix2="0~20.04"
mirror="http://archive.ubuntu.com/ubuntu"
export LC_ALL=C.UTF-8
scriptdir="$(dirname \"${0}\")"
workdir="${HOME}/build/${pkgname}"
oldpkgversuffix="${oldpkgversuffix1}${oldpkgversuffix2}"
oldgittag="jdk-${oldpkgver}"
newpkgversuffix="${newpkgversuffix1}${newpkgversuffix2}"
newgittag="jdk-${newpkgver}"
sudo tee "/etc/apt/sources.list.d/build-${pkgname}.list" >/dev/null <<EOF
deb ${mirror} focal main universe multiverse
deb-src ${mirror} focal main universe multiverse
deb ${mirror} focal-security main universe multiverse
deb-src ${mirror} focal-security main universe multiverse
deb ${mirror} focal-updates main universe multiverse
deb-src ${mirror} focal-updates main universe multiverse
deb ${mirror} focal-backports main universe multiverse
deb-src ${mirror} focal-backports main universe multiverse
deb ${mirror} focal-proposed main universe multiverse
deb-src ${mirror} focal-proposed main universe multiverse
EOF
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential devscripts ubuntu-dev-tools
sudo apt-get build-dep "${pkgname}"
mkdir --parents "${workdir}"
cd "${workdir}"
#apt-get source "openjdk-17=17.0.2+8-1~20.04"
apt-get source "${pkgname}=${oldpkgver}-${oldpkgversuffix2}"
cd "${pkgname}-${oldpkgver}"
# the existing watch file contains the wrong repo URL and does other strange things, so replace it with an adapted version of the watch file from openjdk-lts/openjdk-11
echo -e 'version=4\nopts="" \\\nhttps://github.com/openjdk/jdk17u/tags \\\n.*/jdk-([0-9.]*\+[0-9]*).tar.gz' > debian/watch
touch --date="@${SOURCE_DATE_EPOCH}" "debian/watch" "debian"
# find, download and repackage orig source code from upstream git repo
uscan --download --repack --compression xz
# finds and downloads ../jdk-17.0.3+7.tar.gz, repackages to ../openjdk-17_17.0.3+7.orig.tar.xz
touch --date="@${SOURCE_DATE_EPOCH}" "../${newgittag}.tar.gz" "../${pkgname}_${newpkgver}.orig.tar.xz"
uupdate --upstream-version="${newpkgver}" --find
cd "../${pkgname}-${newpkgver}"
# the existing watch file contains the wrong repo URL and does other strange things, so replace it with an adapted version of the watch file from openjdk-lts/openjdk-11
echo -e 'version=4\nopts="" \\\nhttps://github.com/openjdk/jdk17u/tags \\\n.*/jdk-([0-9.]*\+[0-9]*).tar.gz' > debian/watch
touch --date="@${SOURCE_DATE_EPOCH}" "debian/watch" "debian" .
# update version numbers in debian/rules file
sed --in-place "s|${oldgittag}|${newgittag}|g" "debian/rules"
touch --date="@${SOURCE_DATE_EPOCH}" "debian/rules" "debian" .
# fix patches
patch --strip=1 <<'EOF'
--- openjdk-17-17.0.2+8/debian/patches/reproducible-build-user.diff
+++ openjdk-17-17.0.3+7/debian/patches/reproducible-build-user.diff
@@ -1,14 +1,14 @@
Description: Makes the build user invariant to improve the reproducibility (it appears in the interval VM version in libjvm.so)
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
---- a/make/autoconf/basic.m4
-+++ b/make/autoconf/basic.m4
-@@ -97,7 +97,7 @@ AC_DEFUN_ONCE([BASIC_SETUP_PATHS],
-
- # Setup username (for use in adhoc version strings etc)
- # Outer [ ] to quote m4.
-- [ USERNAME=`$ECHO "$USER" | $TR -d -c '[a-z][A-Z][0-9]'` ]
-+ [ USERNAME="unknown" ]
+--- a/make/autoconf/jdk-version.m4
++++ b/make/autoconf/jdk-version.m4
+@@ -76,7 +76,7 @@ AC_DEFUN_ONCE([JDKVER_SETUP_JDK_VERSION_
+ USERNAME="$with_build_user"
+ else
+ # Outer [ ] to quote m4.
+- [ USERNAME=`$ECHO "$USER" | $TR -d -c '[a-z][A-Z][0-9]'` ]
++ [ USERNAME="unknown" ]
+ fi
AC_SUBST(USERNAME)
- ])
EOF
touch --date="@${SOURCE_DATE_EPOCH}" "debian/patches/reproducible-build-user.diff" "debian/patches" "debian" .
# update changelog
( cat; cat "${workdir}/${pkgname}-${oldpkgver}/debian/changelog" ) >"${workdir}/${pkgname}-${newpkgver}/debian/changelog" <<EOF
${pkgname} (${newpkgver}${newpkgversuffix}) focal-security; urgency=high
* OpenJDK ${newpkgver} build (release).
-- ${UBUMAIL} $(date --utc --date="@${SOURCE_DATE_EPOCH}" --rfc-email)
EOF
touch --date="@${SOURCE_DATE_EPOCH}" "debian/changelog" "debian" .
# build orig source tarball and dsc file
dpkg-source -b .
touch --date="@${SOURCE_DATE_EPOCH}" "../${pkgname}_${newpkgver}${newpkgversuffix}.dsc" "../${pkgname}_${newpkgver}${newpkgversuffix}.debian.tar.xz"
# build actual packages
dpkg-buildpackage
#!/bin/bash
set -euo pipefail
export UBUMAIL="Pascal Ernster <pascal.ernster@localhost>"
# obtained timestamp from https://github.com/openjdk/jdk11u/releases/tag/jdk-11.0.15%2B10
export SOURCE_DATE_EPOCH=1650397300
pkgname="openjdk-lts"
# openjdk-lts 11.0.14.1+1-0ubuntu1~20.04
oldpkgver="11.0.14.1+1"
oldpkgversuffix="-0ubuntu1~20.04"
# openjdk-lts 11.0.15+10-0ubuntu0~20.04
newpkgver="11.0.15+10"
newpkgversuffix="-0ubuntu0~20.04"
mirror="http://archive.ubuntu.com/ubuntu"
export LC_ALL=C.UTF-8
scriptdir="$(dirname \"${0}\")"
workdir="${HOME}/build/${pkgname}"
oldgittag="jdk-${oldpkgver}"
newgittag="jdk-${newpkgver}"
sudo tee "/etc/apt/sources.list.d/build-${pkgname}.list" >/dev/null <<EOF
deb ${mirror} focal main universe multiverse
deb-src ${mirror} focal main universe multiverse
deb ${mirror} focal-security main universe multiverse
deb-src ${mirror} focal-security main universe multiverse
deb ${mirror} focal-updates main universe multiverse
deb-src ${mirror} focal-updates main universe multiverse
deb ${mirror} focal-backports main universe multiverse
deb-src ${mirror} focal-backports main universe multiverse
deb ${mirror} focal-proposed main universe multiverse
deb-src ${mirror} focal-proposed main universe multiverse
EOF
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential devscripts ubuntu-dev-tools
sudo apt-get build-dep "${pkgname}"
mkdir --parents "${workdir}"
cd "${workdir}"
apt-get source "${pkgname}=${oldpkgver}${oldpkgversuffix}"
cd "${pkgname}-${oldpkgver}"
# find, download and repackage orig source code from upstream git repo
uscan --download --repack --compression xz
# finds and downloads ../jdk-11.0.15+10.tar.gz, repackages to ../openjdk-lts_11.0.15+10.orig.tar.xz
touch --date="@${SOURCE_DATE_EPOCH}" "../${newgittag}.tar.gz" "../${pkgname}_${newpkgver}.orig.tar.xz"
uupdate --upstream-version="${newpkgver}" --find
cd "../${pkgname}-${newpkgver}"
# update version numbers in debian/rules file
sed --in-place "s|${oldgittag}|${newgittag}|g" "debian/rules"
touch --date="@${SOURCE_DATE_EPOCH}" "debian/rules" "debian" .
# fix patches
patch --strip=1 <<'EOF'
--- openjdk-lts-11.0.14.1+1/debian/patches/generated-headers.patch
+++ openjdk-lts-11.0.15+10/debian/patches/generated-headers.patch
@@ -16,5 +16,5 @@
- CFLAGS := $(CFLAGS_JDKLIB), \
+ CFLAGS := $(CFLAGS_JDKLIB) -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop, \
HEADERS_FROM_SRC := $(LIBJPEG_HEADERS_FROM_SRC), \
- DISABLED_WARNINGS_gcc := clobbered implicit-fallthrough shift-negative-value, \
+ DISABLED_WARNINGS_gcc := clobbered implicit-fallthrough shift-negative-value array-bounds, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
--- openjdk-lts-11.0.14.1+1/debian/patches/machine-flag.diff
+++ openjdk-lts-11.0.15+10/debian/patches/machine-flag.diff
@@ -7,7 +7,7 @@
+ case "$host" in *x32) MACHINE_FLAG=;; esac
fi
- # FIXME: global flags are not used yet...
+ if test "x$OPENJDK_TARGET_OS" = xmacosx; then
@@ -330,11 +331,8 @@ AC_DEFUN([FLAGS_SETUP_TOOLCHAIN_CONTROL]
AC_SUBST(COMPILER_COMMAND_FILE_FLAG)
AC_SUBST(COMPILER_BINDCMD_FILE_FLAG)
--- openjdk-lts-11.0.14.1+1/debian/patches/series
+++ openjdk-lts-11.0.15+10/debian/patches/series
@@ -44,5 +44,5 @@ reproducible-copyright-headers.diff
reproducible-build-user.diff
reproducible-build-jmod.diff
hotspot-test-fix-npe-on-missing-file.patch
-8222825.diff
+# 8222825.diff
8262085.diff
EOF
touch --date="@${SOURCE_DATE_EPOCH}" "debian/patches/"{"generated-headers.patch","machine-flag.diff","series"} "debian/patches" "debian" .
# update changelog
( cat; cat "${workdir}/${pkgname}-${oldpkgver}/debian/changelog" ) >"${workdir}/${pkgname}-${newpkgver}/debian/changelog" <<EOF
${pkgname} (${newpkgver}${newpkgversuffix}) focal-security; urgency=high
* OpenJDK ${newpkgver} build (release).
-- ${UBUMAIL} $(date --utc --date="@${SOURCE_DATE_EPOCH}" --rfc-email)
EOF
touch --date="@${SOURCE_DATE_EPOCH}" "debian/changelog" "debian" .
# build orig source tarball and dsc file
dpkg-source -b .
touch --date="@${SOURCE_DATE_EPOCH}" "../${pkgname}_${newpkgver}${newpkgversuffix}.dsc" "../${pkgname}_${newpkgver}${newpkgversuffix}.debian.tar.xz"
# build actual packages
dpkg-buildpackage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment