Home | History | Annotate | Line # | Download | only in amdgpu
amdgpu2netbsd revision 1.4
      1 #!/bin/sh
      2 
      3 #	$NetBSD: amdgpu2netbsd,v 1.4 2021/12/19 10:20:31 riastradh Exp $
      4 #
      5 # $ /path/to/amdgpu2netbsd > /path/to/files.amdgpu.new
      6 #
      7 # Run from the top-level dist/amd/amdgpu source directory, ideally
      8 # before import.
      9 
     10 set -Ceu
     11 
     12 : ${GMAKE:=gmake}
     13 : ${MV:=mv}
     14 
     15 # Location of amdgpu sources relative to $NETBSDSOURCEDIR.
     16 amdgpu_top=external/bsd/drm2/dist/drm/amd/amdgpu
     17 
     18 # config(5) flag for the amdgpu driver.
     19 amdgpu_flag=amdgpu
     20 
     21 {
     22 	printf 'show-amdgpu-y:\n'
     23 	printf '\t@echo $(amdgpu-y)\n'
     24 	printf 'include Makefile\n'
     25 } | env \
     26 	env CONFIG_ACPI=y \
     27 	env CONFIG_DRM_AMDGPU=y \
     28 	env CONFIG_DRM_AMDGPU_CIK=y \
     29 	env CONFIG_DRM_AMDGPU_SI=y \
     30 	env CONFIG_DRM_AMD_ACP=y \
     31 	env CONFIG_DRM_AMD_DC=y \
     32 	env CONFIG_DRM_AMD_DC_DCN=y \
     33 	env CONFIG_DRM_AMD_DC_HDCP=y \
     34 	env srctree="`pwd`" \
     35 	env src=. \
     36 	${GMAKE} -f - -s show-amdgpu-y \
     37 | tr ' ' '\n' \
     38 | grep -v '^$' \
     39 | sed -e 's,\.o$,.c,' \
     40 | sort -u \
     41 | awk '
     42 	BEGIN {
     43 		duplicates = 0
     44 	}
     45 	{
     46 		if (index($1, "/")) {
     47 			dir = $1
     48 			sub("/[^/]*$", "/", dir)
     49 			base = $1
     50 			sub("^.*/", "", base)
     51 		} else {
     52 			dir = ""
     53 			base = $1
     54 		}
     55 		fqbase = (base ~ "^amdgpu_" ? "" : "amdgpu_") base
     56 		if (seen[fqbase]) {
     57 			printf("Duplicate basename: %s %s\n", fqbase,
     58 			    seen[fqbase]) >"/dev/stderr"
     59 			duplicates = 1
     60 		}
     61 		if (duplicates)
     62 			next
     63 		printf("%s %s\n", $1, dir fqbase)
     64 	}
     65 	END {
     66 		if (duplicates) {
     67 			printf("Time to rewite me!\n") > "/dev/stderr"
     68 			exit 1
     69 		}
     70 	}
     71 ' \
     72 | while read from to; do
     73 	# If the move already happened, that's fine: the makefile
     74 	# detects duplicates.
     75 	if [ "x$from" != "x$to" -a \! -f "$to" ]; then
     76 		${MV} -f -- "$from" "$to"
     77 	fi
     78 	printf 'file\t%s\t%s\n' "$amdgpu_top/$to" "$amdgpu_flag"
     79 done \
     80 | sort -u
     81