linux-qubasis
linux oasis port as a qubes template
git clone https://9o.is/git/linux-qubasis.git
commit 6c931c06fd2e034878a1db5ffb922ef837aea84d parent c2ad2a0df87d417cef6226f426dee1ddb8904edf Author: Jul <jul@9o.is> Date: Thu, 4 Sep 2025 22:05:38 +0800 add linux-headers Diffstat:
| M | ninja/functions.sh | | | 22 | +++++++++++++++++++--- |
| M | ninja/rules.ninja | | | 4 | ++++ |
| M | pkg/linux-headers/gen.sh | | | 63 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | pkg/linux-headers/header.sed | | | 7 | +++++++ |
| A | pkg/linux-headers/unistd.awk | | | 18 | ++++++++++++++++++ |
| A | pkg/linux-headers/version.awk | | | 8 | ++++++++ |
6 files changed, 119 insertions(+), 3 deletions(-)
diff --git a/ninja/functions.sh b/ninja/functions.sh @@ -171,6 +171,12 @@ gen() { fi } +headers_exist() { + if _ninja_has $1 $_ninja_buffer_headers; then + return 0 + fi + return 1 +} ## ## Internal ninja functions and variables @@ -204,6 +210,9 @@ _ninja_initglobals() { _ninja_dir="$_ninja_basedir"/$1 _ninja_ninjadir="$_ninja_basedir"/$BUILDDIR/ninja + DIR="$_ninja_dir" + SRCDIR="$_ninja_dir/repo" + case $1 in .) _ninja_type=root @@ -593,9 +602,16 @@ _ninja_flush_headers() { _srcs= for _src in $_ninja_buffer_headers; do - _out=$outdir/include/${_src##*/} - _srcs="$_srcs $_out" - build copy $_out $_src + case $_src in + \$srcdir/*) + _out=$outdir/include/${_src##*/} + _srcs="$_srcs $_out" + build copy $_out $_src + ;; + *) + _srcs="$_srcs $_src" + ;; + esac done build phony $tgtdir/headers $_srcs diff --git a/ninja/rules.ninja b/ninja/rules.ninja @@ -92,3 +92,7 @@ rule extract-deflate rule patch command = git -C $srcdir am --3way --keep-non-patch --no-gpg-sign --whitespace=nowarn $PWD/$in && touch $out description = PATCH $in + +rule sed + command = sed $expr $in >$out + description = SED $out diff --git a/pkg/linux-headers/gen.sh b/pkg/linux-headers/gen.sh @@ -6,3 +6,66 @@ fetch curl \ 'linux-*/arch/*/entry/syscalls/' \ 'linux-*/include/uapi/' \ 'linux-*/scripts/unifdef.c' + +case $TARGET_ARCH in + x86_64) linux_headers_arch=x86;; + *) error "Unsupported arch $TARGET_ARCH";; +esac + +rule header 'sed -E -f $dir/header.sed $in >$out.tmp && { $hostdir/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ $out.tmp >$out; [ $$? -le 1 ]; } && rm $out.tmp' +bind description 'LINUX HEADER $out' +rule wrapper 'printf "#include <asm-generic/%s>\n" $file >$out' +bind description 'LINUX HEADER $out' + +host() { + exe unifdef scripts/unifdef.c +} + +add_header() { + sync $1 + headers $2 +} + +uapi_headers() { + srcs="$(find $SRCDIR/$1/* -name '*.h' | sed "s|^$SRCDIR|$srcdir|" | LC_COLLATE=C sort)" + for src in $srcs; do + outfile=$outdir/include/${src#*/uapi/} + build header $outfile $src '|' $dir/header.sed $hostdir/unifdef + add_header $src $outfile + done +} + +wrap_mandatory() { + for src in $*; do + outfile=$outdir/include/asm/$src + if ! headers_exist $outfile; then + build wrapper $outfile + bind file $src + headers $outfile + fi + done +} + +unistd_header() { + out=$outdir/include/asm/$1 + src=$srcdir/$2 + build awk $out $src '|' $dir/unistd.awk + bind expr "-f $dir/unistd.awk -v arch=x86 -v file='$1' -v spec='${4-}' -v abi='$3'" + headers $out +} + +uapi_headers include/uapi +uapi_headers arch/$linux_headers_arch/include/uapi + +build awk $outdir/include/linux/version.h $srcdir/Makefile '|' $dir/version.awk +bind expr '-f $dir/version.awk' +add_header $srcdir/Makefile $outdir/include/linux/version.h + +wrap_mandatory "$(cat $SRCDIR/include/uapi/asm-generic/Kbuild | grep -E '^mandatory-y' | sed 's|^mandatory-y += ||')" + +if [ $linux_headers_arch = x86 ]; then + unistd_header unistd_32.h arch/x86/entry/syscalls/syscall_32.tbl i386 + unistd_header unistd_x32.h arch/x86/entry/syscalls/syscall_64.tbl 'common|x32' __X32_SYSCALL_BIT + unistd_header unistd_64.h arch/x86/entry/syscalls/syscall_64.tbl 'common|64' +fi + diff --git a/pkg/linux-headers/header.sed b/pkg/linux-headers/header.sed @@ -0,0 +1,7 @@ +# scripts/headers_install.sh +s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g +s/__attribute_const__([[:space:]]|$)/\1/g +s@^#include <linux/compiler(_types)?.h>@@ +s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g +s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g +s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @ diff --git a/pkg/linux-headers/unistd.awk b/pkg/linux-headers/unistd.awk @@ -0,0 +1,18 @@ +BEGIN { + guard = toupper("_ASM_" arch "_" file) + gsub(/[^A-Za-z0-9_]/, "_", guard) + print "#ifndef " guard + print "#define " guard " 1" + print "" +} + +$0 ~ /^[^#]+/ && $2 ~ "^(" abi ")$" { + if (off != "") + $1 = "(" off " + " $1 ")" + print "#define __NR_" $3, $1 +} + +END { + print "" + print "#endif /* " guard " */" +} diff --git a/pkg/linux-headers/version.awk b/pkg/linux-headers/version.awk @@ -0,0 +1,8 @@ +/^VERSION = / { version = $3 } +/^PATCHLEVEL = / { patchlevel = $3 } +/^SUBLEVEL = / { sublevel = $3 } + +END { + print "#define LINUX_VERSION_CODE " (version * 65536 + patchlevel * 256 + sublevel) + print "#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))" +}