tiny_tds 1.3.0-x86-mingw32 → 2.0.0.pre1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6225cc799d69e728e410bf1337d2a6f317fed30
4
- data.tar.gz: 7b12e0f70e4e0fffec8a0b6650fc42a9a851b985
3
+ metadata.gz: 7bf04af2f26764153c7f5143905ff9d684375ebe
4
+ data.tar.gz: 15a5461aafaa5820349642e9a6c7ab9fc83eca2f
5
5
  SHA512:
6
- metadata.gz: eea851e93ca716ba0f692623764a967beed5929bac750892451e1e4a81edbf098b575a578837e99b40130c596bc4ca5cf55861871693befbaf6fcf6cf82494b0
7
- data.tar.gz: d648206a095db5d8e3225d3cc47764c5f0e2de01bba117d634cd69327197ed711e5c36f51bf37710ea8824212e749bc6fc578f2efa74845e0fb6f4673c4efd9c
6
+ metadata.gz: 89185ad072bb93a215f6bfa8d97ad402399ba744ea4ae736a2263ed9446e5bbf08d761a1df638cbb3053393325c79cfea8815f5a17940f7aab14fa9150f4a19a
7
+ data.tar.gz: 6d63d8b824ba8e15e289c037e66c89f60419a9e8cd2dfd8233c25d1148fa788d1df98c1eb01e46aacb2533b1e5b2ae53fb7bde38770121429b23769a51ce71ff
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ services:
4
4
  - docker
5
5
  env:
6
6
  global:
7
+ - PATH=/opt/local/bin:$PATH
7
8
  - TESTOPTS="-v"
8
9
  - TINYTDS_UNIT_HOST=localhost
9
10
  rvm:
@@ -11,15 +12,11 @@ rvm:
11
12
  - 2.2.5
12
13
  - 2.3.1
13
14
  before_install:
14
- - export PATH=/opt/local/bin:$PATH
15
15
  - docker info
16
- - sudo ./test/bin/setup.sh
17
16
  - sudo ./test/bin/install-openssl.sh
18
- - openssl version
19
17
  - sudo ./test/bin/install-freetds.sh
20
- - tsql -C
18
+ - sudo ./test/bin/setup.sh
21
19
  install:
22
- - export PATH=/opt/local/bin:$PATH
23
20
  - gem install bundler
24
21
  - bundle --version
25
22
  - bundle install
data/Gemfile CHANGED
@@ -3,5 +3,8 @@ gemspec
3
3
 
4
4
  group :development do
5
5
  gem 'rake-compiler-dock', github: 'rake-compiler/rake-compiler-dock'
6
- gem 'byebug'
6
+ end
7
+
8
+ group :test do
9
+ gem 'minitest'
7
10
  end
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ## Supporting TinyTDS/Adapter
12
12
 
