shithub: pointless

ref: f8396fb5c9652368e1722976df158f5c4ae8ab64
dir: /generate/

View raw version
#!/bin/rc

rfork en

fn usage {
	aux/usage
	exit usage
}

fn verbose {
	if(! ~ $#flagv 0)
		echo $*
}

args='dir'
flagfmt='v, o:outdir outdir'

if(! eval `{aux/getflags $*})
	usage

if(~ $#outdir 0)
	outdir=`{pwd}^/out

if(! ~ $#* 1)
	usage

mkdir -p $outdir
dircp $1 $outdir

@ {
	cd $outdir
	pointlessroot=`{pwd}
}

verbose '*** executing pre-generation hooks ***'

for(index in `{walk $outdir | grep 'index\.rc$'}) @{
	verbose --- $index ---
	cd `{basename -d $index}
	. index.rc
	rm index.rc
}

verbose '*** preprocessing templates ***'

for(ptless in `{walk $outdir | grep '\.ptless$'}) @{
	verbose --- $ptless ---
	cd `{basename -d $ptless}
	ptless=`{basename $ptless}
	pointless/pointless.awk $ptless >`{echo $ptless | sed 's@\[email protected]@'}
	rm $ptless
}

verbose '*** executing post-generation hooks ***'

for(epilogue in `{walk $outdir | grep 'epilogue\.rc$'}) @{
	verbose --- $epilogue ---
	cd `{basename -d $epilogue}
	. epilogue.rc
	rm epilogue.rc
}

verbose '*** finished ***'