forked from Dovetail-Automata/mk-cross-builder
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
422 lines (368 loc) · 12.7 KB
/
Dockerfile
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
MAINTAINER John Morris <john@zultron.com>
###################################################################
# Build configuration settings
# - Passed in from hooks/build script based on Docker tag
ARG DEBIAN_ARCH
ARG HOST_MULTIARCH
ARG DISTRO_CODENAME
ARG DISTRO_VER
ARG SYS_ROOT
ARG EXTRA_FLAGS
ARG LDEMULATION
# - Set in container environment
ENV DEBIAN_ARCH=${DEBIAN_ARCH}
ENV HOST_MULTIARCH=${HOST_MULTIARCH}
ENV DISTRO_CODENAME=${DISTRO_CODENAME}
ENV DISTRO_VER=${DISTRO_VER}
ENV SYS_ROOT=${SYS_ROOT}
ENV EXTRA_FLAGS=${EXTRA_FLAGS}
ENV LDEMULATION=${LDEMULATION}
###################################################################
# Generic apt configuration
ENV TERM=dumb
# apt config: silence warnings and set defaults
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN=true
ENV LC_ALL=C.UTF-8
ENV LANGUAGE=C.UTF-8
ENV LANG=C.UTF-8
# turn off recommends on container OS and proot OS
RUN echo 'APT::Install-Recommends "0";\nAPT::Install-Suggests "0";' > \
/etc/apt/apt.conf.d/01norecommend
# use stable Debian mirror
ARG DEBIAN_MIRROR=ftp.debian.org
ARG DEBIAN_SECURITY_MIRROR=security.debian.org
RUN sed -i /etc/apt/sources.list \
-e "s/deb.debian.org/${DEBIAN_MIRROR}/" \
-e "s/security.debian.org/${DEBIAN_SECURITY_MIRROR}/"
###################################################################
# Add foreign arches and update OS
# add foreign architectures
RUN if test -n "${SYS_ROOT}"; then \
dpkg --add-architecture $DEBIAN_ARCH; \
fi
# update Debian OS
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get clean
###################################################################
# Install utility and dev packages
# Utilities
RUN apt-get -y install \
libfile-fcntllock-perl \
locales \
git \
bzip2 \
sharutils \
net-tools \
time \
procps \
help2man \
xvfb \
xauth \
python-sphinx \
wget \
sudo \
lftp \
apt-transport-https \
ca-certificates \
multistrap \
debian-keyring \
debian-archive-keyring \
python-apt \
rubygems \
&& { \
test $DISTRO_VER -ge 10 \
|| apt-get install -y \
python-restkit; \
} \
&& apt-get clean
# Dev tools
RUN apt-get install -y \
build-essential \
devscripts \
fakeroot \
equivs \
lsb-release \
less \
python-debian \
libtool \
ccache \
autoconf \
automake \
quilt \
psmisc \
pkg-config \
qemu-user-static \
linux-libc-dev:${DEBIAN_ARCH} \
dh-python \
libreadline-dev \
&& { \
if test $DISTRO_VER -ge 9 -a \
\( $DEBIAN_ARCH = armhf -o $DEBIAN_ARCH = arm64 \); then \
apt-get install -y \
crossbuild-essential-${DEBIAN_ARCH}; \
fi; \
} \
&& apt-get clean
# - amd64 -> i386 multiarch/multilib compiles
RUN if test $DISTRO_VER -eq 8; then \
apt-get install -y \
binutils-i586-linux-gnu \
gcc-4.9-multilib \
g++-4.9-multilib; \
elif test $DISTRO_VER -eq 9; then \
apt-get install -y \
binutils-multiarch \
gcc-6-multilib \
g++-6-multilib \
libgcc-6-dev:$DEBIAN_ARCH; \
else \
apt-get install -y \
binutils-multiarch \
gcc-8-multilib \
g++-8-multilib \
libgcc-8-dev:$DEBIAN_ARCH; \
fi
# - Linaro gcc cross compiler for armhf, Jessie only
RUN if test $DISTRO_VER -eq 8; then \
VER=4.9.4-2017.01 && \
ARCH=arm-linux-gnueabihf && \
DIR=gcc-linaro-${VER}-x86_64_${ARCH} && \
TXZ=${DIR}.tar.xz && \
URI=http://releases.linaro.org/components/toolchain/binaries/latest-4/${ARCH} && \
WORKD=/tmp/linaro && \
mkdir -p ${WORKD} && cd ${WORKD} && \
echo "Downloading gcc-linaro-${VER}" && \
wget --progress=dot:mega ${URI}/${TXZ} && \
wget -q ${URI}/${TXZ}.asc && \
echo "Validating checksum of compiler download" && \
md5sum -c ${TXZ}.asc && \
echo "Extracting compiler to /opt/" && \
tar xCf /opt ${WORKD}/${TXZ} && \
ln -snf ${DIR} /opt/gcc-linaro-hf && \
rm -rf ${WORKD} && \
ln -s ../../bin/ccache /usr/lib/ccache/arm-linux-gnueabihf-gcc && \
ln -s ../../bin/ccache /usr/lib/ccache/arm-linux-gnueabihf-g++ ; \
fi
# - Qemu for emulating ARM on amd64
RUN if test $DEBIAN_ARCH = armhf -o $DEBIAN_ARCH = arm64; then \
apt-get install -y qemu binfmt-support qemu-user-static \
&& apt-get clean; \
fi
###########################################
# Packagecloud.io
# FIXME this began failing in Stretch
# # Add packagecloud cli and prune utility
# RUN gem install package_cloud --no-rdoc --no-ri
# ADD packagecloud/packagecloud-prune.py /usr/bin/packagecloud-prune
# ADD packagecloud/packagecloud-upload.sh /usr/bin/packagecloud-upload
# ADD packagecloud/PackagecloudIo.py /usr/lib/python2.7
###################################################################
# Build environment
ENV CPPFLAGS="${SYS_ROOT:+--sysroot=$SYS_ROOT ${EXTRA_FLAGS}}"
ENV LDFLAGS="${SYS_ROOT:+--sysroot=$SYS_ROOT ${EXTRA_FLAGS}}"
ENV PKG_CONFIG_PATH="${SYS_ROOT:+$SYS_ROOT/usr/lib/$HOST_MULTIARCH/pkgconfig:$SYS_ROOT/usr/lib/pkgconfig:$SYS_ROOT/usr/share/pkgconfig}"
ENV DPKG_ROOT=$SYS_ROOT
# armhf build root environment
ENV ARM_HOST_MULTIARCH=arm-linux-gnueabihf
# arm64
ENV ARM64_HOST_MULTIARCH=aarch64-linux-gnu
# i386 build root environment
ENV I386_HOST_MULTIARCH=i386-linux-gnu
###########################################
# Monkey-patches and multistrap setup
# Create sysroot directory
RUN test -z "$SYS_ROOT" || mkdir $SYS_ROOT
# Add multistrap configurations
ADD multistrap-configs/ /tmp/multistrap-configs/
# Add `{dh_shlibdeps,dpkg-shlibdeps} --sysroot` argument
ADD dpkg-shlibdeps-*.patch /tmp/
RUN cd / && \
patch -p0 -F 0 -N < /tmp/dpkg-shlibdeps-$DISTRO_VER.patch && \
rm /tmp/dpkg-shlibdeps-*.patch
RUN test -z "$SYS_ROOT" \
|| { \
mkdir -p ${SYS_ROOT}/etc \
&& cp /etc/ld.so.conf ${SYS_ROOT}/etc/ld.so.conf \
&& echo '/lib/arm-linux-gnueabihf\n/usr/lib/arm-linux-gnueabihf' > \
/etc/ld.so.conf.d/arm-linux-gnueabihf.conf \
&& echo '/lib/aarch64-linux-gnu\n/usr/lib/aarch64-linux-gnu' > \
/etc/ld.so.conf.d/aarch64-linux-gnu.conf; \
}
# Symlink i586 binutils to i386 so ./configure can find them
RUN test $DISTRO_VER -gt 8 || \
for i in /usr/bin/i586-linux-gnu-*; do \
ln -s $(basename $i) $(echo $i | sed 's/i586/i386/'); \
done
# Give dh_strip the multiarch utility names it needs
RUN test $DISTRO_VER -eq 8 || { \
ln -s x86_64-linux-gnu-objcopy /usr/bin/i686-linux-gnu-objcopy && \
ln -s x86_64-linux-gnu-objdump /usr/bin/i686-linux-gnu-objdump && \
ln -s x86_64-linux-gnu-strip /usr/bin/i686-linux-gnu-strip; \
}
# Symlink armhf-arch pkg-config, Jessie only
RUN if test $DISTRO_VER -eq 8; then \
ln -s pkg-config /usr/bin/${ARM_HOST_MULTIARCH}-pkg-config; \
fi
###################################################################
# Machinekit: Configure apt
# add Machinekit package archive
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 31B5958F43DDF224
RUN echo "deb http://deb.machinekit.io/debian $DISTRO_CODENAME main" > \
/etc/apt/sources.list.d/machinekit.list
###################################################################
# Machinekit: Install dependency packages
# Xenomai threads still supported on Jessie
RUN if test $DISTRO_CODENAME = jessie -a -z "$SYS_ROOT"; then \
apt-get install -y libxenomai-dev \
&& apt-get clean; \
fi
##############################
# Machinekit: Configure multistrap
# Set up debian/control files for `mk-build-deps`
# FIXME download parts from upstream
ADD pkgs/ /tmp/pkgs/
RUN MK_CROSS_BUILDER=1 /tmp/pkgs/mk-hal/debian/configure \
&& if test $DISTRO_VER -eq 8; then \
MK_CROSS_BUILDER=1 /tmp/pkgs/mk-cnc/debian/configure -prx; \
else \
MK_CROSS_BUILDER=1 /tmp/pkgs/mk-cnc/debian/configure -pr; \
fi
# Directory for `mk-build-deps` apt repository
RUN mkdir /tmp/debs && \
touch /tmp/debs/Sources
# Create deps package and local package repo
RUN if test $DISTRO_VER -eq 8; then \
mk-build-deps --arch $DEBIAN_ARCH \
/tmp/pkgs/mk-hal/debian/control \
/tmp/pkgs/mk-cnc/debian/control; \
else \
mk-build-deps --build-arch $DEBIAN_ARCH --host-arch $DEBIAN_ARCH \
/tmp/pkgs/mk-hal/debian/control \
/tmp/pkgs/mk-cnc/debian/control; \
fi \
&& mv *.deb /tmp/debs \
&& ( cd /tmp/debs && dpkg-scanpackages -m . > /tmp/debs/Packages )
# Add deps repo to apt sources for native builds
RUN if test $DISTRO_VER -le 9 -a $DEBIAN_ARCH = amd64; then \
echo "deb file:///tmp/debs ./" > /etc/apt/sources.list.d/local.list \
&& apt-get update; \
fi
##############################
# Machinekit: Host arch build environment
# Native arch: Install build dependencies
RUN if test -z "$SYS_ROOT"; then \
apt-get update \
&& if test $DISTRO_VER -le 9; then \
apt-get install -y -o Apt::Get::AllowUnauthenticated=true \
machinekit-hal-build-deps \
machinekit-cnc-build-deps \
&& sed -i /etc/apt/sources.list.d/local.list -e '/^deb/ s/^/#/' \
&& apt-get update ; \
else \
apt-get install -y /tmp/debs/machinekit-hal-build-deps_*.deb; \
fi \
&& apt-get clean; \
fi
# Patch multistrap on Buster
# https://github.com/volumio/Build/issues/348#issuecomment-462271607
RUN if test $DISTRO_VER -ge 9; then \
sed -i /usr/sbin/multistrap \
-e '/AllowUnauthenticated/ s/"$/ -o Acquire::AllowInsecureRepositories=true"/'; \
fi
# Foreign arch: Build "sysroot"
# - Select and unpack build dependency packages
RUN test -z "$SYS_ROOT" \
|| multistrap -f /tmp/multistrap-configs/$DISTRO_CODENAME.conf \
-a $DEBIAN_ARCH -d $SYS_ROOT
# - Fix symlinks in "sysroot" libdir pointing to `/lib/$MULTIARCH`
RUN test -z "$SYS_ROOT" \
|| { \
for link in $(find $SYS_ROOT/usr/lib/${HOST_MULTIARCH}/ -type l); do \
if test $(dirname $(readlink $link)) != .; then \
ln -sf ../../../lib/${HOST_MULTIARCH}/$(basename \
$(readlink $link)) $link; \
fi; \
done; \
}
# - Link tcl/tk setup scripts
RUN test -z "$SYS_ROOT" \
|| { \
mkdir -p /usr/lib/${HOST_MULTIARCH} && \
ln -s $SYS_ROOT/usr/lib/${HOST_MULTIARCH}/tcl8.6 \
/usr/lib/${HOST_MULTIARCH} && \
ln -s $SYS_ROOT/usr/lib/${HOST_MULTIARCH}/tk8.6 \
/usr/lib/${HOST_MULTIARCH}; \
}
# - Link directories with glib/gtk includes in the wrong place
RUN test -z "$SYS_ROOT" \
|| { \
ln -s $SYS_ROOT/usr/lib/${HOST_MULTIARCH}/glib-2.0 \
/usr/lib/${HOST_MULTIARCH} && \
ln -s $SYS_ROOT/usr/lib/${HOST_MULTIARCH}/gtk-2.0 \
/usr/lib/${HOST_MULTIARCH}; \
}
# - Link `xeno-config` to where autoconf can find it
RUN test -z "$SYS_ROOT" -o $DISTRO_VER -gt 8 || \
ln -s /sysroot/usr/bin/xeno-config /usr/bin/
##############################
# Machinekit: Build arch build environment
# Install Multi-Arch: foreign dependencies
RUN apt-get update \
&& apt-get install -y \
cython \
uuid-runtime \
protobuf-compiler \
python-protobuf \
python-pyftpdlib \
python-tk \
netcat-openbsd \
tcl8.6 tk8.6 \
cgroup-tools \
&& if test $DISTRO_VER -le 9; then \
apt-get install -y \
yapps2-runtime yapps2; \
else \
apt-get install -y \
python-yapps yapps2; \
fi \
&& apt-get clean
# Monkey-patch entire /usr/include, and re-add build-arch headers
RUN test -z "$SYS_ROOT" \
|| { \
mv /usr/include /usr/include.build && \
ln -s $SYS_ROOT/usr/include /usr/include && \
ln -sf /usr/include.build/x86_64-linux-gnu $SYS_ROOT/usr/include; \
}
# On Buster, the libczmq.pc file requires libsystemd but the
# libczmq-dev package doesn't require libsystemd-dev; take care of
# native case (sysroot case taken care of in multistrap config)
RUN if test $DISTRO_VER -eq 10 -a -z "$SYS_ROOT"; then \
apt-get install -y libsystemd-dev \
&& apt-get clean; \
fi
###########################################
# Set up environment
#
# Customize the following to match the user's environment
# Set up user ID inside container to match your ID
ENV USER=travis
ENV UID=1000
ENV GID=1000
ENV HOME=/home/${USER}
ENV SHELL=/bin/bash
ENV PATH=/usr/lib/ccache:/opt/gcc-linaro-hf/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN echo "${USER}:x:${UID}:${GID}::${HOME}:${SHELL}" >> /etc/passwd
RUN echo "${USER}:*:17967:0:99999:7:::" >> /etc/shadow
RUN echo "${USER}:x:${GID}:" >> /etc/group
# Customize the run environment to your taste
# - bash prompt
# - 'ls' alias
RUN sed -i /etc/bash.bashrc \
-e 's/^PS1=.*/PS1="\\h:\\W\\$ "/' \
-e '$a alias ls="ls -aFs"'
# Configure sudo, passwordless for everyone
RUN echo "ALL ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers