├── README.md ├── dbgcv.patch └── Dockerfile /README.md: -------------------------------------------------------------------------------- 1 | # 7zip Static Build Dockerfile 2 | 3 | [Docker](http://docker.com) container to build [7-Zip](https://www.7-zip.org/) as a static executable. 4 | 5 | 6 | ## Usage 7 | 8 | ### Install 9 | 10 | You can build the `7zip_static` Docker container from source, during the container's build it will create the UASM and 7-Zip binaries as statically linked executables. 11 | 12 | In the case of UASM it will compile the executable with Clang as `/usr/local/bin/uasm`. In the case of 7-Zip it will compile the executable with Clang as `/usr/local/bin/7zz`. 13 | 14 | #### To create the Docker container from scratch and copy the binaries to the current working directory. 15 | 16 | ##### first, view https://www.7-zip.org/history.txt and get 7-zip latest build number,example: 17 | ``` 18 | HISTORY of the 7-Zip 19 | -------------------- 20 | 21 | 21.04 beta 2021-11-02 22 | ------------------------- 23 | ``` 24 | you can get the latest build number is 21.04, so variable VERSION=2104, Important without decimal point! 25 | 26 | ##### second, run the commands below: 27 | ``` 28 | git clone https://github.com/justdan96/7zip_static.git 29 | cd 7zip_static 30 | docker build --build-arg VERSION=2104 -t 7zip_static . 2>&1 | tee build.log 31 | docker run -it --rm -v $(pwd):/workdir -w="/workdir" 7zip_static sh -c "cp /usr/local/bin/* /workdir" 32 | ``` -------------------------------------------------------------------------------- /dbgcv.patch: -------------------------------------------------------------------------------- 1 | --- dbgcv.c.orig 2021-06-09 16:42:58.071853143 +0100 2 | +++ dbgcv.c 2021-06-10 10:32:31.453195825 +0100 3 | @@ -17,7 +17,24 @@ 4 | #include 5 | #include 6 | #include 7 | +#ifdef _WIN32 8 | #include 9 | +#endif 10 | +#ifdef __UNIX__ 11 | +#include 12 | +#include 13 | +#include 14 | +#endif 15 | +#ifndef PATH_MAX 16 | +#define PATH_MAX 4096 17 | +#endif 18 | +#define _MAX_PATH PATH_MAX 19 | +#ifndef _getcwd 20 | +#define _getcwd getcwd 21 | +#endif 22 | +#ifndef _pgmptr 23 | +#define _pgmptr "uasm" 24 | +#endif 25 | #include 26 | 27 | #define SIZE_CV_SEGBUF ( MAX_LINE_LEN * 4 ) 28 | @@ -1252,7 +1269,9 @@ 29 | #define USEMD5 30 | 31 | #ifdef USEMD5 32 | +#ifndef BUFSIZ 33 | #define BUFSIZ 1024*4 34 | +#endif 35 | #define MD5_LENGTH ( sizeof( uint_32 ) + sizeof( uint_16 ) + 16 + sizeof( uint_16 ) ) 36 | 37 | static int calc_md5(const char* filename, unsigned char* sum) 38 | @@ -1565,22 +1584,31 @@ 39 | s = strcpy(s, "cwd") + 4; 40 | s = strcpy(s, cv.currdir) + q + 1; 41 | s = strcpy(s, "exe") + 4; 42 | + 43 | len = strlen(_pgmptr) + 1; 44 | s = strcpy(s, _pgmptr) + len; 45 | + 46 | s = strcpy(s, "src") + 4; 47 | p = cv.files[0].name; 48 | if (_memicmp(p, cv.currdir, q) == 0) 49 | p += q + 1; 50 | - 51 | + 52 | len = strlen(p) + 1; 53 | s = strcpy(s, p) + len; 54 | *s++ = '\0'; 55 | + #ifdef _WIN32 56 | EnvBlock->reclen = (unsigned short)(s - cv.ps - 2); 57 | + #else 58 | + EnvBlock->reclen = (unsigned short)(s - (char*)cv.ps - 2); 59 | + #endif 60 | cv.ps = s; 61 | 62 | /* length needs to be added for each symbol */ 63 | - 64 | + #ifdef _WIN32 65 | cv.section->length += (s - start); 66 | + #else 67 | + cv.section->length += (s - (char*)start); 68 | + #endif 69 | 70 | } 71 | else { 72 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | MAINTAINER Dan Bryant (daniel.bryant@linux.com) 3 | 4 | # add variable VERSION for 7zip build number, The default value here is 2103 5 | ARG VERSION=2103 6 | ENV TZ=Europe/London 7 | 8 | # install all the Linux build dependencies 9 | RUN apk add --no-cache alpine-sdk git patch wget clang make build-base musl-dev 10 | RUN apk add --no-cache clang-dev gcc lld 11 | RUN apk add --no-cache llvm curl libarchive-tools 12 | 13 | # we will try to compile UASM on Linux 14 | RUN mkdir /usr/local/src && cd /usr/local/src && git clone --branch v2.52 https://github.com/Terraspace/UASM.git 15 | COPY dbgcv.patch /usr/local/src/UASM/dbgcv.patch 16 | RUN cd /usr/local/src/UASM && patch < dbgcv.patch 17 | RUN sed -i.bak 's!#ifndef _TYPES_H_INCLUDED!#ifndef _TYPES_H_INCLUDED_!g' /usr/local/src/UASM/H/types.h 18 | RUN cd /usr/local/src/UASM && CFLAGS="-std=c99 -static" make CC="clang -fcommon" -f gccLinux64.mak 19 | RUN cp /usr/local/src/UASM/GccUnixR/uasm /usr/local/bin/uasm 20 | 21 | # we need to install 7zip to compile 7zip? As per jo620kix's suggestion we can use bsdtar instead 22 | RUN curl -o /tmp/7z${VERSION}-src.7z "https://www.7-zip.org/a/7z${VERSION}-src.7z" 23 | RUN mkdir /usr/local/src/7z${VERSION} && cd /usr/local/src/7z${VERSION} && bsdtar -xf /tmp/7z${VERSION}-src.7z 24 | RUN rm -f /tmp/7z${VERSION}-src.7z 25 | 26 | # MUSL doesn't support pthread_attr_setaffinity_np so we have to disable affinity 27 | # we also have to amend the warnings so we don't trip over "disabled expansion of recursive macro" 28 | # we need a small patch to ensure UASM doesn't try to align the stack in any assembler functions - this mimics expected asmc behaviour 29 | RUN cd /usr/local/src/7z${VERSION} && sed -i -e '1i\OPTION FRAMEPRESERVEFLAGS:ON\nOPTION PROLOGUE:NONE\nOPTION EPILOGUE:NONE' Asm/x86/*.asm 30 | 31 | # create the Clang version 32 | RUN cd /usr/local/src/7z${VERSION}/CPP/7zip/Bundles/Alone2 && make CFLAGS_BASE_LIST="-c -static -D_7ZIP_AFFINITY_DISABLE=1" MY_ASM=uasm MY_ARCH="-static" CFLAGS_WARN_WALL="-Wall -Wextra" -f ../../cmpl_clang_x64.mak 33 | RUN mv /usr/local/src/7z${VERSION}/CPP/7zip/Bundles/Alone2/b/c_x64/7zz /usr/local/bin/7zz 34 | 35 | # clean up the source files for our binaries 36 | RUN rm -rf /usr/local/src/UASM 37 | RUN rm -rf /usr/local/src/7z${VERSION} --------------------------------------------------------------------------------