summaryrefslogtreecommitdiff
path: root/src/main/docker/windoof-gcc.Dockerfile
blob: 69cc18ecd16c37ba78987c397650d70f4f7930fe (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#
# Windoof GCC build env
#

ARG BASE_IMG=alpine:3.16.0
FROM $BASE_IMG

ARG PKGSTOADD="ca-certificates curl mingw-w64-gcc make tar"
ARG PKGSTODEL="ca-certificates curl"
ARG PKGADD="apk add"
ARG PKGDEL="apk del"
ARG PKGCLEAN="true"
ARG PKGINIT="true"
ARG VERSION_CJSON="1.7.15"
ARG VERSION_EXPAT="2.4.2"
ARG VERSION_LUA="5.4.3"
ARG VERSION_MBEDTLS="3.1.0"
ARG VERSION_SDL2="2.0.20"
ARG VERSION_SQLITE="3.33.0"
ARG VERSION_ZLIB="1.2.11"

ENV NDEBUG=1 MAKE_JOBS=8 HOST=x86_64-w64-mingw32

RUN true \
    && $PKGINIT && $PKGADD $PKGSTOADD \
    #
    && ensureSourceIsCached () { \
           local localPath=${1:?}; \
           local url=${2:?}; \
           if test -f "${localPath:?}"; then \
               echo "[DEBUG] Source avail as \"${localPath:?}\""; \
               return; \
           fi; \
           echo "[DEBUG] Downloading \"${localPath:?}\""; \
           echo "[DEBUG]   from \"${url:?}\""; \
           curl -L "$url" -o "${localPath:?}"; \
       } \
    #
    && makeZlib () { echo "\n  Build zlib\n" \
    &&     local version="${1:?}" \
    &&     local tarbal="${2:?}" \
    &&     local origDir="${PWD:?}" \
    &&     mkdir "/tmp/zlib" && cd "/tmp/zlib" \
    &&     tar xzf "${tarbal:?}" \
    &&     cd zlib-* \
    &&     mkdir build \
    &&     export DESTDIR=./build BINARY_PATH=/bin INCLUDE_PATH=/include LIBRARY_PATH=/lib \
    &&     sed -i "s;^PREFIX =.\*\$;;" win32/Makefile.gcc \
    &&     make -e -j$MAKE_JOBS -fwin32/Makefile.gcc PREFIX="${HOST:?}"- \
    &&     make -e -fwin32/Makefile.gcc install PREFIX="${HOST:?}"- \
    &&     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-${version:?}-windoof.tgz" \
    &&     cd / && rm -rf "/tmp/zlib" \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f "/tmp/zlib-${version:?}-windoof.tgz" -x include lib \
    &&     echo -e "\n  zlib Done :)\n" \
    &&     cd "${origDir:?}" ; } \
    && ensureSourceIsCached "/tmp/zlib-${VERSION_ZLIB:?}.tgz" "https://downloads.sourceforge.net/project/libpng/zlib/${VERSION_ZLIB:?}/zlib-${VERSION_ZLIB}.tar.gz" \
    && makeZlib "${VERSION_ZLIB:?}" "/tmp/zlib-${VERSION_ZLIB:?}.tgz" \
    #
    && $PKGADD xz \
    && makeExpat () { echo -e "\n  Build Expat\n" \
    &&     local version="${1:?}" \
    &&     local tarbal="${2:?}" \
    &&     local origDir="${PWD:?}" \
    &&     mkdir /tmp/expat && cd /tmp/expat \
    &&     tar xf "${tarbal:?}" --strip-components=1 \
    &&     mkdir build \
    &&     ./configure --prefix="${PWD:?}/build" --host="${HOST:?}" CFLAGS="-Wall -pedantic --std=c99 -O2" \
    &&     make -e clean \
    &&     make -e -j$MAKE_JOBS \
    &&     make -e install \
    &&     cp README.md build/. \
    &&     (cd build && rm -rf lib/cmake lib/libexpat.la lib/pkgconfig) \
    &&     (cd build && find -type f -not -name MD5SUM -exec md5sum -b {} + > MD5SUM) \
    &&     (cd build && tar --owner=0 --group=0 -cz *) > "/tmp/expat-${version:?}-debian.tgz" \
    &&     cd / && rm -rf /tmp/expat \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/expat-2.4.2-debian.tgz -x bin include lib \
    &&     echo -e "\n  Expat Done :)\n" ; } \
    && ensureSourceIsCached "/tmp/expat-${VERSION_EXPAT}.txz" "https://github.com/libexpat/libexpat/releases/download/R_2_4_2/expat-${VERSION_EXPAT}.tar.xz" \
    && makeExpat "${VERSION_EXPAT:?}" "/tmp/expat-${VERSION_EXPAT}.txz" \
    #
    && makeCJSON () { echo -e "\n  Build cJSON\n" \
    &&     local version="${1:?}" \
    &&     local tarbal="${2:?}" \
    &&     local origDir="${PWD:?}" \
    &&     mkdir /tmp/cJSON && cd /tmp/cJSON \
    &&     tar xf "${tarbal:?}" \
    &&     cd * \
    &&     mkdir build build/obj build/lib build/include \
    &&     CC="${HOST:?}-gcc" \
    &&     AR="${HOST:?}-ar" \
    &&     CFLAGS="-Wall -pedantic -fPIC" \
    &&     ${CC:?} $CFLAGS -c -o build/obj/cJSON.o cJSON.c \
    &&     ${CC:?} $CFLAGS -shared -o build/lib/libcJSON.so.1.7.15 build/obj/cJSON.o \
    &&     (cd build/lib && ln -s libcJSON.so."${version:?}" libcJSON.so."${version%.*}") \
    &&     (cd build/lib && ln -s libcJSON.so."${version%.*}" libcJSON.so."${version%.*.*}") \
    &&     ${AR:?} rcs build/lib/libcJSON.a build/obj/cJSON.o \
    &&     unset CC AR CFLAGS \
    &&     cp -t build/. LICENSE README.md \
    &&     cp -t build/include/. cJSON.h \
    &&     rm -rf build/obj \
    &&     (cd build && find -type f -not -name MD5SUM -exec md5sum -b {} + > MD5SUM) \
    &&     (cd build && tar --owner=0 --group=0 -f "/tmp/cJSON-${version:?}-debian.tgz" -cz *) \
    &&     cd / && rm -rf /tmp/cJSON \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/cJSON-${version:?}-debian.tgz -x include lib \
    &&     echo -e "\n  cJSON Done :)\n"; } \
    && ensureSourceIsCached "/tmp/cJSON-${VERSION_CJSON:?}.tgz" "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.15.tar.gz" \
    && makeCJSON "${VERSION_CJSON:?}" "/tmp/cJSON-${VERSION_CJSON:?}.tgz" \
    #
    && $PKGADD python3 \
    && makeMbedtls () { echo -e "\n  Build mbedtls\n" \
    &&     local version="${1:?}" \
    &&     local tarbal="${2:?}" \
    &&     local origDir="${PWD:?}" \
    &&     mkdir /tmp/mbedtls && cd /tmp/mbedtls \
    &&     tar xf "${tarbal:?}" \
    &&     cd * \
    &&     sed -i 's;^DESTDIR=.*$;DESTDIR='"$PWD"'/build;' Makefile \
    # Yet another hack around as gethostname seems not to exist and I do
    # not understand how to disable compiling those "programs" which I
    # do not want anyway.
    &&     rm programs/ssl/ssl_mail_client.c programs/test/udp_proxy.c \
    &&     sed -i '/^\t\+\(ssl\/ssl_mail_client\|test\/udp_proxy\) \+\\$/d' programs/Makefile \
    &&     sed -i '/^ \+ssl_mail_client$/d' programs/ssl/CMakeLists.txt \
    &&     export CC="${HOST:?}-gcc" AR="${HOST:?}-ar" WINDOWS_BUILD=1 SHARED=1 \
    &&     make -e -j$MAKE_JOBS no_test \
    &&     if [ -e build ]; then echo "ERR already exists: $PWD/build"; false; fi \
    &&     make -e install \
    &&     unset CC AR WINDOWS_BUILD SHARED \
    &&     (cd build && tar --owner=0 --group=0 -cz *) > "/tmp/mbedtls-${version:?}-windoof.tgz" \
    &&     cd / && rm -rf /tmp/mbedtls \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/mbedtls-${version:?}-windoof.tgz -x bin include lib \
    &&     cd "${origDir:?}" \
    &&     echo -e "\n  mbedtls Done :)\n" ; } \
    && ensureSourceIsCached "/tmp/mbedtls-${VERSION_MBEDTLS:?}.tgz" "https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v${VERSION_MBEDTLS:?}.tar.gz" \
    && makeMbedtls "${VERSION_MBEDTLS:?}" "/tmp/mbedtls-${VERSION_MBEDTLS:?}.tgz" \
    #
    && makeSqLite () { echo -e "\n  Build SqLite\n" \
    &&     local version="${1:?}" \
    &&     local tarbal="${2:?}" \
    &&     local origDir="${PWD:?}" \
    &&     mkdir /tmp/sqlite && cd /tmp/sqlite \
    &&     tar xf "${tarbal:?}" \
    &&     cd * \
    &&     mkdir build \
    &&     $PKGADD gcc musl-dev tcl \
    &&     export CC="${HOST}-gcc" CPP="${HOST:?}-cpp" CXX="${HOST:?}-g++" BCC=gcc \
    &&     ./configure --prefix="${PWD:?}/build" --host=$HOST CC=$CC CPP=$CPP CXX=$CXX BCC=gcc BEXE=.exe config_TARGET_EXEEXT=.exe \
    &&     ln -s mksourceid.exe mksourceid \
    &&     make -e clean \
    &&     make -e -j$MAKE_JOBS \
    &&     $PKGDEL gcc musl-dev tcl \
    &&     make -e install \
    &&     unset CC CPP CXX BCC \
    &&     (cd build && rm -rf lemon* mksourceid lib/pkgconfig lib/*.la) \
    &&     cp README.md LICENSE.md VERSION build/. \
    &&     (cd build && find -not -name MD5SUM -type f -exec md5sum -b {} + > MD5SUM) \
    &&     (cd build && tar --owner=0 --group=0 -cz *) > "/tmp/sqlite-3.33.0-windoof.tgz" \
    &&     cd / && rm -rf /tmp/sqlite \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/sqlite-${version:?}-windoof.tgz -x bin include lib \
    &&     cd "$origDir" \
    &&     echo -e "\n  SqLite Done :)\n"; } \
    && ensureSourceIsCached "/tmp/sqlite-${VERSION_SQLITE:?}.tgz" "https://github.com/sqlite/sqlite/archive/refs/tags/version-3.33.0.tar.gz" \
    && makeSqLite "${VERSION_SQLITE:?}" "/tmp/sqlite-${VERSION_SQLITE:?}.tgz" \
    #
    && $PKGADD binutils \
    && makeLua () { echo -e "\n  Build Lua\n" \
    &&     local version="${1:?}" \
    &&     local tarbal="${2:?}" \
    &&     local origDir="${PWD:?}" \
    &&     mkdir /tmp/lua && cd /tmp/lua \
    &&     tar xf "${tarbal:?}" \
    &&     cd * \
    &&     mkdir -p build/bin build/include build/lib build/man/man1 \
    &&     make -e -j$MAKE_JOBS PLAT=mingw CC="${HOST:?}-gcc -std=gnu99" "AR=${HOST:?}-ar rcu" "RANLIB=${HOST:?}-ranlib" \
    &&     cp -t build/. README \
    &&     cp -t build/bin/. src/lua.exe src/luac.exe \
    &&     cp -t build/include/. src/lua.h src/luaconf.h src/lualib.h src/lauxlib.h src/lua.hpp \
    &&     cp -t build/lib/. src/liblua.a \
    &&     cp -t build/man/man1/. doc/lua.1 doc/luac.1 \
    &&     (cd build && find -not -name MD5SUM -type f -exec md5sum -b {} + > MD5SUM) \
    &&     (cd build && tar --owner=0 --group=0 -cz *) > "/tmp/lua-${version:?}-windoof.tgz" \
    &&     cd / && rm -rf /tmp/lua \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/lua-${version:?}-windoof.tgz -x bin include lib man \
    &&     cd "$origDir" \
    &&     echo -e "\n  Lua Done :)\n"; } \
    && ensureSourceIsCached "/tmp/lua-${VERSION_LUA:?}.tgz" "https://www.lua.org/ftp/lua-${VERSION_LUA:?}.tar.gz" \
    && makeLua "${VERSION_LUA:?}" "/tmp/lua-${VERSION_LUA:?}.tgz" \
    #
    && $PKGADD alsa-lib libxext-dev pulseaudio-dev \
    && makeSDL2 () { echo -e "\n  Build SDL2\n" \
    &&     local version="${1:?}" \
    &&     local tarbal="${2:?}" \
    &&     local origDir="${PWD:?}" \
    &&     mkdir /tmp/SDL2 && cd /tmp/SDL2 \
    &&     tar xf "${tarbal:?}" \
    &&     cd * \
    &&     ./configure --prefix="${PWD:?}/build" --host="${HOST:?}" \
    &&     make -e -j$MAKE_JOBS \
    &&     make -e install \
    &&     cp -t build/. CREDITS.txt LICENSE.txt README-SDL.txt README.md \
    &&     (cd build \
    &&         ls -A \
               | egrep -v '^(CREDITS.txt|LICENSE.txt|README-SDL.txt|RADME.md|bin|lib|include)$' \
               | xargs rm -rf) \
    &&     (cd build && rm -rf lib/cmake lib/pkgconfig lib/*.la) \
    &&     (cd build && find -type f -exec md5sum -b {} + > MD5SUM) \
    &&     (cd build && tar --owner=0 --group=0 -cz *) > "/tmp/SDL2-${version:?}-windoof.tgz" \
    &&     cd / && rm -rf /tmp/SDL2 \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/SDL2-${version:?}-windoof.tgz -x include lib \
    &&     cd "$origDir" \
    &&     echo -e "\n  SDL2 Done :)\n"; } \
    && ensureSourceIsCached "/tmp/SDL2-${VERSION_SDL2:?}.tgz" "https://www.libsdl.org/release/SDL2-${VERSION_SDL2}.tar.gz" \
    && makeSDL2 "${VERSION_SDL2:?}" "/tmp/SDL2-${VERSION_SDL2:?}.tgz" \
    #
    && $PKGDEL $PKGSTODEL && $PKGCLEAN \
    && true

WORKDIR /work

CMD sleep 999999999