#!/usr/bin/env ruby # Copyright (C) 2013, 2014 Apple Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'getoptlong' require 'pathname' require 'shellwords' require 'tmpdir' def mychdir(path) puts "-> #{path.to_s}" Dir.chdir(path) { yield } puts "<- #{path.to_s}" end def mysys(*cmd) cmd = cmd.map{|value| value.to_s} commandArray = cmd.map{|value| Shellwords.shellescape(value)}.join(' ') $stderr.puts " $ #{commandArray}" raise unless system(*cmd) end $libraryPackage = Pathname.new("LLVMLibraries.tar.bz2") $includePackage = Pathname.new("LLVMIncludes.tar.bz2") $llvmBuild = Pathname.new("./llvm") $llvmBinary = Pathname.new("./llvm/Release") $llvmSource = Pathname.new("./llvm") $prefix = nil $compression = "bzip2" def usage puts "export-llvm-build" puts puts "--library-package (-l) Change where to put the compressed library package." puts " Default is #{$libraryPackage}." puts "--include-package (-i) Change wehre to put the compressed header package." puts " Default is #{$includePackage}." puts "--llvm-build (-b) Change which LLVM build directory to use." puts " Default is #{$llvmBuild}." puts "--llvm-binary (-B) Change which LLVM binary directory to use." puts " Default is #{$llvmBinary}." puts "--llvm-source (-s) Change which LLVM source directory to use." puts " Default is #{$llvmSource}." puts "--prefix (-p) Use an \"installed\" LLVM with the given prefix." puts "--compression Change what compression to do. Can be one of gzip," puts " bzip2, or none." puts " Default is #{$compression}." exit 1 end GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT], ['--library-package', '-l', GetoptLong::REQUIRED_ARGUMENT], ['--include-package', '-i', GetoptLong::REQUIRED_ARGUMENT], ['--llvm-build', '-b', GetoptLong::REQUIRED_ARGUMENT], ['--llvm-binary', '-B', GetoptLong::REQUIRED_ARGUMENT], ['--llvm-source', '-s', GetoptLong::REQUIRED_ARGUMENT], ['--prefix', '-p', GetoptLong::REQUIRED_ARGUMENT], ['--compression', GetoptLong::REQUIRED_ARGUMENT]).each { | opt, arg | case opt when '--help' usage when '--library-package' $libraryPackage = Pathname.new(arg) when '--include-package' $includePackage = Pathname.new(arg) when '--llvm-build' $llvmBuild = Pathname.new(arg) when '--llvm-binary' $llvmBinary = Pathname.new(arg) when '--llvm-source' $llvmSource = Pathname.new(arg) when '--prefix' $prefix = Pathname.new(arg) when '--compression' $compression = arg else raise end } $currentPath = Pathname.pwd def compressionChar case $compression when "gzip" "z" when "bzip2" "y" when "none" "" else raise "Bad choice of compression." end end if $prefix $llvmBinary = $prefix $llvmBuild = $prefix $llvmSource = $prefix end mychdir($llvmBinary + "lib") { mysys("tar", "-c#{compressionChar}vf", ($currentPath + $libraryPackage).to_s, *Dir.entries('.').select { | value | value =~ /\.a$/ and value !~ /libgtest/ }) } Dir.mktmpdir { | directory | directory = Pathname.new(directory).realpath mychdir($llvmSource) { begin mysys("svn", "export", "include", directory + "include") rescue mysys("ditto", "include", directory + "include") end } ["include/llvm/Config"].each { | genDirName | configSrcPath = $llvmBuild + genDirName raise unless configSrcPath.directory? configDstPath = directory + genDirName Dir.foreach(configSrcPath) { | filename | next unless filename =~ /\.def$/ or filename =~ /\.h$/ mysys("cp", configSrcPath + filename, configDstPath + filename) } } ["include/llvm/Support/DataTypes.h"].each { | genFileName | mysys("cp", $llvmBuild + genFileName, directory + genFileName) } mychdir(directory + "include") { mysys("tar", "-cyvf", $currentPath + $includePackage, ".") } } puts puts "LLVM has been packaged for use by WebKit." puts puts "You can use it right now by setting these environment variables:" puts puts "export LLVM_LIBRARY_PACKAGE=#{Shellwords.shellescape($libraryPackage.realpath.to_s)}" puts "export LLVM_INCLUDE_PACKAGE=#{Shellwords.shellescape($includePackage.realpath.to_s)}" puts