Last active
August 29, 2015 14:10
-
-
Save shannonwells/e11bee9c589df50b061b to your computer and use it in GitHub Desktop.
This is an annotated ports.rake file for compiling platform-specific gems of tiny_tds for OS X and linux,statically linked with a custom build of freetds with openssl. Please use the tiny_tds_extconf.rb file if you want this to work as such.
This file contains 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
require 'mini_portile' | |
# All my notes are tagged with --shannonwells. | |
# I was able to compile platform-specfic gems on OS X Mavericks, AWS-linux AMI and AWS ubuntu AMI. | |
# Please feel free to pm me here or on Twitter (@shannonewells) if you want help --shannonwells | |
# If you're using 0.82, you may have to make a conf file to get it to work. For example: | |
# $ export FREETDSCONF='/opt/local/etc/freetds/freetds.conf' | |
ICONV_VERSION = "1.14" | |
FREETDS_VERSION = ENV['TINYTDS_FREETDS_VERSION'] || "0.91" | |
FREETDS_VERSION_INFO = Hash.new { |h,k| | |
h[k] = {:files => "ftp://ftp.astron.com/pub/freetds/stable/freetds-#{k}.tar.gz"} | |
}.merge({ | |
"0.82" => {:files => "ftp://ftp.astron.com/pub/freetds/old/0.82/freetds-0.82.tar.gz"}, | |
"0.91" => {:files => "ftp://ftp.astron.com/pub/freetds/stable/freetds-0.91.tar.gz"}, | |
"current" => {:files => "ftp://ftp.astron.com/pub/freetds/current/freetds-current.tgz"} | |
}) | |
# all ports depends on this directory to exist | |
directory "ports" | |
def define_libiconv_recipe(platform, host) | |
recipe = MiniPortile.new "libiconv", ICONV_VERSION | |
recipe.files << "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz" | |
recipe.host = host | |
desc "Compile libiconv for '#{platform}' (#{host})" | |
task "ports:libiconv:#{platform}" => ["ports"] do | |
checkpoint = "ports/.#{recipe.name}-#{recipe.version}-#{recipe.host}.installed" | |
unless File.exist?(checkpoint) | |
# always produce position independent code | |
recipe.configure_options << "CFLAGS='-fPIC'" | |
recipe.cook | |
touch checkpoint | |
end | |
end | |
recipe | |
end | |
def define_freetds_recipe(platform, host, libiconv) | |
recipe = MiniPortile.new "freetds", FREETDS_VERSION | |
recipe.files << FREETDS_VERSION_INFO[FREETDS_VERSION][:files] | |
recipe.host = host | |
if recipe.respond_to?(:patch_files) && FREETDS_VERSION == "0.91" | |
recipe.patch_files << File.expand_path(File.join('..', '..', 'ext', 'patch', 'sspi_w_kerberos.diff'), __FILE__) | |
recipe.patch_files << File.expand_path(File.join('..', '..', 'ext', 'patch', 'dblib-30-char-username.diff'), __FILE__) | |
unless RUBY_PLATFORM =~ /mswin|mingw/ | |
recipe.patch_files << File.expand_path(File.join('..', '..', 'ext', 'patch', 'Makefile.in.diff'), __FILE__) | |
end | |
end | |
desc "Compile freetds for '#{platform}' (#{host})" | |
task "ports:freetds:#{platform}" => ["ports", "ports:libiconv:#{platform}"] do | |
checkpoint = "ports/.#{recipe.name}-#{recipe.version}-#{recipe.host}.installed" | |
unless File.exist?(checkpoint) | |
with_tdsver = ENV['TINYTDS_FREETDS_VERSION'] =~ /0\.8/ ? "--with-tdsver=8.0" : "--with-tdsver=7.1" | |
for_windows = recipe.host =~ /mswin|mingw/i | |
recipe.configure_options << '--with-pic' | |
# Leave this line in for linux, take out for OS X unless you require statically linked iconv. --shannonwells | |
recipe.configure_options << "--with-libiconv-prefix=#{libiconv.path}" | |
recipe.configure_options << '--sysconfdir="C:/Sites"' if for_windows | |
recipe.configure_options << '--enable-sspi' if for_windows | |
# THIS LINE MAKES THE LINUX PLATFORM BUILD FAIL. It's because this disable, for some reason, | |
# causes the find_library and find_header checks to fail for libsybdb and libct (which are part of freetds). | |
# Take this line out if you find your build failing for these reasons. It may very well | |
# occur on OS X, too; I'm not sure I wasn't linking against a previous, brew-installed version | |
# of freetds-dev, possibly does not have the same issue. --shannonwells | |
recipe.configure_options << "--disable-odbc" | |
# NOTE THOUGH: the whole point of this was getting it to compile with openssl. None of the freetds | |
# packages are compiled with openssl by default. Be aware of this, if you link against default builds | |
# or pre-installed versions, you probably won't have encryption in the gem. --shannonwells | |
# Take this out if you don't want encryption and you care a whole lot about disk space. | |
recipe.configure_options << "--with-openssl" | |
recipe.configure_options << with_tdsver | |
recipe.cook | |
touch checkpoint | |
end | |
end | |
recipe | |
end | |
# native compilation of ports | |
host = RbConfig::CONFIG["host"] | |
libiconv = define_libiconv_recipe(RUBY_PLATFORM, host) | |
freetds = define_freetds_recipe(RUBY_PLATFORM, host, libiconv) | |
# compile native FreeTDS | |
desc "Compile native freetds" | |
task "ports:freetds" => ["ports:freetds:#{RUBY_PLATFORM}"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment