preparation*: |
def edit_content(content)
content.gsub!(/\$Release\$/, @release)
content.gsub!(/\$Release:.*?\$/, "$Release: #{@release} $")
content.gsub!(/\$Copyright.*?\$/, @copyright)
content.gsub!(/\$License.*?\$/, @license)
content
end
properties:
- project : motto-mysql
- target : motto_mysql
- release : 0.1.0
- copyright : copyright(c) 2008 kuwata-lab.com all rights reserved.
- license : "License: Ruby's license"
#- mysql_ruby_version: '2.7.4'
#- mysql_ruby_version: '2.7.5'
#- mysql_ruby_version: '2.7.6'
#- mysql_ruby_version: '2.8pre4'
- mysql_ruby_version: '2.8'
- mysql_srcdir: external/mysql-ruby-$(mysql_ruby_version)
- mysql_c : $(mysql_srcdir)/mysql.c
parameters:
#- rook_product: :all
recipes:
- product: :all
ingreds: [:build, :install, :test, :clean, :package]
- product: :build
desc: create Makefile and compile
ingreds: [ ext/Makefile, ext/$(target).h ]
method*: |
chdir "ext" do sys "make" end
- product: :install
ingreds: [ :build ]
method*: |
chdir "ext" do sys "sudo make install" end
- product: :uninstall
method*: |
files = Dir.glob('/usr/local/lib/ruby/site_ruby/1.8/*/motto_mysql.*')
#sys "sudo rm #{files.join(' ')}"
rm_f files
- product: :test
method*: |
sys "testrb test"
- product: :clean
method*: |
rm_rf 'ext/Makefile', 'ext/$(target).o', 'ext/$(target).bundle', 'ext/mkmf.log'
- product: ext/Makefile
ingreds: [ ext/extconf.rb ]
method*: |
chdir "ext" do
#sys "ruby extconf.rb --with-mysql-dir=/usr/local/mysql"
#sys "ruby extconf.rb --with-mysql-config"
sys "ruby extconf.rb"
end
- product: :header
desc: create 'ext/*.h' file
ingreds: [ ext/$(target).h ]
- product: ext/$(target).h
ingreds: [ $(mysql_c), Rookbook.yaml ]
method*: |
source = File.read('$(mysql_c)')
s = ''
s << "/* ------------------------ copied from mysql.c ------------------------ */\n"
s << "\n"
s << (source =~ /^\#define MYSQL_RUBY_VERSION.*?\n/ and $&)
s << "\n"
s << "/* struct mysql_res */\n"
s << (source =~ /^struct mysql_res \{.*?^\};\n/m and $&)
s << "\n"
s << "/* macro GetMysqlRes */\n"
s << (source =~ /^\#define GetMysqlRes\(obj\).*?\n/ and $&)
s << "\n"
s << "/* struct mysql_stmt */\n"
s << (source =~ /^struct mysql_stmt \{.*?\};\n/m and $&)
s << "\n"
s << "/* macro GetMysqlStmt */\n"
s << (source =~ /^\#define GetMysqlStmt\(obj\).*?\n/ and $&)
s << "\n"
s << "/* check_free() */\n"
s << (source =~ /^static void check_free\(VALUE \w+\)\n\{.*?^\}\n/m and $&)
s << "\n"
s << "/* check_stmt_closed() */\n"
s << (source =~ /^static void check_stmt_closed\(VALUE \w+\)\n\{.*?^\}\n/m and $&)
s << "\n"
s << "/* mysql_stmt_raise() */\n"
s << (source =~ /^static void mysql_stmt_raise\(MYSQL_STMT\* \w+\)\n\{.*?^\}\n/m and $&)
s << "\n"
s << "/* --------------------------------------------------------------------- */\n"
File.open(@product, 'w') {|f| f.write(s) }
- product: README.html
ingreds: [ README.txt ]
method*: |
sys "rd2 #{@ingred} > #{@product}"
# - product: README.html
# ingreds: [ README.rdoc ]
# method*: |
# #sys "rdoc -1 #{@ingred} > #{@product}"
# #sys "rdoc #{@ingred}"
# sys "rdoc --template hefss #{@ingred}"
# #sys "rdoc --template kilmer #{@ingred}"
# mv "doc/files/README_rdoc.html", @product
# mv "doc/rdoc-style.css", "rdoc-style.css"
# rm_rf "doc"
# edit @product do |content|
# content.sub! '<body bgcolor="#BBBBBB">', '<body>'
# content.sub! 'href=".././rdoc-style.css"', 'href="rdoc-style.css"'
# content
# end
# edit "rdoc-style.css" do |content|
# content.sub! 'background: #BBBBBB;', '/*background: #BBBBBB;*/'
# content << "\n"
# content << "dt { font-weight: bold; color: #000000; margin-top: 5px; }\n"
# content << "dd { margin-top: 5px; margin-bottom: 10px; }\n"
# end
- product: :package
desc: create *.tar.gz and *.gem under 'build' directory
ingreds: [ :clean ]
method*: |
## remove and create build directory
base = "$(project)-$(release)"
dir = "build/#{base}"
rm_rf dir
mkdir_p dir
## copy files
store %w[README.txt $(project).gemspec setup.rb], dir
store 'ext/**/*', 'test/**/*', dir
## edit files
edit "#{dir}/**/*" do |content|
edit_content(content)
end
## create packages
chdir "build" do
tar_czf "#{base}.tar.gz", base
end
chdir dir do
#sys "gem build $(project).gemspec"
Gem.manage_gems
require 'rubygems/gem_runner'
Gem::GemRunner.new.run ['build', '$(project).gemspec']
mv "#{base}.gem", ".."
end
- product: :index
ingreds: [ website/index.html ]
- product: website/index.html
ingreds: [ README.txt ]
method*: |
mkdir "website" unless test(?d, "website")
download_url = "http://rubyforge.org/projects/$(project)/"
sys "rd2 #{@ingred} | tidy -q -i -wrap 9999 -ashtml > #{@product}"
edit @product do |content|
body = (content =~ /<body>.*<\/body>/m) && $&
#body.gsub! /<h1>.*<\/h1>/, "<h1>$(project): README.txt</h1>"
#body.gsub! /README-$(project)/, 'README'
body.gsub! /<!-- RDLabel: ".*" -->/, ''
body.gsub! /(<h\d>)<a name=".*?" id=".*?">/, '\1'
body.gsub! /<\/a>(<\/h\d>)/, '\1'
edit_content(body)
body.gsub! /copyright\(c\)/, 'copyright©'
#body.sub! /http:\/\/$(project)\.rubyforge\.org\//, '<a href="\&">\&</a><br />'
#body.sub! /http:\/\/rubyforge\.org\/projects\/$(project)\//, '<a href="\&">\&</a>'
#body.sub! /http:\/\/github\.com\/\w+\/$(project)\//, '<a href="\&">\&</a>'
#body.sub! /http:\/\/kuwata-lab-products\.googlegroups.com\/?/, '<a href="\&">\&</a>'
body.gsub! /(http:\/\/[-\w:\/.]+[^.<])/, '<a href="\1">\1</a>'
#body.sub! /$(project)-$(release)\.tar\.gz/, "<a href=\"#{download_url}\">\\&</a>"
#body.sub! /CGI-Exception/, '<a href="http://cgi-exception.rubyforge.org/">\&</a>'
html = <<END
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>$(project): README.txt</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
#{body}
</html>
END
content[0..-1] = html
content
end
- product: :debug
method*: |
items = %w[string var_string int24 long longlong float double
timestamp datetime date time
tiny short year decimal blob tiny_blob medium_blob newdecimal bit]
s = ''
s << "#if DEBUG\n"
s << " int _type = buffer_type;\n"
s << " int _length = s->result.length[i];\n"
s << " switch (_type) {\n"
for item in items
t = item.upcase
s << " case MYSQL_TYPE_#{t}: fprintf(stderr, \"*** debug: MYSQL_TYPE_#{t}(%d), length=%d\\n\", _type, _length); break;\n"
end
s << " default: fprintf(stderr, \"*** debug: unknown type(%d)\\n\", _type);\n"
s << " }\n"
s << "#endif\n"
File.open('debug', 'w') {|f| f << s }