Release 0.2
[make-headers.git] / make-headers.py
blobccaec4497e076f399cc46adb77c129fe906ab040
1 #!/usr/bin/env python
2 import os, shutil, re, sys
3 from optparse import OptionParser
5 version = '0.1'
6 parser = OptionParser(usage="usage: %prog [options]")
7 parser.add_option("-k", "--keep", help="keep a file we would normally delete", action='append')
8 parser.add_option("-V", "--version", help="display version information", action='store_true')
9 (options, args) = parser.parse_args()
11 if options.version:
12 print "Make-headers (zero-install) " + version
13 print "Copyright (C) 2007 Thomas Leonard"
14 print "This program comes with ABSOLUTELY NO WARRANTY,"
15 print "to the extent permitted by law."
16 print "You may redistribute copies of this program"
17 print "under the terms of the GNU General Public License."
18 print "For more information about these matters, see the file named COPYING."
19 sys.exit(0)
21 configure = os.path.join(os.environ['SRCDIR'], 'configure')
22 prefix = os.environ['DISTDIR']
24 def run(*argv):
25 if os.spawnvp(os.P_WAIT, argv[0], argv):
26 raise Exception("Command '%s' failed" % repr(argv))
28 run(configure, '--prefix', prefix)
29 run('make', 'install')
31 keep = options.keep or []
33 os.chdir(prefix)
34 for path in ['bin', 'man', 'share']:
35 if path not in keep and os.path.isdir(path):
36 shutil.rmtree(path)
38 os.chdir('lib')
39 for x in os.listdir('.'):
40 if os.path.isfile(x) or os.path.islink(x):
41 if re.match('^lib.*\.so[.0-9]*$', x) or \
42 re.match('^lib.*\.l?a$', x):
43 os.unlink(x)
44 elif os.path.isdir(x):
45 if re.match('^python.*$', x):
46 shutil.rmtree(x)
48 os.chdir('pkgconfig')
49 for pc in os.listdir('.'):
50 if pc.endswith('.pc'):
51 data = file(pc).read().split('\n')
52 for i in range(len(data)):
53 if data[i].startswith('prefix='):
54 data[i] = 'prefix=${pcfiledir}/../..'
55 out = file(pc, 'w')
56 out.write('\n'.join(data))
57 out.close()