From 4015f6de5c98cab856991a05b27713af90e97e7f Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Sun, 19 Feb 2023 17:20:30 +0100 Subject: (build) Simplify build doc - Include target tripplet into version - Refactor docker build env by a more flexible script variant --- contrib/build-using-docker/Dockerfile | 35 ------------- contrib/build-using-docker/README.md | 64 ----------------------- contrib/build-with-debian/README.md | 73 +++++++++++++++++++++++++++ contrib/build-with-mingw64/README.md | 95 +++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 99 deletions(-) delete mode 100644 contrib/build-using-docker/Dockerfile delete mode 100644 contrib/build-using-docker/README.md create mode 100644 contrib/build-with-debian/README.md create mode 100644 contrib/build-with-mingw64/README.md (limited to 'contrib') diff --git a/contrib/build-using-docker/Dockerfile b/contrib/build-using-docker/Dockerfile deleted file mode 100644 index dabcf43..0000000 --- a/contrib/build-using-docker/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ - -ARG PARENT_IMAGE=alpine:3.16.0 -FROM $PARENT_IMAGE - -ARG GIT_TAG= -ARG CONFIGURE_OPTS= -ARG MAKE_OPTS= -ARG PKGS_TO_ADD="curl gcc git make musl-dev tar zlib-dev" -ARG PKGS_TO_DEL="curl gcc git make musl-dev tar zlib-dev" -ARG PKGINIT=true -ARG PKGADD="apk add" -ARG PKGDEL="apk del" -ARG PKGCLEAN=true - -WORKDIR /work - -RUN true \ - && $PKGINIT \ - && $PKGADD $PKGS_TO_ADD \ - && BR=$(if test -n "$GIT_TAG"; then echo " --branch $GIT_TAG"; else echo ""; fi) \ - && git clone --depth 42 $BR https://github.com/hiddenalpha/DeflateAndInflate.git . \ - && ./configure $CONFIGURE_OPTS \ - && make clean $MAKE_OPTS && make $MAKE_OPTS && make install $MAKE_OPTS \ - && find . -not -wholename './dist*' -delete \ - && find /work -exec chown 1000:1000 {} + \ - && $PKGDEL $PKGS_TO_DEL \ - && $PKGCLEAN \ - && true - -USER 1000:1000 - -# run for max 10 hrs. Because this container is not meant to stay running -# forever. -CMD ["sleep", "36000"] - diff --git a/contrib/build-using-docker/README.md b/contrib/build-using-docker/README.md deleted file mode 100644 index 3bf0ae4..0000000 --- a/contrib/build-using-docker/README.md +++ /dev/null @@ -1,64 +0,0 @@ - -Showcase how to build and install -================================= - -Sometimes happy developers (like me) have no choice but using horribly -restricted systems where setting up tools to run even something as simple as -configure/make/install becomes a nightmare. I found it to be easier to have a -Dockerfile to build on a totally unrelated machine (but where I have the needed -privileges) and then just copy-paste the built result over to where I need it. - - -## Setup variable to reduce annoying repetitions - -```sh -IMG=deflateandinflate-showcase:latest -``` - -## Make and install dockerimage - -```sh -curl -sSL https://github.com/hiddenalpha/DeflateAndInflate/raw/master/contrib/build-using-docker/Dockerfile | sudo docker build . -f - -t "${IMG:?}" -``` - -## Grab distribution archive - -Most probably we wanna get the distribution archive. We can copy it out the -dockerimage to our host using: - -```sh -sudo docker run --rm -i "${IMG:?}" sh -c 'true && cd dist && tar c *' | tar x -``` - -WARN: Think for ABI compatibility! By default the dockerimage uses alpine linux - for compilation. Scroll down to "other targets" if you need to build - for other targets. - - -## Play around - -Or if we wanna browse the image or play around with the built utility we could -launch a shell. Once in the shell, try `deflate --help` and/or `inflate --help`. - -```sh -sudo docker run --rm -ti "${IMG:?}" sh -``` - - -## Other targets - -The dockerfile is parameterized and should work for other systems too. For -example to compile for debian we could use command like below. May set *IMG* -differently if you need to keep multiple images. - -```sh -curl -sSL https://github.com/hiddenalpha/DeflateAndInflate/raw/master/contrib/build-using-docker/Dockerfile | sudo docker build . -f - -t "${IMG:?}" \ - --build-arg PARENT_IMAGE=debian:buster-20220622-slim \ - --build-arg PKGS_TO_ADD="curl gcc git make libc-dev ca-certificates tar zlib1g-dev" \ - --build-arg PKGS_TO_DEL="curl gcc git make libc-dev zlib1g-dev" \ - --build-arg PKGINIT="apt-get update" \ - --build-arg PKGADD="apt-get install -y --no-install-recommends" \ - --build-arg PKGDEL="apt-get purge -y" \ - --build-arg PKGCLEAN="apt-get clean" -``` - diff --git a/contrib/build-with-debian/README.md b/contrib/build-with-debian/README.md new file mode 100644 index 0000000..0e3b895 --- /dev/null +++ b/contrib/build-with-debian/README.md @@ -0,0 +1,73 @@ + +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 new file mode 100644 index 0000000..d90dd71 --- /dev/null +++ b/contrib/build-with-mingw64/README.md @@ -0,0 +1,95 @@ + +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