summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2016-04-14 00:21:44 -0700
committerMichael Forney <mforney@mforney.org>2016-04-15 02:10:08 -0700
commit20a3b2ad4421763e4b19d7897cc5addecf06898d (patch)
treeecc00da23403820c355f5ff81f9da2ae8531f466
parentb3a4eb3f51f308a1d7fdde8a7cf77f4b8df2f308 (diff)
Allow independent generation of ninja files
-rw-r--r--.gitignore3
-rw-r--r--core/cparser/gen.rc8
-rw-r--r--core/file/gen.rc2
-rw-r--r--core/gen.rc11
-rw-r--r--core/libfirm/.gitignore5
-rw-r--r--core/libfirm/gen.rc4
-rw-r--r--core/loksh/gen.rc2
-rw-r--r--gen.rc32
-rw-r--r--ninja.rc18
-rw-r--r--rules.ninja15
-rw-r--r--scripts/tree.rc4
-rwxr-xr-xsetup.rc125
12 files changed, 119 insertions, 110 deletions
diff --git a/.gitignore b/.gitignore
index a01ee289..204b657d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
+/build.ninja
+local.ninja
+local.perms
.*.swp
diff --git a/core/cparser/gen.rc b/core/cparser/gen.rc
index ada89217..725e931d 100644
--- a/core/cparser/gen.rc
+++ b/core/cparser/gen.rc
@@ -1,6 +1,6 @@
cflags\
- -I '$root_srcdir'/core/libfirm/src/include\
- -I '$root_outdir'/core/libfirm\
+ -I core/libfirm/src/include\
+ -I '$builddir'/core/libfirm\
-I '$srcdir'/src/src\
-I '$outdir'
@@ -9,7 +9,7 @@ build '$outdir'/revision.h revision_hdr
cd src
srcs=src/^( main.c */*.c )
-for(src in $srcs) cc $src '|' '$outdir'/revision.h '||' '$root_outdir/core/libfirm/stamp'
-link cparser $srcs.o '$root_outdir'/core/libfirm/libfirm.a
+for(src in $srcs) cc $src '|' '$outdir'/revision.h '||' '$builddir/core/libfirm/stamp'
+link cparser $srcs.o '$builddir'/core/libfirm/libfirm.a
file bin/cparser '$outdir'/cparser 755
file share/man/man1/cparser.1 '$srcdir'/src/cparser.1 644
diff --git a/core/file/gen.rc b/core/file/gen.rc
index 83e71b35..6b92f79a 100644
--- a/core/file/gen.rc
+++ b/core/file/gen.rc
@@ -103,7 +103,7 @@ srcs=(\
\
src/fmtcheck.c\
) {
- for(src in $srcs) cc $src '|' '$outdir/include/magic.h' '||' core/zlib/stamp
+ for(src in $srcs) cc $src '|' '$outdir/include/magic.h' '||' '$builddir/core/zlib/stamp'
ar libmagic.a $srcs.o
}
diff --git a/core/gen.rc b/core/gen.rc
new file mode 100644
index 00000000..428fb488
--- /dev/null
+++ b/core/gen.rc
@@ -0,0 +1,11 @@
+subgen cparser
+subgen file
+subgen libfirm
+subgen loksh
+subgen plan9port
+subgen sbase
+subgen sinit
+subgen skeleton
+subgen tz
+subgen ubase
+subgen zlib
diff --git a/core/libfirm/.gitignore b/core/libfirm/.gitignore
new file mode 100644
index 00000000..afd86171
--- /dev/null
+++ b/core/libfirm/.gitignore
@@ -0,0 +1,5 @@
+/TEMPLATE.ninja
+/amd64.ninja
+/arm.ninja
+/ia32.ninja
+/sparc.ninja
diff --git a/core/libfirm/gen.rc b/core/libfirm/gen.rc
index bbfcbee4..8e5bea1e 100644
--- a/core/libfirm/gen.rc
+++ b/core/libfirm/gen.rc
@@ -51,8 +51,8 @@ for(backend in $backends) {
build $"outs $type '$srcdir'/src/ir/be/$backend/$backend^_spec.pl
}
for(src in $srcs) cc $src '||' '$outdir/stamp'
- } >$outdir/$backend.ninja
- echo 'subninja $outdir'/$backend.ninja
+ } >../$backend.ninja
+ subninja '$srcdir'/$backend.ninja
}
ar libfirm.a $objs
diff --git a/core/loksh/gen.rc b/core/loksh/gen.rc
index 59e52b07..cc561e03 100644
--- a/core/loksh/gen.rc
+++ b/core/loksh/gen.rc
@@ -1,4 +1,4 @@
-cflags -I '$root_srcdir/include' -D_GNU_SOURCE
+cflags -I include -D_GNU_SOURCE
exe ksh\
alloc.c\
c_ksh.c\
diff --git a/gen.rc b/gen.rc
index 5a153d99..4045a2fb 100644
--- a/gen.rc
+++ b/gen.rc
@@ -1,29 +1,7 @@
-root_inputs=()
-root_perms=()
+subgen core
-packages=(\
- cparser\
- file\
- libfirm\
- loksh\
- plan9port\
- sbase\
- sinit\
- skeleton\
- tz\
- ubase\
- zlib\
-)
+file .perms '$outdir'/root.perms 644
-set hash_root '$repo.hash'
-build '$repo.stamp' gitinit
-
-for(pkg in $packages) subgen core/$pkg
-
-printf '%s\n' $root_perms >$outdir/root_perms.txt
-file .perms '$outdir'/root_perms.txt 644
-
-let tag tree -- build '$repo.git/refs/tags/tree' gittree $root_inputs '|' '$repo.stamp' '$root_srcdir/scripts/tree.rc'
-let tag tree -- build '$repo.tar' gitarchive '|' '$repo.git/refs/tags/tree'
-
-for(pkg in $packages) subninja core/$pkg/local.ninja
+build '$builddir/$repo.stamp' gitinit
+let tag tree -- build '$builddir/$repo.git/refs/tags/tree' gittree '$outdir/root.tree' '|' '$builddir/$repo.stamp' ./scripts/tree.rc
+let tag tree -- build '$builddir/$repo.tar' gitarchive '|' '$builddir/$repo.git/refs/tags/tree'
diff --git a/ninja.rc b/ninja.rc
index 13d83ec1..0170ea4f 100644
--- a/ninja.rc
+++ b/ninja.rc
@@ -116,22 +116,24 @@ fn yacc {
# packaging rules
fn file {
- out='$repo.hash'/$1
+ out='$builddir/$repo.hash'/$1
let args 100$3' '$1 --\
- build $out githash $2 '|' '$repo.stamp' '$root_srcdir/scripts/hash.rc'
- root_inputs=( $root_inputs $out )
+ build $out githash $2 '|' '$builddir/$repo.stamp' scripts/hash.rc
+ tree_inputs=( $tree_inputs $out )
- if(! ~ $3 755 644) root_perms=( $root_perms 100$3' '$1 )
+ if(! ~ $3 755 644) tree_perms=( $tree_perms 100$3' '$1 )
status=()
}
fn dir {
- root_perms=( $root_perms '010'$2' '$1 )
+ tree_perms=( $tree_perms '010'$2' '$1 )
}
fn sym {
- out='$repo.hash'/$1
+ out='$builddir/$repo.hash'/$1
let args 120000' '$1' '$2 --\
- build $out githash '| $repo.stamp' '$root_srcdir/scripts/hash.rc'
- root_inputs=( $root_inputs $out )
+ build $out githash '|' '$builddir/$repo.stamp' scripts/hash.rc
+ tree_inputs=( $tree_inputs $out )
}
+
+status=()
diff --git a/rules.ninja b/rules.ninja
index 43e84027..7fc28808 100644
--- a/rules.ninja
+++ b/rules.ninja
@@ -1,5 +1,5 @@
rule gen
- command = rc $in -d $root_srcdir $$PWD
+ command = rc ./setup.rc -n -b $builddir $srcdir
generator = 1
# toolchain
@@ -14,13 +14,16 @@ rule link
rule ar
command = $ar crsD $out $in
+# misc tools
rule stamp
command = touch $out
rule copy
command = ln -f $in $out
-# misc tools
+rule cat
+ command = cat $in >$out.tmp && mv $out.tmp $out
+
rule yacc
command = oldpwd=$$PWD && cd $outdir && $yacc $yaccflags $$oldpwd/$in
@@ -28,14 +31,14 @@ rule sed
command = sed $expr >$out.tmp $in && mv $out.tmp $out
rule githash
- command = rc $root_srcdir/scripts/hash.rc $repo.git $out $args $in
+ command = rc ./scripts/hash.rc $builddir/$repo.git $out $args $in
rule gittree
- command = rc $root_srcdir/scripts/tree.rc $repo.git $tag $in
+ command = rc ./scripts/tree.rc $builddir/$repo.git $tag $in
restat = 1
rule gitarchive
- command = git -C $repo.git archive -o $$PWD/$out $tag
+ command = git -C $builddir/$repo.git archive -o $$PWD/$out $tag
rule gitinit
- command = mkdir -p $repo.git && git -C $repo.git init --bare && touch $out
+ command = mkdir -p $builddir/$repo.git && git -C $builddir/$repo.git init --bare && touch $out
diff --git a/scripts/tree.rc b/scripts/tree.rc
index 1ace9935..b641c922 100644
--- a/scripts/tree.rc
+++ b/scripts/tree.rc
@@ -4,7 +4,7 @@ flag e +
repo=$1
tag=$2
-shift 2
+index=$3
fn checkstatus {
s=$status if(! ~ $s '' '|') exit $s
@@ -15,6 +15,6 @@ ifs=() { oldpwd=`{pwd | head -c -1} }
cd $repo
git read-tree --empty
-cat $oldpwd/$* | git update-index --index-info
+git update-index --index-info <$oldpwd/$index
tree=`{git write-tree} ; checkstatus
git update-ref refs/tags/$tag $tree
diff --git a/setup.rc b/setup.rc
index cb58eec6..8a6d6945 100755
--- a/setup.rc
+++ b/setup.rc
@@ -2,86 +2,93 @@
flag e +
-while(~ $1 -*) switch($1) {
-case -d
- cd $2
- shift 2
+fn usage {
+ {
+ echo 'usage: '$0' [-b builddir]'
+ echo ' '$0' [-n]'
+ } >[1=2]
+ exit 2
}
-if(~ $#* 0) outdir=out
-if not outdir=$1
-mkdir -p $outdir
+builddir=out
+norecurse=()
-ifs=() {
- abs_srcdir=`{readlink -f . | head -c -1}
- abs_outdir=`{readlink -f $outdir | head -c -1}
+while(~ $1 -*) switch($1) {
+case -b
+ builddir=$2
+ shift 2
+case -n
+ norecurse=1
+ shift
+case *
+ usage $0
}
-# find relative path from outdir to srcdir
-ifs=/ {
- srcdir=`{printf %s $abs_srcdir}
- outdir=`{printf %s $abs_outdir}
-}
+. ./ninja.rc
-if(~ $#outdir 0) ifs=() { rel_srcdir=`{ifs=() pwd | head -c -1} }
-if not n=() {
- for(i in `{awk 'BEGIN {for (i = 1; i <= '$#outdir'; i++) print i}'}) {
- if(~$#n 0 && ! ~ $srcdir($i) $outdir($i)) {
- ifs=() { rel_srcdir=`{printf /%s $srcdir($i-) | tail -c +2} }
- n=$i
- }
- if(~ $#n 1) {
- if(~ $#rel_srcdir 0) rel_srcdir=..
- if not rel_srcdir=../$rel_srcdir
- }
+fn subgen {
+ dir=$pre$1 {
+ subninja $dir/local.ninja
+ gen_inputs=( $gen_inputs $dir/local.ninja )
+ tree_inputs=( $tree_inputs '$builddir'/$dir/root.tree )
+ tree_perms=( $tree_perms '$builddir'/$dir/root.perms )
}
+ if(~ $recurse 1) @ gen $1 &
+ status=()
}
-root_srcdir=$abs_srcdir
-root_outdir=$abs_outdir
-setup_outs=( build.ninja )
-setup_ins=()
+fn gen {
+ if(~ $dir '' .) dir=$1
+ if not dir=$dir/$1
-. ./ninja.rc
+ if(~ $dir .) { suf='' pre='' }
+ if not { suf=/$dir pre=$dir/ }
-fn subgen {
- olddir=$dir
- dir=$1
- srcdir=$root_srcdir/$dir
- outdir=$root_outdir/$dir
-
- printf 'generating in %s\n' $dir >[1=2]
+ cd $1
- setup_outs=( $setup_outs $dir/local.ninja )
- setup_ins=( $setup_ins '$root_srcdir'/$dir/gen.rc )
+ tree_perms=()
+ perms_inputs=()
+ tree_inputs=()
+ gen_inputs=()
- mkdir -p $outdir
- cd $srcdir
{
- echo 'outdir = '$dir
- echo 'srcdir = $root_srcdir/'$dir
+ set srcdir $dir
+ set outdir '$builddir'$suf
+
+ ifs=() { old_pwd=`{pwd | head -c -1} }
. ./gen.rc
- } >$outdir/local.ninja
- cd $root_srcdir
- dir=$olddir
- srcdir=$root_srcdir/$dir
- outdir=$root_outdir/$dir
+ build '$srcdir'/local.ninja gen '|' setup.rc ninja.rc '$srcdir'/gen.rc $gen_inputs
+
+ if(! ~ $#tree_perms 0) {
+ printf '%s\n' $tree_perms >$old_pwd/local.perms
+ perms_inputs=( $perms_inputs '$srcdir'/local.perms )
+ }
+ if(~ $#perms_inputs 0) build '$outdir/root.perms' stamp
+ if not build '$outdir/root.perms' cat $perms_inputs
+ if(~ $#tree_inputs 0) build '$outdir/root.tree' stamp
+ if not build '$outdir/root.tree' cat $tree_inputs
+ } >local.ninja
+
+ wait
}
-subgen .
+if(! ~ $#* 0) { gen $1 ; exit }
-{
- set root_srcdir $rel_srcdir
- set root_outdir .
+if(~ $#norecurse 0) {
+ recurse=1
+ @ gen .
+}
- include '$root_srcdir/config.ninja'
- include '$root_srcdir/rules.ninja'
+{
+ set builddir $builddir
- let generator 1 pool console --\
- build $"setup_outs gen '$root_srcdir/setup.rc' '|' $setup_ins
+ include config.ninja
+ include rules.ninja
subninja local.ninja
-} >$root_outdir/build.ninja.tmp
-mv $root_outdir/^( build.ninja.tmp build.ninja )
+ build build.ninja gen '|' setup.rc ninja.rc local.ninja
+} >build.ninja.tmp
+
+mv build.ninja.tmp build.ninja