1#!/bin/sh
2
3#         $NetBSD: prepare-import.sh,v 1.2 2021/12/19 10:20:38 riastradh Exp $
4#
5# $ /path/to/prepare-import.sh
6#
7# Run from the directory that will be imported as
8# sys/external/bsd/drm2/dist.  Be sure to also run drm/drm2netbsd and
9# nouveau/nouveau2netbsd in their respective directories.
10
11set -Ceu
12
13find . -name '*.h' \
14| while read f; do
15          cleantags "$f"
16          (printf '/*\t%c%s%c\t*/\n\n' '$' NetBSD '$' && cat -- "$f") > "$f".tmp
17          mv -f -- "$f".tmp "$f"
18done
19
20find . -name '*.c' \
21| while read f; do
22        # Probably not necessary -- Linux tends not to have RCS ids --
23        # but a precaution out of paranoia.
24          cleantags "$f"
25          # Heuristically apply NetBSD RCS ids: a comment at the top of
26          # the file, and a __KERNEL_RCSID before the first cpp line,
27          # which, with any luck, should be the first non-comment line
28          # and lie between the copyright notice and the header.
29          awk '
30                    BEGIN {
31                              done = 0
32                              printf("/*\t%c%s%c\t*/\n\n", "$","NetBSD","$")
33                    }
34                    /^#/ && !done {
35                              printf("#include <sys/cdefs.h>\n")
36                              printf("__KERNEL_RCSID(0, \"%c%s%c\");\n",
37                                  "$","NetBSD","$")
38                              printf("\n")
39                              done = 1
40                    }
41                    {
42                              print
43                    }
44          ' < "$f" > "$f".tmp
45          mv -f -- "$f".tmp "$f"
46done
47