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