Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # This script will take a number ($ENV{SCRIPT_INPUT_FILE_COUNT}) of static archive files |
| 4 | # and pull them apart into object files. These object files will be placed in a directory |
| 5 | # named the same as the archive itself without the extension. Each object file will then |
| 6 | # get renamed to start with the archive name and a '-' character (for archive.a(object.o) |
| 7 | # the object file would becomde archive-object.o. Then all object files are re-made into |
| 8 | # a single static library. This can help avoid name collisions when different archive |
| 9 | # files might contain object files with the same name. |
| 10 | |
| 11 | use strict; |
| 12 | use File::Basename; |
| 13 | use File::Glob ':glob'; |
| 14 | use List::Util qw[min max]; |
| 15 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 16 | our $llvm_srcroot = $ENV{SCRIPT_INPUT_FILE_0}; |
| 17 | our $llvm_dstroot = $ENV{SCRIPT_INPUT_FILE_1}; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | |
Sean Callanan | 6c98ba7 | 2011-08-11 20:11:18 +0000 | [diff] [blame] | 19 | our $llvm_clang_outfile = $ENV{SCRIPT_OUTPUT_FILE_0}; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | our ($llvm_clang_basename, $llvm_clang_dirname) = fileparse ($llvm_clang_outfile); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | our $llvm_configuration = $ENV{LLVM_CONFIGURATION}; |
| 23 | |
Sean Callanan | 6e12c7a | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 24 | our $llvm_revision = "152265"; |
| 25 | our $clang_revision = "152265"; |
Sean Callanan | 047eea6 | 2011-08-18 18:18:33 +0000 | [diff] [blame] | 26 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 27 | our $SRCROOT = "$ENV{SRCROOT}"; |
| 28 | our $llvm_dstroot_zip = "$SRCROOT/llvm.zip"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | our @archs = split (/\s+/, $ENV{ARCHS}); |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 30 | my $os_release = 11; |
| 31 | |
Jason Molenda | daaa9d1 | 2012-04-02 08:56:42 +0000 | [diff] [blame] | 32 | my $original_env_path = $ENV{PATH}; |
| 33 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 34 | our %llvm_config_info = ( |
| 35 | 'Debug' => { configure_options => '--disable-optimized --disable-assertions', make_options => 'DEBUG_SYMBOLS=1'}, |
| 36 | 'Debug+Asserts' => { configure_options => '--disable-optimized --enable-assertions' , make_options => 'DEBUG_SYMBOLS=1'}, |
| 37 | 'Release' => { configure_options => '--enable-optimized --disable-assertions' , make_options => ''}, |
| 38 | 'Release+Debug' => { configure_options => '--enable-optimized --disable-assertions' , make_options => 'DEBUG_SYMBOLS=1'}, |
| 39 | ); |
| 40 | |
| 41 | our $llvm_config_href = undef; |
| 42 | if (exists $llvm_config_info{"$llvm_configuration"}) |
| 43 | { |
| 44 | $llvm_config_href = $llvm_config_info{$llvm_configuration}; |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | die "Unsupported LLVM configuration: '$llvm_configuration'\n"; |
| 49 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | |
| 51 | our @archive_files = ( |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 52 | "$llvm_configuration/lib/libclang.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | "$llvm_configuration/lib/libclangAnalysis.a", |
| 54 | "$llvm_configuration/lib/libclangAST.a", |
| 55 | "$llvm_configuration/lib/libclangBasic.a", |
| 56 | "$llvm_configuration/lib/libclangCodeGen.a", |
Sean Callanan | 6e12c7a | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 57 | "$llvm_configuration/lib/libclangEdit.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | "$llvm_configuration/lib/libclangFrontend.a", |
| 59 | "$llvm_configuration/lib/libclangDriver.a", |
| 60 | "$llvm_configuration/lib/libclangIndex.a", |
| 61 | "$llvm_configuration/lib/libclangLex.a", |
| 62 | "$llvm_configuration/lib/libclangRewrite.a", |
| 63 | "$llvm_configuration/lib/libclangParse.a", |
| 64 | "$llvm_configuration/lib/libclangSema.a", |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 65 | "$llvm_configuration/lib/libclangSerialization.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | "$llvm_configuration/lib/libEnhancedDisassembly.a", |
| 67 | "$llvm_configuration/lib/libLLVMAnalysis.a", |
| 68 | "$llvm_configuration/lib/libLLVMArchive.a", |
| 69 | "$llvm_configuration/lib/libLLVMARMAsmParser.a", |
| 70 | "$llvm_configuration/lib/libLLVMARMAsmPrinter.a", |
| 71 | "$llvm_configuration/lib/libLLVMARMCodeGen.a", |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 72 | "$llvm_configuration/lib/libLLVMARMDesc.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | "$llvm_configuration/lib/libLLVMARMDisassembler.a", |
| 74 | "$llvm_configuration/lib/libLLVMARMInfo.a", |
| 75 | "$llvm_configuration/lib/libLLVMAsmParser.a", |
| 76 | "$llvm_configuration/lib/libLLVMAsmPrinter.a", |
| 77 | "$llvm_configuration/lib/libLLVMBitReader.a", |
| 78 | "$llvm_configuration/lib/libLLVMBitWriter.a", |
| 79 | "$llvm_configuration/lib/libLLVMCodeGen.a", |
| 80 | "$llvm_configuration/lib/libLLVMCore.a", |
| 81 | "$llvm_configuration/lib/libLLVMExecutionEngine.a", |
| 82 | "$llvm_configuration/lib/libLLVMInstCombine.a", |
| 83 | "$llvm_configuration/lib/libLLVMInstrumentation.a", |
| 84 | "$llvm_configuration/lib/libLLVMipa.a", |
| 85 | "$llvm_configuration/lib/libLLVMInterpreter.a", |
| 86 | "$llvm_configuration/lib/libLLVMipo.a", |
| 87 | "$llvm_configuration/lib/libLLVMJIT.a", |
| 88 | "$llvm_configuration/lib/libLLVMLinker.a", |
| 89 | "$llvm_configuration/lib/libLLVMMC.a", |
| 90 | "$llvm_configuration/lib/libLLVMMCParser.a", |
Greg Clayton | c9b6000 | 2010-07-21 16:57:26 +0000 | [diff] [blame] | 91 | "$llvm_configuration/lib/libLLVMMCDisassembler.a", |
Sean Callanan | c049274 | 2011-05-23 21:40:23 +0000 | [diff] [blame] | 92 | "$llvm_configuration/lib/libLLVMMCJIT.a", |
| 93 | "$llvm_configuration/lib/libLLVMObject.a", |
| 94 | "$llvm_configuration/lib/libLLVMRuntimeDyld.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | "$llvm_configuration/lib/libLLVMScalarOpts.a", |
| 96 | "$llvm_configuration/lib/libLLVMSelectionDAG.a", |
| 97 | "$llvm_configuration/lib/libLLVMSupport.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | "$llvm_configuration/lib/libLLVMTarget.a", |
| 99 | "$llvm_configuration/lib/libLLVMTransformUtils.a", |
| 100 | "$llvm_configuration/lib/libLLVMX86AsmParser.a", |
| 101 | "$llvm_configuration/lib/libLLVMX86AsmPrinter.a", |
| 102 | "$llvm_configuration/lib/libLLVMX86CodeGen.a", |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 103 | "$llvm_configuration/lib/libLLVMX86Desc.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | "$llvm_configuration/lib/libLLVMX86Disassembler.a", |
| 105 | "$llvm_configuration/lib/libLLVMX86Info.a", |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 106 | "$llvm_configuration/lib/libLLVMX86Utils.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | ); |
| 108 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 109 | if (-e "$llvm_srcroot/lib") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | { |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 111 | print "Using existing llvm sources in: '$llvm_srcroot'\n"; |
| 112 | print "Using standard LLVM build directory:\n SRC = '$llvm_srcroot'\n DST = '$llvm_dstroot'\n"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 113 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 114 | elsif (-e $llvm_dstroot_zip) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | { |
| 116 | # Check for an old llvm source install (not the minimal zip based |
| 117 | # install by looking for a .svn file in the llvm directory |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 118 | chomp(my $llvm_zip_md5 = `md5 -q '$llvm_dstroot_zip'`); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | my $llvm_zip_md5_file = "$ENV{SRCROOT}/llvm/$llvm_zip_md5"; |
| 120 | if (!-e "$llvm_zip_md5_file") |
| 121 | { |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 122 | print "Updating LLVM to use checkpoint from: '$llvm_dstroot_zip'...\n"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | if (-d "$ENV{SRCROOT}/llvm") |
| 124 | { |
| 125 | do_command ("cd '$ENV{SRCROOT}' && rm -rf llvm", "removing old llvm repository", 1); |
| 126 | } |
| 127 | do_command ("cd '$ENV{SRCROOT}' && unzip -q llvm.zip && touch '$llvm_zip_md5_file'", "expanding llvm.zip", 1); |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 128 | |
| 129 | } |
| 130 | my $arch_idx = 0; |
Sean Callanan | 7537dce | 2011-11-04 22:46:46 +0000 | [diff] [blame] | 131 | |
| 132 | if (!-d "${llvm_dstroot}") |
| 133 | { |
| 134 | do_command ("mkdir -p '${llvm_dstroot}'", "Creating directory '${llvm_dstroot}'", 1); |
| 135 | } |
| 136 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 137 | foreach my $arch (@archs) |
| 138 | { |
| 139 | my $llvm_dstroot_arch = "${llvm_dstroot}/${arch}"; |
| 140 | # Check for our symlink to our .a file |
| 141 | if (!-l "$llvm_dstroot_arch/$llvm_clang_basename") |
| 142 | { |
| 143 | # Symlink doesn't exist, make sure it isn't a normal file |
| 144 | if (-e "$llvm_dstroot_arch/$llvm_clang_basename") |
| 145 | { |
| 146 | # the .a file is a normal file which means it can't be from the |
| 147 | # zip file, we must remove the previous arch directory |
| 148 | do_command ("rm -rf '$llvm_dstroot_arch'", "Removing old '$llvm_dstroot_arch' directory", 1); |
Sean Callanan | 7537dce | 2011-11-04 22:46:46 +0000 | [diff] [blame] | 149 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 150 | # Create a symlink to the .a file from the zip file |
Sean Callanan | 7537dce | 2011-11-04 22:46:46 +0000 | [diff] [blame] | 151 | do_command ("cd '$llvm_dstroot' ; ln -s $ENV{SRCROOT}/llvm/$arch", "making llvm archive symlink", 1); |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 152 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | exit 0; |
| 155 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 156 | else |
| 157 | { |
| 158 | print "Checking out llvm sources from revision $llvm_revision...\n"; |
| 159 | do_command ("cd '$SRCROOT' && svn co --quiet --revision $llvm_revision http://llvm.org/svn/llvm-project/llvm/trunk llvm", "checking out llvm from repository", 1); |
| 160 | print "Checking out clang sources from revision $clang_revision...\n"; |
| 161 | do_command ("cd '$llvm_srcroot/tools' && svn co --quiet --revision $clang_revision http://llvm.org/svn/llvm-project/cfe/trunk clang", "checking out clang from repository", 1); |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 162 | print "Applying any local patches to LLVM/Clang..."; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 163 | |
| 164 | my @llvm_patches = bsd_glob("$ENV{SRCROOT}/scripts/llvm.*.diff"); |
| 165 | |
| 166 | foreach my $patch (@llvm_patches) |
| 167 | { |
| 168 | do_command ("cd '$llvm_srcroot' && patch -p0 < $patch"); |
| 169 | } |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 170 | |
| 171 | my @clang_patches = bsd_glob("$ENV{SRCROOT}/scripts/clang.*.diff"); |
| 172 | |
| 173 | foreach my $patch (@clang_patches) |
| 174 | { |
| 175 | do_command ("cd '$llvm_srcroot/tools/clang' && patch -p0 < $patch"); |
| 176 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 177 | |
| 178 | print "Removing the llvm/test and llvm/tools/clang/test directories...\n"; |
| 179 | do_command ("cd '$llvm_srcroot' && rm -rf test && rm -rf tools/clang/test ", "removing test directories", 1); |
| 180 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 181 | |
| 182 | # If our output file already exists then we need not generate it again. |
Greg Clayton | 6487558 | 2011-08-02 19:00:17 +0000 | [diff] [blame] | 183 | if (-e $llvm_clang_outfile) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | { |
| 185 | exit 0; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | # Get our options |
| 190 | |
| 191 | our $debug = 1; |
| 192 | |
| 193 | sub parallel_guess |
| 194 | { |
| 195 | my $cpus = `sysctl -n hw.availcpu`; |
| 196 | chomp ($cpus); |
| 197 | my $memsize = `sysctl -n hw.memsize`; |
| 198 | chomp ($memsize); |
| 199 | my $max_cpus_by_memory = int($memsize / (750 * 1024 * 1024)); |
| 200 | return min($max_cpus_by_memory, $cpus); |
| 201 | } |
| 202 | sub build_llvm |
| 203 | { |
| 204 | #my $extra_svn_options = $debug ? "" : "--quiet"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | # Make the llvm build directory |
| 206 | my $arch_idx = 0; |
| 207 | foreach my $arch (@archs) |
| 208 | { |
| 209 | my $llvm_dstroot_arch = "${llvm_dstroot}/${arch}"; |
| 210 | |
| 211 | # if the arch destination root exists we have already built it |
| 212 | my $do_configure = 0; |
| 213 | my $do_make = 0; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 214 | my $is_arm = $arch =~ /^arm/; |
| 215 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | my $llvm_dstroot_arch_archive = "$llvm_dstroot_arch/$llvm_clang_basename"; |
| 217 | print "LLVM architecture root for ${arch} exists at '$llvm_dstroot_arch'..."; |
| 218 | if (-e $llvm_dstroot_arch) |
| 219 | { |
| 220 | print "YES\n"; |
| 221 | $do_configure = !-e "$llvm_dstroot_arch/config.log"; |
| 222 | |
| 223 | # dstroot for llvm build exists, make sure all .a files are built |
| 224 | for my $llvm_lib (@archive_files) |
| 225 | { |
| 226 | if (!-e "$llvm_dstroot_arch/$llvm_lib") |
| 227 | { |
| 228 | print "missing archive: '$llvm_dstroot_arch/$llvm_lib'\n"; |
| 229 | $do_make = 1; |
| 230 | } |
| 231 | } |
| 232 | if (!-e $llvm_dstroot_arch_archive) |
| 233 | { |
| 234 | $do_make = 1; |
Greg Clayton | c9b6000 | 2010-07-21 16:57:26 +0000 | [diff] [blame] | 235 | } |
| 236 | else |
| 237 | { |
| 238 | print "LLVM architecture archive for ${arch} is '$llvm_dstroot_arch_archive'\n"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | print "NO\n"; |
| 244 | do_command ("mkdir -p '$llvm_dstroot_arch'", "making llvm build directory '$llvm_dstroot_arch'", 1); |
| 245 | $do_configure = 1; |
| 246 | $do_make = 1; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 247 | |
| 248 | if ($is_arm) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | { |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 250 | my $llvm_dstroot_arch_bin = "${llvm_dstroot_arch}/bin"; |
| 251 | |
| 252 | if (!-d $llvm_dstroot_arch_bin) |
| 253 | { |
| 254 | do_command ("mkdir -p '$llvm_dstroot_arch_bin'", "making llvm build arch bin directory '$llvm_dstroot_arch_bin'", 1); |
| 255 | my @tools = ("ar", "nm", "ranlib", "strip", "lipo", "ld", "as"); |
| 256 | my $script_mode = 0755; |
| 257 | my $prog; |
| 258 | for $prog (@tools) |
| 259 | { |
| 260 | chomp(my $actual_prog_path = `xcrun -sdk '$ENV{SDKROOT}' -find ${prog}`); |
| 261 | my $script_prog_path = "$llvm_dstroot_arch_bin/arm-apple-darwin${os_release}-${prog}"; |
| 262 | open (SCRIPT, ">$script_prog_path") or die "Can't open $! for writing...\n"; |
| 263 | print SCRIPT "#!/bin/sh\nexec '$actual_prog_path' \"\$\@\"\n"; |
| 264 | close (SCRIPT); |
| 265 | chmod($script_mode, $script_prog_path); |
| 266 | } |
| 267 | # Tools that must have the "-arch" and "-sysroot" specified |
| 268 | my @arch_sysroot_tools = ("clang", "clang++", "gcc", "g++"); |
| 269 | for $prog (@arch_sysroot_tools) |
| 270 | { |
| 271 | chomp(my $actual_prog_path = `xcrun -sdk '$ENV{SDKROOT}' -find ${prog}`); |
| 272 | my $script_prog_path = "$llvm_dstroot_arch_bin/arm-apple-darwin${os_release}-${prog}"; |
| 273 | open (SCRIPT, ">$script_prog_path") or die "Can't open $! for writing...\n"; |
| 274 | print SCRIPT "#!/bin/sh\nexec '$actual_prog_path' -arch ${arch} -isysroot '$ENV{SDKROOT}' \"\$\@\"\n"; |
| 275 | close (SCRIPT); |
| 276 | chmod($script_mode, $script_prog_path); |
| 277 | } |
Jason Molenda | daaa9d1 | 2012-04-02 08:56:42 +0000 | [diff] [blame] | 278 | my $new_path = "$original_env_path:$llvm_dstroot_arch_bin"; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 279 | print "Setting new environment PATH = '$new_path'\n"; |
| 280 | $ENV{PATH} = $new_path; |
| 281 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 284 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | if ($do_configure) |
| 286 | { |
| 287 | # Build llvm and clang |
| 288 | print "Configuring clang ($arch) in '$llvm_dstroot_arch'...\n"; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 289 | my $lldb_configuration_options = "--enable-targets=x86_64,arm $llvm_config_href->{configure_options}"; |
| 290 | |
| 291 | if ($is_arm) |
| 292 | { |
| 293 | $lldb_configuration_options .= " --host=arm-apple-darwin${os_release} --target=arm-apple-darwin${os_release} --build=i686-apple-darwin${os_release}"; |
| 294 | } |
| 295 | else |
| 296 | { |
| 297 | $lldb_configuration_options .= " --build=$arch-apple-darwin${os_release}"; |
| 298 | } |
| 299 | do_command ("cd '$llvm_dstroot_arch' && '$llvm_srcroot/configure' $lldb_configuration_options", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 300 | "configuring llvm build", 1); |
| 301 | } |
| 302 | |
| 303 | if ($do_make) |
| 304 | { |
| 305 | # Build llvm and clang |
| 306 | my $num_cpus = parallel_guess(); |
| 307 | print "Building clang using $num_cpus cpus ($arch)...\n"; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 308 | my $extra_make_flags = ''; |
| 309 | if ($is_arm) |
| 310 | { |
| 311 | $extra_make_flags = "UNIVERSAL=1 UNIVERSAL_ARCH=${arch} UNIVERSAL_SDK_PATH='$ENV{SDKROOT}'"; |
| 312 | } |
| 313 | do_command ("cd '$llvm_dstroot_arch' && make -j$num_cpus clang-only VERBOSE=1 $llvm_config_href->{make_options} NO_RUNTIME_LIBS=1 PROJECT_NAME='llvm' $extra_make_flags", "making llvm and clang", 1); |
| 314 | do_command ("cd '$llvm_dstroot_arch' && make -j$num_cpus tools-only VERBOSE=1 $llvm_config_href->{make_options} NO_RUNTIME_LIBS=1 PROJECT_NAME='llvm' $extra_make_flags EDIS_VERSION=1", "making libedis", 1); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 315 | # Combine all .o files from a bunch of static libraries from llvm |
| 316 | # and clang into a single .a file. |
| 317 | create_single_llvm_arhive_for_arch ($llvm_dstroot_arch, 1); |
| 318 | } |
| 319 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 320 | ++$arch_idx; |
| 321 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | #---------------------------------------------------------------------- |
| 325 | # quote the path if needed and realpath it if the -r option was |
| 326 | # specified |
| 327 | #---------------------------------------------------------------------- |
| 328 | sub finalize_path |
| 329 | { |
| 330 | my $path = shift; |
| 331 | # Realpath all paths that don't start with "/" |
| 332 | $path =~ /^[^\/]/ and $path = abs_path($path); |
| 333 | |
| 334 | # Quote the path if asked to, or if there are special shell characters |
| 335 | # in the path name |
| 336 | my $has_double_quotes = $path =~ /["]/; |
| 337 | my $has_single_quotes = $path =~ /[']/; |
| 338 | my $needs_quotes = $path =~ /[ \$\&\*'"]/; |
| 339 | if ($needs_quotes) |
| 340 | { |
| 341 | # escape and double quotes in the path |
| 342 | $has_double_quotes and $path =~ s/"/\\"/g; |
| 343 | $path = "\"$path\""; |
| 344 | } |
| 345 | return $path; |
| 346 | } |
| 347 | |
| 348 | sub do_command |
| 349 | { |
| 350 | my $cmd = shift; |
| 351 | my $description = @_ ? shift : "command"; |
| 352 | my $die_on_fail = @_ ? shift : undef; |
| 353 | $debug and print "% $cmd\n"; |
| 354 | system ($cmd); |
| 355 | if ($? == -1) |
| 356 | { |
| 357 | $debug and printf ("error: %s failed to execute: $!\n", $description); |
| 358 | $die_on_fail and $? and exit(1); |
| 359 | return $?; |
| 360 | } |
| 361 | elsif ($? & 127) |
| 362 | { |
| 363 | $debug and printf("error: %s child died with signal %d, %s coredump\n", |
| 364 | $description, |
| 365 | ($? & 127), |
| 366 | ($? & 128) ? 'with' : 'without'); |
| 367 | $die_on_fail and $? and exit(1); |
| 368 | return $?; |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | my $exit = $? >> 8; |
| 373 | if ($exit) |
| 374 | { |
| 375 | $debug and printf("error: %s child exited with value %d\n", $description, $exit); |
| 376 | $die_on_fail and exit(1); |
| 377 | } |
| 378 | return $exit; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | sub create_single_llvm_arhive_for_arch |
| 383 | { |
| 384 | my $arch_dstroot = shift; |
| 385 | my $split_into_objects = shift; |
| 386 | my @object_dirs; |
| 387 | my $object_dir; |
| 388 | my $tmp_dir = $arch_dstroot; |
| 389 | my $arch_output_file = "$arch_dstroot/$llvm_clang_basename"; |
| 390 | -e $arch_output_file and return; |
| 391 | my $files = "$arch_dstroot/files.txt"; |
| 392 | open (FILES, ">$files") or die "Can't open $! for writing...\n"; |
| 393 | |
| 394 | for my $path (@archive_files) |
| 395 | { |
| 396 | my $archive_fullpath = finalize_path ("$arch_dstroot/$path"); |
| 397 | if (-e $archive_fullpath) |
| 398 | { |
| 399 | if ($split_into_objects) |
| 400 | { |
| 401 | my ($archive_file, $archive_dir, $archive_ext) = fileparse($archive_fullpath, ('.a')); |
| 402 | |
| 403 | $object_dir = "$tmp_dir/$archive_file"; |
| 404 | push @object_dirs, $object_dir; |
| 405 | |
| 406 | do_command ("cd '$tmp_dir'; mkdir '$archive_file'; cd '$archive_file'; ar -x $archive_fullpath"); |
| 407 | |
| 408 | my @objects = bsd_glob("$object_dir/*.o"); |
| 409 | |
| 410 | foreach my $object (@objects) |
| 411 | { |
| 412 | my ($o_file, $o_dir) = fileparse($object); |
| 413 | my $new_object = "$object_dir/${archive_file}-$o_file"; |
| 414 | print FILES "$new_object\n"; |
| 415 | do_command ("mv '$object' '$new_object'"); |
| 416 | } |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | # just add the .a files into the file list |
| 421 | print FILES "$archive_fullpath\n"; |
| 422 | } |
| 423 | } |
Greg Clayton | 193e6d5 | 2010-07-13 22:26:45 +0000 | [diff] [blame] | 424 | else |
| 425 | { |
| 426 | print "warning: archive doesn't exist: '$archive_fullpath'\n"; |
| 427 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | } |
| 429 | close (FILES); |
| 430 | do_command ("libtool -static -o '$arch_output_file' -filelist '$files'"); |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 431 | do_command ("ranlib '$arch_output_file'"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 432 | |
| 433 | foreach $object_dir (@object_dirs) |
| 434 | { |
| 435 | do_command ("rm -rf '$object_dir'"); |
| 436 | } |
| 437 | do_command ("rm -rf '$files'"); |
| 438 | } |
| 439 | |
| 440 | build_llvm(); |