]> git.sesse.net Git - x264/blob - tools/cltostr.pl
Update to current libav/ffmpeg API
[x264] / tools / cltostr.pl
1 # Perl script used for compiling OpenCL src into x264 binary
2 #
3 # Copyright (C) 2013 x264 project
4 # Authors: Steve Borho <sborho@multicorewareinc.com>
5
6 use Digest::MD5 qw(md5_hex);
7
8 # xxd takes a VAR, which will be the variable name
9 # and BYTES, a string of bytes to beencoded.
10 sub xxd
11 {
12   my %args = @_;
13   my $var = $args{VAR};
14   my $bytes = $args{BYTES};
15   my @hexbytes;
16   my @bytes = split //, $$bytes;
17   foreach $b (@bytes)
18   {
19     push @hexbytes, sprintf("0x%02X", ord($b));
20   }
21
22   # Format 'em nice and pretty-like.
23   print 'static const char ' . $var . '[] = {' . "\n";
24   my $count = 0;
25   foreach my $h (@hexbytes)
26   {
27     print "$h, ";
28     $count++;
29     if ($count == 16)
30     {
31       print "\n";
32       $count = 0;
33     }
34   }
35   print "\n0x00 };\n\n";
36
37   return;
38 }
39
40 if (@ARGV < 1)
41 {
42   printf "%s: VARNAME ", $0 . "\n";
43   exit(-1);
44 }
45
46
47 my @lines;
48 while(<STDIN>)
49 {
50   s/^\s+//;                # trim leading whitespace
51   if (/^\/\//)
52   {
53     next;   # skip the line if it starts with '//'
54   }
55   push @lines, $_;
56 }
57
58 my $lines = join '', @lines;
59 xxd(VAR => @ARGV[0], BYTES => \$lines);
60
61 my $hash = md5_hex($lines);
62 @hash = ( $hash =~ m/../g );
63
64
65 xxd(VAR => @ARGV[0] . "_hash", BYTES => \$hash);