makeplist revision 1.18
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.18Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
81.18Sapb. "${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.18Sapb	-a arch		set arch (e.g, m68k, mips, powerpc)	[${MACHINE_ARCH}]
161.18Sapb	-m machine	set machine (e.g, amiga, i386, macppc)	[${MACHINE}]
171.18Sapb	-s setsdir	directory to find sets			[${setsdir}]
181.18Sapb	-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.18Sapb		MACHINE_ARCH="${OPTARG}"
291.18Sapb		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
301.1Sjwise		;;
311.12Slukem	m)
321.18Sapb		MACHINE="${OPTARG}"
331.1Sjwise		;;
341.12Slukem	p)
351.18Sapb		prefix="${OPTARG}"
361.1Sjwise		;;
371.12Slukem	s)
381.18Sapb		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.18Sapbpkgname="$2"
511.7Sagc
521.18Sapbfilename="/tmp/makeplist.$$"
531.18Sapbffilename="/tmp/makeplist.files.$$"
541.18Sapbdfilename="/tmp/makeplist.dirs.$$"
551.7Sagc
561.18Sapblist_set_files "${setname}" | \
571.18Sapb    ${ENV_CMD} PLISTPKG="${pkgname}" ${AWK} '
581.12Slukem	$2 == ENVIRON["PLISTPKG"] {
591.12Slukem		sub("^\\./", "", $1);
601.12Slukem		print $1
611.18Sapb	}' | ${SORT} -u > "${filename}"
621.8Sdyoung
631.16SdyoungSELECTDIRS="-prune -type d"
641.16SdyoungSELECTNONDIRS="! -type d -print -o ( -type d -prune )"
651.8Sdyoung
661.18Sapbcd "${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.18Sapb# 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.18Sapb# command-line, and 'find ${args} ${SELECTDIRS}' to put them at the end.
761.8Sdyoung#
771.18Sapbxargs echo ${SELECTDIRS} < "${filename}" | \
781.16Sdyoungwhile read ignore ignore ignore args; do
791.18Sapb	[ -z "${args}" ] && break 
801.18Sapb	${FIND} ${args} ${SELECTDIRS}
811.18Sapbdone | ${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.18Sapbxargs echo ${SELECTNONDIRS} < "${filename}" | \
891.16Sdyoungwhile read ignore ignore ignore ignore ignore ignore ignore ignore ignore \
901.16Sdyoung    ignore args; do
911.18Sapb	[ -z "${args}" ] && break 
921.18Sapb	${FIND} ${args} ${SELECTNONDIRS}
931.18Sapbdone > "${ffilename}"
941.8Sdyoung
951.8Sdyoungcd -
961.7Sagc
971.18Sapbecho "@cwd ${prefix}"
981.18Sapbif [ -s "${ffilename}" ]; then
991.18Sapb	cat "${ffilename}"
1001.1Sjwisefi
1011.18Sapbif [ -s "${dfilename}" ]; then
1021.18Sapb        ${SORT} -r "${dfilename}"
1031.7Sagcfi
1041.7Sagc
1051.18Sapbrm -f "${filename}" "${ffilename}" "${dfilename}"
1061.7Sagc
1071.7Sagcexit 0
108