Top Level Namespace

Defined Under Namespace

Modules: Nokogiri, XMLSec, Xmlsec

Constant Summary collapse

ROOT =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))

Instance Method Summary collapse

Instance Method Details

#asplode(lib) ⇒ Object



17
18
19
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 17

def asplode(lib)
  abort "-----\n#{lib} is missing."
end

#do_cleanObject



50
51
52
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 50

def do_clean
  exit! 0
end

#do_helpObject



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
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 21

def do_help
  print <<HELP
usage: ruby #{$0} [options]

    --disable-static
        Do not statically link bundled libraries.

    --with-iconv-dir=DIR
        Use the iconv library placed under DIR.

    --with-zlib-dir=DIR
        Use the zlib library placed under DIR.

    --use-system-libraries
        Use system libraries intead of building and using the bundled
        libraries.

    --with-xmlsec1-dir=DIR / --with-xmlsec1-config=CONFIG
    --with-xml2-dir=DIR / --with-xml2-config=CONFIG
    --with-xslt-dir=DIR / --with-xslt-config=CONFIG
    --with-exslt-dir=DIR / --with-exslt-config=CONFIG
        Use xmlsec1/libxml2/libxslt/libexslt as specified.

    --enable-cross-build
        Do cross-build.
HELP
  exit! 0
end

#each_iconv_idir {|"/usr/include"| ... } ⇒ Object

Yields:

  • ("/usr/include")


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 76

def each_iconv_idir
  # If --with-iconv-dir or --with-opt-dir is given, it should be
  # the first priority
  %w[iconv opt].each { |config|
    idir = preserving_globals {
      dir_config(config)
    }.first and yield idir
  }

  # Try the system default
  yield "/usr/include"

  cflags, = preserving_globals {
    pkg_config('libiconv')
  }
  if cflags
    cflags.shellsplit.each { |arg|
      arg.sub!(/\A-I/, '') and
      yield arg
    }
  end

  nil
end

#have_iconv?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 68

def have_iconv?
  have_header('iconv.h') or return false
  %w{ iconv_open libiconv_open }.any? do |method|
    have_func(method, 'iconv.h') or
      have_library('iconv', method, 'iconv.h')
  end
end

#iconv_prefixObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 101

def iconv_prefix
  # Make sure libxml2 is built with iconv
  each_iconv_idir { |idir|
    next unless File.file?(File.join(idir, 'iconv.h'))

    prefix, dir = File.split(idir)
    next unless dir == 'include'

    preserving_globals {
      # Follow the way libxml2's configure uses a value given with
      # --with-iconv[=DIR]
      $CPPFLAGS = "-I#{idir}".quote << ' ' << $CPPFLAGS
      $LIBPATH.unshift(File.join(prefix, "lib"))
      have_iconv?
    } and break prefix
  } or asplode "libiconv"
end

#lib_a(ldflag) ⇒ Object

functions



10
11
12
13
14
15
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 10

def lib_a(ldflag)
  case ldflag
  when /\A-l(.+)/
    "lib#{$1}.#{$LIBEXT}"
  end
end

#message!(important_message) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 119

def message!(important_message)
  message important_message
  if !$stdout.tty? && File.chardev?('/dev/tty')
    File.open('/dev/tty', 'w') { |tty|
      tty.print important_message
    }
  end
rescue Errno::ENXIO
end

#monkey_patch_mini_portileObject

Workaround for nokogiri issue #1102



224
225
226
227
228
229
230
231
232
233
234
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 224

def monkey_patch_mini_portile
  MiniPortile.class_eval do
    def patch
      @patch_files.each do |full_path|
        next unless File.exists?(full_path)
        output "Running patch with #{full_path}..."
        execute('patch', %Q(patch -p1 < #{full_path}))
      end
    end
  end
end

#preserving_globalsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 54

def preserving_globals
  values = [
    $arg_config,
    $CFLAGS, $CPPFLAGS,
    $LDFLAGS, $LIBPATH, $libs
  ].map(&:dup)
  yield
ensure
  $arg_config,
  $CFLAGS, $CPPFLAGS,
  $LDFLAGS, $LIBPATH, $libs =
    values
end

#process_recipe(name, version, static_p, cross_p) ⇒ Object



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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/nokogiri_ext_xmlsec/extconf.rb', line 129

def process_recipe(name, version, static_p, cross_p)
  MiniPortile.new(name, version).tap do |recipe|
    recipe.target = portsdir = File.join(ROOT, "ports")
    # Prefer host_alias over host in order to use i586-mingw32msvc as
    # correct compiler prefix for cross build, but use host if not set.
    recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
    recipe.patch_files = Dir[File.join(portsdir, "patches", name, "*.patch")].sort

    yield recipe

    env = Hash.new { |hash, key|
      hash[key] = "#{ENV[key]}"  # (ENV[key].dup rescue '')
    }

    recipe.configure_options.flatten!

    recipe.configure_options.delete_if { |option|
      case option.shellsplit.first
      when /\A(\w+)=(.*)\z/
        env[$1] = $2
        true
      else
        false
      end
    }

    if static_p
      recipe.configure_options += [
        "--disable-shared",
        "--enable-static",
      ]
      env['CFLAGS'] = "-fPIC #{env['CFLAGS']}"
    else
      recipe.configure_options += [
        "--enable-shared",
        "--disable-static",
      ]
    end

    if cross_p
      recipe.configure_options += [
        "--target=#{recipe.host}",
        "--host=#{recipe.host}",
      ]
    end

    if RbConfig::CONFIG['target_cpu'] == 'universal'
      %w[CFLAGS LDFLAGS].each { |key|
        unless env[key].shellsplit.include?('-arch')
          env[key] << ' ' << RbConfig::CONFIG['ARCH_FLAG']
        end
      }
    end

    recipe.configure_options += env.map { |key, value|
      "#{key}=#{value}".shellescape
    }

    if recipe.patch_files.empty?
      message! "Building #{name}-#{version} for nokogiri-xmlsec1.\n"
    else
      message! "Building #{name}-#{version} for nokogiri-xmlsec1 with the following patches applied:\n"

      recipe.patch_files.each { |patch|
        message! "\t- %s\n" % File.basename(patch)
      }
    end

    message! <<-"EOS"
************************************************************************
IMPORTANT! nokogiri-xmlsec1 builds and uses a packaged version of #{name}.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri-xmlsec1
as follows:

    gem install nokogiri-xmlsec1 -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri-xmlsec1 --use-system-libraries
    bundle install
************************************************************************
    EOS

    checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
    unless File.exist?(checkpoint)
      recipe.cook
      FileUtils.touch checkpoint
    end
    recipe.activate
  end
end