summaryrefslogtreecommitdiff
path: root/setup.rc
blob: 680d8b8cb143bf78a1939b1aff43fae989a8808d (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
78
79
80
81
82
83
#!/bin/rc

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

if(! ~ $#* 0 1) usage

if(! [ -f config.rc ])
	cp config.def.rc config.rc
. ./config.rc

flag e +

if(! [ -f config.ninja ])
	cp config.def.ninja config.ninja

# call this after a command capture to ensure it succeeded
fn checkstatus {}

ifs='
'

. ./ninja.rc

fn subgen {
	subninja '$dir'/$1/local.ninja
	ninja_inputs=($ninja_inputs '$dir'/$1/ninja)
	index_inputs=($index_inputs '$outdir'/$1/root.index)
	perms_inputs=($perms_inputs '$outdir'/$1/root.perms)
	if(~ $recurse 1 || ! [ -f $1/local.ninja ]) @ gen $1 &
	status=()
}

fn gen {
	pkg=`{basename $1}
	checkstatus
	if(~ $dir '' .) dir=$1
	if not dir=$dir/$1

	cd $1

	allsrcs=()
	tree_perms=()
	perms_inputs=()
	index_inputs=()
	gen_inputs=()
	ninja_inputs=()

	absdir=`{pwd}
	{
		set dir $dir
		if(~ $dir .) set outdir '$builddir'
		if not set outdir '$builddir/$dir'

		if([ -e rev ]) set srcdir '$dir'/src

		. $absdir/gen.rc

		build '$dir'/local.ninja gen '|' setup.rc config.rc ninja.rc '$dir'/gen.rc $gen_inputs
		phony ninja '$dir'/local.ninja $ninja_inputs

		if(! ~ $#tree_perms 0) {
			printf '%s\n' $tree_perms | sort -k 2 >$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(~ $#index_inputs 0) build '$outdir/root.index' empty
		if not build '$outdir/root.index' cat $index_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 .