makeplist revision 1.16
11.1Sjwise#!/bin/sh
21.1Sjwise#
31.1Sjwise# Print out the files in some or all lists.
41.4Sdyoung# Usage: makeplist [-a arch] [-m machine] [-s setsdir] [-p prefix] setname pkgname
51.1Sjwise#
61.1Sjwise
71.15Serhrundir=${0%/*}
81.15Serh. ${rundir}/sets.subr
91.1Sjwiseprefix=/
101.1Sjwise
111.12Slukemusage()
121.12Slukem{
131.12Slukem	cat 1>&2 <<USAGE
141.12SlukemUsage: ${0##*/} [-a arch] [-m machine] [-s setsdir] [-p prefix] setname pkgname
151.13Slukem	-a arch		set arch (e.g, m68k, mips, powerpc)	[$MACHINE_ARCH]
161.13Slukem	-m machine	set machine (e.g, amiga, i386, macppc)	[$MACHINE]
171.12Slukem	-s setsdir	directory to find sets			[$setsdir]
181.12Slukem	-p prefix	prefix for created plist		[$prefix]
191.12Slukem	setname pkgname	set and package to build plist for
201.12SlukemUSAGE
211.12Slukem	exit 1
221.1Sjwise}
231.1Sjwise
241.1Sjwise# handle args
251.14Sdyoungwhile getopts a:m:p:s: ch; do
261.12Slukem	case ${ch} in
271.12Slukem	a)
281.13Slukem		MACHINE_ARCH=${OPTARG}
291.13Slukem		MACHINE_CPU=$(arch_to_cpu ${OPTARG})
301.1Sjwise		;;
311.12Slukem	m)
321.13Slukem		MACHINE=${OPTARG}
331.1Sjwise		;;
341.12Slukem	p)
351.12Slukem		prefix=${OPTARG}
361.1Sjwise		;;
371.12Slukem	s)
381.12Slukem		setsdir=${OPTARG}
391.1Sjwise		;;
401.12Slukem	*)
411.1Sjwise		usage
421.1Sjwise		;;
431.1Sjwise	esac
441.1Sjwisedone
451.12Slukemshift $((${OPTIND} - 1))
461.12Slukemif [ $# -ne 2 ]; then
471.1Sjwise	usage
481.1Sjwisefi
491.12Slukemsetname="$1"
501.12Slukempkgname=$2
511.7Sagc
521.7Sagcfilename=/tmp/makeplist.$$ 
531.7Sagcffilename=/tmp/makeplist.files.$$ 
541.7Sagcdfilename=/tmp/makeplist.dirs.$$ 
551.7Sagc
561.8Sdyounglist_set_files $setname | \
571.12Slukem    env PLISTPKG=$pkgname awk '
581.12Slukem	$2 == ENVIRON["PLISTPKG"] {
591.12Slukem		sub("^\\./", "", $1);
601.12Slukem		print $1
611.12Slukem	}' | sort -u > $filename
621.8Sdyoung
631.16SdyoungSELECTDIRS="-prune -type d"
641.16SdyoungSELECTNONDIRS="! -type d -print -o ( -type d -prune )"
651.8Sdyoung
661.8Sdyoungcd $prefix
671.8Sdyoung#
681.16Sdyoung# Match the directories.  Use find(1) to avoid repeat calls to
691.16Sdyoung# 'test -d'.
701.16Sdyoung#
711.16Sdyoung# This is a little clever.  I cannot use 'xargs find', because
721.16Sdyoung# find wants for the option arguments to follow the path arguments.
731.16Sdyoung# So I use 'xargs echo $SELECTDIRS' to make a maximum-length proto-command
741.16Sdyoung# line.  I use 'read' to peel the options off the front of the
751.16Sdyoung# command-line, and 'find $args $SELECTDIRS' to put them at the end.
761.8Sdyoung#
771.8Sdyoungxargs echo $SELECTDIRS < $filename | \
781.16Sdyoungwhile read ignore ignore ignore args; do
791.8Sdyoung	[ -z "$args" ] && break 
801.8Sdyoung	find $args $SELECTDIRS
811.8Sdyoungdone | awk '{ print "@dirrm " $1; }' > $dfilename
821.8Sdyoung
831.8Sdyoung#
841.16Sdyoung# Match the non-directories.  Use find(1) to avoid repeat calls to
851.16Sdyoung# 'test ! -d'.  See 'Match the directories' for an explanation of the
861.16Sdyoung# cleverness.
871.8Sdyoung#
881.8Sdyoungxargs echo $SELECTNONDIRS < $filename | \
891.16Sdyoungwhile read ignore ignore ignore ignore ignore ignore ignore ignore ignore \
901.16Sdyoung    ignore args; do
911.8Sdyoung	[ -z "$args" ] && break 
921.8Sdyoung	find $args $SELECTNONDIRS
931.8Sdyoungdone > $ffilename
941.8Sdyoung
951.8Sdyoungcd -
961.7Sagc
971.7Sagcecho "@cwd $prefix"
981.7Sagcif [ -s $ffilename ]; then
991.7Sagc	cat $ffilename
1001.1Sjwisefi
1011.7Sagcif [ -s $dfilename ]; then
1021.7Sagc        sort -r $dfilename
1031.7Sagcfi
1041.7Sagc
1051.7Sagcrm -f $filename $ffilename $dfilename
1061.7Sagc
1071.7Sagcexit 0
108