• 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    mips64)
50        musl_arch=mips64
51        kernel_arch=mips
52        CC=mips64-linux-gnuabi64-gcc CFLAGS="-march=mips64r2 -mabi=64" \
53          ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes
54        make install -j4
55        ;;
56    mips64el)
57        musl_arch=mips64el
58        kernel_arch=mips
59        CC=mips64el-linux-gnuabi64-gcc CFLAGS="-march=mips64r2 -mabi=64" \
60          ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes
61        make install -j4
62        ;;
63    s390x)
64        musl_arch=s390x
65        kernel_arch=s390
66        CC=s390x-linux-gnu-gcc \
67          ./configure --prefix="/musl-${musl_arch}" --enable-wrapper=yes
68        make install -j4
69        ;;
70    *)
71        echo "Unknown target arch: \"${1}\""
72        exit 1
73        ;;
74esac
75
76
77# shellcheck disable=SC2103
78cd ..
79rm -rf $MUSL
80
81# Download, configure, build, and install musl-sanitized kernel headers:
82KERNEL_HEADER_VER="4.19.88"
83curl --retry 5 -L \
84     "https://github.com/sabotage-linux/kernel-headers/archive/v${KERNEL_HEADER_VER}.tar.gz" | \
85    tar xzf -
86(
87    cd kernel-headers-${KERNEL_HEADER_VER}
88    make ARCH="${kernel_arch}" prefix="/musl-${musl_arch}" install -j4
89)
90rm -rf kernel-headers-${KERNEL_HEADER_VER}
91