summaryrefslogtreecommitdiff
path: root/contrib/build-env-setup/README.txt
blob: 438ec5c777abbf1b8f753caa404a0568757005aa (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

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 far 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:

### Debian config
true \
  && PKGS_TO_ADD="ca-certificates curl gcc git make libc-dev tar" \
  && PKGS_TO_DEL="curl gcc git make libc-dev" \
  && 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

### Alpine with w64 cross compiler setup
true \
  && PKGS_TO_ADD="curl mingw-w64-gcc git make tar" \
  && PKGS_TO_DEL="curl mingw-w64-gcc git make" \
  && printf '#!/bin/sh\nsu - root -c "$(echo "$@")"\n' >/home/user/mysudo \
  && chmod +x /home/user/mysudo \
  && SUDO="/home/user/mysudo" \
  && PKGINIT=true \
  && PKGADD="$SUDO apk add" \
  && PKGDEL="$SUDO apk del" \
  && PKGCLEAN=true \
  && HOST="x86_64-w64-mingw32" \
  && true


## make, install

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

true \
  && GIT_TAG="master" \
  && ZLIB_VERSION="1.2.11" \
  && WORKDIR="/home/${USER}/work" \
  && ZLIB_URL="https://downloads.sourceforge.net/project/libpng/zlib/${ZLIB_VERSION:?}/zlib-${ZLIB_VERSION:?}.tar.gz" \
  && ZLIB_LOCAL=zlib-${ZLIB_VERSION:?}.tgz \
  && if test -n "$HOST"; then true \
     && INSTALL_ROOT="/usr/${HOST:?}" \
     ;else true \
     && INSTALL_ROOT="/usr/local" \
     ;fi \
  && true \
  && mkdir -p "${WORKDIR:?}" && cd "${WORKDIR:?}" \
  && ${PKGINIT:?} && ${PKGADD:?} $PKGS_TO_ADD \
  && if test -f "/var/tmp/${ZLIB_LOCAL:?}"; then true \
     && echo "[DEBUG] Already have \"/var/tmp/${ZLIB_LOCAL:?}\"" \
     ;else true \
     && echo "[DEBUG] Downloading \"/var/tmp/${ZLIB_LOCAL:?}\"" \
     && echo "[DEBUG]   from \"${ZLIB_URL:?}\"" \
     && curl -sSL "${ZLIB_URL:?}" -o "/var/tmp/${ZLIB_LOCAL:?}" \
     ;fi \
  && printf '\nMake zlib\n\n' \
  && (cd /tmp \
    && tar xzf "/var/tmp/${ZLIB_LOCAL:?}" \
    && export SRCDIR="/tmp/zlib-${ZLIB_VERSION:?}" \
    && mkdir ${SRCDIR:?}/build && cd ${SRCDIR:?} \
    && if test -n "$HOST"; then true \
       && export DESTDIR=./build BINARY_PATH=/bin INCLUDE_PATH=/include LIBRARY_PATH=/lib \
       && sed -i "s;^PREFIX =.\*\$;;" win32/Makefile.gcc \
       && make -e -j$(nproc) -fwin32/Makefile.gcc PREFIX=${HOST:?}- \
       && make -e -fwin32/Makefile.gcc install PREFIX=${HOST:?}- \
       && unset DESTDIR BINARY_PATH INCLUDE_PATH LIBRARY_PATH \
       ;else true \
       && ./configure --prefix=${SRCDIR:?}/build/ \
       && make -j$(nproc) && make install \
       ;fi \
    && cp README build/. \
    && (cd build \
      && rm -rf lib/pkgconfig \
      && find -type f -not -name MD5SUM -exec md5sum -b {} + > MD5SUM \
      && tar --owner=0 --group=0 -cz * > /var/tmp/zlib-${ZLIB_VERSION:?}-bin.tgz \
      ;) \
    && cd / && rm -rf /tmp/zlib-${ZLIB_VERSION:?} \
    && printf '\n\n  zlib Done :)\n\n' \
    ;) \
  && $SUDO tar -C "${INSTALL_ROOT:?}" -f /var/tmp/zlib-${ZLIB_VERSION:?}-bin.tgz -x include lib \
  && printf '\n  Build project itself\n\n' \
  && git clone --depth 42 --branch "${GIT_TAG:?}" https://github.com/hiddenalpha/DeflateAndInflate.git . \
  && git config advice.detachedHead false \
  && git checkout "${GIT_TAG:?}" \
  && ./configure \
  && if test -n "$HOST"; then true \
     && sed -Ei 's;^CC=gcc$;CC='"${HOST}"'-gcc;' Makefile \
     ;fi \
  && 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  BTW: In addition 'deflate' and 'inflate' got installed and are ready-to-use.\n\n' "${dirOfDistBundle:?}" "$USER" "${dirOfDistBundle:?}" \
  && true