1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
require 'mkmf'
# Available options:
#
# --enable-clean (default)
# --disable-clean
#
# This file is largely based on Nokogiri's extconf.rb.
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
if arg_config('--clean')
require 'pathname'
require 'fileutils'
root = Pathname(ROOT)
pwd = Pathname(Dir.pwd)
# Skip if this is a development work tree
unless (root + '.git').exist?
message "Cleaning files only used during build.\n"
# (root + 'tmp') cannot be removed at this stage because
# gpgme_n.so is yet to be copied to lib.
# clean the ports build directory
Pathname.glob(pwd.join('tmp', '*', 'ports')) { |dir|
FileUtils.rm_rf(dir, { :verbose => true })
FileUtils.rmdir(dir.parent, { :parents => true, :verbose => true })
}
# ports installation can be safely removed if statically linked.
FileUtils.rm_rf(root + 'ports', { :verbose => true })
end
exit
end
if arg_config('--use-system-libraries', ENV['RUBY_GPGME_USE_SYSTEM_LIBRARIES'])
unless find_executable('gpgme-config')
$stderr.puts("gpgme-config not found")
exit(1)
end
$CFLAGS += ' ' << `gpgme-config --cflags`.chomp
$libs += ' ' << `gpgme-config --libs`.chomp
else
message <<-'EOS'
************************************************************************
IMPORTANT! gpgme gem uses locally built versions of required C libraries,
namely libgpg-error, libassuan, and gpgme.
If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall gpgme gem as
follows:
gem install gpgme -- --use-system-libraries
************************************************************************
EOS
require 'rubygems'
require 'mini_portile'
libgpg_error_recipe = MiniPortile.new('libgpg-error', '1.12').tap do |recipe|
recipe.target = File.join(ROOT, "ports")
recipe.files = ["ftp://ftp.gnupg.org/gcrypt/#{recipe.name}/#{recipe.name}-#{recipe.version}.tar.bz2"]
recipe.configure_options = [
'--disable-shared',
'--enable-static',
'--disable-nls',
"CFLAGS='-fPIC #{ENV["CFLAGS"]}'",
]
checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
FileUtils.touch checkpoint
end
recipe.activate
end
libassuan_recipe = MiniPortile.new('libassuan', '2.1.1').tap do |recipe|
recipe.target = File.join(ROOT, "ports")
recipe.files = ["ftp://ftp.gnupg.org/gcrypt/#{recipe.name}/#{recipe.name}-#{recipe.version}.tar.bz2"]
recipe.configure_options = [
'--disable-shared',
'--enable-static',
"--with-gpg-error-prefix=#{libgpg_error_recipe.path}",
"CFLAGS='-fPIC #{ENV["CFLAGS"]}'",
]
checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
FileUtils.touch checkpoint
end
recipe.activate
end
gpgme_recipe = MiniPortile.new('gpgme', '1.4.3').tap do |recipe|
recipe.target = File.join(ROOT, "ports")
recipe.files = ["ftp://ftp.gnupg.org/gcrypt/#{recipe.name}/#{recipe.name}-#{recipe.version}.tar.bz2"]
recipe.configure_options = [
'--disable-shared',
'--enable-static',
"--with-gpg-error-prefix=#{libgpg_error_recipe.path}",
"--with-libassuan-prefix=#{libassuan_recipe.path}",
"CFLAGS='-fPIC #{ENV["CFLAGS"]}'",
]
checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
FileUtils.touch checkpoint
end
recipe.activate
end
# special treatment to link with static libraries
$libs = $libs.shellsplit.tap {|libs|
File.join(gpgme_recipe.path, "bin", "gpgme-config").tap {|config|
# call config scripts explicit with 'sh' for compat with Windows
$CPPFLAGS = `sh #{config} --cflags`.strip << ' ' << $CPPFLAGS
`sh #{config} --libs`.strip.shellsplit.each {|arg|
case arg
when /\A-L(.+)\z/
lpath=$1
# Prioritize ports' directories
if lpath.start_with?(ROOT + '/')
$LIBPATH = [lpath] | $LIBPATH
else
$LIBPATH = $LIBPATH | [lpath]
end
when /\A-l./
libs.push(arg)
else
$LDFLAGS << ' ' << arg.shellescape
end
}
}
}.shelljoin
message 'checking for linker flags for static linking... '
case
when try_link('int main(void) { return 0; }',
['-Wl,-Bstatic', '-lgpgme', '-Wl,-Bdynamic'].shelljoin)
message "-Wl,-Bstatic\n"
$libs = $libs.shellsplit.map {|arg|
case arg
when '-lgpgme', '-lassuan', '-lgpg-error'
['-Wl,-Bstatic', arg, '-Wl,-Bdynamic']
else
arg
end
}.flatten.shelljoin
else
message "NONE\n"
end
unless have_header 'gpgme.h'
abort <<-EOS
************************************************************************
ERROR! Cannot locate 'gpgme.h'.
************************************************************************
EOS
end
end
checking_for('gpgme >= 1.1.3') do
if try_run(<<'End')
#include <gpgme.h>
#include <stdlib.h>
int main (void) {
return gpgme_check_version ("1.1.3") == NULL;
}
End
true
else
$CFLAGS += ' -DRUBY_GPGME_NEED_WORKAROUND_KEYLIST_NEXT'
false
end
end
have_func('gpgme_op_export_keys')
create_makefile ('gpgme_n')
if enable_config('clean', true)
# Do not clean if run in a development work tree.
File.open('Makefile', 'a') { |mk|
mk.print <<EOF
all: clean-ports
clean-ports: $(DLLIB)
-$(Q)$(RUBY) $(srcdir)/extconf.rb --clean
EOF
}
end
|