linux-qubasis

linux oasis port as a qubes template

git clone https://9o.is/git/linux-qubasis.git

commit 891dbe47c8dba4606f59c3d8fb6459fd6939dc57
parent 6d1778ccfe07590d5051507c7c7dbf03c8acd12b
Author: Jul <jul@9o.is>
Date:   Wed, 20 Aug 2025 02:26:08 -0400

introduce ninja build with abduco

Diffstat:
M.gitignore | 4+++-
Dbuild | 91-------------------------------------------------------------------------------
Aconfig.def.sh | 12++++++++++++
Aconfigure | 30++++++++++++++++++++++++++++++
Agen.sh | 17+++++++++++++++++
Aninja/functions.sh | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aninja/rules.ninja | 24++++++++++++++++++++++++
Aninja/sync.sh | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dpkg/abduco/build | 18------------------
Dpkg/abduco/config.h | 14--------------
Apkg/abduco/gen.sh | 8++++++++
Apkg/abduco/headers/config.h | 15+++++++++++++++
Apkg/abduco/version | 3+++
13 files changed, 340 insertions(+), 124 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,3 @@ -out/ +/out +/config.sh +/build.ninja diff --git a/build b/build @@ -1,91 +0,0 @@ -#!/bin/sh -set -euo pipefail - -script_root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) -pkgdir="$script_root/pkg" - - -display_help() { - echo "Usage: $0 [OPTIONS] [DIRECTORY]" - echo "" - echo "This script executes build scripts in child directories." - echo "" - echo "Options:" - echo " --all, -a Execute build scripts in ALL immediate subdirectories." - echo " --help, -h Display this help message and exit." - echo "" - echo "Arguments:" - echo " DIRECTORY Specify a single child directory to execute its build script." - echo " If a directory is provided, --all is ignored." - echo "" - echo "Examples:" - echo " $0 --all" - echo " $0 module_a" - echo " $0 ./module_b" -} - -run_all=false -targets=() - -export skip_clean=false -export local_install=false - -if [ "$#" -eq 0 ]; then - echo "Error: No arguments provided." - display_help - exit 1 -fi - -for arg in "$@"; do - case "$arg" in - --all|-a) - run_all=true - ;; - --local-install|-l) - local_install=true - ;; - --skip-clean|-s) - skip_clean=true - ;; - --help|-h) - display_help - exit 0 - ;; - -*) - echo "Error: Unknown option '$arg'." - display_help - exit 1 - ;; - *) - if [ ! -d "$pkgdir/$arg" ]; then - echo "Error: Unknown build target '$arg'" - display_help - exit 1 - fi - - targets+=("$arg") - ;; - esac -done - -if [ $run_all == 'true' ]; then - targets=(`find $pkgdir/* -maxdepth 0 -type d | sed "s|^$pkgdir/||"`) -fi - -echo "Building: ${targets[@]}" - -index=0 -for target in ${targets[*]}; do - index=$((index + 1)) - echo "[$index/${#targets[@]}] Building $target" - - export srcdir="$pkgdir/$target" - export outdir="$script_root/out/pkg/$target" - - $srcdir/build - - managedir="/rw/sync/manage/sync/$target" - sudo rm -rf "$managedir" - sudo cp -r "$outdir" "$managedir" - sudo chown -R sync-manage:sftponly "$managedir" -done diff --git a/config.def.sh b/config.def.sh @@ -0,0 +1,12 @@ +PREFIX= +BUILD_DIR='out' + +TARGET_ARCH='x86_64' +TARGET_PLATFORM="$TARGET_ARCH-linux-musl" +TARGET_CFLAGS='-Os -fPIE -pipe -Werror=implicit-function-declaration' +TARGET_LDFLAGS='-s -static-pie' + +HOST_CFLAGS='-O2 -pipe' +HOST_LDFLAGS= + +NINJA_CMD=samu diff --git a/configure b/configure @@ -0,0 +1,30 @@ +#!/bin/sh +set -eu + +export basedir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +require() { + if ! which $1 >/dev/null 2>&1; then + echo "Error: host dependency not found in path: $1" + exit 1 + fi +} + +if [ ! -f "$basedir"/config.sh ]; then + cp "$basedir"/config.def.sh "$basedir"/config.sh +fi + +. "$basedir"/config.sh +. "$basedir"/ninja/functions.sh + +require $TARGET_PLATFORM-cc +require $TARGET_PLATFORM-ld +require $TARGET_PLATFORM-ar +require $TARGET_PLATFORM-as +require $TARGET_PLATFORM-objcopy + +gen "${1:-.}" + +if [ ! "${1-}" ]; then + ln -sf "$basedir"/"$BUILD_DIR"/ninja/root.ninja "$basedir"/build.ninja +fi diff --git a/gen.sh b/gen.sh @@ -0,0 +1,17 @@ +setv 'ninja_required_version' '1.8' +setv 'basedir' '.' +setv 'builddir' "$BUILD_DIR" +setv 'ninjadir' '$builddir/ninja' +setv 'dir' '$basedir' + +setv ar $TARGET_PLATFORM-ar +setv as $TARGET_PLATFORM-as +setv cc $TARGET_PLATFORM-cc +setv ld $TARGET_PLATFORM-ld +setv objcopy $TARGET_PLATFORM-objcopy +setv cflags $TARGET_CFLAGS +setv ldflags $TARGET_LDFLAGS + +include '$basedir/ninja/rules.ninja' + +subgen pkg/abduco diff --git a/ninja/functions.sh b/ninja/functions.sh @@ -0,0 +1,172 @@ +ninja_dir=$BUILD_DIR/ninja +ninja_gen_files='$basedir/config.sh $basedir/ninja/functions.sh $dir/gen.sh' + +ninja_queue_subgen= +ninja_buffer_subninja= +ninja_buffer_builds= +ninja_buffer_exe= +ninja_buffer_exe_srcs= +ninja_buffer_exe_objs= +ninja_buffer_dep= +ninja_buffer_dep_srcs= +ninja_buffer_sync_srcs= + +setv() { + local v=$1; shift; + printf '%s = %s\n' "$v" "$*" >> "$ninja_fullpath" +} + +bind() { + local v=$1; shift; + setv " $v" "$*" +} + +include() { + printf 'include %s\n' "$1" >> "$ninja_fullpath" +} + +subninja() { + printf 'subninja $ninjadir/%s.ninja\n' "$1" >> "$ninja_fullpath" +} + +build() { + local rule="$1"; shift; + local out="$1"; shift; + local value="$*" + + printf 'build %s: %s %s\n' "$out" "$rule" "$value" >> "$ninja_fullpath" +} + +cflags() { + setv cflags '$cflags' "$*" +} + +copy() { + local src="$1" + local dst="${2-$src}" + + build copy "\$outdir/$dst" "\$srcdir/$src" +} + +exe() { + ninja_buffer_exe="\$outdir/$1"; shift; + ninja_buffer_exe_srcs="$*" + + ninja_buffer_builds="$ninja_buffer_builds $ninja_buffer_exe" +} + +dep() { + ninja_buffer_dep="\$outdir/$1"; shift; + ninja_buffer_dep_srcs="$*" +} + +subgen() { + ninja_queue_subgen="$ninja_queue_subgen $subgendir$1" + ninja_buffer_subninja="$ninja_buffer_subninja $1" +} + +ninja_flush_exe() { + local objs='' + local val='' + + for src in $ninja_buffer_exe_srcs; do + case $src in + *.c) + val="\$srcdir/$src" + ninja_buffer_sync_srcs="$ninja_buffer_sync_srcs $val" + + if [ "$ninja_buffer_exe" = "$ninja_buffer_dep" ]; then + val="$val || $ninja_buffer_dep_srcs" + fi + + build cc "\$outdir/o/$src.o" "$val" + objs="$objs \$outdir/o/$src.o" + ;; + *) + printf "Error gen $ninja_file: unknown file to compile: %s" "$src" + exit 1 + esac + done + + if [ "$objs" ]; then + build link $ninja_buffer_exe $objs + fi + + ninja_buffer_exe= + ninja_buffer_exe_srcs= + + if [ "$ninja_buffer_exe" = "$ninja_buffer_dep" ]; then + ninja_buffer_dep= + ninja_buffer_dep_srcs= + fi +} + +ninja_flush_subninja() { + local subbuilds='' + + for pkg in $ninja_buffer_subninja; do + subbuilds="$subbuilds \$gendir/$pkg/build" + subninja $pkg + done + + build phony '$gendir/configure' "\$ninjadir/$ninja_file" + build phony '$gendir/build' "$ninja_buffer_builds" "$subbuilds" + + ninja_buffer_subninja= + ninja_buffer_builds= +} + +ninja_flush_sync() { + local verfile="$dir"/version + + if [ ! -f "$verfile" ]; then + return + fi + + build sync '$outdir/o/version' '$gendir/version | $basedir/ninja/sync.sh' + build phony "$ninja_buffer_sync_srcs" '$outdir/o/version' + + ninja_buffer_sync_srcs= +} + +ninja_flush() { + ninja_flush_exe + ninja_flush_subninja + ninja_flush_sync +} + +gen() { + dir="$basedir"/$1 + + if [ "$1" = '.' ]; then + subgendir= + ninja_file=root.ninja + else + subgendir="$1/" + ninja_file=$1.ninja + fi + + ninja_fullpath="$basedir"/$ninja_dir/$ninja_file + mkdir -p "$basedir"/$ninja_dir/pkg + printf '' > "$ninja_fullpath" + + setv 'gendir' "$1" + + if [ "$1" != '.' ]; then + setv 'dir' '$basedir/$gendir' + setv 'outdir' '$builddir/$gendir' + setv 'srcdir' '$dir/repo' + fi + + . "$dir"/gen.sh + + ninja_flush + build gen "\$ninjadir/$ninja_file" "| $ninja_gen_files" + + if [ "$ninja_queue_subgen" ]; then + set -- $ninja_queue_subgen + local pkg=$1; shift; + ninja_queue_subgen="$@" + gen $pkg + fi +} diff --git a/ninja/rules.ninja b/ninja/rules.ninja @@ -0,0 +1,24 @@ +rule gen + command = sh $basedir/configure $gendir + description = CONFIGURE $gendir + generator = 1 + +rule sync + command = cd $basedir && sh $basedir/ninja/sync.sh $gendir $in $out >/dev/null + description = SYNC $gendir + generator = 1 + pool = console + +rule cc + command = $cc -MD -MF $out.d $cflags -c -o $out $in + depfile = $out.d + deps = gcc + description = CC $out + +rule link + command = $cc $ldflags -o $out $in $ldlibs + description = LINK $out + +rule copy + command = ln -f $in $out + description = COPY $out diff --git a/ninja/sync.sh b/ninja/sync.sh @@ -0,0 +1,56 @@ +set -e + + +if [ "$#" != 3 ] ; then + echo 'usage: sync.sh gendir in out' >&2 + exit 2 +fi + +dir="$1" +version_file="$2" +out_file="$3" + +. "$version_file" + +if [ ! "${method-}" ]; then + printf "Error sync $dir: missing sync method\n" >&2 + exit 1 +fi + +sync_git() { + local repo="$1" + local ref="$2" + local rel="$3" + + git submodule update --init --checkout $repo + git -C $repo clean -dx + git -C $repo reset --hard $ref + + if [ -d patch ] ; then + git -C $repo am --keep-non-patch --no-gpg-sign \ + --whitespace=nowarn ../patch/*.patch + fi + + git -C $repo tag -f r$rel +} + +case $method in + git) + if [ ! "${ref-}" ]; then + printf "Error sync $dir: missing git ref\n" >&2 + exit 1 + fi + + if [ ! "${rel-}" ]; then + printf "Error sync $dir: missing git rel\n" >&2 + exit 1 + fi + + sync_git $dir/repo $ref $rel + ;; + *) + printf "Error sync $dir: unknown sync method '%s'\n" "$method" >&2 + exit 1 +esac + +ln -f "$version_file" "$out_file" diff --git a/pkg/abduco/build b/pkg/abduco/build @@ -1,18 +0,0 @@ -#!/bin/sh - -repodir="$srcdir/repo" - -( - cd $repodir - ./configure --prefix=/usr -) - -rm -rf "$outdir" -cp "$srcdir/config.h" "$repodir" - -make -C "$repodir" -make DESTDIR="$outdir" -C "$repodir" install - -if [ "$local_install" == "true" ]; then - sudo make -C "$repodir" install -fi diff --git a/pkg/abduco/config.h b/pkg/abduco/config.h @@ -1,14 +0,0 @@ -#define ABDUCO_CMD "dvtm" -static char KEY_DETACH = CTRL('\\'); -static char KEY_REDRAW = 0; - -static struct Dir { - char *path; - char *env; - bool personal; -} socket_dirs[] = { - { .env = "ABDUCO_SOCKET_DIR", false }, - { .env = "TMPDIR", false }, - { .path = "/tmp", false }, -}; - diff --git a/pkg/abduco/gen.sh b/pkg/abduco/gen.sh @@ -0,0 +1,8 @@ +cflags -std=c99 \ + -D _POSIX_C_SOURCE=200809L \ + -D _XOPEN_SOURCE=700 \ + -D VERSION='\"0.6\"' \ + -I '$dir/headers' + +exe abduco abduco.c +copy 'abduco.1' diff --git a/pkg/abduco/headers/config.h b/pkg/abduco/headers/config.h @@ -0,0 +1,15 @@ +#define ABDUCO_CMD "dvtm" + +static char KEY_DETACH = CTRL('\\'); +static char KEY_REDRAW = 0; + +static struct Dir { + char *path; + char *env; + bool personal; +} socket_dirs[] = { + { .env = "ABDUCO_SOCKET_DIR", false }, + { .env = "TMPDIR", false }, + { .path = "/tmp", false }, +}; + diff --git a/pkg/abduco/version b/pkg/abduco/version @@ -0,0 +1,3 @@ +method=git +ref=8c32909a +rel=0