summaryrefslogtreecommitdiff
path: root/contrib/build-env-setup/README.md
blob: 89fcb01664a4ed61b7a08ee735e2ec2e06e3a3e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

Showcase how to build and install
=================================

WARN: Do NOT perform any of these steps on your host system! This script
      MUST only be run on a system which is a
      just-throw-it-away-if-broken system.

Sometimes happy developers (like me) have no choice but using terribly
restricted systems where setting up tools to run even something as
trivial as configure/make/install becomes a nightmare if not impossible.
I found it to be very handy to have some independent qemu VM at hand
which lets me install whatever I need, neither with any special software
nor any annoying privileges on a host machine. Qemu runs portable and in
user mode even doesn't need any annoying permissions at all.



## Setup a minimal system in your qemu VM

This setup mainly targets debian. Nevertheless it tries to stay POSIX
compatible as possible. So setup a minimal install of your system of
choice and then as soon you've SSH access to a (posix) shell, you're
ready for the next step.

Still not sure which system to use? Link below provides some candidates.
HINT: Windows IMHO is a terrible choice. So stop complaining if you go
this route.

https://en.wikipedia.org/wiki/POSIX#POSIX-oriented_operating_systems



## Start VM with SSH access

Easiest way to work with your machine is via SSH. Therefore if you've
chosen to use a qemu VM, make sure you've setup and configured sshd
properly inside the VM. Then just pass args like those to qemu:

  --device e1000,netdev=n0 --netdev user,id=n0,hostfwd=tcp:127.0.0.1:2222-:22

Started this way, the SSHDaemon inside the VM is accessible from your
host via "localhost" at port "2222":

  ssh localhost -p2222

I strongly recommend using SSH paired with a well-designed
terminal-emulator in place of some fancy VGA/GUI emulators or similar.
Those commandline tools give immediate benefits like copy-pasting of
script snippets which becomes very handy with the scripts which follow,
or also with file transfers to get the final build result out the VM. My
condolence to users which still think windows is the only way to use a
computer.



## Configure build environment

Setup environ vars according to your chosen build system. Here are few examlpes:

### Config for debian
####### automake autoconf libtool
true \
  && PKGS_TO_ADD="git make gcc libc6-dev cmake autoconf automake libtool m4" \
  && PKGS_TO_DEL="cmake autoconf automake libtool m4" \
  && SUDO=sudo \
  && PKGINIT="$SUDO apt update" \
  && PKGADD="$SUDO apt install -y --no-install-recommends" \
  && PKGDEL="$SUDO apt purge -y" \
  && PKGCLEAN="$SUDO apt clean" \
  && HOST= \
  && true


## make, install

As soon environ is configured, we can trigger the build:

