| @@ -1,117 +1,119 @@ | | | @@ -1,117 +1,119 @@ |
1 | #!/bin/sh | | 1 | #!/bin/sh |
2 | | | 2 | |
3 | # $NetBSD: nouveau2netbsd,v 1.2 2014/08/05 19:49:13 riastradh Exp $ | | 3 | # $NetBSD: nouveau2netbsd,v 1.3 2018/08/27 00:46:04 riastradh Exp $ |
4 | # | | 4 | # |
5 | # $ /path/to/nouveau2netbsd > /path/to/files.nouveau.new | | 5 | # $ /path/to/nouveau2netbsd > /path/to/files.nouveau.new |
6 | # | | 6 | # |
7 | # Run from the top-level Nouveau source directory. This stupid kludge | | 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 | | 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 | | 9 | # file names, renames the ones that have obscure and/or colliding |
10 | # basenames to be less obscure and unlikely (though not guaranteed) to | | 10 | # basenames to be less obscure and unlikely (though not guaranteed) to |
11 | # collide, and spits out config(5) directives for all of them. | | 11 | # collide, and spits out config(5) directives for all of them. |
12 | | | 12 | |
13 | set -Ceu | | 13 | set -Ceu |
14 | | | 14 | |
| | | 15 | : ${MV:=mv} |
| | | 16 | |
15 | # Location of the Nouveau sources relative to $NETBSDSRCDIR. | | 17 | # Location of the Nouveau sources relative to $NETBSDSRCDIR. |
16 | nouveau_top=external/bsd/drm2/dist/drm/nouveau | | 18 | nouveau_top=external/bsd/drm2/dist/drm/nouveau |
17 | | | 19 | |
18 | # config(5) flag for the Nouveau driver. | | 20 | # config(5) flag for the Nouveau driver. |
19 | nouveau_flag=nouveau | | 21 | nouveau_flag=nouveau |
20 | | | 22 | |
21 | filemap= | | 23 | filemap= |
22 | | | 24 | |
23 | clean () | | 25 | clean () |
24 | { | | 26 | { |
25 | [ -z "$filemap" ] || rm -f -- "$filemap" || : | | 27 | [ -z "$filemap" ] || rm -f -- "$filemap" || : |
26 | } | | 28 | } |
27 | trap clean EXIT HUP INT TERM | | 29 | trap clean EXIT HUP INT TERM |
28 | | | 30 | |
29 | filemap="$(mktemp -t ${0##*/})" | | 31 | filemap="$(mktemp -t ${0##*/})" |
30 | | | 32 | |
31 | cat Makefile \ | | 33 | cat Makefile \ |
32 | | sed -e 's,^include \(.*\)$,.include "\1",' \ | | 34 | | sed -e 's,^include \(.*\)$,.include "\1",' \ |
33 | | sed -e 's,^ifdef \(.*\)$,.if !empty(\1:M[yY][eE][sS]),' \ | | 35 | | sed -e 's,^ifdef \(.*\)$,.if !empty(\1:M[yY][eE][sS]),' \ |
34 | | sed -e 's,^endif$,.endif,' \ | | 36 | | sed -e 's,^endif$,.endif,' \ |
35 | | make -f /dev/stdin -V nouveau-y src=. \ | | 37 | | make -f /dev/stdin -V nouveau-y src=. \ |
36 | | tr ' ' '\n' \ | | 38 | | tr ' ' '\n' \ |
37 | | sed -e 's,^$,,' \ | | 39 | | sed -e 's,^$,,' \ |
38 | | sort -u \ | | 40 | | sort -u \ |
39 | | sed -e 's,\.o$,.c,' \ | | 41 | | sed -e 's,\.o$,.c,' \ |
40 | | awk ' | | 42 | | awk ' |
41 | BEGIN { | | 43 | BEGIN { |
42 | duplicates = 0 | | 44 | duplicates = 0 |
43 | } | | 45 | } |
44 | $1 ~ "nouveau_[^/]*$" { | | 46 | $1 ~ "nouveau_[^/]*$" { |
45 | if (seen[$1]) | | 47 | if (seen[$1]) |
46 | printf("Duplicate basename: %s\n", $1) | | 48 | printf("Duplicate basename: %s\n", $1) |
47 | seen[$1] = $1 | | 49 | seen[$1] = $1 |
48 | printf("%s %s\n", $1, $1) | | 50 | printf("%s %s\n", $1, $1) |
49 | next | | 51 | next |
50 | } | | 52 | } |
51 | { | | 53 | { |
52 | if (index($1, "/")) { | | 54 | if (index($1, "/")) { |
53 | dir = $1 | | 55 | dir = $1 |
54 | sub("/[^/]*$", "/", dir) | | 56 | sub("/[^/]*$", "/", dir) |
55 | } else { | | 57 | } else { |
56 | dir = "" | | 58 | dir = "" |
57 | } | | 59 | } |
58 | base = $1 | | 60 | base = $1 |
59 | sub("^core/", "", base) | | 61 | sub("^core/", "", base) |
60 | gsub("/", "_", base) | | 62 | gsub("/", "_", base) |
61 | if (seen[base]) { | | 63 | if (seen[base]) { |
62 | printf("Duplicate basename: %s %s\n", seen[base], $1) \ | | 64 | printf("Duplicate basename: %s %s\n", seen[base], $1) \ |
63 | > "/dev/stderr" | | 65 | > "/dev/stderr" |
64 | duplicates = 1 | | 66 | duplicates = 1 |
65 | } | | 67 | } |
66 | if (duplicates) | | 68 | if (duplicates) |
67 | next | | 69 | next |
68 | seen[base] = $1 | | 70 | seen[base] = $1 |
69 | printf("%s %s\n", $1, dir "nouveau_" base) | | 71 | printf("%s %s\n", $1, dir "nouveau_" base) |
70 | } | | 72 | } |
71 | END { | | 73 | END { |
72 | if (duplicates) { | | 74 | if (duplicates) { |
73 | printf("Time to rewite me!\n") > "/dev/stderr" | | 75 | printf("Time to rewite me!\n") > "/dev/stderr" |
74 | exit 1 | | 76 | exit 1 |
75 | } | | 77 | } |
76 | } | | 78 | } |
77 | ' >> "$filemap" | | 79 | ' >> "$filemap" |
78 | | | 80 | |
79 | while read from to; do | | 81 | while read from to; do |
80 | if [ "x$from" != "x$to" ]; then | | 82 | if [ "x$from" != "x$to" ]; then |
81 | mv -f -- "$from" "$to" | | 83 | ${MV} -f -- "$from" "$to" |
82 | fi | | 84 | fi |
83 | # Probably not necessary -- Linux tends not to have RCS ids -- | | 85 | # Probably not necessary -- Linux tends not to have RCS ids -- |
84 | # but a precaution out of paranoia. | | 86 | # but a precaution out of paranoia. |
85 | cleantags "$to" | | 87 | cleantags "$to" |
86 | case $to in | | 88 | case $to in |
87 | *.c) | | 89 | *.c) |
88 | # Heuristically apply NetBSD RCS ids: a comment at the | | 90 | # Heuristically apply NetBSD RCS ids: a comment at the |
89 | # top of the file, and a __KERNEL_RCSID before the | | 91 | # top of the file, and a __KERNEL_RCSID before the |
90 | # first cpp line, which, with any luck, should be the | | 92 | # first cpp line, which, with any luck, should be the |
91 | # first non-comment line and lie between the copyright | | 93 | # first non-comment line and lie between the copyright |
92 | # notice and the header. | | 94 | # notice and the header. |
93 | awk ' | | 95 | awk ' |
94 | BEGIN { | | 96 | BEGIN { |
95 | done = 0 | | 97 | done = 0 |
96 | printf("/*\t%c%s%c\t*/\n\n", "$","NetBSD","$") | | 98 | printf("/*\t%c%s%c\t*/\n\n", "$","NetBSD","$") |
97 | } | | 99 | } |
98 | /^#/ && !done { | | 100 | /^#/ && !done { |
99 | printf("#include <sys/cdefs.h>\n") | | 101 | printf("#include <sys/cdefs.h>\n") |
100 | printf("__KERNEL_RCSID(0, \"%c%s%c\");\n", | | 102 | printf("__KERNEL_RCSID(0, \"%c%s%c\");\n", |
101 | "$","NetBSD","$") | | 103 | "$","NetBSD","$") |
102 | printf("\n") | | 104 | printf("\n") |
103 | done = 1 | | 105 | done = 1 |
104 | } | | 106 | } |
105 | { | | 107 | { |
106 | print | | 108 | print |
107 | } | | 109 | } |
108 | ' < "$to" > "$to".tmp | | 110 | ' < "$to" > "$to".tmp |
109 | ;; | | 111 | ;; |
110 | esac | | 112 | esac |
111 | mv -f -- "$to".tmp "$to" | | 113 | mv -f -- "$to".tmp "$to" |
112 | printf 'file\t%s\t%s\n' "$nouveau_top/$to" "$nouveau_flag" | | 114 | printf 'file\t%s\t%s\n' "$nouveau_top/$to" "$nouveau_flag" |
113 | done < "$filemap" | sort | | 115 | done < "$filemap" | sort |
114 | | | 116 | |
115 | # We sort the output again at the end because we renamed some files but | | 117 | # We sort the output again at the end because we renamed some files but |
116 | # left $TOP/nouveau_* unchanged, so their sort order relative to the | | 118 | # left $TOP/nouveau_* unchanged, so their sort order relative to the |
117 | # ones that got renamed may have changed. | | 119 | # ones that got renamed may have changed. |