Top Level Namespace

Includes:
RroongaBuild

Defined Under Namespace

Modules: Groonga

Instance Method Summary collapse

Instance Method Details

#build_groonga(major, minor, micro) ⇒ Object



224
225
226
227
228
229
230
# File 'ext/groonga/extconf.rb', line 224

def build_groonga(major, minor, micro)
  if RequiredGroongaVersion::RELEASED_DATE > Time.now
    build_groonga_from_git(major, minor, micro)
  else
    build_groonga_from_tar_gz(major, minor, micro)
  end
end

#build_groonga_from_git(major, minor, micro) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'ext/groonga/extconf.rb', line 177

def build_groonga_from_git(major, minor, micro)
  message("removing old cloned repository...")
  FileUtils.rm_rf("groonga")
  message(" done\n")

  run_command("cloning...",
              "git clone --depth 1 https://github.com/groonga/groonga")

  Dir.chdir("groonga") do
    run_command("running autogen.sh...",
                "./autogen.sh")
    install_for_gnu_build_system(local_groonga_install_dir)
  end

  message("removing cloned repository...")
  FileUtils.rm_rf("groonga")
  message(" done\n")
end

#build_groonga_from_tar_gz(major, minor, micro) ⇒ Object



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
222
# File 'ext/groonga/extconf.rb', line 196

def build_groonga_from_tar_gz(major, minor, micro)
  tar_gz = "groonga-#{major}.#{minor}.#{micro}.tar.gz"
  url = "http://packages.groonga.org/source/groonga/#{tar_gz}"

  download(url)

  message("extracting...")
  if xsystem("tar xfz #{tar_gz}")
    message(" done\n")
  else
    message(" failed\n")
    exit(false)
  end

  groonga_source_dir = "groonga-#{major}.#{minor}.#{micro}"
  Dir.chdir(groonga_source_dir) do
    install_for_gnu_build_system(local_groonga_install_dir)
  end

  message("removing source...")
  FileUtils.rm_rf(groonga_source_dir)
  message(" done\n")

  message("removing source archive...")
  FileUtils.rm_rf(tar_gz)
  message(" done\n")
end

#configure_command_line(prefix) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'ext/groonga/extconf.rb', line 154

def configure_command_line(prefix)
  command_line = ["./configure"]
  debug_build_p = ENV["RROONGA_DEBUG_BUILD"] == "yes"
  debug_flags = ["CFLAGS=-g3 -O0", "CXXFLAGS=-g3 -O0"]
  command_line.concat(debug_flags) if debug_build_p
  command_line << "--prefix=#{prefix}"
  command_line << "--disable-static"
  command_line << "--disable-document"
  escaped_command_line = command_line.collect do |command|
    Shellwords.escape(command)
  end
  escaped_command_line.join(" ")
end

#disable_optimization_build_flag(flags) ⇒ Object



276
277
278
279
280
281
282
# File 'ext/groonga/extconf.rb', line 276

def disable_optimization_build_flag(flags)
  if gcc?
    flags.gsub(/(^|\s)?-O\d(\s|$)?/, '\\1-O0\\2')
  else
    flags
  end
end

#download(url) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'ext/groonga/extconf.rb', line 85

def download(url)
  message("downloading %s...", url)
  base_name = File.basename(url)
  if File.exist?(base_name)
    message(" skip (use downloaded file)\n")
  else
    open(url, "rb") do |input|
      File.open(base_name, "wb") do |output|
        while (buffer = input.read(1024))
          output.print(buffer)
        end
      end
    end
    message(" done\n")
  end
end

#enable_debug_build_flag(flags) ⇒ Object



284
285
286
287
288
289
290
# File 'ext/groonga/extconf.rb', line 284

def enable_debug_build_flag(flags)
  if gcc?
    flags.gsub(/(^|\s)?-g\d?(\s|$)?/, '\\1-ggdb3\\2')
  else
    flags
  end
end

#extract_groonga_win32_binary(major, minor, micro) ⇒ Object



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

def extract_groonga_win32_binary(major, minor, micro)
  if ENV["RROONGA_USE_GROONGA_X64"]
    architecture = "x64"
  else
    architecture = "x86"
  end
  zip = "groonga-#{major}.#{minor}.#{micro}-#{architecture}.zip"
  url = "http://packages.groonga.org/windows/groonga/#{zip}"
  install_dir = local_groonga_install_dir

  download(url)

  message("extracting...")
  extract_zip(zip, ".")
  message(" done\n")

  if File.exist?(install_dir)
    message("removing old install... #{install_dir}")
    FileUtils.rm_rf(install_dir)
    message(" done\n")
  end

  message("installing...")
  FileUtils.mv(File.basename(zip, ".zip"), install_dir)
  message(" done\n")

  message("removing binary archive...")
  FileUtils.rm_rf(zip)
  message(" done\n")
end

#extract_zip(filename, destrination_dir) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'ext/groonga/extconf.rb', line 102

def extract_zip(filename, destrination_dir)
  begin
    require "archive/zip"
  rescue LoadError
    require "rubygems"
    require "archive/zip"
  end

  Archive::Zip.extract(filename, destrination_dir)
end

#gcc?Boolean

Returns:

  • (Boolean)


272
273
274
# File 'ext/groonga/extconf.rb', line 272

def gcc?
  CONFIG["GCC"] == "yes"
end

#install_for_gnu_build_system(install_dir) ⇒ Object



168
169
170
171
172
173
174
175
# File 'ext/groonga/extconf.rb', line 168

def install_for_gnu_build_system(install_dir)
  run_command("configuring...",
              configure_command_line(install_dir))
  run_command("building (maybe long time)...",
              "make")
  run_command("installing...",
              "make install")
end

#install_groonga_locally(major, minor, micro) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'ext/groonga/extconf.rb', line 71

def install_groonga_locally(major, minor, micro)
  FileUtils.mkdir_p(local_groonga_base_dir)

  Dir.chdir(local_groonga_base_dir) do
    if win32?
      extract_groonga_win32_binary(major, minor, micro)
    else
      build_groonga(major, minor, micro)
    end
  end

  prepend_pkg_config_path_for_local_groonga
end

#run_command(start_message, command) ⇒ Object



144
145
146
147
148
149
150
151
152
# File 'ext/groonga/extconf.rb', line 144

def run_command(start_message, command)
  message(start_message)
  if xsystem(command)
    message(" done\n")
  else
    message(" failed\n")
    exit(false)
  end
end

#win32?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'ext/groonga/extconf.rb', line 52

def win32?
  /cygwin|mingw|mswin/ =~ RUBY_PLATFORM
end