13
- Both TinyTDS and the Rails SQL Server Adapter are MIT-licensed open source projects. Its ongoing development is made possible thanks to the support by these awesome [backers](https://github.com/rails-sqlserver/tiny_tds/blob/master/BACKERS.md). If you'd like to join them, check out [MetaSkills Patreon Campaign](https://www.patreon.com/metaskills).
13
+ Both TinyTDS and the Rails SQL Server Adapter are MIT-licensed open source projects. Its ongoing development is made possible thanks to the support by these awesome [backers](https://github.com/rails-sqlserver/tiny_tds/blob/master/BACKERS.md). If you'd like to join them, check out our [Patreon Campaign](https://www.patreon.com/metaskills).
14
14
 
15
15
 
16
16
  ## About TinyTDS
@@ -52,30 +52,18 @@ $ make install
52
52
  If none exist, our native extension will use MiniPortile to install any missing dependencies listed above for your specific platform. These dependencies will be built and linked within the installed TinyTDS gem. Please read the MiniPortile and/or Windows sections at the end of this file for advanced configuration options past the following:
53
53
 
54
54
  ```
55
- --enable-system-freetds / --disable-system-freetds
56
- --enable-system-iconv / --disable-system-iconv
57
- --enable-system-openssl / --disable-system-openssl
58
- Force use of system or builtin freetds/iconv/openssl library.
59
- Default is to prefer system libraries and fallback to builtin.
60
-
61
55
  --with-freetds-dir=DIR
62
56
  Use the freetds library placed under DIR.
63
-
64
- --enable-lookup
65
- Search for freetds through all paths in the PATH environment variable.
66
-
67
- --enable-cross-build
68
- Do cross-build.
69
57
  ```
70
58
 
71
59
 
72
60
  ## Getting Started
73
61
 
74
- Optionally, Microsoft has done a great job writing some articls on how to get started with SQL Server and Ruby using TinyTDS. Please checkout one of the following posts that match your platform.
62
+ Optionally, Microsoft has done a great job writing some articles on how to get started with SQL Server and Ruby using TinyTDS. Please checkout one of the following posts that match your platform.
75
63
 
76
- * [SQL Server on a Mac](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby-mac)
77
- * [SQL Server on RHEL](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby-rhel)
78
- * [SQL Server on Ubuntu](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby-ubuntu)
64
+ * [SQL Server on a Mac](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/mac)
65
+ * [SQL Server on RHEL](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/rhel)
66
+ * [SQL Server on Ubuntu](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/ubuntu)
79
67
 
80
68
 
81
69
  ## FreeTDS Compatibility & Configuration
@@ -403,19 +391,6 @@ This is possible using FreeTDS version 0.95 or higher. You must use the `use_utf
403
391
  The default is true and since FreeTDS v1.0 would do this as well.
404
392
 
405
393
 
406
- ## Using MiniPortile
407
-
408
- MiniPortile is a minimalistic implementation of a port/recipe system. <https://github.com/luislavena/mini_portile>
409
-
410
- The TinyTDS project uses MiniPortile so that we can easily install a local version of FreeTDS and supporting libraries to link against when building a test version of TinyTDS. This same system is also used when installing TinyTDS with Rubygems and building native extensions. It is possible to build TinyTDS with a specific version of FreeTDS using the `TINYTDS_FREETDS_VERSION` environment variable. Here are some exampbles of possible values.
411
-
412
- ```
413
- $ rake TDSVER='7.1' TINYTDS_FREETDS_VERSION='0.95' -- --disable-system-freetds --disable-system-iconv
414
- ```
415
-
416
- To find out more about the FreeTDS release system [visit this thread](http://lists.ibiblio.org/pipermail/freetds/2012q1/027756.html) on their mailing list. You can also browse thier FTP server [ftp://ftp.astron.com/pub/freetds/](ftp://ftp.astron.com/pub/freetds/) for version number strings.
417
-
418
-
419
394
  ## Compiling Gems for Windows
420
395
 
421
396
  For the convenience of Windows users, TinyTDS ships pre-compiled gems for Ruby 2.0, 2.1, 2.2, and 2.3 on Windows. In order to generate these gems, [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) is used. This project provides a [Docker image](https://registry.hub.docker.com/u/larskanis/rake-compiler-dock/) with rvm, cross-compilers and a number of different target versions of Ruby.
@@ -463,13 +438,20 @@ CREATE USER [tinytds] FOR LOGIN [tinytds];
463
438
  EXEC sp_addrolemember N'db_owner', N'tinytds';
464
439
  ```
465
440
 
466
- From here you can now run the tests. This assumes you have both Ruby & the needed FreeTDS installed.
441
+ From here you can build and run tests against an installed version of FreeTDS.
467
442
 
468
443
  ```shell
469
444
  $ bundle install
470
445
  $ bundle exec rake
471
446
  ```
472
447
 
448
+ If you don't have FreeTDS installed on your system you can let the MiniPortile build tasks build and link all the dependencies for you.
449
+ ```shell
450
+ $ bundle install
451
+ $ bundle exec rake ports build
452
+ $ bundle exec rake ports test
453
+ ```
454
+
473
455
  Examples us using enviornment variables to customize the test task.
474
456
 
475
457
  ```
@@ -479,13 +461,6 @@ $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
479
461
  $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_UNIT_PORT=5000 TINYTDS_SCHEMA=sybase_ase
480
462
  ```
481
463
 
482
- If you do not want to use MiniPortile to compile a local project version of FreeTDS and instead use your local system version, use the `TINYTDS_SKIP_PORTS` environment variable. This will ignore any port tasks and will instead build and link to your system's FreeTDS installation as a normal gem install would.
483
-
484
- ```
485
- $ rake TINYTDS_SKIP_PORTS=1
486
- ```
487
-
488
-
489
464
  ## Help & Support
490
465
 
491
466
  * Github Source: http://github.com/rails-sqlserver/tiny_tds
data/Rakefile CHANGED
@@ -1,107 +1,50 @@
1
1
  # encoding: UTF-8
2
+ require 'rbconfig'
2
3
  require 'rake'
3
4
  require 'rake/clean'
4
- require 'rbconfig'
5
- require 'rake/testtask'
6
5
  require 'rake/extensiontask'
7
- require 'rubygems/package_task'
8
6
  require_relative './ext/tiny_tds/extconsts'
9
7
 
10
- def test_libs
11
- %w(lib test)
12
- end
13
-
14
- def test_files
15
- if ENV['TEST_FILES']
16
- ENV['TEST_FILES'].split(',').map(&:strip).sort
17
- else
18
- Dir.glob('test/**/*_test.rb').sort
19
- end
20
- end
21
-
22
- def add_file_to_gem(spec, relative_path)
23
- target_path = File.join gem_build_path(spec), relative_path
24
- target_dir = File.dirname(target_path)
25
- mkdir_p target_dir
26
- rm_f target_path
27
- safe_ln relative_path, target_path
28
- spec.files += [relative_path]
29
- end
30
-
31
- def gem_build_path(spec)
32
- File.join 'pkg', spec.full_name
33
- end
34
-
35
- gemspec = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
36
-
37
- Rake::TestTask.new do |t|
38
- t.libs = test_libs
39
- t.test_files = test_files
40
- t.verbose = true
41
- end
42
-
43
- Gem::PackageTask.new(gemspec) do |pkg|
44
- pkg.need_tar = false
45
- pkg.need_zip = false
46
- end
47
-
48
- task :compile
8
+ SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
9
+ GEM_PLATFORM_HOSTS = {
10
+ 'x86-mingw32' => 'i686-w64-mingw32',
11
+ 'x64-mingw32' => 'x86_64-w64-mingw32'
12
+ }
49
13
 
50
- task build: [:clean, :compile]
51
- task(:build_quietly) { capture_stds { Rake::Task[:build].invoke } }
14
+ # Add our project specific files to clean for a rebuild
15
+ CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
16
+ FileList["exe/*"]
52
17
 
53
- task default: [:build, :test]
18
+ # Clobber all our temp files and ports files including .install files
19
+ # and archives
20
+ CLOBBER.include FileList["tmp/**/*"],
21
+ FileList["ports/**/*"].exclude(%r{^ports/archives})
54
22
 
55
23
  Dir['tasks/*.rake'].sort.each { |f| load f }
56
24
 
57
- Rake::ExtensionTask.new('tiny_tds', gemspec) do |ext|
25
+ Rake::ExtensionTask.new('tiny_tds', SPEC) do |ext|
58
26
  ext.lib_dir = 'lib/tiny_tds'
59
27
  ext.cross_compile = true
60
- ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
61
- ext.cross_config_options += %w(--disable-lookup --enable-cross-build)
28
+ ext.cross_platform = GEM_PLATFORM_HOSTS.keys
29
+
62
30
  # Add dependent DLLs to the cross gems
63
31
  ext.cross_compiling do |spec|
64
- platform_host_map = {
65
- 'x86-mingw32' => 'i686-w64-mingw32',
66
- 'x64-mingw32' => 'x86_64-w64-mingw32'
67
- }
32
+ platform_host_map = GEM_PLATFORM_HOSTS
68
33
  gemplat = spec.platform.to_s
69
34
  host = platform_host_map[gemplat]
70
- dlls = [
71
- "libcrypto32-#{OPENSSL_VERSION}-#{host}.dll",
72
- "libssl32-#{OPENSSL_VERSION}-#{host}.dll",
73
- 'libiconv-2.dll',
74
- 'libsybdb-5.dll'
75
- ]
35
+
76
36
  # We don't need the sources in a fat binary gem
77
37
  spec.files = spec.files.reject { |f| f =~ %r{^ports\/archives/} }
78
- spec.files += dlls.map { |dll| "ports/#{host}/bin/#{File.basename(dll)}" }
38
+
39
+ # Make sure to include the ports binaries and libraries
40
+ spec.files += FileList["ports/#{host}/**/**/{bin,lib}/*"].exclude do |f|
41
+ File.directory? f
42
+ end
43
+
79
44
  spec.files += Dir.glob('exe/*')
80
45
  end
81
46
  end
82
47
 
83
- # Bundle the freetds sources to avoid download while gem install.
84
- task gem_build_path(gemspec) do
85
- add_file_to_gem gemspec, "ports/archives/freetds-#{FREETDS_VERSION}.tar.bz2"
86
- end
87
-
88
- desc 'Build the windows binary gems per rake-compiler-dock'
89
- task 'gem:windows' do
90
- require 'rake_compiler_dock'
91
- RakeCompilerDock.sh <<-EOT
92
- bundle && rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.6:2.0.0 CFLAGS="-Wall"
93
- EOT
94
- end
48
+ task build: [:clean, :compile]
49
+ task default: [:build, :test]
95
50
 
96
- def capture_stds
97
- pstdout = $stdout
98
- $stdout = StringIO.new
99
- pstderr = $stderr
100
- $stderr = StringIO.new
101
- yield
102
- $stdout.string
103
- $stderr.string
104
- ensure
105
- $stdout = pstdout
106
- $stderr = pstderr
107
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 2.0.0.pre1
data/appveyor.yml CHANGED
@@ -9,12 +9,15 @@ skip_branch_with_pr: true
9
9
  matrix:
10
10
  fast_finish: true
11
11
  install:
12
+ # Output debugging info
12
13
  - ps: Update-AppveyorBuild -Version "$(Get-Content $env:appveyor_build_folder\VERSION).$env:appveyor_build_number"
13
14
  - perl --version
14
15
  - ruby --version
15
16
  - gem --version
17
+
18
+ # Set up project prerequisits
16
19
  - bundle install
17
- - bundle exec rake build
20
+ - bundle exec rake ports
18
21
  build: off
19
22
  branches:
20
23
  except:
@@ -26,13 +29,13 @@ test_script:
26
29
  - ps: Start-Service 'MSSQL$SQL2014'
27
30
  - timeout /t 4 /nobreak > NUL
28
31
  - sqlcmd -S ".\SQL2014" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
29
- - bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014 TDSVER=7.1
30
- - bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014
32
+ - bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014 TDSVER=7.1
33
+ - bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014
31
34
  - ps: Stop-Service 'MSSQL$SQL2014'
32
35
  - ps: Start-Service 'MSSQL$SQL2012SP1'
33
36
  - timeout /t 4 /nobreak > NUL
34
37
  - sqlcmd -S ".\SQL2012SP1" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
35
- - bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2012SP1" TINYTDS_SCHEMA=sqlserver_2014
38
+ - bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2012SP1" TINYTDS_SCHEMA=sqlserver_2014
36
39
  environment:
37
40
  CI_AZURE_HOST:
38
41
  secure: 8ydpYysZYKEBKvp6plKlYfepH98/zAuT27FFCaJ9Sss=
data/circle.yml CHANGED
@@ -13,13 +13,11 @@ machine:
13
13
 
14
14
  dependencies:
15
15
  override:
16
+ - sudo ./test/bin/install-openssl.sh
17
+ - sudo ./test/bin/install-freetds.sh
16
18
  - rvm-exec 2.1.9 bundle install
17
19
  - rvm-exec 2.2.5 bundle install
18
20
  - rvm-exec 2.3.1 bundle install
19
- - sudo ./test/bin/install-openssl.sh
20
- - openssl version
21
- - sudo ./test/bin/install-freetds.sh
22
- - tsql -C
23
21
 
24
22
  database:
25
23
  post:
@@ -3,366 +3,63 @@ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
3
3
  # :stopdoc:
4
4
 
5
5
  require 'mkmf'
6
- require 'fileutils'
7
-
8
- # The gem version constraint in the gemspec is not respected at install time.
9
- # Keep this version in sync with the one in the gemspec !
10
- gem 'mini_portile2', '~> 2.0'
11
- require 'mini_portile2'
6
+ require 'rbconfig'
12
7
  require_relative './extconsts'
13
8
 
14
- OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
15
-
16
9
  # Shamelessly copied from nokogiri
17
10
  #
18
11
 
19
12
  def do_help
20
13
  print <<HELP
21
14
  usage: ruby #{$0} [options]
22
-
23
- --enable-system-freetds / --disable-system-freetds
24
- --enable-system-iconv / --disable-system-iconv
25
- --enable-system-openssl / --disable-system-openssl
26
- Force use of system or builtin freetds/iconv/openssl library.
27
- Default is to prefer system libraries and fallback to builtin.
28
-
29
15
  --with-freetds-dir=DIR
30
16
  Use the freetds library placed under DIR.
31
-
32
- --enable-lookup
33
- Search for freetds through all paths in the PATH environment variable.
34
-
35
- --disable-openssl
36
- Disable OpenSSL for freetds build. No effect on system-freetds.
37
-
38
- --enable-gnutls
39
- Use GnuTLS instead of OpenSSL for freetds build.
40
-
41
- --enable-cross-build
42
- Do cross-build.
43
17
  HELP
44
18
  exit! 0
45
19
  end
46
20
 
47
21
  do_help if arg_config('--help')
48
22
 
49
- FREETDSDIR = ENV['FREETDS_DIR']
50
-
51
- if FREETDSDIR.nil? || FREETDSDIR.empty?
52
- LIBDIR = RbConfig::CONFIG['libdir']
53
- INCLUDEDIR = RbConfig::CONFIG['includedir']
54
- else
55
- puts "Will use #{FREETDSDIR}"
56
- LIBDIR = "#{FREETDSDIR}/lib"
57
- INCLUDEDIR = "#{FREETDSDIR}/include"
23
+ # Make sure to check the ports path for the configured host
24
+ host = RbConfig::CONFIG['host']
25
+ project_dir = File.join(['..']*4)
26
+ freetds_dir = File.join(project_dir, 'ports', host, 'freetds', FREETDS_VERSION)
27
+ freetds_dir = File.expand_path(freetds_dir)
28
+
29
+ # Add all the special path searching from the original tiny_tds build
30
+ # order is important here! First in, last searched.
31
+ %w(
32
+ /usr/local
33
+ /opt/local
34
+ ).each do |path|
35
+ idir = "#{path}/include"
36
+ ldir = "#{path}/lib"
37
+
38
+ dir_config('freetds',
39
+ [idir, "#{idir}/freetds"],
40
+ [ldir, "#{ldir}/freetds"]
41
+ )
58
42
  end
59
43
 
60
- $CFLAGS << " #{ENV["CFLAGS"]}"
61
- $LDFLAGS << " #{ENV["LDFLAGS"]}"
62
- $LIBS << " #{ENV["LIBS"]}"
63
-
64
- SEARCHABLE_PATHS = begin
65
- eop_regexp = /#{File::SEPARATOR}bin$/
66
- paths = ENV['PATH']
67
- paths = paths.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
68
- paths = paths.split(File::PATH_SEPARATOR)
69
- bin_paths = paths.select{ |p| p =~ eop_regexp }
70
- bin_paths.map{ |p| p.sub(eop_regexp,'') }.compact.reject{ |p| p.empty? }.uniq
44
+ # Add the ports directory if it exists for local developer builds
45
+ if File.directory?(freetds_dir)
46
+ puts "Using freetds port path #{freetds_dir}"
47
+ dir_config('freetds', "#{freetds_dir}/include", "#{freetds_dir}/lib")
71
48
  end
72
49
 
73
- def searchable_paths_with_directories(*directories)
74
- SEARCHABLE_PATHS.map do |path|
75
- directories.map do |paths|
76
- dir = File.join path, *paths
77
- File.directory?(dir) ? dir : nil
78
- end.flatten.compact
79
- end.flatten.compact
50
+ have_dependencies = [
51
+ find_header('sybfront.h'),
52
+ find_header('sybdb.h'),
53
+ find_library('sybdb', 'tdsdbopen'),
54
+ find_library('sybdb', 'dbanydatecrack')
55
+ ].inject(true) do |memo, current|
56
+ memo && current
80
57
  end
81
58
 
82
- class BuildRecipe < MiniPortile
83
- def initialize(name, version, files)
84
- super(name, version)
85
- self.files = files
86
- self.target = File.expand_path('../../../ports', __FILE__)
87
- self.host = consolidated_host(RbConfig::CONFIG["host"])
88
- self.patch_files = Dir[File.join(self.target, "patches", self.name, self.version, "*.diff")].sort
89
- end
90
-
91
- def consolidated_host(name)
92
- # Host name and prefix of build tools are different on Windows 32 bit.
93
- name.gsub('i686-pc-mingw32', 'i686-w64-mingw32')
94
- end
95
-
96
- def configure_defaults
97
- [
98
- "--host=#{host}", # build for specific target (host)
99
- "--disable-static",
100
- "--enable-shared",
101
- ]
102
- end
103
-
104
- # Use the same path for all recipes, so that only one include/lib path is required.
105
- def port_path
106
- "#{target}/#{host}"
107
- end
108
-
109
- # We use the same port_path for all recipes. That breaks the standard installed? method.
110
- def installed?
111
- false
112
- end
113
-
114
- # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
115
- # folders don't support symlinks, but libiconv expects it for a build on
116
- # Linux. We work around this limitation by using the temp dir for cooking.
117
- def chdir_for_build
118
- build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
119
- Dir.chdir(build_dir) do
120
- yield
121
- end
122
- end
123
-
124
- def cook_and_activate
125
- checkpoint = File.join(self.target, "#{self.name}-#{self.version}-#{self.host}.installed")
126
- unless File.exist?(checkpoint)
127
- chdir_for_build do
128
- self.cook
129
- end
130
- FileUtils.touch checkpoint
131
- end
132
- self.activate
133
- self
134
- end
59
+ unless have_dependencies
60
+ abort 'Failed! Do you have FreeTDS 0.95.80 or higher installed?'
135
61
  end
136
62
 
137
- def define_libssl_recipe(host)
138
- BuildRecipe.new("openssl", OPENSSL_VERSION, [OPENSSL_SOURCE_URI]).tap do |recipe|
139
- class << recipe
140
- def extract_file(file, target)
141
- filename = File.basename(file)
142
- FileUtils.mkdir_p target
143
-
144
- message "Extracting #{filename} into #{target}... "
145
- result = `#{tar_exe} #{tar_compression_switch(filename)}xf "#{file}" -C "#{target}" 2>&1`
146
- if $?.success?
147
- output "OK"
148
- else
149
- # tar on windows returns error exit code, because it can not extract symlinks
150
- output "ERROR (ignored)"
151
- end
152
- end
153
-
154
- def execute(action, command, options={})
155
- prev_path = ENV['PATH']
156
- if host=~/mingw/
157
- git_perl = 'C:/Program Files/Git/usr/bin'
158
- if File.directory?(git_perl)
159
- ENV['PATH'] = git_perl + ';' + ENV['PATH']
160
- ENV['PERL'] = 'perl'
161
- end
162
- end
163
- super
164
- ENV['PATH'] = prev_path
165
- end
166
-
167
- def configure
168
- config = if host=~/mingw/
169
- host=~/x86_64/ ? 'mingw64' : 'mingw'
170
- end
171
- args = [ "CFLAGS=-DDSO_WIN32",
172
- "./Configure",
173
- "no-shared",
174
- configure_prefix,
175
- config,
176
- ]
177
- args.unshift("CROSS_COMPILE=#{host}-") if enable_config("cross-build")
178
-
179
- execute "configure", "sh -c \"#{args.join(" ")}\""
180
- end
181
-
182
- def dllwrap(dllname, outputlib, deffile, linkto)
183
- gcc = consolidated_host(RbConfig::CONFIG["CC"])
184
-
185
- #RbConfig does not provide dlltool, but it should exist where dllwrap lives
186
- dlltool = consolidated_host(RbConfig::CONFIG["DLLWRAP"]).sub('dllwrap','dlltool')
187
-
188
- execute "gcc-#{dllname}-compile", "#{gcc} -Wl,--base-file,#{dllname}.base -mdll -o #{dllname}.dll --leading-underscore #{linkto}"
189
- execute "dlltool-#{dllname}-exp", "#{dlltool} --base-file #{dllname}.base --output-exp #{dllname}.exp --dllname #{dllname}.dll --def #{deffile}"
190
- execute "gcc-#{dllname}-dll", "#{gcc} -Wl,--base-file,#{dllname}.base #{dllname}.exp -mdll -o #{dllname}.dll --leading-underscore #{linkto}"
191
- execute "dlltool-#{dllname}-outputlib", "#{dlltool} --base-file #{dllname}.base --output-exp #{dllname}.exp --dllname #{dllname}.dll --def #{deffile} --output-lib #{outputlib}"
192
- execute "gcc-#{dllname}-link", "#{gcc} #{dllname}.exp -mdll -o #{dllname}.dll --leading-underscore #{linkto}"
193
- end
194
-
195
- def compile
196
- super
197
- # OpenSSL DLLs are called "libcrypto32.dll" and "libssl32.dll" per default,
198
- # regardless to the version. This is best suited to meet the Windows DLL hell.
199
- # To avoid any conflicts we do a static build and build DLLs afterwards,
200
- # with our own naming scheme.
201
- execute "mkdef-crypto32", "(perl util/mkdef.pl crypto 32 >libcrypto32.def)"
202
- execute "mkdef-ssl32", "(perl util/mkdef.pl ssl 32 >libssl32.def)"
203
- dllwrap("libcrypto32-#{version}-#{host}", "libcrypto.dll.a", "libcrypto32.def", "libcrypto.a -lws2_32 -lgdi32 -lcrypt32")
204
- dllwrap("libssl32-#{version}-#{host}", "libssl.dll.a", "libssl32.def", "libssl.a libcrypto.dll.a")
205
- end
206
-
207
- def install
208
- unless installed?
209
- execute('install', %Q(#{make_cmd} install_sw install_ssldirs))
210
- end
211
- FileUtils.cp "#{work_path}/libcrypto32-#{version}-#{host}.dll", "#{path}/bin/"
212
- FileUtils.cp "#{work_path}/libssl32-#{version}-#{host}.dll", "#{path}/bin/"
213
- FileUtils.cp "#{work_path}/libcrypto.dll.a", "#{path}/lib/"
214
- FileUtils.cp "#{work_path}/libssl.dll.a", "#{path}/lib/"
215
- end
216
- end
217
- end
218
- end
219
-
220
- def define_libiconv_recipe(host)
221
- BuildRecipe.new("libiconv", ICONV_VERSION, [ICONV_SOURCE_URI]).tap do |recipe|
222
- # always produce position independent code
223
- # and set an explicit optimization to avoid inline functions being optimized
224
- # out of libiconv
225
- recipe.configure_options << "CFLAGS=-fPIC -O2"
226
- end
227
- end
228
-
229
- def define_freetds_recipe(host, libiconv, libssl, gnutls)
230
- BuildRecipe.new("freetds", FREETDS_VERSION, [FREETDS_SOURCE_URI]).tap do |recipe|
231
- with_tdsver = FREETDS_VERSION =~ /0\.91/ ? "--with-tdsver=7.1" : "--with-tdsver=7.3"
232
- for_windows = recipe.host =~ /mswin|mingw/i
233
- recipe.configure_options << '--with-pic'
234
- recipe.configure_options << "--with-libiconv-prefix=#{libiconv.path}" if libiconv
235
- if true == libssl
236
- recipe.configure_options << "--with-openssl"
237
- elsif libssl
238
- recipe.configure_options << "--with-openssl=#{libssl.path}"
239
- end
240
- recipe.configure_options << "--with-gnutls" if gnutls
241
- recipe.configure_options << '--sysconfdir=C:\Sites' if for_windows
242
- recipe.configure_options << '--enable-sspi' if for_windows
243
- recipe.configure_options << "--disable-odbc"
244
- recipe.configure_options << with_tdsver
245
- if libiconv
246
- # For some reason freetds doesn't honor --with-libiconv-prefix
247
- # so we have do add it by hand:
248
- recipe.configure_options << "CFLAGS=-I#{libiconv.path}/include"
249
- recipe.configure_options << "LDFLAGS=-L#{libiconv.path}/lib -liconv"
250
- end
251
-
252
- class << recipe
253
-
254
- def configure
255
- cross = enable_config("cross-build")
256
- if cross
257
- prev_cc = ENV['CC']
258
- ENV['CC'] = consolidated_host(gcc_cmd) + ' -static-libgcc'
259
- end
260
- super
261
- ENV['CC'] = prev_cc if cross
262
- end
263
-
264
- def install
265
- super_value = super
266
- # Install binstub target binaries.
267
- if super_value
268
- bin_path = File.expand_path File.join(path, 'bin')
269
- exe_path = File.expand_path File.join(target, '..', 'exe')
270
- return unless File.directory?(bin_path)
271
- ['tsql', 'defncopy'].each do |bin|
272
- ['.exe', ''].each do |ext|
273
- exe = File.join bin_path, "#{bin}#{ext}"
274
- next unless File.exists?(exe)
275
- next unless File.executable?(exe)
276
- FileUtils.cp exe, exe_path
277
- end
278
- end
279
- end
280
- super_value
281
- end
282
-
283
- end
284
-
285
- end
286
- end
287
-
288
- if RbConfig::CONFIG['target_os'] =~ /mswin32|mingw32/
289
- lib_prefix = 'lib' unless RbConfig::CONFIG['target_os'] =~ /mingw32/
290
- # There's no default include/lib dir on Windows. Let's just add the Ruby ones
291
- # and resort on the search path specified by INCLUDE and LIB environment
292
- # variables
293
- HEADER_DIRS = [INCLUDEDIR]
294
- LIB_DIRS = [LIBDIR]
295
- else
296
- lib_prefix = ''
297
- HEADER_DIRS = [
298
- # First search /opt/local for macports
299
- '/opt/local/include',
300
- # Then search /usr/local for people that installed from source
301
- '/usr/local/include',
302
- # Check the ruby install locations
303
- INCLUDEDIR,
304
- # Finally fall back to /usr
305
- '/usr/include'
306
- ].reject{ |dir| !File.directory?(dir) }
307
- LIB_DIRS = [
308
- # First search /opt/local for macports
309
- '/opt/local/lib',
310
- # Then search /usr/local for people that installed from source
311
- '/usr/local/lib',
312
- # Check the ruby install locations
313
- LIBDIR,
314
- # Finally fall back to /usr
315
- '/usr/lib',
316
- ].reject{ |dir| !File.directory?(dir) }
317
- end
318
-
319
- FREETDS_HEADER_DIRS = (searchable_paths_with_directories(['include'],['include','freetds']) + HEADER_DIRS).uniq
320
- FREETDS_LIB_DIRS = (searchable_paths_with_directories(['lib'],['lib','freetds']) + LIB_DIRS).uniq
321
-
322
- # lookup over searchable paths is great for native compilation, however, when
323
- # cross compiling we need to specify our own paths.
324
- if enable_config("lookup", true)
325
- dir_config('freetds', FREETDS_HEADER_DIRS, FREETDS_LIB_DIRS)
326
- else
327
- dir_config('freetds')
328
-
329
- # remove LDFLAGS
330
- $LDFLAGS = ENV.fetch("LDFLAGS", "")
331
- end
332
-
333
- def asplode(lib)
334
- msg = "-----\n"
335
- msg << "#{lib} is missing.\n"
336
- msg << "Do you have FreeTDS 0.95.80 or higher installed?\n" if lib == 'freetds'
337
- msg << "-----"
338
- abort(msg)
339
- end
340
-
341
- def freetds_usable?(lib_prefix)
342
- have_header('sybfront.h') && have_header('sybdb.h') &&
343
- find_library("#{lib_prefix}sybdb", 'tdsdbopen') &&
344
- find_library("#{lib_prefix}sybdb", 'dbanydatecrack')
345
- end
346
-
347
- # We use freetds, when available already, and fallback to compilation of ports
348
- system_freetds = enable_config('system-freetds', ENV['TINYTDS_SKIP_PORTS'] || freetds_usable?(lib_prefix))
349
-
350
- # We expect to have iconv and OpenSSL available on non-Windows systems
351
- host = RbConfig::CONFIG["host"]
352
- system_iconv = enable_config('system-iconv', host =~ /mingw|mswin/ ? false : true)
353
- system_openssl = enable_config('system-openssl', host =~ /mingw|mswin/ ? false : true )
354
- enable_gnutls = enable_config('gnutls', false )
355
- enable_openssl = enable_config('openssl', !enable_gnutls )
356
-
357
- unless system_freetds
358
- libssl = define_libssl_recipe(host).cook_and_activate unless system_openssl
359
- libiconv = define_libiconv_recipe(host).cook_and_activate unless system_iconv
360
- freetds = define_freetds_recipe(host, libiconv, libssl || enable_openssl, enable_gnutls).cook_and_activate
361
- dir_config('freetds', freetds.path + "/include", freetds.path + "/lib")
362
- end
363
-
364
- asplode 'freetds' unless freetds_usable?(lib_prefix)
365
-
366
63
  create_makefile('tiny_tds/tiny_tds')
367
64
 
368
65
  # :startdoc: