• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env sh
2#
3# Install musl and musl-sanitized linux kernel headers
4# to musl-{$1} directory
5
6set -ex
7
8MUSL_VERSION=1.1.24
9MUSL="musl-${MUSL_VERSION}"
10
11# Download, configure, build, and install musl:
12curl --retry 5 https://www.musl-libc.org/releases/${MUSL}.tar.gz | tar xzf -
13
14cd $MUSL
15case ${1} in
16    aarch64)
17        musl_arch=aarch64
18        kernel_arch=arm64
19        CC=aarch64-linux-gnu-gcc \
20          ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes
21        make install -j4
22        ;;
23    arm)
24        musl_arch=arm
25        kernel_arch=arm
26        CC=arm-linux-gnueabihf-gcc CFLAGS="-march=armv6 -marm -mfpu=vfp" \
27          ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes
28        make install -j4
29        ;;
30    i686)
31        # cross-compile musl for i686 using the system compiler on an x86_64
32        # system.
33        musl_arch=i686
34        kernel_arch=i386
35        # Specifically pass -m32 in CFLAGS and override CC when running
36        # ./configure, since otherwise the script will fail to find a compiler.
37        CC=gcc CFLAGS="-m32" \
38          ./configure --prefix="/musl-${musl_arch}" --disable-shared --target=i686
39        # unset CROSS_COMPILE when running make; otherwise the makefile will
40        # call the non-existent binary 'i686-ar'.
41        make CROSS_COMPILE= install -j4
42        ;;
43    x86_64)
44        musl_arch=x86_64
45        kernel_arch=x86_64
46        ./configure --prefix="/musl-${musl_arch}"
47        make install -j4
48        ;;
49    s390x)
50        musl_arch=s390x
51        kernel_arch=s390
52        CC=s390x-linux-gnu-gcc \
53          ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes
54        make install -j4
55        ;;
56    *)
57        echo "Unknown target arch: \"${1}\""
58        exit 1
59        ;;
60esac
61
62
63# shellcheck disable=SC2103
64cd ..
65rm -rf $MUSL
66
67# Download, configure, build, and install musl-sanitized kernel headers:
68KERNEL_HEADER_VER="4.19.88"
69curl --retry 5 -L \
70     "https://github.com/sabotage-linux/kernel-headers/archive/v${KERNEL_HEADER_VER}.tar.gz" | \
71    tar xzf -
72(
73    cd kernel-headers-${KERNEL_HEADER_VER}
74    make ARCH="${kernel_arch}" prefix="/musl-${musl_arch}" install -j4
75)
76rm -rf kernel-headers-${KERNEL_HEADER_VER}
77