#!/bin/rc flag e + fn usage { echo 'usage: '$0' [dir]' >[1=2] exit 2 } if(! ~ $#* 0 1) usage . ./ninja.rc fn subgen { subninja '$dir'/$1/local.ninja gen_inputs=($gen_inputs phony/'$dir'/$1/ninja) tree_inputs=($tree_inputs '$outdir'/$1/root.tree) perms_inputs=($perms_inputs '$outdir'/$1/root.perms) if(~ $recurse 1 || ! [ -f $1/local.ninja ]) @ gen $1 & status=() } fn gen { if(~ $dir '' .) dir=$1 if not dir=$dir/$1 cd $1 tree_perms=() perms_inputs=() tree_inputs=() gen_inputs=() absdir=`{pwd} { set dir $dir if(~ $dir .) set outdir '$builddir' if not set outdir '$builddir/$dir' if([ -d src ]) { cd src if(~ $dir .) set srcdir src if not set srcdir '$dir/src' } . $absdir/gen.rc build '$dir/local.ninja' gen '|' setup.rc ninja.rc '$dir/gen.rc' phony ninja '$dir/local.ninja' $gen_inputs if(! ~ $#tree_perms 0) { printf '%s\n' $tree_perms | sort >$absdir/local.perms perms_inputs=($perms_inputs '$dir'/local.perms) } if(~ $#perms_inputs 0) build '$outdir/root.perms' empty if not build '$outdir/root.perms' mergeperms $perms_inputs if(~ $#tree_inputs 0) build '$outdir/root.tree' empty if not build '$outdir/root.tree' cat $tree_inputs } >local.ninja.tmp mv $absdir/^(local.ninja.tmp local.ninja) echo 'generated '$dir >[1=2] wait } if(! ~ $#* 0) { gen $1 ; exit } recurse=1 @ gen .