Debian Codegraph @

scripts/release/build-static-linux-x86_64.zsh

raw
1 #!/bin/zsh
2 # -*- vim:fenc=utf-8:et:sw=2:ts=2:sts=2
3 #
4 # Copyright (c) 2026 Enrico M. Crisostomo
5 #
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 3, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # this program. If not, see <http://www.gnu.org/licenses/>.
17
18 setopt local_options
19 setopt local_traps
20 unsetopt glob_subst
21
22 set -o errexit
23 set -o nounset
24
25 PROGNAME=${0:t}
26 PROGDIR=${0:A:h}
27
28 . "${PROGDIR}/lib.zsh"
29
30 usage()
31 {
32 print -- "Usage: ${PROGNAME} VERSION"
33 print
34 print -- "Build fswatch-VERSION-linux-x86_64-static.tar.gz."
35 }
36
37 (( $# == 1 )) || {
38 usage
39 exit 1
40 }
41
42 release_parse_version "$1"
43
44 repo_root=$(release_repo_root)
45 cd "${repo_root}"
46
47 [[ "$(uname -s)" == "Linux" ]] ||
48 release_die "static convenience binary must be built on Linux"
49 [[ "$(uname -m)" == "x86_64" ]] ||
50 release_die "static convenience binary must be built on x86_64"
51
52 for required_command in file git ldd make readelf sha256sum tar
53 do
54 command -v "${required_command}" > /dev/null ||
55 release_die "required command not found: ${required_command}"
56 done
57
58 artifact="fswatch-${RELEASE_VERSION}-linux-x86_64-static.tar.gz"
59 work_root="${TMPDIR:-/tmp}/fswatch-static-linux-x86_64-${RELEASE_VERSION}-$$"
60 source_dir="${work_root}/source"
61 build_dir="${work_root}/build"
62 stage_dir="${work_root}/stage"
63
64 cleanup()
65 {
66 rm -rf "${work_root}"
67 }
68 trap cleanup EXIT
69
70 rm -f "${artifact}"
71 mkdir -p "${source_dir}" "${build_dir}" "${stage_dir}"
72
73 git ls-files -z |
74 tar --null -T - -cf - |
75 tar -C "${source_dir}" -xf -
76
77 (
78 cd "${source_dir}"
79 ./autogen.sh
80 )
81
82 (
83 cd "${build_dir}"
84 "${source_dir}/configure" \
85 --disable-shared \
86 --enable-static \
87 --disable-nls \
88 CFLAGS="-O2" \
89 CXXFLAGS="-O2" \
90 LDFLAGS="-static"
91 jobs="${JOBS:-$(getconf _NPROCESSORS_ONLN 2> /dev/null || print 2)}"
92 make -j "${jobs}" -C libfswatch/src
93 make -j "${jobs}" -C fswatch/src \
94 AM_LDFLAGS="-all-static" \
95 LDFLAGS="-static -no-pie -static-libgcc -static-libstdc++"
96 )
97
98 built_fswatch="${build_dir}/fswatch/src/fswatch"
99 if ! file "${built_fswatch}" | grep -Eq 'ELF 64-bit.*x86-64'
100 then
101 if [[ -x "${build_dir}/fswatch/src/.libs/fswatch" ]]
102 then
103 built_fswatch="${build_dir}/fswatch/src/.libs/fswatch"
104 fi
105 fi
106
107 file "${built_fswatch}" | tee "${work_root}/file.txt"
108 ldd "${built_fswatch}" > "${work_root}/ldd.txt" 2>&1 || true
109 cat "${work_root}/ldd.txt"
110 readelf -d "${built_fswatch}" > "${work_root}/readelf-d.txt" 2>&1 || true
111 cat "${work_root}/readelf-d.txt"
112
113 file "${built_fswatch}" | grep -Eq 'ELF 64-bit.*x86-64' ||
114 release_die "fswatch is not a Linux x86_64 ELF executable"
115
116 if readelf -l "${built_fswatch}" | grep -q 'INTERP'
117 then
118 release_die "fswatch has an ELF interpreter and is dynamically linked"
119 fi
120
121 if grep -q '(NEEDED)' "${work_root}/readelf-d.txt"
122 then
123 release_die "fswatch has NEEDED shared library entries"
124 fi
125
126 if ! grep -Eiq 'not a dynamic executable|not a valid dynamic|statically linked' "${work_root}/ldd.txt"
127 then
128 release_die "ldd did not identify fswatch as a static executable"
129 fi
130
131 cp "${built_fswatch}" "${stage_dir}/fswatch"
132 cp "${source_dir}/COPYING" "${stage_dir}/COPYING"
133 cat > "${stage_dir}/README.binary" <<EOF
134 fswatch ${RELEASE_VERSION} Linux x86_64 static convenience binary
135
136 This is an experimental convenience binary for Linux x86_64 systems only.
137 It is built as a static executable, using a musl-based build environment in the
138 GitHub release workflow.
139
140 This binary is not the recommended installation path. Package managers and
141 distro packages remain the recommended way to install fswatch. If you need
142 integration with your distribution, use your distribution's fswatch package
143 instead.
144
145 This package intentionally contains only the fswatch executable and license
146 metadata. It does not include libfswatch ABI/API artifacts, headers,
147 pkg-config files, man pages, shared libraries, or static libraries.
148 EOF
149
150 (
151 cd "${stage_dir}"
152 sha256sum fswatch COPYING README.binary > SHA256SUMS
153 tar -czf "${repo_root}/${artifact}" fswatch COPYING README.binary SHA256SUMS
154 )
155
156 tar -tzf "${artifact}" | sed '/./!d' > "${work_root}/tar-contents.txt"
157 if ! cmp -s "${work_root}/tar-contents.txt" =(print -l fswatch COPYING README.binary SHA256SUMS)
158 then
159 print -u2 -- "unexpected tarball contents:"
160 cat "${work_root}/tar-contents.txt" >&2
161 release_die "${artifact} does not contain exactly the expected files"
162 fi
163
164 release_info "created ${artifact}"