summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fankhauser hiddenalpha.ch2023-02-19 17:20:30 +0100
committerAndreas Fankhauser hiddenalpha.ch2023-02-19 17:20:30 +0100
commit4015f6de5c98cab856991a05b27713af90e97e7f (patch)
tree1464d6b6fefeb7b41e78a46fcdb158c38fad6381
parent9e4ff1fe33081c1a4a8639fe2e27ffc6f2d4f48a (diff)
downloadDeflateAndInflate-4015f6de5c98cab856991a05b27713af90e97e7f.zip
DeflateAndInflate-4015f6de5c98cab856991a05b27713af90e97e7f.tar.gz
(build) Simplify build doc
- Include target tripplet into version - Refactor docker build env by a more flexible script variant
-rwxr-xr-xconfigure4
-rw-r--r--contrib/build-using-docker/Dockerfile35
-rw-r--r--contrib/build-using-docker/README.md64
-rw-r--r--contrib/build-with-debian/README.md73
-rw-r--r--contrib/build-with-mingw64/README.md95
-rw-r--r--src/main/c/inflate.c13
6 files changed, 178 insertions, 106 deletions
diff --git a/configure b/configure
index 85aa010..d838adf 100755
--- a/configure
+++ b/configure
@@ -59,9 +59,9 @@ printMakefile () {
printf '%s' 'PROJECT_VERSION=$(shell'
printf '%s' ' ret=$$(git describe --tags 2>/dev/null |sed -E "s;^v;;");'
printf '%s' ' if test -n "$$ret" -a -n "$$(git status --porcelain 2>/dev/null)"; then'
- printf '%s' ' ret="$$ret+dirt";'
+ printf '%s' ' ret="$$ret+dirt.$$($(CC) -dumpmachine)";'
printf '%s' ' fi;'
- printf '%s' ' if test -z "$$ret"; then ret=$$(date -u +0.0.0-%Y%m%d.%H%M%S); fi;'
+ printf '%s' ' if test -z "$$ret"; then ret=$$(date -u +0.0.0-%Y%m%d.%H%M%S)"+$$($(CC) -dumpmachine)"; fi;'
printf '%s\n' ' echo "$$ret")'
if test "$verbose" = "0"; then printf '\n%s\n' '.SILENT:'; fi
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.
+
diff --git a/src/main/c/inflate.c b/src/main/c/inflate.c
index 4b50a0a..ab4eb0b 100644
--- a/src/main/c/inflate.c
+++ b/src/main/c/inflate.c
@@ -28,14 +28,14 @@ struct MyInflate {
static void printHelp( void ){
printf("\n %s%s", strrchr(__FILE__,'/')+1, " @ " STR_QUOT(PROJECT_VERSION) "\n"
"\n"
- "inflates stdin to stdout\n"
+ " inflates stdin to stdout\n"
"\n"
- "Options:\n"
+ " Options:\n"
"\n"
" --raw\n"
- " By default, we'll try to decode leading headers. Using this\n"
- " option, no header parsing is done and the input is expected to\n"
- " be a pure deflate stream.\n"
+ " By default, we'll try to decode leading headers. Using this\n"
+ " option, no header parsing is done and the input is expected to\n"
+ " be a pure deflate stream.\n"
"\n"
"\n");
}
@@ -110,6 +110,7 @@ static int doInflate( MyInflate*myInflate ){
}
if( space > 0 && !inputIsEOF ){
err = fread(innBuf + innBuf_len, 1, space, stdin);
+ //fprintf(stderr, "fread(buf+%d, 1, %d, stdin) -> %d\n", innBuf_len, space, err);
if(unlikely( err <= 0 )){
if( feof(stdin) ){
inputIsEOF = !0;
@@ -152,6 +153,8 @@ static int doInflate( MyInflate*myInflate ){
int flush = inputIsEOF ? Z_FINISH : Z_NO_FLUSH;
errno = 0;
err = inflate(&strm, flush);
+ //fprintf(stderr, "inflate({.avI=%d, .avO=%d}, %d) -> %d\n", strm.avail_in, strm.avail_out,
+ // flush, err);
if(unlikely( err != Z_OK )){
if( err == Z_STREAM_END ){
outputIsEOF = !0;