nouveau2netbsd revision 1.1 1 #!/bin/sh
2
3 # $NetBSD: nouveau2netbsd,v 1.1 2014/08/05 17:39:07 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 # Location of the Nouveau sources relative to $NETBSDSRCDIR.
16 nouveau_top=external/bsd/drm2/dist/drm/nouveau
17
18 # config(5) flag for the Nouveau driver.
19 nouveau_flag=nouveau
20
21 filemap=
22
23 clean ()
24 {
25 [ -z "$filemap" ] || rm -f -- "$filemap" || :
26 }
27 trap clean EXIT HUP INT TERM
28
29 filemap="$(mktemp -t ${0##*/})"
30
31 cat Makefile \
32 | sed -e 's,^include \(.*\)$,.include "\1",' \
33 | sed -e 's,^ifdef \(.*\)$,.if !empty(\1:M[yY][eE][sS]),' \
34 | sed -e 's,^endif$,.endif,' \
35 | make -f /dev/stdin -V nouveau-y src=. \
36 | tr ' ' '\n' \
37 | sed -e 's,^$,,' \
38 | sort -u \
39 | sed -e 's,\.o$,.c,' \
40 | awk '
41 BEGIN {
42 duplicates = 0
43 }
44 $1 ~ "nouveau_[^/]*$" {
45 if (seen[$1])
46 printf("Duplicate basename: %s\n", $1)
47 seen[$1] = $1
48 printf("%s %s\n", $1, $1)
49 next
50 }
51 {
52 if (index($1, "/")) {
53 dir = $1
54 sub("/[^/]*$", "/", dir)
55 } else {
56 dir = ""
57 }
58 base = $1
59 sub("^core/", "", base)
60 gsub("/", "_", base)
61 if (seen[base]) {
62 printf("Duplicate basename: %s %s\n", seen[base], $1) \
63 > "/dev/stderr"
64 duplicates = 1
65 }
66 if (duplicates)
67 next
68 seen[base] = $1
69 printf("%s %s\n", $1, dir "nouveau_" base)
70 }
71 END {
72 if (duplicates) {
73 printf("Time to rewite me!\n") > "/dev/stderr"
74 exit 1
75 }
76 }
77 ' >> "$filemap"
78
79 while read from to; do
80 if [ "x$from" != "x$to" ]; then
81 mv -f -- "$from" "$to"
82 fi
83 # Probably not necessary -- Linux tends not to have RCS ids --
84 # but a precaution out of paranoia.
85 cleantags "$to"
86 case $to in
87 *.c)
88 awk '
89 BEGIN {
90 done = 0
91 printf("/*\t%c%s%c\t*/\n\n", "$","NetBSD","$")
92 }
93 /^#include/ && !done {
94 printf("#include <sys/cdefs.h>\n")
95 printf("__KERNEL_RCSID(0, \"%c%s%c\");\n",
96 "$","NetBSD","$")
97 printf("\n")
98 done = 1
99 }
100 {
101 print
102 }
103 ' < "$to" > "$to".tmp
104 ;;
105 esac
106 mv -f -- "$to".tmp "$to"
107 printf 'file\t%s\t%s\n' "$nouveau_top/$to" "$nouveau_flag"
108 done < "$filemap" | sort
109
110 # We sort the output again at the end because we renamed some files but
111 # left $TOP/nouveau_* unchanged, so their sort order relative to the
112 # ones that got renamed may have changed.
113