11.1Sriastrad#!/bin/sh
21.1Sriastrad
31.1Sriastrad#	$NetBSD: vmwgfx2netbsd,v 1.1 2022/02/17 01:21:03 riastradh Exp $
41.1Sriastrad#
51.1Sriastrad# $ /path/to/vmwgfx2netbsd > /path/to/files.vmwgfx.new
61.1Sriastrad#
71.1Sriastrad# Run from the top-level vmwgfx source directory.
81.1Sriastrad
91.1Sriastradset -Ceu
101.1Sriastrad
111.1Sriastrad: ${MV:=mv}
121.1Sriastrad
131.1Sriastrad# Location of the vmwgfx sources relative to $NETBSDSRCDIR.
141.1Sriastradvmwgfx_top=external/bsd/drm2/dist/drm/vmwgfx
151.1Sriastrad
161.1Sriastrad# config(5) flag for the vmwgfx driver.
171.1Sriastradvmwgfx_flag=vmwgfx
181.1Sriastrad
191.1Sriastradenv CONFIG_ACPI=y \
201.1Sriastradenv src=. \
211.1Sriastradmake -f Makefile -V '$(vmwgfx-y)' \
221.1Sriastrad| tr ' ' '\n' \
231.1Sriastrad| grep -v -e '^[[:space:]]*$' \
241.1Sriastrad| sed -e 's,\.o$,.c,' \
251.1Sriastrad| sort -u \
261.1Sriastrad| awk '
271.1Sriastrad	BEGIN {
281.1Sriastrad		duplicates = 0
291.1Sriastrad	}
301.1Sriastrad	{
311.1Sriastrad		if (index($1, "/")) {
321.1Sriastrad			dir = $1
331.1Sriastrad			sub("/[^/]*$", "/", dir)
341.1Sriastrad			base = $1
351.1Sriastrad			sub("^.*/", "", base)
361.1Sriastrad		} else {
371.1Sriastrad			dir = ""
381.1Sriastrad			base = $1
391.1Sriastrad		}
401.1Sriastrad		fqbase = (base ~ "^vmwgfx_" ? "" : "vmwgfx_") base
411.1Sriastrad		if (seen[fqbase]) {
421.1Sriastrad			printf("Duplicate basename: %s %s\n", fqbase,
431.1Sriastrad			    seen[fqbase]) >"/dev/stderr"
441.1Sriastrad			duplicates = 1
451.1Sriastrad		}
461.1Sriastrad		if (duplicates)
471.1Sriastrad			next
481.1Sriastrad		printf("%s %s\n", $1, dir fqbase)
491.1Sriastrad	}
501.1Sriastrad	END {
511.1Sriastrad		if (duplicates) {
521.1Sriastrad			printf("Time to rewite me!\n") > "/dev/stderr"
531.1Sriastrad			exit 1
541.1Sriastrad		}
551.1Sriastrad	}
561.1Sriastrad' \
571.1Sriastrad| while read from to; do
581.1Sriastrad	# If the move already happened, that's fine: the makefile
591.1Sriastrad	# detects duplicates.
601.1Sriastrad	if [ "x$from" != "x$to" -a \! -f "$to" ]; then
611.1Sriastrad		${MV} -f -- "$from" "$to"
621.1Sriastrad	fi
631.1Sriastrad	printf 'file\t%s\t%s\n' "$vmwgfx_top/$to" "$vmwgfx_flag"
641.1Sriastraddone \
651.1Sriastrad| sort -u
66