1. get linux kernel source

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.3.9.tar.xz

2. install dependency packages

brew install openssl

3. compile and fix compile errors

compile

choose using llvm toolchain to build.

# install llvm if you don't have it
brew install llvm

ref:Building Linux with Clang/LLVM

make ARCH=arm64 LLVM=1 menuconfig

GNU Make >= 3.82 is required

install make, and use gmake to compile

brew install make
# generate .config
gmake ARCH=arm64 LLVM=1 menuconfig
# compile
gmake ARCH=arm64 LLVM=1 -j`nproc --all`

<elf.h> not found

# download elf.h to /usr/local/include dir
curl https://raw.githubusercontent.com/bminor/glibc/master/elf/elf.h > /usr/local/include/elf.h

gmake ARCH=arm64 LLVM=1 HOSTCFLAGS="-I/usr/local/include" -j`nproc --all`

<endian.h> not found

curl https://gist.github.com/dendisuhubdy/19482135d26da86cdcf442b3724e0728/raw/7c15d65789c794de84006d648dccbbe99c167399/endian.h > /usr/local/include/endian.h

<openssl/bio.h> file not found

brew info openssl
# specify compile and link flags
gmake ARCH=arm64 LLVM=1 HOSTCFLAGS="-I/usr/local/include -I/opt/homebrew/opt/openssl/include" HOSTLDFLAGS="-L/opt/homebrew/opt/openssl/lib" -j`nproc --all`

typedef redefinition with different types ‘struct uuid_t’ vs ‘__darwin_uuid_t’

modify scripts/mod/file2alias.c file:

/* backwards compatibility, don't use in new code */
typedef struct {
        __u8 b[16];
} uuid_le;

// 在uuid_t结构体定义之前通过宏定义为其换个壳
#ifdef __APPLE__
#define uuid_t compat_uuid_t
#endif

typedef struct {
        __u8 b[16];
} uuid_t;