aboutsummaryrefslogtreecommitdiffstats
path: root/linux/version_patch.pl
blob: c3765562898192449bdacf0eeb665e0b39568da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
use strict;


sub patch_file($$$$)
{
	my $filename = shift;
	my $function = shift;
	my $after_line = shift;
	my $media_build_version = shift;
	my $patched;
	my $warning = "WARNING: You are using an experimental version of the media stack.";

	open IN, "$filename" or die "can't open $filename";
	my $is_function;
	my $file;
	while (<IN>) {
		next if (m/($warning)/);
		$file .= $_;
		if (m/($function)/) {
			$is_function = 1;
			next;
		};
		next if (!$is_function);
		if (/\}/) {
			$is_function--;
			next;
		};
		if (m/\{/) {
			$is_function++;
			next;
		};
		if ($is_function && m/($after_line)/) {
			$file .= "\tprintk(KERN_ERR \"$warning\\n" .
				 "\\t\\tAs the driver is backported to an older kernel, it doesn't offer enough\\n" .
				 "\\t\\tquality for its usage in production.\\n" .
				 "\\t\\tUse it with care.\\n$media_build_version\\n\");\n";
			$is_function = 0;
			$patched++;
			next;
		};
	}
	close IN;

	open OUT, ">$filename.new" or die "Can't open $filename.new";
	print OUT $file;
	close OUT;
	rename "$filename", "$filename~" or die "Can't rename $filename to $filename~";
	rename "$filename.new", "$filename" or die "Can't rename $filename.new to $filename";
	if ($patched) {
		print "Patched $filename\n";
	} else {
		die "$filename was not patched.\n";
	}
}

#
# Main
#

# Prepare patches message
open IN, "git_log" or die "can't open git_log";
my $logs;
$logs.=$_ while (<IN>);
close IN;
$logs =~ s/\s+$//;
$logs =~ s,\n,\\n\\t,g;
$logs = "Latest git patches:\\n\\t$logs";

my $need_patch;
open IN, "md5sum git_log|" or die "can't find git_log";
my $hash = <IN>;
close IN;
open IN, ".git_log.md5" or $need_patch = 1;
if (!$need_patch) {
	$need_patch = 1 if ($hash ne <IN>);
}

if ($need_patch) {
	# Patch dvbdev
	patch_file "drivers/media/dvb/dvb-core/dvbdev.c", "__init init_dvbdev", "MKDEV", $logs;
	# Patch v4l2-dev
	patch_file "drivers/media/video/v4l2-dev.c", "__init videodev_init", "printk", $logs;
	# Patch rc core
	patch_file "drivers/media/rc/rc-main.c", "__init rc_core_init", "rc_map_register", $logs;

	open OUT,">.git_log.md5";
	print OUT $hash;
	close OUT;
}

Privacy Policy