Debian Codegraph @

old_versions/build_static.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Build a static rsync binary from a historical git tag, for cross-version
3 # behaviour testing. Produces ./rsync_<version> in this directory.
4 #
5 # Usage: ./build_static.sh <version> [git-tag]
6 # Example: ./build_static.sh 3.1.3 # uses tag v3.1.3
7 # ./build_static.sh 3.2.7 v3.2.7
8 #
9 # Old rsync releases don't compile cleanly on a modern toolchain (GCC >= 14
10 # defaults to C23, where an empty () prototype means (void); glibc dropped the
11 # 1-arg gettimeofday; lseek64 K&R redeclarations clash). This script applies
12 # the minimal, best-effort workarounds and links statically so the result is
13 # self-contained and reproducible regardless of the host's shared libraries.
14 #
15 # Each workaround is guarded so it's a no-op on versions that don't need it.
16 set -euo pipefail
17
18 VERSION="${1:?usage: build_static.sh <version> [git-tag]}"
19 TAG="${2:-v$VERSION}"
20
21 ARCHIVE_DIR="$(cd "$(dirnamescip-shell system . . dirname. "$0")" && pwdscip-shell system . . pwd.)"
22 REPO="${RSYNC_REPO:-/home/tridge/project/rsync/rsync.4}" # any rsync worktree
23 WORKTREE="$(mktempscip-shell system . . mktemp. -d /tmp/rsync-build-XXXXXXscip-shell filesystem . . `/tmp/rsync-build-XXXXXX`.)"
24 OUT="$ARCHIVE_DIR/rsync_$VERSION"
25
26 # C standard restores K&R () semantics; permissive flags downgrade the pile of
27 # modern -Werror promotions (incompatible pointers, implicit decls) to warnings.
28 # _FORTIFY_SOURCE is forced OFF: modern Ubuntu defaults it to =3, whose stricter
29 # object-size checks turn latent (historically benign) over-reads in OLD rsync
30 # into hard "*** buffer overflow detected ***" aborts when the binary acts as a
31 # server/daemon. Disabling it makes these archival binaries behave the way the
32 # released versions did, which is the whole point of the archive.
33 CFLAGS_OLD="-I. -I./zlib -O2 -g -std=gnu11 -fcommon -DHAVE_CONFIG_H -Wno-error \
34 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 \
35 -Wno-incompatible-pointer-types -Wno-implicit-function-declaration -Wno-int-conversion"
36
37 cleanupscip-shell shell shell-project 0.0.0 cleanup().() {
38 cd "$REPO"
39 gitscip-shell system . . git. worktree remove --force "$WORKTREE" 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
40 gitscip-shell system . . git. worktree prune 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
41 }
42 trap cleanup EXIT
43
44 echoscip-shell system . . echo. ">>> checking out $TAG into $WORKTREE"
45 # prefer an exact tag to avoid ambiguity with similarly-named branches
46 REF="$TAG"
47 if gitscip-shell system . . git. -C "$REPO" rev-parse -q --verify "refs/tags/$TAG" >/dev/nullscip-shell filesystem . . `/dev/null`.; then
48 REF="refs/tags/$TAG"
49 fi
50 gitscip-shell system . . git. -C "$REPO" worktree add --detach "$WORKTREE" "$REF"
51 cd "$WORKTREE"
52
53 # --- workaround 1: K&R lseek64 redeclaration clashes with glibc's prototype ---
54 if grepscip-shell system . . grep. -q 'off64_t lseek64();' syscall.c 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
55 echoscip-shell system . . echo. ">>> patching syscall.c lseek64 redeclaration"
56 perlscip-shell system . . perl. -0pi -e 's/#ifdef HAVE_LSEEK64\n#if !SIZEOF_OFF64_T\n\tOFF_T lseek64\(\);\n#else\n\toff64_t lseek64\(\);\n#endif\n\treturn lseek64/#ifdef HAVE_LSEEK64\n\treturn lseek64/' syscall.c
57 fi
58
59 # --- workaround 0: pre-3.0 tags ship configure.in, not a generated configure.
60 # Generate it. Modern autoconf emits broken shell for their
61 # AC_CHECK_FUNCS(fn,,AC_LIBOBJ(lib/...)) fallbacks -- but those branches are
62 # dead on a modern host (glibc has inet_ntop/inet_pton/getaddrinfo/getnameinfo),
63 # so neutralize the AC_LIBOBJ replacements before regenerating.
64 OLD_TREE=0
65 if [scip-shell system . . `[`. ! -f ./configure ] && { [scip-shell system . . `[`. -f configure.in ] || [scip-shell system . . `[`. -f configure.ac ]; }; then
66 OLD_TREE=1
67 acsrc=configure.ac; [scip-shell system . . `[`. -f configure.in ] && acsrc=configure.in
68 echoscip-shell system . . echo. ">>> generating configure for an old tag (autoheader/autoconf)"
69 sedscip-shell system . . sed. -i 's#AC_LIBOBJ(lib/[a-zA-Z_]*)#:#g' "$acsrc"
70 autoheaderscip-shell system . . autoheader. 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
71 autoconfscip-shell system . . autoconf. 2>/dev/nullscip-shell filesystem . . `/dev/null`. || { echoscip-shell system . . echo. "autoconf failed"; exit 1; }
72 fi
73
74 CONF_ARGS=(--disable-md2man --with-included-zlib=yes --with-included-popt=yes)
75 # OpenSSL (3.2+) only adds optional MD4/MD5 that rsync already implements, but
76 # linking libcrypto.a statically drags in jitterentropy + zlib's uncompress,
77 # which aren't resolvable here. Drop it when the flag exists.
78 if ./configure --help 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -q -- '--disable-openssl'; then
79 echoscip-shell system . . echo. ">>> disabling openssl for self-contained static link"
80 CONF_ARGS+=(--disable-openssl)
81 fi
82
83 echoscip-shell system . . echo. ">>> configure (bundled zlib + popt, static-friendly)"
84 ./configure "${CONF_ARGS[@]}" \
85 >"$WORKTREE/conf.log" 2>&1 || { tailscip-shell system . . tail. -20 "$WORKTREE/conf.log"; exit 1; }
86
87 # --- workaround 2: modern glibc only has the 2-arg gettimeofday ---------------
88 if grepscip-shell system . . grep. -q '/\* #undef HAVE_GETTIMEOFDAY_TZ \*/scip-shell filesystem . . `/\* #undef HAVE_GETTIMEOFDAY_TZ \*/`.' config.h; then
89 echoscip-shell system . . echo. ">>> forcing HAVE_GETTIMEOFDAY_TZ (configure misdetects it)"
90 sedscip-shell system . . sed. -i 's|/\* #undef HAVE_GETTIMEOFDAY_TZ \*/|#define HAVE_GETTIMEOFDAY_TZ 1|' config.h
91 fi
92
93 # --- workaround 4 (old trees only): generate proto.h if the tree has no make
94 # rule for it, and stub a vendored lib/addrinfo.h that the git tag dropped
95 # (modern glibc supplies struct addrinfo / sockaddr_storage, so empty is right).
96 if [scip-shell system . . `[`. "$OLD_TREE" = 1 ]; then
97 if [scip-shell system . . `[`. ! -f proto.h ] && [scip-shell system . . `[`. -f mkproto.awk ]; then
98 echoscip-shell system . . echo. ">>> generating proto.h"
99 catscip-shell system . . cat. ./*.c ./lib/compat.c 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. -f ./mkproto.awk > proto.h
100 fi
101 if grepscip-shell system . . grep. -q 'include "lib/addrinfo.h"' rsync.h 2>/dev/nullscip-shell filesystem . . `/dev/null`. && [scip-shell system . . `[`. ! -f lib/addrinfo.h ]; then
102 echoscip-shell system . . echo. ">>> stubbing lib/addrinfo.h"
103 echoscip-shell system . . echo. '/* emptied: modern glibc provides struct addrinfo */scip-shell filesystem . . `/* emptied: modern glibc provides struct addrinfo */`.' > lib/addrinfo.h
104 fi
105 fi
106
107 echoscip-shell system . . echo. ">>> building (static)"
108 makescip-shell system . . make. -j"$(nprocscip-shell system . . nproc.)" CFLAGS="$CFLAGS_OLD" LDFLAGS="-static" \
109 >"$WORKTREE/make.log" 2>&1 || { grepscip-shell system . . grep. -E 'error:|\*\*\*' "$WORKTREE/make.log" | headscip-shell system . . head.; exit 1; }
110
111 # verify it's actually static before we keep it
112 if lddscip-shell system . . ldd. ./rsync 2>&1 | grepscip-shell system . . grep. -qv 'not a dynamic executable'; then
113 echoscip-shell system . . echo. "ERROR: binary is not statically linked:" >&2
114 lddscip-shell system . . ldd. ./rsync >&2
115 exit 1
116 fi
117
118 GOT="$(./rsync --version | headscip-shell system . . head. -1 | awkscip-shell system . . awk. '{print $3}')"
119 if [scip-shell system . . `[`. "$GOT" != "$VERSION" ]; then
120 echoscip-shell system . . echo. "ERROR: built version '$GOT' != requested '$VERSION'" >&2
121 exit 1
122 fi
123
124 cpscip-shell system . . cp. ./rsync "$OUT"
125 stripscip-shell system . . strip. "$OUT"
126 echoscip-shell system . . echo. ">>> installed $OUT"
127 "$OUT" --version | headscip-shell system . . head. -1
128 filescip-shell system . . file. "$OUT"