summaryrefslogtreecommitdiff
path: root/src/main/docker/gcc.Dockerfile
blob: 5894667b9ca1285216a13302ab47d96f73acff73 (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
#
# Debian GCC build env
#

ARG BASE_IMG=debian:9-slim
FROM $BASE_IMG

ARG PKGSTOADD="ca-certificates curl gcc make tar"
ARG PKGSTODEL="ca-certificates curl"
ARG PKGADD="apt-get install -y --no-install-recommends"
ARG PKGDEL="apt-get purge -y"
ARG PKGCLEAN="apt-get clean"
ARG PKGINIT="apt-get update"
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

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:?}"; \
       } \
    #
    && $PKGADD libc-dev \
    && 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 \
    &&     ./configure --prefix="${PWD:?}/build/" \
    &&     make -e -j$MAKE_JOBS \
    &&     make install \
    &&     cp README build/. \
    &&     (cd build \
    &&         find -type f -not -name MD5SUM -exec md5sum -b {} + > MD5SUM) \
    &&     (cd build && tar --owner=0 --group=0 -cz *) > "/tmp/zlib-${version:?}-debian.tgz" \
    &&     cd / && rm -rf "/tmp/zlib" \
    &&     mkdir -p /usr/local/ \
    &&     tar -C /usr/local -f "/tmp/zlib-${version:?}-debian.tgz" -x include lib \
    &&     cd "${origDir:?}" \
    &&     echo -e "\n  zlib Done :)\n" ; } \
    && 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 libc-dev xz-utils \
    && 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" 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 \
    &&     cd "$origDir" \
    &&     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" \
    #
    && $PKGADD libc-dev \
    && 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 \
    &&     CFLAGS="-Wall -pedantic -fPIC" \
    &&     gcc $CFLAGS -c -o build/obj/cJSON.o cJSON.c \
    &&     gcc $CFLAGS -shared -o build/lib/libcJSON.so.1.7.15 build/obj/cJSON.o \
    &&     unset CFLAGS \
    &&     (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 \
    &&     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 \
    &&     cd "$origDir" \
    &&     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 libc-dev 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 \
    &&     SHARED=1 make -e -j$MAKE_JOBS tests lib mbedtls_test \
    &&     if [ -e build ]; then echo "ERR already exists: $PWD/build"; false; fi \
    &&     make -e install \
    &&     (cd build && tar --owner=0 --group=0 -cz *) > "/tmp/mbedtls-${version:?}-debian.tgz" \
    &&     cd / && rm -rf /tmp/mbedtls \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/mbedtls-${version:?}-debian.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" \
    #
    && $PKGADD libc-dev tcl \
    && 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 \
    &&     ./configure --prefix="${PWD:?}/build" \
    &&     make -e clean \
    &&     make -e -j$MAKE_JOBS \
    &&     make -e install \
    &&     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-${version:?}-debian.tgz" \
    &&     cd / && rm -rf /tmp/sqlite \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/sqlite-${version:?}-debian.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 libc-dev \
    && 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 \
    &&     cp -t build/. README \
    &&     cp -t build/bin/. src/lua src/luac \
    &&     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:?}-debian.tgz" \
    &&     cd / && rm -rf /tmp/lua \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/lua-${version:?}-debian.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 libc-dev libasound2-dev libxext-dev libpulse-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= \
    &&     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:?}-debian.tgz" \
    &&     cd / && rm -rf /tmp/SDL2 \
    &&     mkdir -p /usr/local \
    &&     tar -C /usr/local -f /tmp/SDL2-${version:?}-debian.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