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