Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / makelib / uld
1 #!/usr/bin/python
2
3 # This module is covered by the GPL v2
4 # Copyright 2006 California Institute of Technology
5
6 """
7 This script provides an extended ld syntax that supports universal binaries
8
9 It supports an extended -arch [i386|ppc] option.
10 if there are two or more architectures it will run ld for each 
11 architecture (writing to a tempfile) and then glue the pieces together
12 with lipo.
13 """
14
15 import os
16 import sys
17 import tempfile
18
19 def ld(output_name, other_args, arch=None):
20   """Build an ld command line and run it
21   """
22   my_args = []
23   if not (arch is None or len(arch) == 0):
24     my_args.append("-arch")
25     my_args.append(arch)
26   
27   cmd = "/usr/bin/ld -o " + output_name + " " + " ".join(other_args+my_args)
28   print cmd
29   os.system(cmd)
30
31 def lipo(output_name, source_files):
32   """Take a list of source files and bind them into a universal object
33   """
34  
35   cmd ="/usr/bin/lipo -create -o " + output_name + " " + " ".join(source_files)
36   print cmd 
37   os.system(cmd)
38
39 def main(args):
40   other_args = []
41   platforms = []
42   output_name = "universal_object"
43   index = 0
44   while index < len(args):
45     if args[index] == "-arch":
46       index += 1
47       platforms.append(args[index])
48     elif args[index] == "-o":
49       index += 1
50       output_name = args[index] 
51     else:    
52       other_args.append(args[index])
53
54     index += 1
55
56   if len(platforms) > 1:
57     filenames = []
58     for arch in platforms:
59       filenames.append(tempfile.mktemp(prefix=output_name))
60       ld(filenames[-1], other_args, arch=arch)
61     lipo(output_name, filenames)
62     for f in filenames:
63       os.unlink(f)
64   else:
65     ld(output_name, other_args)
66
67
68 if __name__ == "__main__":
69   main(sys.argv[1:])