From e5fea8382b8cf32fa349d613df32afa187ae969c Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Sat, 26 Aug 2023 13:06:41 +0200 Subject: Replace build env doc by qemu. --- contrib/build-env-setup/README.txt | 157 +++++++++++++++++++++++++++++++++++ contrib/build-with-debian/README.md | 73 ---------------- contrib/build-with-mingw64/README.md | 95 --------------------- 3 files changed, 157 insertions(+), 168 deletions(-) create mode 100644 contrib/build-env-setup/README.txt delete mode 100644 contrib/build-with-debian/README.md delete mode 100644 contrib/build-with-mingw64/README.md (limited to 'contrib') diff --git a/contrib/build-env-setup/README.txt b/contrib/build-env-setup/README.txt new file mode 100644 index 0000000..438ec5c --- /dev/null +++ b/contrib/build-env-setup/README.txt @@ -0,0 +1,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 + + + + + diff --git a/contrib/build-with-debian/README.md b/contrib/build-with-debian/README.md deleted file mode 100644 index 0e3b895..0000000 --- a/contrib/build-with-debian/README.md +++ /dev/null @@ -1,73 +0,0 @@ - -Showcase how to build and install on debian -=========================================== - -Guide how to build on a debian based system. - - -## Get Source - -Change into an EMPTY directory and do: - -```sh -git clone --depth=256 https://github.com/hiddenalpha/DeflateAndInflate.git ./. -``` - - -## Choose a debian 9 system. - -Take the debian system you want to use to build. A nice way to achieve -this is via docker (TIPP: take an older image for better ABI -portability): - -In the command below, make sure WORK points to the dir where you cloned -the project to. - -```sh -true \ - && WORK="$PWD" \ - && IMG=debian:oldstable-20230208-slim \ - && CNTR=DeflateAndInflate-DebianBuild \ - && docker pull "${IMG:?}" \ - && docker create --name "${CNTR:?}" -v "${WORK:?}:/work" -w /work "${IMG:?}" sh -c "while true;do sleep 1||break;done" \ - && docker start "${CNTR:?}" \ - && true -``` - - -## Setup build environment - -```sh -docker exec -ti -u0:0 "${CNTR:?}" sh -c 'true\ - && apt-get update \ - && apt-get install -y --no-install-recommends \ - curl gcc git make libc-dev ca-certificates tar zlib1g-dev \ - && true' -``` - - -## configure & make - -```sh -docker exec -ti -u$(id -u):$(id -g) "${CNTR:?}" sh -c 'true\ - && ./configure \ - && make -e clean \ - && make -e \ - && true' -``` - -A ready-to-distribute tarball is now ready in `./dist/`. If you'd like -to install it somewhere else, all you need is this tarball. If you want -to install on same system where you did build you can continue with the -*install* step below. - - -## install - -BTW: This does nothing else than unpacking the built tar into configured - directories. - -```sh -make -e install -``` - diff --git a/contrib/build-with-mingw64/README.md b/contrib/build-with-mingw64/README.md deleted file mode 100644 index d90dd71..0000000 --- a/contrib/build-with-mingw64/README.md +++ /dev/null @@ -1,95 +0,0 @@ - -Guide how to cross build for windoof -==================================== - -## Get Source - -Change into an EMPTY directory and do: - -```sh -git clone --depth=256 https://github.com/hiddenalpha/DeflateAndInflate.git ./. -``` - - -## Choose an alpine system - -Take the alpine system you want to use as build env. A nice way to -achieve this is via docker. - -In the command below, make sure WORK points to the dir where you cloned -the project to. - -```sh -true\ - && WORK="${PWD:?}" \ - && IMG=alpine:3.17.2 \ - && CNTR=DeflateAndInflate-AlpineMingw64 \ - && docker pull "${IMG:?}" \ - && docker create --name "${CNTR:?}" -v "${WORK:?}:/work" -w /work "${IMG:?}" sh -c "while true;do sleep 1||break;done" \ - && docker start "${CNTR:?}" \ - && true -``` - -All snippets here assume this docker setup. But can easily be used -without docker and should work in any POSIX compliant shell. For this -only copy the shell script inside the ticks (') of each command. In -other words just use the part starting with *true* and ending with -another *true*. - - -## Setup dependencies - -```sh -docker exec -ti -u0:0 "${CNTR:?}" sh -c 'true \ - && apk add curl git make mingw-w64-gcc tar \ - && ZLIB_VERSION="1.2.11" \ - && THEOLDPWD="$PWD" \ - && cd /tmp \ - && curl -LsS -o "/tmp/zlib-${ZLIB_VERSION}.tgz" "https://github.com/madler/zlib/archive/refs/tags/v${ZLIB_VERSION:?}.tar.gz" \ - && tar xzf "/tmp/zlib-${ZLIB_VERSION:?}.tgz" \ - && export SRCDIR="/tmp/zlib-${ZLIB_VERSION:?}" \ - && mkdir $SRCDIR/build \ - && cd "${SRCDIR:?}" \ - && export DESTDIR=./build BINARY_PATH=/bin INCLUDE_PATH=/include LIBRARY_PATH=/lib \ - && sed -i "s;^PREFIX =.\*\$;;" win32/Makefile.gcc \ - && make -e -fwin32/Makefile.gcc PREFIX=x86_64-w64-mingw32- \ - && make -e -fwin32/Makefile.gcc install PREFIX=x86_64-w64-mingw32- \ - && unset DESTDIR BINARY_PATH INCLUDE_PATH LIBRARY_PATH \ - && cp README build/. \ - && (cd build && rm -rf lib/pkgconfig) \ - && (cd build && find -type f -not -name MD5SUM -exec md5sum -b {} + > MD5SUM) \ - && (cd build && tar --owner=0 --group=0 -cz *) > /tmp/zlib-1.2.11-windoof.tgz \ - && cd / \ - && rm -rf /tmp/zlib-1.2.11 \ - && mkdir -p /usr/local/x86_64-w64-mingw32 \ - && tar -C /usr/x86_64-w64-mingw32 -f /tmp/zlib-1.2.11-windoof.tgz -x include lib \ - && cd "${THEOLDPWD:?}" \ - && unset THEOLDPWD ZLIB_VERSION \ - && true' -``` - -## configure & make - -Build the project itself. - -```sh -docker exec -ti -u$(id -u):$(id -g) "${CNTR:?}" sh -c 'true\ - && export CC=x86_64-w64-mingw32-gcc \ - && sh ./configure \ - && make -e clean \ - && make -e \ - && true' -``` - -A ready-to-distribute tarball is now available in `./dist/`. If you'd -like to install it somewhere else, all you need is this tarball. If you -want to install on same system where you did build you can continue with -the *install* step below. - - -## install - -There is no trivial *make-install* equivalent for windoof. Therefore -unpack the tarball into an appropriate directory of your choise and make -sure *bin* subdir is in your PATH. - -- cgit v1.1