true \
  && GIT_TAG="master" \
  && LIBARCHIVE_VERSION="3.6.2" \
  && CURL_VERSION="8.3.0" \
  && CJSON_VERSION="1.7.15" \
  \
  && WORKDIR="/home/${USER}/work" \
  && INSTALL_ROOT="/usr/${HOST:-local}" \
  && CJSON_URL="https://github.com/DaveGamble/cJSON/archive/refs/tags/v${CJSON_VERSION:?}.tar.gz" \
  && CJSON_SRCTGZ="/var/tmp/cJSON-${CJSON_VERSION:?}.tgz" \
  && CJSON_BINTGZ="${CJSON_SRCTGZ%.*}-bin.tgz" \
  && CURL_VERSION_UGLY="$(echo "$CURL_VERSION"|sed 's;\.;_;g')" \
  && CURL_URL="https://github.com/curl/curl/archive/refs/tags/curl-${CURL_VERSION_UGLY:?}.tar.gz" \
  && CURL_SRCTGZ="/var/tmp/curl-${CURL_VERSION:?}.tgz" \
  && CURL_BINTGZ="${CURL_SRCTGZ%.*}-bin.tgz" \
  && LIBARCHIVE_URL="https://github.com/libarchive/libarchive/archive/refs/tags/v${LIBARCHIVE_VERSION:?}.tar.gz" \
  && LIBARCHIVE_SRCTGZ="/var/tmp/libarchive-${LIBARCHIVE_VERSION:?}.tgz" \
  && LIBARCHIVE_BINTGZ="${LIBARCHIVE_SRCTGZ%.*}-bin.tgz" \
  \
  && ${PKGINIT:?} && ${PKGADD:?} $PKGS_TO_ADD \
  && printf '\n  Download Dependency Sources\n\n'
  && if test ! -e "${CJSON_SRCTGZ:?}"; then true \
    && echo "Download ${CJSON_URL:?}" \
    && curl -sSLo "${CJSON_SRCTGZ:?}" "${CJSON_URL:?}" \
    ;fi \
  && if test ! -e "${LIBARCHIVE_SRCTGZ:?}"; then true \
    && echo "Download ${LIBARCHIVE_URL:?}" \
    && curl -sSLo "${LIBARCHIVE_SRCTGZ:?}" "${LIBARCHIVE_URL:?}" \
    ;fi \
  && if test ! -e "${CURL_SRCTGZ:?}"; then true \
     && echo "Download ${CURL_URL:?}" \
     && curl -sSLo "${CURL_SRCTGZ:?}" "${CURL_URL:?}" \
     ;fi \
  && if test ! -e "${CJSON_BINTGZ:?}"; then (true \
     && printf '\n  Build cJSON\n\n' \
     && cd /tmp \
     && tar xf "${CJSON_SRCTGZ:?}" \
     && cd "cJSON-${CJSON_VERSION:?}" \
     && mkdir build build/obj build/lib build/include \
     && CFLAGS="-Wall -pedantic -fPIC" \
     && ${HOST_}cc $CFLAGS -c -o build/obj/cJSON.o cJSON.c \
     && ${HOST_}cc $CFLAGS -shared -o build/lib/libcJSON.so.${CJSON_VERSION:?} build/obj/cJSON.o \
     && unset CFLAGS \
     && (cd build/lib \
        && MIN=${CJSON_VERSION%.*} && MAJ=${MIN%.*} \
        && ln -s libcJSON.so.${CJSON_VERSION:?} libcJSON.so.${MIN:?} \
        && ln -s libcJSON.so.${MIN:?} libcJSON.so.${MAJ} \
        ) \
     && ar rcs build/lib/libcJSON.a build/obj/cJSON.o \
     && cp -t build/. LICENSE README.md \
     && cp -t build/include/. cJSON.h \
     && rm -rf build/obj \
     && (cd build && tar --owner=0 --group=0 -czf "${CJSON_BINTGZ:?}" *) \
     && cd /tmp \
     && rm -rf "cJSON-${CJSON_VERSION:?}" \
     && $SUDO tar -C /usr/local -xzf "${CJSON_BINTGZ:?}" \
     );fi \
  && if test ! -e "${LIBARCHIVE_BINTGZ}"; then (true \
     && printf '\n  Build libarchive\n\n' \
     && cd /tmp \
     && tar xf "${LIBARCHIVE_SRCTGZ:?}" \
     && cd "libarchive-${LIBARCHIVE_VERSION:?}" \
     && cmake -D CMAKE_INSTALL_PREFIX="${PWD:?}/build/usr_local" . \
     && make -j$(nproc) && make install \
     && rm -rf build/usr_local/lib/pkgconfig \
     && (cd build/usr_local && tar --owner=0 --group=0 -czf "${LIBARCHIVE_BINTGZ:?}" *) \
     && cd /tmp && rm -rf "libarchive-${LIBARCHIVE_VERSION:?}" \
     && $SUDO tar -C /usr/local -xzf "${LIBARCHIVE_BINTGZ:?}" \
     );fi \
  && if test ! -e "${CURL_BINTGZ:?}"; then (true
     && printf '\n  Build curl\n\n' \
     && cd /tmp \
     && tar xf "${CURL_SRCTGZ:?}" \
     && cd "curl-curl-${CURL_VERSION_UGLY:?}" \
     && autoreconf -fi \
     && ./configure --prefix="$PWD/build/usr_local" --enable-http --with-nghttp2 --with-nghttp3 --disable-alt-svc --disable-ares --disable-aws --disable-basic-auth --disable-bearer-auth --disable-bindlocal --disable-cookies --disable-curldebug --disable-dateparse --disable-debug --disable-dependency-tracking --disable-dict --disable-digest-auth --disable-dnsshuffle --disable-doh --disable-ech --disable-file --disable-form-api --disable-ftp --disable-get-easy-options --disable-gopher --disable-headers-api --disable-hsts --disable-http-auth --disable-imap --enable-ipv6 --disable-kerberos-auth --disable-largefile --disable-ldap --disable-ldaps --disable-libcurl-option --disable-libtool-lock --enable-manual --disable-mime --disable-mqtt --disable-negotiate-auth --disable-netrc --enable-ntlm --enable-ntlm-wb --disable-openssl-auto-load-config --disable-optimize --disable-pop3 --disable-progress-meter --enable-proxy --disable-pthreads --disable-rt --disable-rtsp --disable-smb --enable-smtp --disable-socketpair --disable-sspi --disable-symbol-hiding --disable-telnet --disable-tftp --disable-threaded-resolver --disable-tls-srp --disable-unix-sockets --disable-verbose --disable-versioned-symbols --disable-warnings --disable-websockets --disable-werror --without-schannel --without-secure-transport --without-amissl --without-ssl --without-openssl --without-gnutls --without-mbedtls --without-wolfssl --without-bearssl --without-rustls --without-test-nghttpx --without-test-caddy --without-test-httpd --without-pic --without-aix-soname --without-gnu-ld --without-sysroot --without-mingw1-deprecated --without-hyper --without-zlib --without-brotli --without-zstd --without-ldap-lib --without-lber-lib --without-gssapi-includes --without-gssapi-libs --without-gssapi --without-default-ssl-backend --without-random --without-ca-bundle --without-ca-path --without-ca-fallback --without-libpsl --without-libgsasl --without-librtmp --without-winidn --without-libidn2 --without-ngtcp2 --without-quiche --without-msh3 --without-zsh-functions-dir --without-fish-functions-dir CFLAGS=-fPIC \
     && make clean && make -j$(nproc) && make install \
     && (cd build/usr_local && rm -rf share/aclocal bin/curl-config lib/libcurl.la lib/pkgconfig) \
     && (cd build/usr_local && tar --owner=0 --group=0 -czf "${CURL_BINTGZ:?}" *) \
     && cd /tmp \
     && rm -rf "curl-curl-${CURL_VERSION_UGLY:?}" \
     && $SUDO tar -C /usr/local -xzf "${CURL_BINTGZ:?}" \
     );fi \

  && printf '\n  Build project itself\n\n' \
  && mkdir -p "${WORKDIR:?}" && cd "${WORKDIR:?}" \
  && git clone --depth 42 --branch "${GIT_TAG:?}" https://github.com/hiddenalpha/GateleenResclone.git . \
  && git config advice.detachedHead false \
  && git checkout --detach "${GIT_TAG:?}" \
  && make clean && make -j$(nproc) \
  && if test -z "$HOST"; then $SUDO make install; fi \
  && find . -not -wholename './dist*' -delete \
  && ${PKGDEL:?} $PKGS_TO_DEL && ${PKGCLEAN:?} \
  && dirOfDistBundle="$(realpath dist)" \
  && printf '\n  SUCCESS  :)  Distribution bundle is ready in:\n\n  %s\n\n  Tip: Before pulling out your hair about how to get that archive out of\n       your qemu VM. STOP kluding around with silly tools and learn how\n       basic tools do the job perfectly fine:\n\n  ssh %s@localhost -p2222 -- sh -c '\''true && cd "%s" && tar c *'\'' | tar x\n\n' "${dirOfDistBundle:?}" "$USER" "${dirOfDistBundle:?}" \
  && true