nouveau2netbsd revision 1.6 1 1.1 riastrad #!/bin/sh
2 1.1 riastrad
3 1.6 riastrad # $NetBSD: nouveau2netbsd,v 1.6 2024/04/16 14:26:53 riastradh Exp $
4 1.1 riastrad #
5 1.1 riastrad # $ /path/to/nouveau2netbsd > /path/to/files.nouveau.new
6 1.1 riastrad #
7 1.1 riastrad # Run from the top-level Nouveau source directory. This stupid kludge
8 1.1 riastrad # reinterprets the GNU makefile as a BSD makefile to extract the source
9 1.1 riastrad # file names, renames the ones that have obscure and/or colliding
10 1.1 riastrad # basenames to be less obscure and unlikely (though not guaranteed) to
11 1.1 riastrad # collide, and spits out config(5) directives for all of them.
12 1.1 riastrad
13 1.1 riastrad set -Ceu
14 1.1 riastrad
15 1.3 riastrad : ${MV:=mv}
16 1.3 riastrad
17 1.1 riastrad # Location of the Nouveau sources relative to $NETBSDSRCDIR.
18 1.1 riastrad nouveau_top=external/bsd/drm2/dist/drm/nouveau
19 1.1 riastrad
20 1.1 riastrad # config(5) flag for the Nouveau driver.
21 1.1 riastrad nouveau_flag=nouveau
22 1.1 riastrad
23 1.1 riastrad filemap=
24 1.1 riastrad
25 1.1 riastrad clean ()
26 1.1 riastrad {
27 1.1 riastrad [ -z "$filemap" ] || rm -f -- "$filemap" || :
28 1.1 riastrad }
29 1.1 riastrad trap clean EXIT HUP INT TERM
30 1.1 riastrad
31 1.1 riastrad filemap="$(mktemp -t ${0##*/})"
32 1.1 riastrad
33 1.4 riastrad cat Kbuild \
34 1.1 riastrad | sed -e 's,^include \(.*\)$,.include "\1",' \
35 1.6 riastrad | sed -e 's,^ifdef \(.*\)$,.if !empty(\1:M[yY]),' \
36 1.1 riastrad | sed -e 's,^endif$,.endif,' \
37 1.6 riastrad | env \
38 1.6 riastrad env CONFIG_ACPI=y \
39 1.6 riastrad env CONFIG_X86=y \
40 1.6 riastrad env src=. \
41 1.6 riastrad make -f /dev/stdin -V '$(nouveau-y)' \
42 1.1 riastrad | tr ' ' '\n' \
43 1.1 riastrad | sed -e 's,^$,,' \
44 1.1 riastrad | sort -u \
45 1.1 riastrad | sed -e 's,\.o$,.c,' \
46 1.1 riastrad | awk '
47 1.1 riastrad BEGIN {
48 1.1 riastrad duplicates = 0
49 1.1 riastrad }
50 1.1 riastrad $1 ~ "nouveau_[^/]*$" {
51 1.1 riastrad if (seen[$1])
52 1.1 riastrad printf("Duplicate basename: %s\n", $1)
53 1.1 riastrad seen[$1] = $1
54 1.1 riastrad printf("%s %s\n", $1, $1)
55 1.1 riastrad next
56 1.1 riastrad }
57 1.1 riastrad {
58 1.1 riastrad if (index($1, "/")) {
59 1.1 riastrad dir = $1
60 1.1 riastrad sub("/[^/]*$", "/", dir)
61 1.1 riastrad } else {
62 1.1 riastrad dir = ""
63 1.1 riastrad }
64 1.1 riastrad base = $1
65 1.1 riastrad sub("^core/", "", base)
66 1.1 riastrad gsub("/", "_", base)
67 1.1 riastrad if (seen[base]) {
68 1.1 riastrad printf("Duplicate basename: %s %s\n", seen[base], $1) \
69 1.1 riastrad > "/dev/stderr"
70 1.1 riastrad duplicates = 1
71 1.1 riastrad }
72 1.1 riastrad if (duplicates)
73 1.1 riastrad next
74 1.1 riastrad seen[base] = $1
75 1.1 riastrad printf("%s %s\n", $1, dir "nouveau_" base)
76 1.1 riastrad }
77 1.1 riastrad END {
78 1.1 riastrad if (duplicates) {
79 1.1 riastrad printf("Time to rewite me!\n") > "/dev/stderr"
80 1.1 riastrad exit 1
81 1.1 riastrad }
82 1.1 riastrad }
83 1.1 riastrad ' >> "$filemap"
84 1.1 riastrad
85 1.1 riastrad while read from to; do
86 1.1 riastrad if [ "x$from" != "x$to" ]; then
87 1.3 riastrad ${MV} -f -- "$from" "$to"
88 1.1 riastrad fi
89 1.1 riastrad printf 'file\t%s\t%s\n' "$nouveau_top/$to" "$nouveau_flag"
90 1.1 riastrad done < "$filemap" | sort
91 1.1 riastrad
92 1.1 riastrad # We sort the output again at the end because we renamed some files but
93 1.1 riastrad # left $TOP/nouveau_* unchanged, so their sort order relative to the
94 1.1 riastrad # ones that got renamed may have changed.
95