xref: /netbsd-src/sys/external/bsd/drm2/amdgpu/amdgpu2netbsd (revision a81e94c51c4898d1fc9af2b2d13bdce08c2c4900)
1#!/bin/sh
2
3#	$NetBSD: amdgpu2netbsd,v 1.2 2018/08/27 14:10:42 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
10set -Ceu
11
12: ${MV:=mv}
13
14# Location of amdgpu sources relative to $NETBSDSOURCEDIR.
15amdgpu_top=external/bsd/drm2/dist/drm/amd/amdgpu
16
17# config(5) flag for the amdgpu driver.
18amdgpu_flag=amdgpu
19
20env CONFIG_ACPI=y \
21env src=. \
22make -f Makefile -V '$(amdgpu-y)' \
23| tr ' ' '\n' \
24| grep -v '^$' \
25| sed -e 's,\.o$,.c,' \
26| sort -u \
27| awk '
28	BEGIN {
29		duplicates = 0
30	}
31	{
32		if (index($1, "/")) {
33			dir = $1
34			sub("/[^/]*$", "/", dir)
35			base = $1
36			sub("^.*/", "", base)
37		} else {
38			dir = ""
39			base = $1
40		}
41		fqbase = (base ~ "^amdgpu_" ? "" : "amdgpu_") base
42		if (seen[fqbase]) {
43			printf("Duplicate basename: %s %s\n", fqbase,
44			    seen[fqbase]) >"/dev/stderr"
45			duplicates = 1
46		}
47		if (duplicates)
48			next
49		printf("%s %s\n", $1, dir fqbase)
50	}
51	END {
52		if (duplicates) {
53			printf("Time to rewite me!\n") > "/dev/stderr"
54			exit 1
55		}
56	}
57' \
58| while read from to; do
59	if [ "x$from" != "x$to" ]; then
60		${MV} -f -- "$from" "$to"
61	fi
62	printf 'file\t%s\t%s\n' "$amdgpu_top/$to" "$amdgpu_flag"
63done \
64| sort -u
65