11.1Sriastrad#!/bin/sh
21.1Sriastrad
31.4Sriastrad#	$NetBSD: radeon2netbsd,v 1.4 2024/07/02 20:09:13 riastradh Exp $
41.1Sriastrad#
51.1Sriastrad# $ /path/to/radeon2netbsd > /path/to/files.radeon.new
61.1Sriastrad#
71.1Sriastrad# Run from the top-level Radeon source directory.
81.1Sriastrad
91.1Sriastradset -Ceu
101.1Sriastrad
111.2Sriastrad: ${MV:=mv}
121.2Sriastrad
131.1Sriastrad# Location of the Radeon sources relative to $NETBSDSRCDIR.
141.1Sriastradradeon_top=external/bsd/drm2/dist/drm/radeon
151.1Sriastrad
161.1Sriastrad# config(5) flag for the Radeon driver.
171.1Sriastradradeon_flag=radeon
181.1Sriastrad
191.1Sriastradenv CONFIG_ACPI=y \
201.4Sriastradenv CONFIG_DRM_FBDEV_EMULATION=y \
211.4Sriastradenv CONFIG_DRM_RADEON=y \
221.4Sriastradenv CONFIG_MMU_NOTIFIER=y \
231.4Sriastradenv CONFIG_VGA_SWITCHEROO=y \
241.1Sriastradenv src=. \
251.1Sriastradmake -f Makefile -V '$(radeon-y)' \
261.1Sriastrad| tr ' ' '\n' \
271.3Sriastrad| grep -v -e '^[[:space:]]*$' \
281.1Sriastrad| sed -e 's,\.o$,.c,' \
291.1Sriastrad| sort -u \
301.2Sriastrad| awk '
311.2Sriastrad	BEGIN {
321.2Sriastrad		duplicates = 0
331.2Sriastrad	}
341.2Sriastrad	{
351.2Sriastrad		if (index($1, "/")) {
361.2Sriastrad			dir = $1
371.2Sriastrad			sub("/[^/]*$", "/", dir)
381.2Sriastrad			base = $1
391.2Sriastrad			sub("^.*/", "", base)
401.2Sriastrad		} else {
411.2Sriastrad			dir = ""
421.2Sriastrad			base = $1
431.2Sriastrad		}
441.2Sriastrad		fqbase = (base ~ "^radeon_" ? "" : "radeon_") base
451.2Sriastrad		if (seen[fqbase]) {
461.2Sriastrad			printf("Duplicate basename: %s %s\n", fqbase,
471.2Sriastrad			    seen[fqbase]) >"/dev/stderr"
481.2Sriastrad			duplicates = 1
491.2Sriastrad		}
501.2Sriastrad		if (duplicates)
511.2Sriastrad			next
521.2Sriastrad		printf("%s %s\n", $1, dir fqbase)
531.2Sriastrad	}
541.2Sriastrad	END {
551.2Sriastrad		if (duplicates) {
561.2Sriastrad			printf("Time to rewite me!\n") > "/dev/stderr"
571.2Sriastrad			exit 1
581.2Sriastrad		}
591.2Sriastrad	}
601.2Sriastrad' \
611.2Sriastrad| while read from to; do
621.2Sriastrad	# If the move already happened, that's fine: the makefile
631.2Sriastrad	# detects duplicates.
641.2Sriastrad	if [ "x$from" != "x$to" -a \! -f "$to" ]; then
651.2Sriastrad		${MV} -f -- "$from" "$to"
661.2Sriastrad	fi
671.2Sriastrad	printf 'file\t%s\t%s\n' "$radeon_top/$to" "$radeon_flag"
681.2Sriastraddone \
691.2Sriastrad| sort -u
70