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