makeplist revision 1.21
11.1Sjwise#!/bin/sh
21.1Sjwise#
31.1Sjwise# Print out the files in some or all lists.
41.19Sapb# Usage: makeplist [options] setname pkgname
51.19Sapb# options:
61.19Sapb# 	-a arch		set arch (e.g, m68k, mips, powerpc)	
71.19Sapb# 	-m machine	set machine (e.g, amiga, i386, macppc)
81.19Sapb# 	-s setsdir	directory to find sets
91.19Sapb# 	-p prefix	prefix for package creation
101.19Sapb# 	-I realprefix	prefix for eventual installation
111.19Sapb# 	setname pkgname	set and package to build plist for
121.1Sjwise#
131.1Sjwise
141.18Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
151.18Sapb. "${rundir}/sets.subr"
161.1Sjwiseprefix=/
171.19Sapbrealprefix=/
181.19Sapbgot_realprefix=false
191.1Sjwise
201.19Sapbusage() {
211.12Slukem	cat 1>&2 <<USAGE
221.19SapbUsage: $0 [options] setname pkgname"
231.19Sapboptions:"
241.18Sapb	-a arch		set arch (e.g, m68k, mips, powerpc)	[${MACHINE_ARCH}]
251.18Sapb	-m machine	set machine (e.g, amiga, i386, macppc)	[${MACHINE}]
261.18Sapb	-s setsdir	directory to find sets			[${setsdir}]
271.18Sapb	-p prefix	prefix for created plist		[${prefix}]
281.19Sapb	-I realprefix	prefix for eventual installation	[${realprefix}]
291.12Slukem	setname pkgname	set and package to build plist for
301.12SlukemUSAGE
311.12Slukem	exit 1
321.1Sjwise}
331.1Sjwise
341.1Sjwise# handle args
351.19Sapbwhile getopts a:I:m:p:s: ch; do
361.12Slukem	case ${ch} in
371.12Slukem	a)
381.18Sapb		MACHINE_ARCH="${OPTARG}"
391.18Sapb		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
401.1Sjwise		;;
411.19Sapb	I)
421.19Sapb		realprefix=${OPTARG}
431.19Sapb		got_realprefix=true
441.19Sapb		;;
451.12Slukem	m)
461.18Sapb		MACHINE="${OPTARG}"
471.1Sjwise		;;
481.12Slukem	p)
491.18Sapb		prefix="${OPTARG}"
501.1Sjwise		;;
511.12Slukem	s)
521.18Sapb		setsdir="${OPTARG}"
531.1Sjwise		;;
541.12Slukem	*)
551.1Sjwise		usage
561.1Sjwise		;;
571.1Sjwise	esac
581.1Sjwisedone
591.12Slukemshift $((${OPTIND} - 1))
601.12Slukemif [ $# -ne 2 ]; then
611.1Sjwise	usage
621.1Sjwisefi
631.12Slukemsetname="$1"
641.18Sapbpkgname="$2"
651.7Sagc
661.19Sapbif ! ${got_realprefix}; then
671.19Sapb    realprefix="${prefix}"
681.19Sapbfi
691.19Sapb
701.18Sapbfilename="/tmp/makeplist.$$"
711.18Sapbffilename="/tmp/makeplist.files.$$"
721.18Sapbdfilename="/tmp/makeplist.dirs.$$"
731.7Sagc
741.18Sapblist_set_files "${setname}" | \
751.18Sapb    ${ENV_CMD} PLISTPKG="${pkgname}" ${AWK} '
761.12Slukem	$2 == ENVIRON["PLISTPKG"] {
771.12Slukem		sub("^\\./", "", $1);
781.12Slukem		print $1
791.18Sapb	}' | ${SORT} -u > "${filename}"
801.8Sdyoung
811.16SdyoungSELECTDIRS="-prune -type d"
821.16SdyoungSELECTNONDIRS="! -type d -print -o ( -type d -prune )"
831.8Sdyoung
841.19Sapb#
851.19Sapb# XXX: The "lists" do not differentiate between directories and files.
861.19Sapb# But we need to differentiate between them, so we do so by checking
871.19Sapb# what's actually present in the file system.  Files or directories that
881.19Sapb# are listed in the "lists" but that do not exist in the file system end
891.19Sapb# up not appearing in our output, and this subverts a large part of the
901.19Sapb# purpose of the "lists".
911.19Sapb#
921.19Sapb# XXX: Given that we have to figure out what is or is not a directory
931.19Sapb# without assistance from the "lists", it would be much more efficient
941.19Sapb# to consult the metalog instead of the file system.
951.19Sapb#
961.19Sapb
971.20Sapb(
981.18Sapbcd "${prefix}"
991.20Sapb
1001.8Sdyoung#
1011.16Sdyoung# Match the directories.  Use find(1) to avoid repeat calls to
1021.16Sdyoung# 'test -d'.
1031.16Sdyoung#
1041.16Sdyoung# This is a little clever.  I cannot use 'xargs find', because
1051.16Sdyoung# find wants for the option arguments to follow the path arguments.
1061.18Sapb# So I use 'xargs echo ${SELECTDIRS}' to make a maximum-length proto-command
1071.16Sdyoung# line.  I use 'read' to peel the options off the front of the
1081.18Sapb# command-line, and 'find ${args} ${SELECTDIRS}' to put them at the end.
1091.8Sdyoung#
1101.18Sapbxargs echo ${SELECTDIRS} < "${filename}" | \
1111.16Sdyoungwhile read ignore ignore ignore args; do
1121.18Sapb	[ -z "${args}" ] && break 
1131.18Sapb	${FIND} ${args} ${SELECTDIRS}
1141.21Sukidone | ${AWK} '{ print "@pkgdir " $1; }' > "${dfilename}"
1151.8Sdyoung
1161.8Sdyoung#
1171.16Sdyoung# Match the non-directories.  Use find(1) to avoid repeat calls to
1181.16Sdyoung# 'test ! -d'.  See 'Match the directories' for an explanation of the
1191.16Sdyoung# cleverness.
1201.8Sdyoung#
1211.18Sapbxargs echo ${SELECTNONDIRS} < "${filename}" | \
1221.16Sdyoungwhile read ignore ignore ignore ignore ignore ignore ignore ignore ignore \
1231.16Sdyoung    ignore args; do
1241.18Sapb	[ -z "${args}" ] && break 
1251.18Sapb	${FIND} ${args} ${SELECTNONDIRS}
1261.18Sapbdone > "${ffilename}"
1271.8Sdyoung
1281.20Sapb)
1291.7Sagc
1301.19Sapbecho "@cwd ${realprefix}"
1311.18Sapbif [ -s "${ffilename}" ]; then
1321.18Sapb	cat "${ffilename}"
1331.1Sjwisefi
1341.18Sapbif [ -s "${dfilename}" ]; then
1351.18Sapb        ${SORT} -r "${dfilename}"
1361.7Sagcfi
1371.7Sagc
1381.18Sapbrm -f "${filename}" "${ffilename}" "${dfilename}"
1391.7Sagc
1401.7Sagcexit 0
141