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 | 06dc17f | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 24 | our $llvm_revision = "HEAD"; |
| 25 | our $clang_revision = "HEAD"; |
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}"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | our @archs = split (/\s+/, $ENV{ARCHS}); |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 29 | my $os_release = 11; |
| 30 | |
Jason Molenda | daaa9d1 | 2012-04-02 08:56:42 +0000 | [diff] [blame] | 31 | my $original_env_path = $ENV{PATH}; |
| 32 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 33 | our %llvm_config_info = ( |
Bob Wilson | bec2ac8 | 2013-01-11 19:24:51 +0000 | [diff] [blame] | 34 | 'Debug' => { configure_options => '--disable-optimized --disable-assertions --enable-libcpp', make_options => 'DEBUG_SYMBOLS=1'}, |
| 35 | 'Debug+Asserts' => { configure_options => '--disable-optimized --enable-assertions --enable-libcpp' , make_options => 'DEBUG_SYMBOLS=1'}, |
| 36 | 'Release' => { configure_options => '--enable-optimized --disable-assertions --enable-libcpp' , make_options => ''}, |
| 37 | 'Release+Debug' => { configure_options => '--enable-optimized --disable-assertions --enable-libcpp' , make_options => 'DEBUG_SYMBOLS=1'}, |
| 38 | 'Release+Asserts' => { configure_options => '--enable-optimized --enable-assertions --enable-libcpp' , make_options => ''}, |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 39 | ); |
| 40 | |
| 41 | our $llvm_config_href = undef; |
| 42 | if (exists $llvm_config_info{"$llvm_configuration"}) |
| 43 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 44 | $llvm_config_href = $llvm_config_info{$llvm_configuration}; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 45 | } |
| 46 | else |
| 47 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 48 | die "Unsupported LLVM configuration: '$llvm_configuration'\n"; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 49 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 51 | our @archive_files = ( |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 52 | "$llvm_configuration/lib/libclang.a", |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +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", |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 58 | "$llvm_configuration/lib/libclangFrontend.a", |
| 59 | "$llvm_configuration/lib/libclangDriver.a", |
| 60 | "$llvm_configuration/lib/libclangLex.a", |
| 61 | "$llvm_configuration/lib/libclangParse.a", |
| 62 | "$llvm_configuration/lib/libclangSema.a", |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 63 | "$llvm_configuration/lib/libclangSerialization.a", |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 64 | "$llvm_configuration/lib/libLLVMAnalysis.a", |
| 65 | "$llvm_configuration/lib/libLLVMArchive.a", |
| 66 | "$llvm_configuration/lib/libLLVMARMAsmParser.a", |
| 67 | "$llvm_configuration/lib/libLLVMARMAsmPrinter.a", |
| 68 | "$llvm_configuration/lib/libLLVMARMCodeGen.a", |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 69 | "$llvm_configuration/lib/libLLVMARMDesc.a", |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 70 | "$llvm_configuration/lib/libLLVMARMDisassembler.a", |
| 71 | "$llvm_configuration/lib/libLLVMARMInfo.a", |
| 72 | "$llvm_configuration/lib/libLLVMAsmParser.a", |
| 73 | "$llvm_configuration/lib/libLLVMAsmPrinter.a", |
| 74 | "$llvm_configuration/lib/libLLVMBitReader.a", |
| 75 | "$llvm_configuration/lib/libLLVMBitWriter.a", |
| 76 | "$llvm_configuration/lib/libLLVMCodeGen.a", |
| 77 | "$llvm_configuration/lib/libLLVMCore.a", |
| 78 | "$llvm_configuration/lib/libLLVMExecutionEngine.a", |
| 79 | "$llvm_configuration/lib/libLLVMInstCombine.a", |
| 80 | "$llvm_configuration/lib/libLLVMInstrumentation.a", |
| 81 | "$llvm_configuration/lib/libLLVMipa.a", |
| 82 | "$llvm_configuration/lib/libLLVMInterpreter.a", |
| 83 | "$llvm_configuration/lib/libLLVMipo.a", |
| 84 | "$llvm_configuration/lib/libLLVMJIT.a", |
| 85 | "$llvm_configuration/lib/libLLVMLinker.a", |
| 86 | "$llvm_configuration/lib/libLLVMMC.a", |
| 87 | "$llvm_configuration/lib/libLLVMMCParser.a", |
| 88 | "$llvm_configuration/lib/libLLVMMCDisassembler.a", |
Sean Callanan | c049274 | 2011-05-23 21:40:23 +0000 | [diff] [blame] | 89 | "$llvm_configuration/lib/libLLVMMCJIT.a", |
| 90 | "$llvm_configuration/lib/libLLVMObject.a", |
| 91 | "$llvm_configuration/lib/libLLVMRuntimeDyld.a", |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 92 | "$llvm_configuration/lib/libLLVMScalarOpts.a", |
| 93 | "$llvm_configuration/lib/libLLVMSelectionDAG.a", |
| 94 | "$llvm_configuration/lib/libLLVMSupport.a", |
| 95 | "$llvm_configuration/lib/libLLVMTarget.a", |
| 96 | "$llvm_configuration/lib/libLLVMTransformUtils.a", |
| 97 | "$llvm_configuration/lib/libLLVMX86AsmParser.a", |
| 98 | "$llvm_configuration/lib/libLLVMX86AsmPrinter.a", |
| 99 | "$llvm_configuration/lib/libLLVMX86CodeGen.a", |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 100 | "$llvm_configuration/lib/libLLVMX86Desc.a", |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 101 | "$llvm_configuration/lib/libLLVMX86Disassembler.a", |
| 102 | "$llvm_configuration/lib/libLLVMX86Info.a", |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 103 | "$llvm_configuration/lib/libLLVMX86Utils.a", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | ); |
| 105 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 106 | if (-e "$llvm_srcroot/lib") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | { |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 108 | print "Using existing llvm sources in: '$llvm_srcroot'\n"; |
| 109 | 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] | 110 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 111 | else |
| 112 | { |
| 113 | print "Checking out llvm sources from revision $llvm_revision...\n"; |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 114 | 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); |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 115 | print "Checking out clang sources from revision $clang_revision...\n"; |
| 116 | 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] | 117 | print "Applying any local patches to LLVM/Clang..."; |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 118 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 119 | my @llvm_patches = bsd_glob("$ENV{SRCROOT}/scripts/llvm.*.diff"); |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 120 | foreach my $patch (@llvm_patches) |
| 121 | { |
| 122 | do_command ("cd '$llvm_srcroot' && patch -p0 < $patch"); |
| 123 | } |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 124 | |
| 125 | my @clang_patches = bsd_glob("$ENV{SRCROOT}/scripts/clang.*.diff"); |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 126 | foreach my $patch (@clang_patches) |
| 127 | { |
| 128 | do_command ("cd '$llvm_srcroot/tools/clang' && patch -p0 < $patch"); |
| 129 | } |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 130 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | |
| 132 | # 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] | 133 | if (-e $llvm_clang_outfile) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 135 | exit 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | |
| 139 | # Get our options |
| 140 | |
| 141 | our $debug = 1; |
| 142 | |
| 143 | sub parallel_guess |
| 144 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 145 | my $cpus = `sysctl -n hw.availcpu`; |
| 146 | chomp ($cpus); |
| 147 | my $memsize = `sysctl -n hw.memsize`; |
| 148 | chomp ($memsize); |
| 149 | my $max_cpus_by_memory = int($memsize / (750 * 1024 * 1024)); |
| 150 | return min($max_cpus_by_memory, $cpus); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | } |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 152 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | sub build_llvm |
| 154 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 155 | #my $extra_svn_options = $debug ? "" : "--quiet"; |
| 156 | # Make the llvm build directory |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | my $arch_idx = 0; |
| 158 | foreach my $arch (@archs) |
| 159 | { |
| 160 | my $llvm_dstroot_arch = "${llvm_dstroot}/${arch}"; |
| 161 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 162 | # if the arch destination root exists we have already built it |
| 163 | my $do_configure = 0; |
| 164 | my $do_make = 0; |
| 165 | my $is_arm = $arch =~ /^arm/; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 166 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 167 | my $llvm_dstroot_arch_archive = "$llvm_dstroot_arch/$llvm_clang_basename"; |
| 168 | print "LLVM architecture root for ${arch} exists at '$llvm_dstroot_arch'..."; |
| 169 | if (-e $llvm_dstroot_arch) |
| 170 | { |
| 171 | print "YES\n"; |
| 172 | $do_configure = !-e "$llvm_dstroot_arch/config.log"; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 173 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 174 | # dstroot for llvm build exists, make sure all .a files are built |
| 175 | for my $llvm_lib (@archive_files) |
| 176 | { |
| 177 | if (!-e "$llvm_dstroot_arch/$llvm_lib") |
| 178 | { |
| 179 | print "missing archive: '$llvm_dstroot_arch/$llvm_lib'\n"; |
| 180 | $do_make = 1; |
| 181 | } |
| 182 | } |
| 183 | if (!-e $llvm_dstroot_arch_archive) |
| 184 | { |
| 185 | $do_make = 1; |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | print "LLVM architecture archive for ${arch} is '$llvm_dstroot_arch_archive'\n"; |
| 190 | } |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | print "NO\n"; |
| 195 | do_command ("mkdir -p '$llvm_dstroot_arch'", "making llvm build directory '$llvm_dstroot_arch'", 1); |
| 196 | $do_configure = 1; |
| 197 | $do_make = 1; |
| 198 | |
| 199 | if ($is_arm) |
| 200 | { |
| 201 | my $llvm_dstroot_arch_bin = "${llvm_dstroot_arch}/bin"; |
| 202 | if (!-d $llvm_dstroot_arch_bin) |
| 203 | { |
| 204 | do_command ("mkdir -p '$llvm_dstroot_arch_bin'", "making llvm build arch bin directory '$llvm_dstroot_arch_bin'", 1); |
| 205 | my @tools = ("ar", "nm", "ranlib", "strip", "lipo", "ld", "as"); |
| 206 | my $script_mode = 0755; |
| 207 | my $prog; |
| 208 | for $prog (@tools) |
| 209 | { |
| 210 | chomp(my $actual_prog_path = `xcrun -sdk '$ENV{SDKROOT}' -find ${prog}`); |
Bob Wilson | 9b21d73 | 2013-01-12 19:33:08 +0000 | [diff] [blame] | 211 | symlink($actual_prog_path, "$llvm_dstroot_arch_bin/${prog}"); |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 212 | my $script_prog_path = "$llvm_dstroot_arch_bin/arm-apple-darwin${os_release}-${prog}"; |
| 213 | open (SCRIPT, ">$script_prog_path") or die "Can't open $! for writing...\n"; |
| 214 | print SCRIPT "#!/bin/sh\nexec '$actual_prog_path' \"\$\@\"\n"; |
| 215 | close (SCRIPT); |
| 216 | chmod($script_mode, $script_prog_path); |
| 217 | } |
| 218 | # Tools that must have the "-arch" and "-sysroot" specified |
| 219 | my @arch_sysroot_tools = ("clang", "clang++", "gcc", "g++"); |
| 220 | for $prog (@arch_sysroot_tools) |
| 221 | { |
| 222 | chomp(my $actual_prog_path = `xcrun -sdk '$ENV{SDKROOT}' -find ${prog}`); |
Bob Wilson | 9b21d73 | 2013-01-12 19:33:08 +0000 | [diff] [blame] | 223 | symlink($actual_prog_path, "$llvm_dstroot_arch_bin/${prog}"); |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 224 | my $script_prog_path = "$llvm_dstroot_arch_bin/arm-apple-darwin${os_release}-${prog}"; |
| 225 | open (SCRIPT, ">$script_prog_path") or die "Can't open $! for writing...\n"; |
| 226 | print SCRIPT "#!/bin/sh\nexec '$actual_prog_path' -arch ${arch} -isysroot '$ENV{SDKROOT}' \"\$\@\"\n"; |
| 227 | close (SCRIPT); |
| 228 | chmod($script_mode, $script_prog_path); |
| 229 | } |
| 230 | my $new_path = "$original_env_path:$llvm_dstroot_arch_bin"; |
| 231 | print "Setting new environment PATH = '$new_path'\n"; |
| 232 | $ENV{PATH} = $new_path; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if ($do_configure) |
| 238 | { |
| 239 | # Build llvm and clang |
| 240 | print "Configuring clang ($arch) in '$llvm_dstroot_arch'...\n"; |
| 241 | my $lldb_configuration_options = "--enable-targets=x86_64,arm $llvm_config_href->{configure_options}"; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 242 | |
| 243 | if ($is_arm) |
| 244 | { |
Bob Wilson | 9b21d73 | 2013-01-12 19:33:08 +0000 | [diff] [blame] | 245 | $lldb_configuration_options .= " --host=arm-apple-darwin${os_release} --target=arm-apple-darwin${os_release} --build=i686-apple-darwin${os_release} --program-prefix=\"\""; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 246 | } |
| 247 | else |
| 248 | { |
| 249 | $lldb_configuration_options .= " --build=$arch-apple-darwin${os_release}"; |
| 250 | } |
Greg Clayton | ee33e96 | 2013-01-16 01:27:32 +0000 | [diff] [blame^] | 251 | if ($is_arm) |
| 252 | { |
| 253 | # Unset "SDKROOT" for ARM builds |
| 254 | do_command ("cd '$llvm_dstroot_arch' && unset SDKROOT && '$llvm_srcroot/configure' $lldb_configuration_options", |
| 255 | "configuring llvm build", 1); |
| 256 | } |
| 257 | else |
| 258 | { |
| 259 | do_command ("cd '$llvm_dstroot_arch' && '$llvm_srcroot/configure' $lldb_configuration_options", |
| 260 | "configuring llvm build", 1); |
| 261 | } |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 262 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 264 | if ($do_make) |
| 265 | { |
| 266 | # Build llvm and clang |
| 267 | my $num_cpus = parallel_guess(); |
| 268 | print "Building clang using $num_cpus cpus ($arch)...\n"; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 269 | my $extra_make_flags = ''; |
| 270 | if ($is_arm) |
| 271 | { |
Greg Clayton | ee33e96 | 2013-01-16 01:27:32 +0000 | [diff] [blame^] | 272 | $extra_make_flags = "UNIVERSAL=1 UNIVERSAL_ARCH=${arch} UNIVERSAL_SDK_PATH='$ENV{SDKROOT}' SDKROOT="; |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 273 | } |
Greg Clayton | ee33e96 | 2013-01-16 01:27:32 +0000 | [diff] [blame^] | 274 | 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); |
| 275 | 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); |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 276 | # Combine all .o files from a bunch of static libraries from llvm |
| 277 | # and clang into a single .a file. |
Bob Wilson | bec2ac8 | 2013-01-11 19:24:51 +0000 | [diff] [blame] | 278 | create_single_llvm_archive_for_arch ($llvm_dstroot_arch, 1); |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 279 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 281 | ++$arch_idx; |
| 282 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | #---------------------------------------------------------------------- |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 286 | # quote the path if needed and realpath it if the -r option was |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 287 | # specified |
| 288 | #---------------------------------------------------------------------- |
| 289 | sub finalize_path |
| 290 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 291 | my $path = shift; |
| 292 | # Realpath all paths that don't start with "/" |
| 293 | $path =~ /^[^\/]/ and $path = abs_path($path); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 294 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 295 | # Quote the path if asked to, or if there are special shell characters |
| 296 | # in the path name |
| 297 | my $has_double_quotes = $path =~ /["]/; |
| 298 | my $has_single_quotes = $path =~ /[']/; |
| 299 | my $needs_quotes = $path =~ /[ \$\&\*'"]/; |
| 300 | if ($needs_quotes) |
| 301 | { |
| 302 | # escape and double quotes in the path |
| 303 | $has_double_quotes and $path =~ s/"/\\"/g; |
| 304 | $path = "\"$path\""; |
| 305 | } |
| 306 | return $path; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | sub do_command |
| 310 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 311 | my $cmd = shift; |
| 312 | my $description = @_ ? shift : "command"; |
| 313 | my $die_on_fail = @_ ? shift : undef; |
| 314 | $debug and print "% $cmd\n"; |
| 315 | system ($cmd); |
| 316 | if ($? == -1) |
| 317 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 318 | $debug and printf ("error: %s failed to execute: $!\n", $description); |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 319 | $die_on_fail and $? and exit(1); |
| 320 | return $?; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 321 | } |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 322 | elsif ($? & 127) |
| 323 | { |
| 324 | $debug and printf("error: %s child died with signal %d, %s coredump\n", |
| 325 | $description, |
| 326 | ($? & 127), |
| 327 | ($? & 128) ? 'with' : 'without'); |
| 328 | $die_on_fail and $? and exit(1); |
| 329 | return $?; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | } |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 331 | else |
| 332 | { |
| 333 | my $exit = $? >> 8; |
| 334 | if ($exit) |
| 335 | { |
| 336 | $debug and printf("error: %s child exited with value %d\n", $description, $exit); |
| 337 | $die_on_fail and exit(1); |
| 338 | } |
| 339 | return $exit; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Bob Wilson | bec2ac8 | 2013-01-11 19:24:51 +0000 | [diff] [blame] | 343 | sub create_single_llvm_archive_for_arch |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 344 | { |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 345 | my $arch_dstroot = shift; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | my $split_into_objects = shift; |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 347 | my @object_dirs; |
| 348 | my $object_dir; |
| 349 | my $tmp_dir = $arch_dstroot; |
| 350 | my $arch_output_file = "$arch_dstroot/$llvm_clang_basename"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | -e $arch_output_file and return; |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 352 | my $files = "$arch_dstroot/files.txt"; |
| 353 | open (FILES, ">$files") or die "Can't open $! for writing...\n"; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 355 | for my $path (@archive_files) |
| 356 | { |
| 357 | my $archive_fullpath = finalize_path ("$arch_dstroot/$path"); |
| 358 | if (-e $archive_fullpath) |
| 359 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | if ($split_into_objects) |
| 361 | { |
| 362 | my ($archive_file, $archive_dir, $archive_ext) = fileparse($archive_fullpath, ('.a')); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 363 | $object_dir = "$tmp_dir/$archive_file"; |
| 364 | push @object_dirs, $object_dir; |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 365 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 366 | do_command ("cd '$tmp_dir'; mkdir '$archive_file'; cd '$archive_file'; ar -x $archive_fullpath"); |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 367 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 368 | my @objects = bsd_glob("$object_dir/*.o"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 369 | foreach my $object (@objects) |
| 370 | { |
| 371 | my ($o_file, $o_dir) = fileparse($object); |
| 372 | my $new_object = "$object_dir/${archive_file}-$o_file"; |
| 373 | print FILES "$new_object\n"; |
| 374 | do_command ("mv '$object' '$new_object'"); |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 375 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | } |
| 377 | else |
| 378 | { |
| 379 | # just add the .a files into the file list |
| 380 | print FILES "$archive_fullpath\n"; |
| 381 | } |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 382 | } |
Greg Clayton | 193e6d5 | 2010-07-13 22:26:45 +0000 | [diff] [blame] | 383 | else |
| 384 | { |
| 385 | print "warning: archive doesn't exist: '$archive_fullpath'\n"; |
| 386 | } |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 387 | } |
| 388 | close (FILES); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 389 | do_command ("libtool -static -o '$arch_output_file' -filelist '$files'"); |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 390 | do_command ("ranlib '$arch_output_file'"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | |
Bob Wilson | a53ac6d | 2013-01-11 19:00:56 +0000 | [diff] [blame] | 392 | foreach $object_dir (@object_dirs) |
| 393 | { |
| 394 | do_command ("rm -rf '$object_dir'"); |
| 395 | } |
| 396 | do_command ("rm -rf '$files'"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | build_llvm(); |