Build the kernel-firmware package (LP #1339172)
[packages/centos6/kernel.git] / kabitool
1 #!/usr/bin/python
2 #
3 # kabitool - Red Hat kABI extraction tool (version 2)
4 #
5 # We use this script to generate RPM dependencies based on symversions.
6 #
7 # Author: Jon Masters <jcm@redhat.com>
8 # Copyright (C) 2009 Red Hat, Inc.
9 #
10 # This software may be freely redistributed under the terms of the GNU
11 # General Public License (GPL).
12
13 # Changelog:
14
15 # 2009/08/01 - New version based on kABI dep plan for RHEL6.
16 #
17
18 __author__ = "Jon Masters <jcm@redhat.com>"
19 __version__ = "$Revisions: 2.0 $"
20 __date__ = "$Date: 2009/08/01 18:21:15 $"
21 __copyright__ = "Copyright (C) 2009 Red Hat, Inc"
22 __license__ = "GPL"
23
24 import getopt
25 import os
26 import re
27 import sha
28 import string
29 import sys
30
31 true = 1
32 false = 0
33
34 def load_symbols(filename):
35         """Load the kernel exported symbols from Module.symvers."""
36
37         ksyms = open(filename,"r")
38
39         symbols={}
40
41         while true:
42                 line = ksyms.readline()
43                 if line == "":
44                         break;
45                 if line == "\n":
46                         continue
47                 checksum,symbol,path,license = string.split(line)
48
49                 symbols[symbol] = dict(checksum=checksum,
50                                        path=path,
51                                        license=license)
52
53         return symbols
54
55 def output_deps(depsfile,symbols):
56
57         deps_file = open(depsfile,"w")
58
59         for symbol in sorted(symbols.keys()):
60                 deps_file.write("kernel("+symbol+") = " +
61                                 symbols[symbol]['checksum'] + "\n")
62
63 def usage():
64         print """
65 kabitool: process Module.symvers into useful exported kABI dependencies
66
67         kabitool [-k kernel] [-s symbols ]
68
69         -o              The file to output sorted dependencies to
70
71         -s              The Module.symvers file to import from
72
73 """
74
75 if __name__ == "__main__":
76
77         symdeps_file = ""
78         symvers_file = ""
79
80         opts, args = getopt.getopt(sys.argv[1:], 'ho:s:')
81
82         for o, v in opts:
83                 if o == "-h":
84                         usage()
85                         sys.exit(0)
86                 if o == "-o":
87                         symdeps_file = v
88                 if o == "-s":
89                         symvers_file = v
90         
91         if (symdeps_file == ""):
92                 symdeps_file = "Module.symdeps"
93
94         if (symvers_file == ""):
95                 symvers_file = "Module.symvers"
96
97         if not (os.path.isfile(symvers_file)):
98                 print "cannot read Module.symvers file"
99                 usage()
100                 exit(1)
101
102         symbols = load_symbols(symvers_file)
103         output_deps(symdeps_file, symbols)