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