summaryrefslogtreecommitdiff
path: root/setup.rc
blob: c01d6a0407361872806db893ee0cb0c7e34a215c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/rc

flag e +

fn usage {
	echo 'usage: '$0' [-q] [dir]' >[1=2]
	exit 2
}

while(~ $1 -?) switch($1) {
	case -v
		quiet=1
		shift
	case *
		usage
}
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)
	tree_perms=($tree_perms '$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=()

	ifs=() { absdir=`{pwd | head -c -1} }
	{
		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 >$absdir/local.perms
			perms_inputs=($perms_inputs '$dir'/local.perms)
		}
		if(~ $#perms_inputs 0) build '$outdir/root.perms' touch
		if not build '$outdir/root.perms' cat $perms_inputs
		if(~ $#tree_inputs 0) build '$outdir/root.tree' touch
		if not build '$outdir/root.tree' cat $tree_inputs
	} >local.ninja.tmp
	mv $absdir/^(local.ninja.tmp local.ninja)

	if(! ~ $quiet 1) echo 'generated '$dir >[1=2]

	wait
}

if(! ~ $#* 0) { gen $1 ; exit }

recurse=1
@ gen .