Browse Source

building amazon linux and debian images from source, that use dynamic linking with a path relative to the binary, tarballs and deb package

pull/1/head
Benedikt Kristinsson 12 months ago
parent
commit
579d8a7526
  1. 3
      .gitignore
  2. 26
      amzn/Dockerfile
  3. 59
      amzn/entrypoint-amzn.sh
  4. 18
      build-amzn.sh
  5. 18
      build-debian.sh
  6. 33
      debian/Dockerfile
  7. 82
      debian/entrypoint.sh

3
.gitignore

@ -0,0 +1,3 @@
dist/
emacs/
*.tar.xz

26
amzn/Dockerfile

@ -0,0 +1,26 @@
FROM amazonlinux:1
ARG VERSION=27.1
ARG CPU_COUNT=8
RUN yum -y update && \
yum -y install devtoolset-9-gcc devtoolset-9-libgccjit-devel gnutls-devel git ncurses-devel && \
yum -y groupinstall "Development Tools"
ADD emacs-${VERSION}.tar.xz /emacs
WORKDIR /emacs/emacs-${VERSION}
ARG PREFIX=/emacs/target
RUN ./configure --prefix=${PREFIX} --with-x=no CFLAGS="-I$ORIGIN/../include" --without-sound \
LDFLAGS="-L$ORIGIN/lib -Wl,-rpath=\\\$\$ORIGIN/../lib"
RUN make -j${CPU_COUNT}
RUN make install -j${CPU_COUNT}
ADD entrypoint-amzn.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint-amzn.sh
ENV VERSION ${VERSION}
ENV PREFIX ${PREFIX}
ENTRYPOINT ["/usr/local/bin/entrypoint-amzn.sh"]
CMD ["package"]

59
amzn/entrypoint-amzn.sh

