1 1.1 riastrad #!/bin/sh 2 1.1 riastrad 3 1.7 riastrad # $NetBSD: nouveau2netbsd,v 1.7 2024/07/02 20:09:01 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.7 riastrad env CONFIG_COMPAT=y \ 40 1.7 riastrad env CONFIG_DRM_NOUVEAU_SVM=y \ 41 1.7 riastrad env CONFIG_LEDS_CLASS=y \ 42 1.7 riastrad env CONFIG_NOUVEAU=y \ 43 1.7 riastrad env CONFIG_NOUVEAU_BACKLIGHT=y \ 44 1.6 riastrad env CONFIG_X86=y \ 45 1.6 riastrad env src=. \ 46 1.6 riastrad make -f /dev/stdin -V '$(nouveau-y)' \ 47 1.1 riastrad | tr ' ' '\n' \ 48 1.1 riastrad | sed -e 's,^$,,' \ 49 1.1 riastrad | sort -u \ 50 1.1 riastrad | sed -e 's,\.o$,.c,' \ 51 1.1 riastrad | awk ' 52 1.1 riastrad BEGIN { 53 1.1 riastrad duplicates = 0 54 1.1 riastrad } 55 1.1 riastrad $1 ~ "nouveau_[^/]*$" { 56 1.1 riastrad if (seen[$1]) 57 1.1 riastrad printf("Duplicate basename: %s\n", $1) 58 1.1 riastrad seen[$1] = $1 59 1.1 riastrad printf("%s %s\n", $1, $1) 60 1.1 riastrad next 61 1.1 riastrad } 62 1.1 riastrad { 63 1.1 riastrad if (index($1, "/")) { 64 1.1 riastrad dir = $1 65 1.1 riastrad sub("/[^/]*$", "/", dir) 66 1.1 riastrad } else { 67 1.1 riastrad dir = "" 68 1.1 riastrad } 69 1.1 riastrad base = $1 70 1.1 riastrad sub("^core/", "", base) 71 1.1 riastrad gsub("/", "_", base) 72 1.1 riastrad if (seen[base]) { 73 1.1 riastrad printf("Duplicate basename: %s %s\n", seen[base], $1) \ 74 1.1 riastrad > "/dev/stderr" 75 1.1 riastrad duplicates = 1 76 1.1 riastrad } 77 1.1 riastrad if (duplicates) 78 1.1 riastrad next 79 1.1 riastrad seen[base] = $1 80 1.1 riastrad printf("%s %s\n", $1, dir "nouveau_" base) 81 1.1 riastrad } 82 1.1 riastrad END { 83 1.1 riastrad if (duplicates) { 84 1.1 riastrad printf("Time to rewite me!\n") > "/dev/stderr" 85 1.1 riastrad exit 1 86 1.1 riastrad } 87 1.1 riastrad } 88 1.1 riastrad ' >> "$filemap" 89 1.1 riastrad 90 1.1 riastrad while read from to; do 91 1.7 riastrad # If the move already happened, that's fine: the makefile 92 1.7 riastrad # detects duplicates. 93 1.7 riastrad if [ "x$from" != "x$to" -a \! -f "$to" ]; then 94 1.3 riastrad ${MV} -f -- "$from" "$to" 95 1.1 riastrad fi 96 1.1 riastrad printf 'file\t%s\t%s\n' "$nouveau_top/$to" "$nouveau_flag" 97 1.1 riastrad done < "$filemap" | sort 98 1.1 riastrad 99 1.1 riastrad # We sort the output again at the end because we renamed some files but 100 1.1 riastrad # left $TOP/nouveau_* unchanged, so their sort order relative to the 101 1.1 riastrad # ones that got renamed may have changed. 102