Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

#!/bin/sh

#	$NetBSD: nouveau2netbsd,v 1.5 2018/08/27 00:46:21 riastradh Exp $
#
# $ /path/to/nouveau2netbsd > /path/to/files.nouveau.new
#
# Run from the top-level Nouveau source directory.  This stupid kludge
# reinterprets the GNU makefile as a BSD makefile to extract the source
# file names, renames the ones that have obscure and/or colliding
# basenames to be less obscure and unlikely (though not guaranteed) to
# collide, and spits out config(5) directives for all of them.

set -Ceu

: ${MV:=mv}

# Location of the Nouveau sources relative to $NETBSDSRCDIR.
nouveau_top=external/bsd/drm2/dist/drm/nouveau

# config(5) flag for the Nouveau driver.
nouveau_flag=nouveau

filemap=

clean ()
{
	[ -z "$filemap" ] || rm -f -- "$filemap" || :
}
trap clean EXIT HUP INT TERM

filemap="$(mktemp -t ${0##*/})"

cat Kbuild								\
| sed -e 's,^include \(.*\)$,.include "\1",'				\
| sed -e 's,^ifdef \(.*\)$,.if !empty(\1:M[yY][eE][sS]),'		\
| sed -e 's,^endif$,.endif,'						\
| make -f /dev/stdin -V '$(nouveau-y)' src=.				\
| tr ' ' '\n'								\
| sed -e 's,^$,,'							\
| sort -u								\
| sed -e 's,\.o$,.c,'							\
| awk '
	BEGIN {
		duplicates = 0
	}
	$1 ~ "nouveau_[^/]*$" {
		if (seen[$1])
			printf("Duplicate basename: %s\n", $1)
		seen[$1] = $1
		printf("%s %s\n", $1, $1)
		next
	}
	{
		if (index($1, "/")) {
			dir = $1
			sub("/[^/]*$", "/", dir)
		} else {
			dir = ""
		}
		base = $1
		sub("^core/", "", base)
		gsub("/", "_", base)
		if (seen[base]) {
			printf("Duplicate basename: %s %s\n", seen[base], $1) \
			    > "/dev/stderr"
			duplicates = 1
		}
		if (duplicates)
			next
		seen[base] = $1
		printf("%s %s\n", $1, dir "nouveau_" base)
	}
	END {
		if (duplicates) {
			printf("Time to rewite me!\n") > "/dev/stderr"
			exit 1
		}
	}
' >> "$filemap"

while read from to; do
	if [ "x$from" != "x$to" ]; then
		${MV} -f -- "$from" "$to"
	fi
	printf 'file\t%s\t%s\n' "$nouveau_top/$to" "$nouveau_flag"
done < "$filemap" | sort

# We sort the output again at the end because we renamed some files but
# left $TOP/nouveau_* unchanged, so their sort order relative to the
# ones that got renamed may have changed.