linux-qubasis
linux oasis port as a qubes template
git clone https://9o.is/git/linux-qubasis.git
commit 8e48a0c8214fdfdb3f3a4f242844eadb22b55aeb parent e91c9bfdacb7a39fdcde00c75c68e06ec234781d Author: Jul <jul@9o.is> Date: Thu, 4 Sep 2025 14:23:59 +0800 clarify ninja targets Diffstat:
| A | README | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | ninja/functions.sh | | | 123 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
| M | ninja/rules.ninja | | | 2 | +- |
3 files changed, 133 insertions(+), 41 deletions(-)
diff --git a/README b/README @@ -0,0 +1,49 @@ +## About + +This project builds a Linux distro with Ninja and is heavily inspired by Michael Forney's Oasis Linux. Many of the packages are from Oasis Linux as well, but unlike Oasis, the scripts to generate the ninja files were written in Posix Shell and includes a tpl/ directory to define multiple templates. Each template outputs a raw image that can be used with virtual machines. + +I personally built this as a means to create lightweight templates for Qubes OS without XDG, Python, or Bash. All packages in the pkg/ directory are compiled with musl libc and may include patches in a patch/ directory. The ninja specs are generated by gen.sh shell scripts using functions defined in the ninja/functions.sh file. + +## Getting Started + +You'll need a few host dependencies including: +- a system toolchain to compile host dependencies which are used for bootstrapping +- a posix shell to run the gen scripts +- musl toolchain to cross-compile target dependencies +- curl for fetching packages +- git for fetching git submodule packages +- samurai - a simpler ninja alternative by Michael Forney + + +Run the configure script to initialize the ninja files. By default, out/ is the build directory and ninja files are saved in out/ninja directory. Then, you can start building with samurai (samu). + +``` +./configure +samu +``` + +## Targets + +"build" is the default target. Below are all of the phony targets you can also use. + +- configure: regenerates ninja file for root +- sync: syncs/fetches all source files in pkg directory +- build-pkgs: build all executables and libraries in pkg directory +- build-tpls: build all raw images in tpl directory +- build: builds all packages and templates +- fspec: generates fspec files in pkg/tpl directories +- pkg/{name}/configure: regenerates ninja file for specified package +- pkg/{name}/sync: syncs/fetches all source files for specified package +- pkg/{name}/build: builds executables and libraries for specified package +- pkg/{name}/fspec: generates fspec files for specified package +- tpl/{name}/configure: regenerates ninja file for specified template +- tpl/{name}/build: builds raw image for specified template +- tpl/{name}/fspec: generates fspec files for specified template + +## Architecture +## Gen API +## Ninja Files Explained + - incremental builds +## The Build Directory +## Qubes Users +## Updating diff --git a/ninja/functions.sh b/ninja/functions.sh @@ -112,6 +112,7 @@ exe() { _ninja_prefix _out $outdir $_out _ninja_prefix _srcs $srcdir $* _ninja_sync $_srcs + _ninja_build $_out _ninja_buffer_exe="$_out $_srcs" } @@ -122,6 +123,7 @@ lib() { _ninja_prefix _out $outdir $_out _ninja_prefix _srcs $srcdir $* _ninja_sync $_srcs + _ninja_build $_out _ninja_buffer_lib="$_out $_srcs" } @@ -233,6 +235,7 @@ _ninja_initglobals() { _ninja_buffer_headers= _ninja_buffer_sync= _ninja_buffer_fetch= + _ninja_buffer_build= _ninja_buffer_fspec= _ninja_buffer_fspec_files= } @@ -302,6 +305,15 @@ _ninja_sync() { done } +_ninja_build() { + for _v in $*; do + case $_v in + \$outdir/*) + _ninja_buffer_build="$_ninja_buffer_build $_v" + esac + done +} + _ninja_fspec() { _ninja_buffer_fspec="$_ninja_buffer_fspec$PREFIX$1 $2 $3 ${4-}\n" } @@ -429,24 +441,6 @@ _ninja_flush_subninjas() { fi } -_ninja_flush_build() { - if [ ${_ninja_host-} ]; then - return - fi - - _srcs= - - for _v in $_ninja_buffer_subgen; do - _srcs="$_srcs \$tgtdir/$_v/build" - done - - case $_ninja_type in - root) build phony $tgtdir/build $_srcs;; - tpl) build phony $tgtdir/build $outdir/rootfs.tar.zst;; - pkg) build phony $tgtdir/build $outdir/_fspec/ALL $_srcs;; - esac -} - _ninja_flush_fetch() { _fetchdir=$outdir/_fetch @@ -511,28 +505,69 @@ _ninja_flush_fetch() { fi } -_ninja_flush_sync() { +_ninja_flush_build() { if [ ${_ninja_host-} ]; then - printf "$_ninja_buffer_sync" return fi - _srcs= - - if [ $_ninja_type != root ]; then - _srcs=$outdir/_fetch/fetched - fi + _subgens= for _v in $_ninja_buffer_subgen; do - _srcs="$_srcs \$tgtdir/$_v/sync" + _subgens="$_subgens \$tgtdir/$_v/build" done - build phony $tgtdir/sync $_srcs + case $_ninja_type in + root) + _subgens_pkg= + _subgens_tpl= + + for _v in $_subgens; do + case $_v in + \$tgtdir/pkg/*) _subgens_pkg="$_subgens_pkg $_v";; + \$tgtdir/tpl/*) _subgens_tpl="$_subgens_tpl $_v";; + esac + done + + build phony $tgtdir/build-pkgs $_subgens_pkg + build phony $tgtdir/build-tpls $_subgens_tpl + build phony $tgtdir/build $_subgens + ;; + pkg) + build phony $tgtdir/build $_ninja_buffer_build $_subgens + ;; + tpl) + build fspec-tar $outdir/rootfs.tar.zst '|' $hostdir/fspec-tar $hostdir/zstd '||' $outdir/_fspec/ALL + build phony $tgtdir/build $outdir/rootfs.tar.zst + ;; + esac +} - if [ "$_ninja_buffer_sync" ]; then - _ninja_dedup _ninja_buffer_sync $_ninja_buffer_sync - build phony "$_ninja_buffer_sync" $outdir/_fetch/fetched +_ninja_flush_sync() { + if [ ${_ninja_host-} ]; then + printf "$_ninja_buffer_sync" + return fi + + _subgens= + + for _v in $_ninja_buffer_subgen; do + case $_v in + pkg/*) _subgens="$_subgens \$tgtdir/$_v/sync" + esac + done + + case $_ninja_type in + root) + build phony $tgtdir/sync $_subgens + ;; + pkg) + build phony $tgtdir/sync $outdir/_fetch/fetched $_subgens + if [ "$_ninja_buffer_sync" ]; then + _ninja_dedup _ninja_buffer_sync $_ninja_buffer_sync + build phony "$_ninja_buffer_sync" $outdir/_fetch/fetched + fi + ;; + esac } _ninja_flush_deps() { @@ -560,12 +595,7 @@ _ninja_flush_headers() { } _ninja_flush_fspec() { - if [ $_ninja_type = root ] || [ ${_ninja_host-} ]; then - return - fi - - if [ ! "$_ninja_buffer_fspec" ] && [ ! "$_ninja_buffer_fspec_files" ]; then - build touch $outdir/_fspec/ALL + if [ ${_ninja_host-} ]; then return fi @@ -596,11 +626,24 @@ _ninja_flush_fspec() { printf "$out " done) - build cat $outdir/_fspec/ALL $_srcs $_ninja_buffer_fspec_files + _subgens= - if [ $_ninja_type = tpl ]; then - build fspec-tar $outdir/rootfs.tar.zst $outdir/_fspec/ALL '|' $hostdir/fspec-tar $hostdir/zstd - fi + for _v in $_ninja_buffer_subgen; do + _subgens="$_subgens \$tgtdir/$_v/fspec" + done + + case $_ninja_type in + root) build phony $tgtdir/fspec $_subgens;; + *) + if [ ! "$_srcs" ] && [ ! "$_ninja_buffer_fspec_files" ]; then + build touch $outdir/_fspec/ALL + else + build cat $outdir/_fspec/ALL $_srcs $_ninja_buffer_fspec_files + fi + + build phony $tgtdir/fspec $outdir/_fspec/ALL + ;; + esac } _ninja_flush() { diff --git a/ninja/rules.ninja b/ninja/rules.ninja @@ -62,7 +62,7 @@ rule fspec description = FSPEC $out rule fspec-tar - command = $hostdir/fspec-tar <$in | $hostdir/zstd >$out + command = $hostdir/fspec-tar <$outdir/_fspec/ALL | $hostdir/zstd >$out description = FSPEC-TAR $out rule yacc