3 # This module is covered by the GPL v2
4 # Copyright 2006 California Institute of Technology
7 This script provides an extended ld syntax that supports universal binaries
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
19 def ld(output_name, other_args, arch=None):
20 """Build an ld command line and run it
23 if not (arch is None or len(arch) == 0):
24 my_args.append("-arch")
27 cmd = "/usr/bin/ld -o " + output_name + " " + " ".join(other_args+my_args)
31 def lipo(output_name, source_files):
32 """Take a list of source files and bind them into a universal object
35 cmd ="/usr/bin/lipo -create -o " + output_name + " " + " ".join(source_files)
42 output_name = "universal_object"
44 while index < len(args):
45 if args[index] == "-arch":
47 platforms.append(args[index])
48 elif args[index] == "-o":
50 output_name = args[index]
52 other_args.append(args[index])
56 if len(platforms) > 1:
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)
65 ld(output_name, other_args)
68 if __name__ == "__main__":