1#!/bin/sh
2#
3# $NetBSD: makeflist,v 1.80 2023/11/08 13:02:47 christos Exp $
4#
5# Print out the files in some or all lists.
6# Usage: makeflist [-bxlo] [-a arch] [-m machine] [-s setsdir] [setname ...]
7#
8
9rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
10. "${rundir}/sets.subr"
11lists=
12
13usage()
14{
15	cat 1>&2 <<USAGE
16Usage: ${0##*/} [-L base,x] [-bxo] [-a arch] [-m machine] [-s setsdir] [setname [...]]
17	-L base,x	print specified lists
18	-b		print netbsd + x11 lists
19	-x		print make x11 lists
20	-l		just list the selected set names, not the contents
21	-o		only match obsolete files
22	-a arch		set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
23	-m machine	set machine (e.g, amiga, i386, macppc) [${MACHINE}]
24	-s setsdir	directory to find sets [${setsdir}]
25	[setname [...]]	sets to build [${lists}]
26USAGE
27	exit 1
28}
29
30umask 022
31# handle args
32while getopts L:bxloa:m:s: ch; do
33	case ${ch} in
34	L)
35		save_IFS="${IFS}"
36		IFS=,
37		for _list in ${OPTARG}; do
38			case $_list in
39			base)	lists="${lists} ${nlists}" ;;
40			x)	lists="${lists} ${xlists}" ;;
41			esac
42		done
43		IFS="${save_IFS}"
44		;;
45	# backward compat
46	b)
47		lists="${nlists} ${xlists}"
48		;;
49	x)
50		lists="${xlists}"
51		;;
52	l)
53		listonly=1
54		;;
55	o)
56		obsolete=1
57		;;
58	a)
59		MACHINE_ARCH="${OPTARG}"
60		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
61		;;
62	m)
63		MACHINE="${OPTARG}"
64		;;
65	s)
66		setsdir="${OPTARG}"
67		;;
68	*)
69		usage
70		;;
71	esac
72done
73shift $((${OPTIND} - 1))
74if [ -n "$1" ]; then
75	lists="$*"
76fi
77
78if [ -n "${listonly}" ]; then
79	echo ${lists} | tr ' ' '\n'
80	exit 0
81fi
82
83list_set_files ${lists:-${nlists}} | ${AWK} '{print $1}' | ${SORT} -u
84