amdgpu2netbsd revision 1.4
11.1Sriastrad#!/bin/sh
21.1Sriastrad
31.4Sriastrad#	$NetBSD: amdgpu2netbsd,v 1.4 2021/12/19 10:20:31 riastradh Exp $
41.1Sriastrad#
51.1Sriastrad# $ /path/to/amdgpu2netbsd > /path/to/files.amdgpu.new
61.1Sriastrad#
71.2Sriastrad# Run from the top-level dist/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.4Sriastrad	env CONFIG_DRM_AMDGPU=y \
281.4Sriastrad	env CONFIG_DRM_AMDGPU_CIK=y \
291.4Sriastrad	env CONFIG_DRM_AMDGPU_SI=y \
301.4Sriastrad	env CONFIG_DRM_AMD_ACP=y \
311.4Sriastrad	env CONFIG_DRM_AMD_DC=y \
321.4Sriastrad	env CONFIG_DRM_AMD_DC_DCN=y \
331.4Sriastrad	env CONFIG_DRM_AMD_DC_HDCP=y \
341.4Sriastrad	env srctree="`pwd`" \
351.4Sriastrad	env src=. \
361.4Sriastrad	${GMAKE} -f - -s show-amdgpu-y \
371.1Sriastrad| tr ' ' '\n' \
381.1Sriastrad| grep -v '^$' \
391.1Sriastrad| sed -e 's,\.o$,.c,' \
401.1Sriastrad| sort -u \
411.2Sriastrad| awk '
421.2Sriastrad	BEGIN {
431.2Sriastrad		duplicates = 0
441.2Sriastrad	}
451.2Sriastrad	{
461.2Sriastrad		if (index($1, "/")) {
471.2Sriastrad			dir = $1
481.2Sriastrad			sub("/[^/]*$", "/", dir)
491.2Sriastrad			base = $1
501.2Sriastrad			sub("^.*/", "", base)
511.2Sriastrad		} else {
521.2Sriastrad			dir = ""
531.2Sriastrad			base = $1
541.2Sriastrad		}
551.2Sriastrad		fqbase = (base ~ "^amdgpu_" ? "" : "amdgpu_") base
561.2Sriastrad		if (seen[fqbase]) {
571.2Sriastrad			printf("Duplicate basename: %s %s\n", fqbase,
581.2Sriastrad			    seen[fqbase]) >"/dev/stderr"
591.2Sriastrad			duplicates = 1
601.2Sriastrad		}
611.2Sriastrad		if (duplicates)
621.2Sriastrad			next
631.2Sriastrad		printf("%s %s\n", $1, dir fqbase)
641.2Sriastrad	}
651.2Sriastrad	END {
661.2Sriastrad		if (duplicates) {
671.2Sriastrad			printf("Time to rewite me!\n") > "/dev/stderr"
681.2Sriastrad			exit 1
691.2Sriastrad		}
701.2Sriastrad	}
711.2Sriastrad' \
721.2Sriastrad| while read from to; do
731.3Sriastrad	# If the move already happened, that's fine: the makefile
741.3Sriastrad	# detects duplicates.
751.3Sriastrad	if [ "x$from" != "x$to" -a \! -f "$to" ]; then
761.2Sriastrad		${MV} -f -- "$from" "$to"
771.2Sriastrad	fi
781.2Sriastrad	printf 'file\t%s\t%s\n' "$amdgpu_top/$to" "$amdgpu_flag"
791.2Sriastraddone \
801.2Sriastrad| sort -u
81