Created
April 5, 2011 20:57
-
-
Save rcreasey/904536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source_package "protobuf" do | |
| version node[:protobuf][:version] | |
| location node[:protobuf][:mirror] | |
| filename node[:protobuf][:filename] | |
| prefix node[:protobuf][:path] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Cookbook Name:: build-essentials | |
| # Definition:: source_package | |
| # | |
| # Copyright 2010, IGN Entertainment | |
| # | |
| # All rights reserved - Do Not Redistribute | |
| # | |
| define :source_package do | |
| source_root = params[:source_root] || "/export/source" | |
| build_root = params[:build_root] || "/export/builds" | |
| build_directory = "#{build_root}/#{$1}" if params[:filename] =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tb2)/ | |
| verify_source = params[:verify_check].nil? ? params[:prefix] : params[:verify_check] | |
| clean_build = params[:clean_build] || true | |
| [source_root, build_root].each do |r| | |
| directory r do | |
| mode 0755 | |
| action :create | |
| not_if { ::File.directory?( r ) } | |
| recursive true | |
| end | |
| end | |
| # extract command | |
| archiver_command = case params[:filename] | |
| when /(tar.gz)|(tgz)$/ | |
| 'tar xzf' | |
| when /(tar.bz2)|(tb2)$/ | |
| 'tar xjf' | |
| when /tar$/ | |
| 'tar xf' | |
| when /zip$/ | |
| 'unzip' | |
| else | |
| raise "Unknown source archive format: #{archive_name}" | |
| end | |
| commands = {:download => "wget -cq #{params[:location]}/#{params[:filename]}", | |
| :extract => "#{archiver_command} #{source_root}/#{params[:filename]}", | |
| :configure => "./configure --prefix=#{params[:prefix]} ", | |
| :compile => 'make', | |
| :install => 'make install'} | |
| # decide what to configure | |
| if params[:configure] | |
| if params[:configure][:with] | |
| params[:configure][:with] = params[:configure][:with].compact.reject {|s| s.empty?} | |
| commands[:configure] << params[:configure][:with].map {|o| "--with-#{o} "}.join(' ') | |
| end | |
| if params[:configure][:enable] | |
| params[:configure][:enable] = params[:configure][:enable].compact.reject {|s| s.empty?} | |
| commands[:configure] << params[:configure][:enable].map {|o| "--enable-#{o} " unless o.eql?('')}.join(' ') | |
| end | |
| if params[:configure][:disable] | |
| params[:configure][:disable] = params[:configure][:disable].compact.reject {|s| s.empty?} | |
| commands[:configure] << params[:configure][:disable].map {|o| "--disable-#{o} " unless o.eql?('')}.join(' ') | |
| end | |
| if params[:configure][:other] | |
| params[:configure][:other] = params[:configure][:other].compact.reject {|s| s.empty?} | |
| commands[:configure] << params[:configure][:other].map {|o| "--#{o} " unless o.eql?('')}.join(' ') | |
| end | |
| end | |
| # execute commands | |
| unless ::File.exists?( verify_source ) | |
| instance_eval( params[:pre_download] ) if params[:pre_download] | |
| execute commands[:download] do | |
| cwd source_root | |
| not_if { ::File.exists?( "#{source_root}/#{params[:filename]}" ) } | |
| end | |
| instance_eval( params[:post_download] ) if params[:post_download] | |
| instance_eval( params[:pre_extract] ) if params[:pre_extract] | |
| execute commands[:extract] do | |
| cwd build_root | |
| end | |
| instance_eval( params[:post_extract] ) if params[:post_extract] | |
| if params[:custom] | |
| execute params[:custom][:build] do | |
| cwd params[:custom][:directory] | |
| end | |
| else | |
| instance_eval( params[:pre_configure] ) if params[:pre_configure] | |
| execute commands[:configure] do | |
| cwd build_directory | |
| end | |
| instance_eval( params[:post_configure] ) if params[:post_configure] | |
| instance_eval( params[:pre_compile] ) if params[:pre_compile] | |
| execute commands[:compile] do | |
| cwd build_directory | |
| end | |
| instance_eval( params[:post_compile] ) if params[:post_compile] | |
| instance_eval( params[:pre_install] ) if params[:pre_install] | |
| execute commands[:install] do | |
| cwd build_directory | |
| end | |
| instance_eval( params[:post_install] ) if params[:post_install] | |
| end | |
| end | |
| if clean_build | |
| [source_root, build_root].each do |r| | |
| directory r do | |
| action :delete | |
| recursive true | |
| only_if { ::File.directory?( r ) } | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment