<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use File::Spec;
use Getopt::Long;
use strict;

&amp;main();
sub main
{
	my($dev_output, $ndev_output, $loc) = ("-", "-", ".");
	&amp;Getopt::Long::Configure(qw(bundling));
	&amp;GetOptions(
		"D=s" =&gt; \$dev_output,
		"N=s" =&gt; \$ndev_output,
		"L=s" =&gt; \$loc,
	);

	my($dev, $ndev) = &amp;scan($loc);
	&amp;output($dev, $ndev, $dev_output, $ndev_output);
}

sub scan
{
	# Normalize file path, mainly to strip away the ending forward slash,
	# or any double forward slashes.
	my $loc = File::Spec-&gt;canonpath(shift @_);
	# We cannot use an absolute path (e.g. /usr/src/linux-5.14.21-150500.41)
	# during find because it's under build root, but rpm wants one later.
	my $abs_loc = rpm_path($loc);
	my(@dev, @ndev);

	foreach $_ (`find "$loc"`)
	{
		chomp $_;
		if (-d $_ &amp;&amp; !-l $_) {
			# Generate directory list later.
			next;
		}
		my $is_devel =
			m{^\Q$loc\E.*/Kconfig} ||
			m{^\Q$loc\E.*/Kbuild} ||
			m{^\Q$loc\E.*/Makefile} ||
			m{^\Q$loc\E/arch/[^/]+/boot/dts/include/dt-bindings\b} ||
			m{^\Q$loc\E/arch/[^/]+/include\b} ||
			m{^\Q$loc\E/arch/.*/module\.lds\b} ||
			m{^\Q$loc\E/arch/arm/[^/]+/include/mach\b} ||
			m{^\Q$loc\E/arch/arm/[^/]+/include/plat\b} ||
			m{^\Q$loc\E/arch/[^/]+/scripts\b} ||
			m{^\Q$loc\E/arch/[^/]+/tools\b} ||
			m{^\Q$loc\E/include/[^/]+\b} ||
			m{^\Q$loc\E/scripts\b};
		my $abs_path = rpm_path($_);
		$is_devel ? push(@dev, $abs_path) : push(@ndev, $abs_path);
	}

	push(@dev, &amp;calc_dirs($abs_loc, \@dev));
	push(@ndev, &amp;calc_dirs($abs_loc, \@ndev));
	return (\@dev, \@ndev);
}

sub calc_dirs
{
	my($base, $files) = @_;
	my %dirs;

	foreach my $file (@$files) {
		my ($volume,$path,$basename) = File::Spec-&gt;splitpath($file);
		my @dirs = File::Spec-&gt;splitdir($path);
		do {
			# Always create $path from catdir() to avoid ending forward slash
			$path = File::Spec-&gt;catdir(@dirs);
			$dirs{$path} = 1;
			pop @dirs;
		} while ($path ne $base);
		# This loop also makes sure that $base itself is included.
	}

	return map { "\%dir $_" } keys %dirs;
}

sub output
{
	my($dev, $ndev, $dev_out, $ndev_out) = @_;
	local *FH;

	open(FH, "&gt; $dev_out") || warn "Error writing to $dev_out: $!";
	print FH join("\n", @$dev), "\n";
	close FH;

	open(FH, "&gt; $ndev_out") || warn "Error writing to $ndev_out: $!";
	print FH join("\n", @$ndev), "\n";
	close FH;
}

sub rpm_path
{
	my $path = shift @_;
	# Always prepend forward slash and let canonpath take care of
	# duplicate forward slashes.
	return File::Spec-&gt;canonpath("/$path");
}
</pre></body></html>