Debian Codegraph @

testbuild.sh

raw
1 #!/bin/sh
2 # Automated builds with various configs, should work on
3 # range of Linux, SunOS (OpenIndiana), *BSD, Darwin(MacOS).
4 # Used in github actions workflow for automated builds,
5 # see .github/workflows/testbuild.yml
6 # Author: Mark Moraes
7
8 PATH=/bin:/usr/bin:/usr/gnu/bin:/opt/SUNWspro/bin:/usr/sfw/bin:/usr/local/bin:/opt/homebrew/bin:/usr/local/sbin:/usr/sbin:/sbin:/bin
9 export PATH
10
11 : ${TB_MACH=$(uname -m)}
12 : ${TB_OS=$(uname)}
13 : ${TB_REV=$(uname -r)}
14 : ${TB_NODE=$(uname -n)}
15 : ${TB_OPTFLAGS=-Os}
16 : ${TB_MINGW=i686-w64-mingw32 x86_64-w64-mingw32}
17
18 dist=$TB_OS-$TB_MACH
19 if test -e /etc/os-release; then
20 . /etc/os-release
21 dist=$dist-${ID-$NAME}-${VERSION_ID-}
22 elif test -e /etc/release; then
23 read ID VERSION_CODENAME VERSION_ID junk < /etc/release
24 dist=$dist-$ID-${VERSION_CODENAME}${VERSION_ID}
25 fi
26 dist="$dist-$TB_REV-$TB_NODE"
27 dist=DIST/$(echo "$dist" | tr '() /*#$?^!~`;<>"'\''' '_')
28 mkdir -p "$dist"
29
30 (echo TB_MACH=$TB_MACH TB_OS=$TB_OS TB_REV=$TB_REV
31 echo
32 for f in /etc/*release; do if test -e "$f"; then echo ">>> $f"; cat "$f"; echo; fi; done
33 set
34
35 ) | tee $dist/TBINFO
36
37 : ${SUDO=sudo}
38 user=$(ls -l $dist/TBINFO|awk '{print $3}')
39 case "$user" in
40 root) SUDO=;;
41 esac
42
43 set -eux
44 case $# in
45 0) ;;
46 *) case "$1" in
47 --preinstall*)
48 ;;
49 *) echo "Usage: $0 --preinstall|--preinstall-only" >&2
50 exit 1
51 ;;
52 esac
53 if type apt-get 2> /dev/null; then
54 if ! $SUDO apt-get update; then
55 # might be because debian moved these to archive
56 sed -i '/-updates/d;s/deb.debian/archive.debian/;s/security.debian/archive.debian/' /etc/apt/sources.list
57 for key in $(apt-key list | awk -v FS='[ /:]+' '/expired/ {print $3}'); do echo $key; apt-key adv --recv-keys --keyserver keyserver.ubuntu.com $key; done
58 # might still fail because of KEYEXPIRED etc so we ignore failure and hope for best in apt-get install
59 $SUDO apt-get update || true
60 fi
61 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y --force-yes gcc make pkg-config ncurses-dev groff exuberant-ctags zip dpkg-dev bzip2
62 case "$TB_MACH" in
63 x86_64) $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y --force-yes mingw-w64;;
64 esac
65 TB_OPTFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2"
66 elif type apk 2> /dev/null; then
67 $SUDO apk update && apk add gcc make pkgconfig musl-dev ncurses-dev groff ctags zip
68 mingwapk="$($SUDO apk list mingw-w64-gcc)"
69 case "$mingwapk" in '') ;; *) apk add mingw-w64-gcc;; esac
70 elif type yum 2> /dev/null; then
71 ctags=ctags
72 case "$ID" in
73 rocky) ctags=;;
74 centos) sed -i -e 's/mirror.centos.org/vault.centos.org/g' \
75 -e 's/^#.*baseurl=http/baseurl=http/g' \
76 -e 's/^mirrorlist=http/#mirrorlist=http/g' \
77 /etc/yum.repos.d/CentOS-*.repo
78 ;;
79 esac
80 $SUDO yum install -y make gcc ncurses-devel groff-base $ctags zip rpm-build
81 elif type brew 2> /dev/null; then
82 brew install make ncurses ctags zip groff
83 elif type pacman 2> /dev/null; then
84 $SUDO pacman -Sy --noconfirm gcc make pkgconf ncurses groff ctags zip
85 elif type nix-shell 2> /dev/null; then
86 $SUDO nix-shell -p gnumake
87 else
88 # not a packaging system we know, hope it already has minimal testbuild needs
89 type cc make mktemp
90 TB_OPTFLAGS=-O
91 fi
92 cc --version || true
93 case "$1" in
94 *only) exit 0;;
95 esac
96 ;;
97 esac
98
99 # directory for artifacts
100 make .version
101 ver=$(cat .version)
102
103 # note: older *BSD, OSX, Solaris require a template
104 td=$(mktemp -d "${TMPDIR:-/tmp}/jvt.XXXXXXXX")
105 dd="DESTDIR=$td"
106 u=$(uname)
107 o=${TB_OPTFLAGS}
108 e=
109 d=
110 x=
111 d=
112 t=-ltermcap
113 lib=
114 jv=NPROCESSORS_ONLN
115 # Some logic below is replicated in/from jmake.sh, needed here because
116 # of the extra non-typical builds that are tested.
117 case $TB_OS in
118 SunOS) x="NROFF=nroff TROFF=troff"
119 d="-DREALSTDC -DPOSIX_PROCS"
120 case "$TB_REV" in
121 5.0) d="-DSYSVR4 -DGRANTPT_BUG";; # really, just do not run this version, it was so so so problematic!
122 5.*) ;;
123 *) echo "$0: Not set up for testing $TB_OS $TB_REV" >&2; exit 1;;
124 esac
125 xi=/usr/gnu/bin/install
126 if test ! -x $xi; then
127 xi=cp
128 fi
129 x="$x XINSTALL=$xi TINSTALL=$xi"
130 ;;
131 GNU|Linux) t=-lncurses
132 if test -e /etc/alpine-release; then
133 d="$d"; lib=MUSL;
134 elif test -e /etc/gentoo-release; then
135 t="-ltinfo"; lib=GLIBC;
136 else
137 lib=GLIBC;
138 fi
139 jv=_NPROCESSORS_ONLN
140 x="$x CC=gcc"
141 ;;
142 esac
143
144 # if we need to add any warnings to skip via -Wno-*
145 skipwarn=
146 case "$o" in
147 -O) w=
148 ;;
149 *) o="$o $skipwarn"
150 w="$skipwarn"
151 ;;
152 esac
153
154 if test -x /usr/bin/getconf; then j=-j$(getconf $jv); else j=; fi
155 # other than the first "make install" with $TB_OS, some of the others
156 # (e.g. PIPEPROCS, TERMINFO) may produce warnings (e.g. no declaration for
157 # ioctl) because we are just testing somewhat abnormal non-POSIX sysdefs.
158 # Try using either old-style TERMCAPLIB, EXTRALIBS or new-style LDLIBS
159 make clean &&
160 JMAKE_OPTS=$j ./jmake.sh $dd/t10-$TB_OS install OPTFLAGS="$o" LOCALCFLAGS="$w" &&
161 make clean &&
162 make $j OPTFLAGS="$o" LOCALCFLAGS="$w" PORTSRVINST=1 SYSDEFS="-DPIPEPROCS $d" TERMCAPLIB=$t EXTRALIBS= $x $dd/t20-pipeprocs install &&
163 make clean &&
164 make $j OPTFLAGS="$o" LOCALCFLAGS="$w" SYSDEFS="-DBSDPOSIX $d" LDLIBS=$t $x $dd/t30-bsdposix install &&
165 make clean &&
166 make $j OPTFLAGS="$o" LOCALCFLAGS="$w" SYSDEFS="-DBAREBONES -DSMALL -DJTC $d" LDLIBS= $x $dd/t60-small install &&
167 make clean &&
168 case "$lib" in
169 GLIBC)
170 make $j OPTFLAGS="$o" LOCALCFLAGS="$w" SYSDEFS="-DXLINUX" TERMCAPLIB=$t EXTRALIBS= $x $dd/t40-xlinux install &&
171 make clean &&
172 make $j OPTFLAGS="$o" LOCALCFLAGS="$w" SYSDEFS="-DTERMINFO -DUSE_VFORK" TERMCAPLIB=$t $x $dd/t50-vfork &&
173 make clean
174 ;;
175 esac &&
176 make $x tgz && mv jove-*.tgz $dist &&
177 if type zip 2> /dev/null; then
178 make $x zip &&
179 mv jove*s.zip $dist
180 fi &&
181 if test -e /etc/redhat-release; then
182 # build and perhaps install RPM
183 joverpm=$(rpm -qa | grep jove)
184 case "$joverpm" in "") ;; *) rpm -e $joverpm; esac
185 rm -f $HOME/rpmbuild/*RPMS/$TB_MACH/jove*.rpm
186 make rpm &&
187 cp -av $HOME/rpmbuild/*RPMS/$TB_MACH/jove-[4-9]*.rpm $dist &&
188 case "${1-}" in *install) rpm -i $HOME/rpmbuild/RPMS/$TB_MACH/jove-[4-9]*.rpm;; esac &&
189 rm -f $HOME/rpmbuild/*RPMS/$TB_MACH/jove-[4-9]*.rpm
190 elif test -e /etc/alpine-release; then
191 # build statically compiled versions using native alpine, since musl is small
192 # so make tarballs that should run on just about on any Linux PC hardware
193 tag=$(gcc -dumpmachine) &&
194 r=jove-$ver-$tag-static &&
195 if test ! -d $dist/$r; then mkdir $dist/$r; fi &&
196 make clobber &&
197 JMAKE_UNAME=$tag ./jmake.sh OPTFLAGS="$o -static" LOCALCFLAGS="$w" all &&
198 strip jjove recover &&
199 mv jjove $dist/$r/jove &&
200 mv recover $dist/$r &&
201 cp -pr README ChangeLog teachjove paths.h doc $dist/$r/ &&
202 tar -c -z -v -f $dist/$r.tar.gz -C $dist $r &&
203 rm -r $dist/$r
204 fi &&
205 for tag in ${TB_MINGW}; do
206 if type ${tag}-gcc 2> /dev/null ; then
207 # build a cross-compiled version for Windows
208 r=jove-$ver-$tag &&
209 if test ! -d $dist/$r; then mkdir $dist/$r; fi &&
210 make clobber &&
211 make XEXT=.exe clobber &&
212 JMAKE_UNAME=$tag ./jmake.sh $j OPTFLAGS="$o" LOCALCFLAGS="$w" all &&
213 ${tag}-strip jjove.exe recover.exe &&
214 mv jjove.exe $dist/$r/jove.exe &&
215 mv recover.exe $dist/$r &&
216 cp -pr README* paths.h ChangeLog doc $dist/$r &&
217 (cd $dist && zip -rm $r.zip $r) &&
218 make XEXT=.exe clobber
219 fi
220 done &&
221 case "$dist" in *-ubuntu-*|*-debian-[1-9][0-9]*)
222 DISTDIR=$(realpath -e $dist) ./pkg/deb/testdeb.sh
223 case "$dist" in *-debian-*)
224 case "$TB_MACH" in x86_64)
225 DISTDIR=$(realpath -e $dist) ./pkg/deb/testdeb.sh i386;;
226 esac
227 ;;
228 esac
229 ;;
230 esac
231 ret=$?
232 # portable for older Unix/SunOS!
233 (cd "$td" && tar cf - .) | gzip > $dist/$ver-builds.tar.gz
234 rm -rf "$td"
235 exit $ret