Home | History | Annotate | Line # | Download | only in sets
makeplist revision 1.16
      1   1.1   jwise #!/bin/sh
      2   1.1   jwise #
      3   1.1   jwise # Print out the files in some or all lists.
      4   1.4  dyoung # Usage: makeplist [-a arch] [-m machine] [-s setsdir] [-p prefix] setname pkgname
      5   1.1   jwise #
      6   1.1   jwise 
      7  1.15     erh rundir=${0%/*}
      8  1.15     erh . ${rundir}/sets.subr
      9   1.1   jwise prefix=/
     10   1.1   jwise 
     11  1.12   lukem usage()
     12  1.12   lukem {
     13  1.12   lukem 	cat 1>&2 <<USAGE
     14  1.12   lukem Usage: ${0##*/} [-a arch] [-m machine] [-s setsdir] [-p prefix] setname pkgname
     15  1.13   lukem 	-a arch		set arch (e.g, m68k, mips, powerpc)	[$MACHINE_ARCH]
     16  1.13   lukem 	-m machine	set machine (e.g, amiga, i386, macppc)	[$MACHINE]
     17  1.12   lukem 	-s setsdir	directory to find sets			[$setsdir]
     18  1.12   lukem 	-p prefix	prefix for created plist		[$prefix]
     19  1.12   lukem 	setname pkgname	set and package to build plist for
     20  1.12   lukem USAGE
     21  1.12   lukem 	exit 1
     22   1.1   jwise }
     23   1.1   jwise 
     24   1.1   jwise # handle args
     25  1.14  dyoung while getopts a:m:p:s: ch; do
     26  1.12   lukem 	case ${ch} in
     27  1.12   lukem 	a)
     28  1.13   lukem 		MACHINE_ARCH=${OPTARG}
     29  1.13   lukem 		MACHINE_CPU=$(arch_to_cpu ${OPTARG})
     30   1.1   jwise 		;;
     31  1.12   lukem 	m)
     32  1.13   lukem 		MACHINE=${OPTARG}
     33   1.1   jwise 		;;
     34  1.12   lukem 	p)
     35  1.12   lukem 		prefix=${OPTARG}
     36   1.1   jwise 		;;
     37  1.12   lukem 	s)
     38  1.12   lukem 		setsdir=${OPTARG}
     39   1.1   jwise 		;;
     40  1.12   lukem 	*)
     41   1.1   jwise 		usage
     42   1.1   jwise 		;;
     43   1.1   jwise 	esac
     44   1.1   jwise done
     45  1.12   lukem shift $((${OPTIND} - 1))
     46  1.12   lukem if [ $# -ne 2 ]; then
     47   1.1   jwise 	usage
     48   1.1   jwise fi
     49  1.12   lukem setname="$1"
     50  1.12   lukem pkgname=$2
     51   1.7     agc 
     52   1.7     agc filename=/tmp/makeplist.$$ 
     53   1.7     agc ffilename=/tmp/makeplist.files.$$ 
     54   1.7     agc dfilename=/tmp/makeplist.dirs.$$ 
     55   1.7     agc 
     56   1.8  dyoung list_set_files $setname | \
     57  1.12   lukem     env PLISTPKG=$pkgname awk '
     58  1.12   lukem 	$2 == ENVIRON["PLISTPKG"] {
     59  1.12   lukem 		sub("^\\./", "", $1);
     60  1.12   lukem 		print $1
     61  1.12   lukem 	}' | sort -u > $filename
     62   1.8  dyoung 
     63  1.16  dyoung SELECTDIRS="-prune -type d"
     64  1.16  dyoung SELECTNONDIRS="! -type d -print -o ( -type d -prune )"
     65   1.8  dyoung 
     66   1.8  dyoung cd $prefix
     67   1.8  dyoung #
     68  1.16  dyoung # Match the directories.  Use find(1) to avoid repeat calls to
     69  1.16  dyoung # 'test -d'.
     70  1.16  dyoung #
     71  1.16  dyoung # This is a little clever.  I cannot use 'xargs find', because
     72  1.16  dyoung # find wants for the option arguments to follow the path arguments.
     73  1.16  dyoung # So I use 'xargs echo $SELECTDIRS' to make a maximum-length proto-command
     74  1.16  dyoung # line.  I use 'read' to peel the options off the front of the
     75  1.16  dyoung # command-line, and 'find $args $SELECTDIRS' to put them at the end.
     76   1.8  dyoung #
     77   1.8  dyoung xargs echo $SELECTDIRS < $filename | \
     78  1.16  dyoung while read ignore ignore ignore args; do
     79   1.8  dyoung 	[ -z "$args" ] && break 
     80   1.8  dyoung 	find $args $SELECTDIRS
     81   1.8  dyoung done | awk '{ print "@dirrm " $1; }' > $dfilename
     82   1.8  dyoung 
     83   1.8  dyoung #
     84  1.16  dyoung # Match the non-directories.  Use find(1) to avoid repeat calls to
     85  1.16  dyoung # 'test ! -d'.  See 'Match the directories' for an explanation of the
     86  1.16  dyoung # cleverness.
     87   1.8  dyoung #
     88   1.8  dyoung xargs echo $SELECTNONDIRS < $filename | \
     89  1.16  dyoung while read ignore ignore ignore ignore ignore ignore ignore ignore ignore \
     90  1.16  dyoung     ignore args; do
     91   1.8  dyoung 	[ -z "$args" ] && break 
     92   1.8  dyoung 	find $args $SELECTNONDIRS
     93   1.8  dyoung done > $ffilename
     94   1.8  dyoung 
     95   1.8  dyoung cd -
     96   1.7     agc 
     97   1.7     agc echo "@cwd $prefix"
     98   1.7     agc if [ -s $ffilename ]; then
     99   1.7     agc 	cat $ffilename
    100   1.1   jwise fi
    101   1.7     agc if [ -s $dfilename ]; then
    102   1.7     agc         sort -r $dfilename
    103   1.7     agc fi
    104   1.7     agc 
    105   1.7     agc rm -f $filename $ffilename $dfilename
    106   1.7     agc 
    107   1.7     agc exit 0
    108