GitHub CI: change build system to meson
[tinc] / .ci / deps.sh
1 #!/bin/sh
2
3 set -eu
4
5 deps_linux_alpine() {
6   apk upgrade
7
8   apk add \
9     git binutils meson pkgconf gcc linux-headers diffutils \
10     procps socat shadow sudo libgcrypt-dev texinfo gzip \
11     openssl-dev zlib-dev lzo-dev ncurses-dev readline-dev musl-dev lz4-dev vde2-dev
12 }
13
14 deps_linux_debian_mingw() {
15   apt-get install -y \
16     mingw-w64 mingw-w64-tools \
17     wine wine-binfmt \
18     libgcrypt-mingw-w64-dev \
19     "$@"
20 }
21
22 deps_linux_debian_linux() {
23   if [ -n "$HOST" ]; then
24     dpkg --add-architecture "$HOST"
25   fi
26
27   apt-get update
28
29   apt-get install -y \
30     binutils make gcc \
31     zlib1g-dev:"$HOST" \
32     libssl-dev:"$HOST" \
33     liblzo2-dev:"$HOST" \
34     liblz4-dev:"$HOST" \
35     libncurses-dev:"$HOST" \
36     libreadline-dev:"$HOST" \
37     libgcrypt-dev:"$HOST" \
38     libminiupnpc-dev:"$HOST" \
39     libvdeplug-dev:"$HOST" \
40     "$@"
41
42   if [ -n "$HOST" ]; then
43     apt-get install -y crossbuild-essential-"$HOST" qemu-user
44   else
45     linux_openssl3
46   fi
47 }
48
49 deps_linux_debian() {
50   export DEBIAN_FRONTEND=noninteractive
51
52   apt-get update
53   apt-get upgrade -y
54   apt-get install -y git pkgconf diffutils sudo texinfo \
55     netcat-openbsd procps socat
56
57   HOST=${HOST:-}
58   if [ "$HOST" = mingw ]; then
59     deps_linux_debian_mingw "$@"
60   else
61     deps_linux_debian_linux "$@"
62   fi
63
64   . /etc/os-release
65
66   # Debian Buster ships an old version of meson (0.49).
67   # MinGW cross-compilation requires something newer than 0.55 that ships in Bullseye,
68   # or it fails when looking for dependencies in the OpenSSL wrap.
69   if [ "${ID:-}/${VERSION_CODENAME:-}" = debian/buster ] || [ "$HOST" = mingw ]; then
70     apt-get install -y python3 python3-pip ninja-build
71     pip3 install meson
72   else
73     apt-get install -y meson
74   fi
75 }
76
77 deps_linux_rhel() {
78   if [ "$ID" != fedora ]; then
79     yum install -y epel-release
80
81     if type dnf; then
82       dnf install -y 'dnf-command(config-manager)'
83       dnf config-manager --enable powertools
84     fi
85   fi
86
87   yum upgrade -y
88
89   yum install -y \
90     git binutils make meson pkgconf gcc diffutils sudo texinfo-tex netcat procps systemd perl-IPC-Cmd \
91     findutils socat lzo-devel zlib-devel lz4-devel ncurses-devel readline-devel libgcrypt-devel "$@"
92
93   if yum info openssl11-devel; then
94     yum install -y openssl11-devel
95   else
96     dnf install -y openssl-devel
97   fi
98
99   if yum info miniupnpc-devel; then
100     yum install -y miniupnpc-devel
101   fi
102 }
103
104 linux_openssl3() {
105   src=/usr/local/src/openssl
106   ssl3=/opt/ssl3
107
108   mkdir -p $src
109
110   git clone --depth 1 --branch openssl-3.0.2 https://github.com/openssl/openssl $src
111   cd $src
112
113   ./Configure --prefix=$ssl3 --openssldir=$ssl3
114   make -j"$(nproc)"
115   make install_sw
116
117   if [ -f /etc/ld.so.conf ]; then
118     echo $ssl3/lib64 >>/etc/ld.so.conf
119     ldconfig -v
120   else
121     ldconfig -v $ssl3/lib64
122   fi
123
124   cd -
125 }
126
127 deps_linux() {
128   . /etc/os-release
129
130   case "$ID" in
131   alpine)
132     deps_linux_alpine "$@"
133     ;;
134
135   debian | ubuntu)
136     deps_linux_debian "$@"
137     ;;
138
139   centos | almalinux | fedora)
140     deps_linux_rhel "$@"
141     linux_openssl3
142     ;;
143
144   *) exit 1 ;;
145   esac
146 }
147
148 deps_macos() {
149   brew install coreutils netcat lzo lz4 miniupnpc libgcrypt openssl meson "$@"
150   pip3 install --user compiledb
151 }
152
153 case "$(uname -s)" in
154 Linux) deps_linux "$@" ;;
155 Darwin) deps_macos "$@" ;;
156 *) exit 1 ;;
157 esac