11.1Sriastrad#!/bin/sh
21.1Sriastrad
31.5Sriastrad#	$NetBSD: amdgpu2netbsd,v 1.5 2024/07/02 20:08:51 riastradh Exp $
41.1Sriastrad#
51.1Sriastrad# $ /path/to/amdgpu2netbsd > /path/to/files.amdgpu.new
61.1Sriastrad#
71.5Sriastrad# Run from the top-level dist/drm/amd/amdgpu source directory, ideally
81.2Sriastrad# before import.
91.1Sriastrad
101.1Sriastradset -Ceu
111.1Sriastrad
121.4Sriastrad: ${GMAKE:=gmake}
131.2Sriastrad: ${MV:=mv}
141.2Sriastrad
151.2Sriastrad# Location of amdgpu sources relative to $NETBSDSOURCEDIR.
161.1Sriastradamdgpu_top=external/bsd/drm2/dist/drm/amd/amdgpu
171.1Sriastrad
181.1Sriastrad# config(5) flag for the amdgpu driver.
191.1Sriastradamdgpu_flag=amdgpu
201.1Sriastrad
211.4Sriastrad{
221.4Sriastrad	printf 'show-amdgpu-y:\n'
231.4Sriastrad	printf '\t@echo $(amdgpu-y)\n'
241.4Sriastrad	printf 'include Makefile\n'
251.4Sriastrad} | env \
261.4Sriastrad	env CONFIG_ACPI=y \
271.5Sriastrad	env CONFIG_COMPAT=y \
281.4Sriastrad	env CONFIG_DRM_AMDGPU=y \
291.4Sriastrad	env CONFIG_DRM_AMDGPU_CIK=y \
301.4Sriastrad	env CONFIG_DRM_AMDGPU_SI=y \
311.4Sriastrad	env CONFIG_DRM_AMD_ACP=y \
321.4Sriastrad	env CONFIG_DRM_AMD_DC=y \
331.5Sriastrad	env CONFIG_DRM_AMD_DC_FP=y \
341.4Sriastrad	env CONFIG_DRM_AMD_DC_HDCP=y \
351.5Sriastrad	env CONFIG_DRM_AMD_DC_SI=y \
361.5Sriastrad	env CONFIG_HMM_MIRROR=y \
371.5Sriastrad	env CONFIG_HSA_AMD=y \
381.5Sriastrad	env CONFIG_HSA_AMD_SVM=y \
391.5Sriastrad	env CONFIG_PERF_EVENTS=y \
401.5Sriastrad	env CONFIG_VGA_SWITCHEROO=y \
411.4Sriastrad	env srctree="`pwd`" \
421.4Sriastrad	env src=. \
431.4Sriastrad	${GMAKE} -f - -s show-amdgpu-y \
441.1Sriastrad| tr ' ' '\n' \
451.1Sriastrad| grep -v '^$' \
461.1Sriastrad| sed -e 's,\.o$,.c,' \
471.1Sriastrad| sort -u \
481.2Sriastrad| awk '
491.2Sriastrad	BEGIN {
501.2Sriastrad		duplicates = 0
511.2Sriastrad	}
521.2Sriastrad	{
531.2Sriastrad		if (index($1, "/")) {
541.2Sriastrad			dir = $1
551.2Sriastrad			sub("/[^/]*$", "/", dir)
561.2Sriastrad			base = $1
571.2Sriastrad			sub("^.*/", "", base)
581.2Sriastrad		} else {
591.2Sriastrad			dir = ""
601.2Sriastrad			base = $1
611.2Sriastrad		}
621.2Sriastrad		fqbase = (base ~ "^amdgpu_" ? "" : "amdgpu_") base
631.2Sriastrad		if (seen[fqbase]) {
641.2Sriastrad			printf("Duplicate basename: %s %s\n", fqbase,
651.2Sriastrad			    seen[fqbase]) >"/dev/stderr"
661.2Sriastrad			duplicates = 1
671.2Sriastrad		}
681.2Sriastrad		if (duplicates)
691.2Sriastrad			next
701.2Sriastrad		printf("%s %s\n", $1, dir fqbase)
711.2Sriastrad	}
721.2Sriastrad	END {
731.2Sriastrad		if (duplicates) {
741.2Sriastrad			printf("Time to rewite me!\n") > "/dev/stderr"
751.2Sriastrad			exit 1
761.2Sriastrad		}
771.2Sriastrad	}
781.2Sriastrad' \
791.2Sriastrad| while read from to; do
801.3Sriastrad	# If the move already happened, that's fine: the makefile
811.3Sriastrad	# detects duplicates.
821.3Sriastrad	if [ "x$from" != "x$to" -a \! -f "$to" ]; then
831.2Sriastrad		${MV} -f -- "$from" "$to"
841.2Sriastrad	fi
851.2Sriastrad	printf 'file\t%s\t%s\n' "$amdgpu_top/$to" "$amdgpu_flag"
861.2Sriastraddone \
871.2Sriastrad| sort -u
88