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