@ -0,0 +1,59 @@
#!/bin/bash
set -e
set -x
if [ "$1" = "shell" ]; then
exec -l /bin/bash
elif [ "$1" = "emacs" ]; then
exec $EMACSROOT/bin/emacs
elif [ ! "$1" = "package" ]; then
echo "invalid args: '$1'"
exit 1
fi
if [ -z "$VERSION" ]; then
echo "varible VERSION must be set!"
exit 1
fi
if [ -z "$PREFIX" ]; then
PREFIX=/emacs/target
fi
CPU_COUNT=$(grep "processor" -c /proc/cpuinfo)
DIST=/emacs/dist
TARGET=$PREFIX
mkdir -p $TARGET
# we compiled emacs with runpath set to '$ORIGIN/../lib' ($ORIGIN is a
# special token so we can specify a location relative to the
# executable
#
# Same as running
# $ patchelf --set-rpath '$ORIGIN/../lib' $TARGET/bin/emacs
#
# https://www.reddit.com/r/emacs/comments/6nnd6x/selfcontainedrelocatableportable_emacs24_for_linux/dkbbs6h/
#
# copying some lib files
cp /lib64/librt.so.1 $TARGET/lib/
cp /usr/lib64/libgnutls.so.26 $TARGET/lib/
# in the output we see that the binary is dynamically linking the
# files we copied
ldd $TARGET/bin/emacs
mkdir -p $DIST/amzn
# make a tarball
(
rm $DIST/amzn/czemacs-${VERSION}.tar.gz || true
cd $TARGET
tar -cf $DIST/amzn/czemacs-${VERSION}.tar.gz .
)
# copy the compiled $TARGET
(
rm -rf $DIST/amzn/czemacs-${VERSION} || true
mkdir -p $DIST/amzn/czemacs-${VERSION}
cp -r $TARGET/* $DIST/amzn/czemacs-${VERSION}/
)

18
build-amzn.sh

@ -0,0 +1,18 @@
#!/bin/bash
set -x
set -e
VERSION="27.1"
PREFIX=/home/bkristinsson/.local
DIST="$(pwd)/dist"
(
cd amzn/
docker build --build-arg PREFIX=$PREFIX --build-arg VERSION=$VERSION -t build-emacs-amzn .
docker run --rm -v $DIST:/emacs/dist -it build-emacs-amzn $1
)
# docker rmi build-emacs-amzn

18
build-debian.sh

@ -0,0 +1,18 @@
#!/bin/bash
set -x
set -e
VERSION="27.1"
PREFIX=/emacs/target
DIST="$(pwd)/dist"
(
cd debian/
docker build --build-arg VERSION=$VERSION -t build-emacs-debian .
docker run -v $DIST/:/emacs/dist --rm -it build-emacs-debian $1
)
# docker image rmi build-emacs-debian

33
debian/Dockerfile

@ -0,0 +1,33 @@
FROM debian:bullseye
ENV DEBIAN_FRONTEND noninteractive
ARG VERSION=27.1
ARG CPU_COUNT=8
RUN mkdir /emacs && mkdir /emacs/target && mkdir /emacs/build/ && \
apt-get update && \
apt-get install -y wget build-essential autoconf texinfo gnutls-bin \
libgnutls28-dev pkg-config libncurses-dev patchelf
# installing fpm
RUN apt-get install -y ruby ruby-dev rubygems build-essential && \
gem install --no-document fpm
# untars !
ADD emacs-${VERSION}.tar.xz /emacs
WORKDIR /emacs/emacs-${VERSION}
ARG PREFIX=/emacs/target
RUN ./configure --prefix=$PREFIX --with-x=no CFLAGS="-I$EMACSROOT/include" \
LDFLAGS="-L$EMACSROOT/lib -Wl,-rpath=\\\$\$ORIGIN/../lib"
RUN make -j${CPU_COUNT}
RUN make install -j${CPU_COUNT}
ADD entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENV VERSION ${VERSION}
ENV PREFIX ${PREFIX}
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["package"]

82
debian/entrypoint.sh

@ -0,0 +1,82 @@
#!/bin/bash
set -e
set -x
if [ "$1" = "shell" ]; then
exec -l /bin/bash
elif [ "$1" = "emacs" ]; then
exec $EMACSROOT/bin/emacs
elif [ ! "$1" = "package" ]; then
echo "invalid args: '$1'"
exit 1
fi
if [ -z "$VERSION" ]; then
echo "varible VERSION must be set!"
exit 1
fi
if [ -z "$PREFIX" ]; then
PREFIX=/emacs/target
fi
CPU_COUNT=$(grep "processor" -c /proc/cpuinfo)
DIST=/emacs/dist
TARGET=$PREFIX
mkdir -p $TARGET
# we compiled emacs with runpath set to '$ORIGIN/../lib' ($ORIGIN is a
# special token so we can specify a location relative to the
# executable
#
# Same as running
# $ patchelf --set-rpath '$ORIGIN/../lib' $TARGET/bin/emacs
#
# https://www.reddit.com/r/emacs/comments/6nnd6x/selfcontainedrelocatableportable_emacs24_for_linux/dkbbs6h/
#
# copying some lib files
cp /lib/x86_64-linux-gnu/librt.so.1 $EMACSROOT/lib/
cp /lib/x86_64-linux-gnu/libtinfo.so.6 $EMACSROOT/lib/
cp /usr/lib/x86_64-linux-gnu/libgnutls.so.30 $EMACSROOT/lib/
# in the output we see that the binary is dynamically linking the
# files we copied
ldd $TARGET/bin/emacs
mkdir -p $DIST/debian
# make a tarball
(
rm $DIST/debian/emacs-${VERSION}.tar.gz || true
cd $TARGET
tar -cf $DIST/debian/emacs-${VERSION}.tar.gz .
)
# make a .deb with fpm
(
# set dependencies (check with apt)
fpm -t deb -v $VERSION -n emacs -s dir $TARGET/=/usr
cp *.deb $DIST/debian/
)
# copy the compiled $TARGET
(
rm -rf $DIST/debian/emacs-${VERSION} || true
mkdir -p $DIST/debian/emacs-${VERSION}
cp -r $TARGET/* $DIST/debian/emacs-${VERSION}/
)
# if [ ! -d "/emacs/emacs-${VERSION}" ]; then
# (
# cd /emacs
# wget https://ftp.gnu.org/gnu/emacs/emacs-${VERSION}.tar.xz
# tar xf emacs-${VERSION}.tar.xz
# rm emacs-${VERSION}.tar.xz
# # todo: check signature
# )
# fi
Loading…
Cancel
Save