diff --git a/Dockerfile b/Dockerfile index cb8a363..eef08c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ENV LC_ALL C ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ - apt-get -y install git curl build-essential + apt-get -y install git curl build-essential RUN mkdir -p /build && \ mkdir -p /dist @@ -16,8 +16,8 @@ RUN chmod +x /build-latest \ /install-latest \ /install-latest-git -VOLUME "/dist" +VOLUME /dist RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -CMD ["/build-latest"] \ No newline at end of file +CMD ["/build-wrapper"] diff --git a/rootfs/build-latest b/rootfs/build-latest index 0214922..3027e26 100644 --- a/rootfs/build-latest +++ b/rootfs/build-latest @@ -2,31 +2,118 @@ set -e set -x -# make version (for skarnet) -make_version=4.1 - -# skarnet versions -musl_version=1.0.4 -skalibs_version=2.3.1.0 -execline_version=2.1.0.0 -s6_version=2.1.1.2 -s6_portable_utils_version=2.0.0.1 - # point to make MAKE_4x=/usr/local/bin/make -# configures /dev/random in order to disable hangs -rm /dev/random -mknod /dev/random c 1 9 +skarnet_packages=( +skalibs +execline +s6 +s6-portable-utils +s6-linux-utils +s6-dns +s6-networking +) + +# software versions +declare -A versions +versions[make]=4.1 +versions[linux]=3.18.5 +versions[musl]=1.0.4 +versions[skalibs]=2.3.1.0 +versions[execline]=2.1.0.0 +versions[s6]=2.1.1.2 +versions[s6-portable-utils]=2.0.0.1 +versions[s6-linux-utils]=2.0.1.0 +versions[s6-dns]=2.0.0.2 +versions[s6-networking]=2.1.0.0 + +declare -A includes +includes[skalibs]="--with-include=/usr/musl/include" +includes[execline]="--with-include=/opt/skalibs/usr/include ${includes[skalibs]}" +includes[s6]="--with-include=/opt/execline/usr/include ${includes[execline]}" +includes[s6-portable-utils]="${includes[s6]}" +includes[s6-linux-utils]="--with-include=/opt/linux-headers/include ${includes[s6]}" +includes[s6-dns]="${includes[s6]}" +includes[s6-networking]="--with-include=/opt/s6-dns/usr/include --with-include=/opt/s6/usr/include ${includes[s6]}" + +declare -A libs +libs[skalibs]="--with-lib=/usr/musl/lib" +libs[execline]="--with-lib=/opt/skalibs/usr/lib ${libs[skalibs]}" +libs[s6]="--with-lib=/opt/execline/usr/lib ${libs[execline]}" +libs[s6-portable-utils]="${libs[s6]}" +libs[s6-linux-utils]="${libs[s6]}" +libs[s6-dns]="${libs[s6]}" +libs[s6-networking]="--with-lib=/opt/s6-dns/usr/lib --with-lib=/opt/s6/usr/lib ${libs[s6]}" + +declare -A sysdeps +sysdeps[skalibs]="" +sysdeps[execline]="--with-sysdeps=/opt/skalibs/usr/lib/skalibs/sysdeps" +sysdeps[s6]="${sysdeps[execline]}" +sysdeps[s6-portable-utils]="${sysdeps[execline]}" +sysdeps[s6-linux-utils]="${sysdeps[execline]}" +sysdeps[s6-dns]="${sysdeps[execline]}" +sysdeps[s6-networking]="${sysdeps[execline]}" + +declare -A configopts +configopts[skalibs]="--datadir=/etc --enable-force-devr" +configopts[execline]="" +configopts[s6]="" +configopts[s6-portable-utils]="" +configopts[s6-dns]="" +configopts[s6-networking]="" + +build_install_skarnet_package() { + local package=$1 + cd /build + curl -R -L -O "http://skarnet.org/software/${package}/${package}-${versions[$package]}.tar.gz" + tar xf "${package}-${versions[$package]}.tar.gz" + cd "${package}-${versions[$package]}" + CC="musl-gcc" ./configure \ + --prefix=/usr \ + --libdir=/usr/lib \ + --enable-static \ + --disable-shared \ + --enable-static-libc \ + ${includes[$package]} \ + ${libs[$package]} \ + ${sysdeps[$package]} \ + ${configopts[$package]} + ${MAKE_4x} + ${MAKE_4x} DESTDIR="/opt/${package}" install +} +tar_skarnet_package() { + local package=$1 + if [[ -d "/opt/${package}/usr/bin" ]]; then + find "/opt/${package}/usr/bin" -type f -exec strip {} \; + fi + + tar -czf "/dist/${package}-${versions[$package]}-linux-amd64-bin.tar.gz" \ + --exclude "usr/lib" \ + --exclude "usr/include" \ + -C "/opt/${package}" . + + local dev_dirs="" + if [[ -d "/opt/${package}/usr/lib" ]]; then + dev_dirs="usr/lib" + fi + if [[ -d "/opt/${package}/usr/include" ]]; then + dev_dirs="${dev_dirs} usr/include" + fi + if [[ -n "${dev_dirs}" ]]; then + tar -czf "/dist/${package}-${versions[$package]}-linux-amd64-dev.tar.gz" \ + -C "/opt/${package}" $dev_dirs + fi +} # create build dir mkdir -p /build # install make cd /build -curl -R -L -O http://ftp.gnu.org/gnu/make/make-${make_version}.tar.gz -tar xf make-${make_version}.tar.gz -cd make-${make_version} +curl -R -L -O http://ftp.gnu.org/gnu/make/make-${versions[make]}.tar.gz +tar xf make-${versions[make]}.tar.gz +cd make-${versions[make]} ./configure make @@ -34,9 +121,9 @@ make install # install musl cd /build -curl -R -L -O http://www.musl-libc.org/releases/musl-${musl_version}.tar.gz -tar xf musl-${musl_version}.tar.gz -cd musl-${musl_version} +curl -R -L -O http://www.musl-libc.org/releases/musl-${versions[musl]}.tar.gz +tar xf musl-${versions[musl]}.tar.gz +cd musl-${versions[musl]} CFLAGS="-fno-toplevel-reorder -fno-stack-protector" \ ./configure \ @@ -46,95 +133,20 @@ CFLAGS="-fno-toplevel-reorder -fno-stack-protector" \ ${MAKE_4x} ${MAKE_4x} install -# install skalibs +# install linux-headers cd /build -curl -R -L https://github.com/skarnet/skalibs/archive/v${skalibs_version}.tar.gz -o skalibs-${skalibs_version}.tar.gz -tar xf skalibs-${skalibs_version}.tar.gz -cd skalibs-${skalibs_version} +curl -R -L -O http://www.kernel.org/pub/linux/kernel/v3.x/linux-${versions[linux]}.tar.xz +tar xf linux-${versions[linux]}.tar.xz +cd linux-${versions[linux]} +for i in /patches/linux/*.patch; do + patch -p1 -i "${i}" || true +done +make headers_install ARCH="$(uname -m)" INSTALL_HDR_PATH="/opt/linux-headers" CC="musl-gcc" -CC="musl-gcc -static" \ - ./configure \ - --prefix=$HOME/usr \ - --enable-static-libc \ - --disable-shared -# replace SKALIBS_ETC to "/etc" -sed -i '/.*SKALIBS_ETC.*/c\\#define SKALIBS_ETC \"\/etc\"' src/include/skalibs/config.h +# install skarnet packages +for package in "${skarnet_packages[@]}"; do + build_install_skarnet_package ${package} + tar_skarnet_package ${package} +done -${MAKE_4x} -${MAKE_4x} install - -# install execline -cd /build -curl -R -L https://github.com/skarnet/execline/archive/v${execline_version}.tar.gz -o execline-${execline_version}.tar.gz -tar xf execline-${execline_version}.tar.gz -cd execline-${execline_version} - -CC="musl-gcc -static" \ - ./configure \ - --prefix=$HOME/usr \ - --exec-prefix=$HOME/dist/execline/usr \ - --with-include=$HOME/usr/include \ - --with-lib=$HOME/usr/lib/skalibs \ - --enable-static-libc \ - --disable-shared -${MAKE_4x} -${MAKE_4x} install - -tar \ - -zcvf $HOME/dist/execline-${execline_version}-linux-amd64.tar.gz \ - -C $HOME/dist/execline \ - ./ - -# install s6 -cd /build -curl -R -L https://github.com/skarnet/s6/archive/v${s6_version}.tar.gz -o s6-${s6_version}.tar.gz -tar xf s6-${s6_version}.tar.gz -cd s6-${s6_version} - -CC="musl-gcc -static" \ - ./configure \ - --prefix=$HOME/usr \ - --exec-prefix=$HOME/dist/s6/usr \ - --with-include=$HOME/usr/include \ - --with-lib=$HOME/usr/lib/skalibs \ - --with-lib=$HOME/usr/lib/execline \ - --enable-static-libc \ - --disable-shared -${MAKE_4x} -${MAKE_4x} install - -mkdir -p $HOME/dist/s6/etc -install -D -m644 $HOME/usr/etc/* $HOME/dist/s6/etc/ - -tar \ - -zcvf $HOME/dist/s6-${s6_version}-linux-amd64.tar.gz \ - -C $HOME/dist/s6 \ - ./ - -# install s6-portable-utils -cd /build -curl -R -L https://github.com/skarnet/s6-portable-utils/archive/v${s6_portable_utils_version}.tar.gz -o s6-portable-utils-${s6_portable_utils_version}.tar.gz -tar xf s6-portable-utils-${s6_portable_utils_version}.tar.gz -cd s6-portable-utils-${s6_portable_utils_version} - -CC="musl-gcc -static" \ - ./configure \ - --prefix=$HOME/usr \ - --exec-prefix=$HOME/dist/s6-portable-utils/usr \ - --with-include=$HOME/usr/include \ - --with-lib=$HOME/usr/lib/skalibs \ - --enable-static-libc \ - --disable-shared -${MAKE_4x} -${MAKE_4x} install - -tar \ - -zcvf $HOME/dist/s6-portable-utils-${s6_portable_utils_version}-linux-amd64.tar.gz \ - -C $HOME/dist/s6-portable-utils \ - ./ - -# copy results -cp $HOME/dist/execline-${execline_version}-linux-amd64.tar.gz /dist -cp $HOME/dist/s6-${s6_version}-linux-amd64.tar.gz /dist -cp $HOME/dist/s6-portable-utils-${s6_portable_utils_version}-linux-amd64.tar.gz /dist diff --git a/rootfs/build-wrapper b/rootfs/build-wrapper new file mode 100755 index 0000000..5b819a7 --- /dev/null +++ b/rootfs/build-wrapper @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +rm -f /dist/*.log +/build-latest 2>&1 | tee "/dist/build-latest-$(date +'%Y%m%d%H%M%S').log" diff --git a/rootfs/patches/linux/1-4-glibc-specific-inclusion-of-sysinfo.h-in-kernel.h.patch b/rootfs/patches/linux/1-4-glibc-specific-inclusion-of-sysinfo.h-in-kernel.h.patch new file mode 100644 index 0000000..0b4cfb1 --- /dev/null +++ b/rootfs/patches/linux/1-4-glibc-specific-inclusion-of-sysinfo.h-in-kernel.h.patch @@ -0,0 +1,12 @@ +--- ./include/uapi/linux/kernel.h.orig ++++ ./include/uapi/linux/kernel.h +@@ -1,7 +1,9 @@ + #ifndef _UAPI_LINUX_KERNEL_H + #define _UAPI_LINUX_KERNEL_H + ++#ifdef __GLIBC__ + #include ++#endif + + /* + * 'kernel.h' contains some often-used function prototypes etc diff --git a/rootfs/patches/linux/3-4-libc-compat.h-fix-some-issues-arising-from-in6.h.patch b/rootfs/patches/linux/3-4-libc-compat.h-fix-some-issues-arising-from-in6.h.patch new file mode 100644 index 0000000..e4ce3d6 --- /dev/null +++ b/rootfs/patches/linux/3-4-libc-compat.h-fix-some-issues-arising-from-in6.h.patch @@ -0,0 +1,61 @@ +--- ./include/uapi/linux/libc-compat.h.orig ++++ ./include/uapi/linux/libc-compat.h +@@ -48,35 +48,26 @@ + #ifndef _UAPI_LIBC_COMPAT_H + #define _UAPI_LIBC_COMPAT_H + +-/* We have included glibc headers... */ +-#if defined(__GLIBC__) ++#ifndef __KERNEL__ /* we're used from userspace */ + +-/* Coordinate with glibc netinet/in.h header. */ +-#if defined(_NETINET_IN_H) ++/* Coordinate with libc netinet/in.h header. */ ++#ifdef _NETINET_IN_H + + /* GLIBC headers included first so don't define anything + * that would already be defined. */ + #define __UAPI_DEF_IN6_ADDR 0 +-/* The exception is the in6_addr macros which must be defined +- * if the glibc code didn't define them. This guard matches +- * the guard in glibc/inet/netinet/in.h which defines the +- * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */ +-#if defined(__USE_MISC) || defined (__USE_GNU) + #define __UAPI_DEF_IN6_ADDR_ALT 0 +-#else +-#define __UAPI_DEF_IN6_ADDR_ALT 1 +-#endif + #define __UAPI_DEF_SOCKADDR_IN6 0 + #define __UAPI_DEF_IPV6_MREQ 0 + #define __UAPI_DEF_IPPROTO_V6 0 + +-#else ++#else /* defined(_NETINET_IN_H) */ + + /* Linux headers included first, and we must define everything +- * we need. The expectation is that glibc will check the ++ * we need. The expectation is that the libc will check the + * __UAPI_DEF_* defines and adjust appropriately. */ + #define __UAPI_DEF_IN6_ADDR 1 +-/* We unconditionally define the in6_addr macros and glibc must ++/* We unconditionally define the in6_addr macros and the libc must + * coordinate. */ + #define __UAPI_DEF_IN6_ADDR_ALT 1 + #define __UAPI_DEF_SOCKADDR_IN6 1 +@@ -89,7 +80,7 @@ + /* If we did not see any headers from any supported C libraries, + * or we are being included in the kernel, then define everything + * that we need. */ +-#else /* !defined(__GLIBC__) */ ++#else /* __KERNEL__ */ + + /* Definitions for in6.h */ + #define __UAPI_DEF_IN6_ADDR 1 +@@ -98,6 +89,6 @@ + #define __UAPI_DEF_IPV6_MREQ 1 + #define __UAPI_DEF_IPPROTO_V6 1 + +-#endif /* __GLIBC__ */ ++#endif /* __KERNEL__ */ + + #endif /* _UAPI_LIBC_COMPAT_H */ diff --git a/rootfs/patches/linux/4-4-libc-compat.h-prevent-redefinition-of-struct-ethhdr.patch b/rootfs/patches/linux/4-4-libc-compat.h-prevent-redefinition-of-struct-ethhdr.patch new file mode 100644 index 0000000..b8ac94f --- /dev/null +++ b/rootfs/patches/linux/4-4-libc-compat.h-prevent-redefinition-of-struct-ethhdr.patch @@ -0,0 +1,39 @@ +--- ./include/uapi/linux/if_ether.h.orig ++++ ./include/uapi/linux/if_ether.h +@@ -22,6 +22,7 @@ + #define _UAPI_LINUX_IF_ETHER_H + + #include ++#include + + /* + * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble +@@ -130,11 +131,12 @@ + * This is an Ethernet frame header. + */ + ++#if __UAPI_DEF_ETHHDR + struct ethhdr { + unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ + unsigned char h_source[ETH_ALEN]; /* source ether addr */ + __be16 h_proto; /* packet type ID field */ + } __attribute__((packed)); +- ++#endif + + #endif /* _UAPI_LINUX_IF_ETHER_H */ +--- ./include/uapi/linux/libc-compat.h.orig ++++ ./include/uapi/linux/libc-compat.h +@@ -50,6 +50,12 @@ + + #ifndef __KERNEL__ /* we're used from userspace */ + ++#ifdef _NETINET_IF_ETHER_H /* musl */ ++#define __UAPI_DEF_ETHHDR 0 ++#else /* glibc uses __NETINET_IF_ETHER_H, and includes the kernel header. */ ++#define __UAPI_DEF_ETHHDR 1 ++#endif ++ + /* Coordinate with libc netinet/in.h header. */ + #ifdef _NETINET_IN_H + diff --git a/rootfs/patches/linux/src.txt b/rootfs/patches/linux/src.txt new file mode 100644 index 0000000..225eb24 --- /dev/null +++ b/rootfs/patches/linux/src.txt @@ -0,0 +1 @@ +Alpine Linux: http://git.alpinelinux.org/cgit/aports/tree/main/linux-headers