glib2 3.3.8 → 3.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,470 +1,18 @@
1
+ # Copyright (C) 2019 Ruby-GNOME Project Team
1
2
  #
2
- # mkmf-gnome2.rb
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
3
7
  #
4
- # Extended mkmf for Ruby-GNOME2 and Ruby/GLib based libraries.
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
5
12
  #
6
- # Copyright(C) 2003-2015 Ruby-GNOME2 Project.
7
- #
8
- # This program is licenced under the same
9
- # license of Ruby-GNOME2.
10
- #
11
-
12
- require 'English'
13
- require 'mkmf'
14
- require 'pkg-config'
15
- require 'glib-mkenums'
16
- require "native-package-installer"
17
-
18
- $CFLAGS += " #{ENV['CFLAGS']}" if ENV['CFLAGS']
19
-
20
- def gcc?
21
- CONFIG["GCC"] == "yes"
22
- end
23
-
24
- def disable_optimization_build_flag(flags)
25
- if gcc?
26
- RbConfig.expand(flags.dup).gsub(/(^|\s)?-O\d(\s|$)?/, '\\1-O0\\2')
27
- else
28
- flags
29
- end
30
- end
31
-
32
- def enable_debug_build_flag(flags)
33
- if gcc?
34
- expanded_flags = RbConfig.expand(flags.dup)
35
- debug_option_pattern = /(^|\s)-g\d?(\s|$)/
36
- if debug_option_pattern =~ expanded_flags
37
- expanded_flags.gsub(debug_option_pattern, '\\1-g3\\2')
38
- else
39
- flags + " -g3"
40
- end
41
- else
42
- flags
43
- end
44
- end
45
-
46
- checking_for(checking_message("--enable-debug-build option")) do
47
- enable_debug_build = enable_config("debug-build", false)
48
- if enable_debug_build
49
- $CFLAGS = disable_optimization_build_flag($CFLAGS)
50
- $CFLAGS = enable_debug_build_flag($CFLAGS)
51
-
52
- $CXXFLAGS = disable_optimization_build_flag($CXXFLAGS)
53
- $CXXFLAGS = enable_debug_build_flag($CXXFLAGS)
54
- end
55
- enable_debug_build
56
- end
57
-
58
- def try_compiler_option(opt, &block)
59
- checking_for "#{opt} option to compiler" do
60
- if try_compile '', opt + " -Werror", &block
61
- $CFLAGS += " #{opt}"
62
- true
63
- else
64
- false
65
- end
66
- end
67
- end
68
-
69
- try_compiler_option '-Wall'
70
- try_compiler_option '-Waggregate-return'
71
- try_compiler_option '-Wcast-align'
72
- # NOTE: Generates way too many false positives.
73
- # try_compiler_option '-Wconversion'
74
- try_compiler_option '-Wextra'
75
- try_compiler_option '-Wformat=2'
76
- try_compiler_option '-Winit-self'
77
- # NOTE: This generates warnings for functions defined in ruby.h.
78
- # try_compiler_option '-Winline'
79
- try_compiler_option '-Wlarger-than-65500'
80
- try_compiler_option '-Wmissing-declarations'
81
- try_compiler_option '-Wmissing-format-attribute'
82
- try_compiler_option '-Wmissing-include-dirs'
83
- try_compiler_option '-Wmissing-noreturn'
84
- try_compiler_option '-Wmissing-prototypes'
85
- try_compiler_option '-Wnested-externs'
86
- try_compiler_option '-Wold-style-definition'
87
- try_compiler_option '-Wpacked'
88
- try_compiler_option '-Wp,-D_FORTIFY_SOURCE=2'
89
- try_compiler_option '-Wpointer-arith'
90
- # NOTE: ruby.h and intern.h have too many of these.
91
- # try_compiler_option '-Wredundant-decls'
92
- # NOTE: Complains about index, for example.
93
- # try_compiler_option '-Wshadow'
94
- try_compiler_option '-Wswitch-default'
95
- try_compiler_option '-Wswitch-enum'
96
- try_compiler_option '-Wundef'
97
- # NOTE: Incredible amounts of false positives.
98
- #try_compiler_option '-Wunreachable-code'
99
- try_compiler_option '-Wout-of-line-declaration'
100
- try_compiler_option '-Wunsafe-loop-optimizations'
101
- try_compiler_option '-Wwrite-strings'
102
-
103
- if /-Wl,--no-undefined/ =~ $LDFLAGS.to_s
104
- $LDFLAGS.gsub!(/-Wl,--no-undefined/, '')
105
- end
106
-
107
- include_path = nil
108
- if ENV['GTK_BASEPATH'] and /cygwin/ !~ RUBY_PLATFORM
109
- include_path = (ENV['GTK_BASEPATH'] + "\\INCLUDE").gsub("\\", "/")
110
- # $hdrdir += " -I#{include_path} "
111
- $INCFLAGS += " -I#{include_path} "
112
- end
113
-
114
- def windows_platform?
115
- /cygwin|mingw|mswin/ === RUBY_PLATFORM
116
- end
117
-
118
- # For backward compatibility
119
- def setup_windows(target_name, base_dir=nil)
120
- checking_for(checking_message("Windows")) do
121
- windows_platform?
122
- end
123
- end
124
- # For backward compatibility
125
- def setup_win32(*args, &block)
126
- setup_windows(*args, &block)
127
- end
128
-
129
- def find_gem_spec(package)
130
- begin
131
- Gem::Specification.find_by_name(package)
132
- rescue LoadError
133
- nil
134
- end
135
- end
136
-
137
- def setup_homebrew
138
- checking_for(checking_message("Homebrew")) do
139
- platform = NativePackageInstaller::Platform.detect
140
- if platform.is_a?(NativePackageInstaller::Platform::Homebrew)
141
- libffi_prefix = `brew --prefix libffi`.chomp
142
- PKGConfig.add_path("#{libffi_prefix}/lib/pkgconfig")
143
- true
144
- else
145
- false
146
- end
147
- end
148
- end
149
-
150
- setup_homebrew
151
-
152
- #add_depend_package("glib2", "ext/glib2", "/...../ruby-gnome2")
153
- def add_depend_package(target_name, target_srcdir, top_srcdir, options={})
154
- gem_spec = find_gem_spec(target_name)
155
- if gem_spec
156
- target_source_dir = File.join(gem_spec.full_gem_path, "ext/#{target_name}")
157
- target_build_dir = target_source_dir
158
- add_depend_package_path(target_name,
159
- target_source_dir,
160
- target_build_dir)
161
- end
162
-
163
- [top_srcdir,
164
- File.join(top_srcdir, target_name),
165
- $configure_args['--topdir'],
166
- File.join($configure_args['--topdir'], target_name)].each do |topdir|
167
- topdir = File.expand_path(topdir)
168
- target_source_dir_full_path = File.join(topdir, target_srcdir)
169
-
170
- top_build_dir = options[:top_build_dir] || topdir
171
- target_build_dir = options[:target_build_dir] || target_srcdir
172
- target_build_dir_full_path = File.join(top_build_dir, target_build_dir)
173
- unless File.exist?(target_build_dir_full_path)
174
- target_build_dir_full_path = File.join(top_build_dir, target_srcdir)
175
- end
176
- unless File.exist?(target_build_dir_full_path)
177
- target_build_dir_full_path = File.join(topdir, target_build_dir)
178
- end
179
- unless File.exist?(target_build_dir_full_path)
180
- target_build_dir_full_path = File.join(topdir, target_srcdir)
181
- end
182
- add_depend_package_path(target_name,
183
- target_source_dir_full_path,
184
- target_build_dir_full_path)
185
- end
186
- end
187
-
188
- def add_depend_package_path(target_name, target_source_dir, target_build_dir)
189
- if File.exist?(target_source_dir)
190
- $INCFLAGS = "-I#{target_source_dir} #{$INCFLAGS}"
191
- end
192
-
193
- return unless File.exist?(target_build_dir)
194
- if target_source_dir != target_build_dir
195
- $INCFLAGS = "-I#{target_build_dir} #{$INCFLAGS}"
196
- end
197
-
198
- library_base_name = target_name.gsub(/-/, "_")
199
- case RUBY_PLATFORM
200
- when /cygwin|mingw/
201
- $libs << " " << File.join(target_build_dir, "#{library_base_name}.so")
202
- when /mswin/
203
- $DLDFLAGS << " /libpath:#{target_build_dir}"
204
- $libs << " #{library_base_name}-$(arch).lib"
205
- end
206
- end
207
-
208
- def add_distcleanfile(file)
209
- $distcleanfiles ||= []
210
- $distcleanfiles << file
211
- end
212
-
213
- def create_pkg_config_file(package_name, c_package,
214
- version=nil, pc_file_name=nil)
215
- pc_file_name ||= "#{package_name.downcase.sub(/\//, '-')}.pc"
216
- version ||= ruby_gnome2_version || PKGConfig.modversion(c_package)
217
-
218
- puts "creating #{pc_file_name}"
219
-
220
- File.open(pc_file_name, 'w') do |pc_file|
221
- if package_name.nil?
222
- c_module_name = PKGConfig.name(c_package)
223
- package_name = "Ruby/#{c_module_name}" if c_module_name
224
- end
225
- pc_file.puts("Name: #{package_name}") if package_name
226
-
227
- description = PKGConfig.description(c_package)
228
- pc_file.puts("Description: Ruby bindings for #{description}") if description
229
- pc_file.printf("Version: #{version}")
230
- end
231
-
232
- add_distcleanfile(pc_file_name)
233
- end
234
-
235
- def ruby_gnome2_version(glib_source_directory=nil)
236
- glib_source_directory ||= File.join(File.dirname(__FILE__), "..",
237
- "ext", "glib2")
238
- rbglib_h = File.join(glib_source_directory, "rbglib.h")
239
- return nil unless File.exist?(rbglib_h)
240
-
241
- version = nil
242
- File.open(rbglib_h) do |h_file|
243
- version_info = {}
244
- h_file.each_line do |line|
245
- case line
246
- when /\A#define RBGLIB_(MAJOR|MINOR|MICRO)_VERSION\s+(\d+)/
247
- version_info[$1] = $2
248
- end
249
- end
250
- version_info = [version_info["MAJOR"],
251
- version_info["MINOR"],
252
- version_info["MICRO"]].compact
253
- version = version_info.join(".") if version_info.size == 3
254
- end
255
-
256
- version
257
- end
258
-
259
- def ensure_objs
260
- return unless $objs.nil?
261
-
262
- source_dir = '$(srcdir)'
263
- RbConfig.expand(source_dir)
264
-
265
- pattern = "*.{#{SRC_EXT.join(',')}}"
266
- srcs = Dir[File.join(source_dir, pattern)]
267
- srcs |= Dir[File.join(".", pattern)]
268
- $objs = srcs.collect do |f|
269
- File.basename(f, ".*") + ".o"
270
- end.uniq
271
- end
272
-
273
- def create_makefile_at_srcdir(pkg_name, srcdir, defs = nil)
274
- base_dir = File.basename(Dir.pwd)
275
- last_common_index = srcdir.rindex(base_dir)
276
- if last_common_index
277
- builddir = srcdir[(last_common_index + base_dir.size + 1)..-1]
278
- end
279
- builddir ||= "."
280
- FileUtils.mkdir_p(builddir)
281
-
282
- Dir.chdir(builddir) do
283
- yield if block_given?
284
-
285
- $defs << defs if defs
286
- ensure_objs
287
- create_makefile(pkg_name, srcdir)
288
- end
289
- end
290
-
291
- def run_make_in_sub_dirs_command(command, sub_dirs)
292
- if /mswin/ =~ RUBY_PLATFORM
293
- sub_dirs.collect do |dir|
294
- <<-EOM.chmop
295
- @cd #{dir}
296
- @nmake -nologo DESTDIR=$(DESTDIR) #{command}
297
- @cd ..
298
- EOM
299
- end.join("\n")
300
- else
301
- sub_dirs.collect do |dir|
302
- "\t@cd #{dir}; $(MAKE) #{command}"
303
- end.join("\n")
304
- end
305
- end
306
-
307
- def create_top_makefile(sub_dirs=["src"])
308
- File.open("Makefile", "w") do |makefile|
309
- makefile.print(<<-EOM)
310
- all:
311
- #{run_make_in_sub_dirs_command("all", sub_dirs)}
312
-
313
- install:
314
- #{run_make_in_sub_dirs_command("install", sub_dirs)}
315
-
316
- site-install:
317
- #{run_make_in_sub_dirs_command("site-install", sub_dirs)}
318
-
319
- clean:
320
- #{run_make_in_sub_dirs_command("clean", sub_dirs)}
321
- EOM
322
-
323
- if /mswin/ =~ RUBY_PLATFORM
324
- makefile.print(<<-EOM)
325
- @if exist extconf.h del extconf.h
326
- @if exist conftest.* del conftest.*
327
- @if exist *.lib del *.lib
328
- @if exist *~ del *~
329
- @if exist mkmf.log del mkmf.log
330
- EOM
331
- else
332
- makefile.print(<<-EOM)
333
-
334
- distclean: clean
335
- #{run_make_in_sub_dirs_command("distclean", sub_dirs)}
336
- @rm -f Makefile extconf.h conftest.*
337
- @rm -f core *~ mkmf.log
338
- EOM
339
- end
340
- end
341
- end
342
-
343
- # This is used for the library which doesn't support version info.
344
- def make_version_header(app_name, pkgname, dir = "src")
345
- version = PKGConfig.modversion(pkgname).split(/\./)
346
- (0..2).each do |v|
347
- version[v] = "0" unless version[v]
348
- if /\A(\d+)/ =~ version[v]
349
- number = $1
350
- tag = $POSTMATCH
351
- unless tag.empty?
352
- version[v] = number
353
- version[3] = tag
354
- end
355
- end
356
- end
357
- filename = "rb#{app_name.downcase}version.h"
358
-
359
- puts "creating #{filename}"
360
-
361
- add_distcleanfile(filename)
362
-
363
- FileUtils.mkdir_p(dir)
364
- out = File.open(File.join(dir, filename), "w")
365
-
366
- version_definitions = []
367
- ["MAJOR", "MINOR", "MICRO", "TAG"].each_with_index do |type, i|
368
- _version = version[i]
369
- next if _version.nil?
370
- version_definitions << "#define #{app_name}_#{type}_VERSION (#{_version})"
371
- end
372
- out.print %Q[/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
373
- /************************************************
374
-
375
- #{filename} -
376
-
377
- This file was generated by mkmf-gnome2.rb.
378
-
379
- ************************************************/
380
-
381
- #ifndef __RB#{app_name}_VERSION_H__
382
- #define __RB#{app_name}_VERSION_H__
383
-
384
- #{version_definitions.join("\n")}
385
-
386
- #define #{app_name}_CHECK_VERSION(major,minor,micro) \\
387
- (#{app_name}_MAJOR_VERSION > (major) || \\
388
- (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION > (minor)) || \\
389
- (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION == (minor) && \\
390
- #{app_name}_MICRO_VERSION >= (micro)))
391
-
392
-
393
- #endif /* __RB#{app_name}_VERSION_H__ */
394
- ]
395
- out.close
396
- end
397
-
398
- def add_obj(name)
399
- ensure_objs
400
- $objs << name unless $objs.index(name)
401
- end
402
-
403
- def glib_mkenums(prefix, files, g_type_prefix, include_files, options={})
404
- add_distcleanfile(prefix + ".h")
405
- add_distcleanfile(prefix + ".c")
406
- GLib::MkEnums.create(prefix, files, g_type_prefix, include_files, options)
407
- add_obj("#{prefix}.o")
408
- end
409
-
410
- def check_cairo(options={})
411
- rcairo_source_dir = options[:rcairo_source_dir]
412
- if rcairo_source_dir.nil?
413
- rcairo_source_base_dir = "rcairo"
414
- top_dir = options[:top_dir]
415
- if top_dir
416
- rcairo_source_dir = File.join(top_dir, "..", rcairo_source_base_dir)
417
- end
418
- end
419
-
420
- if rcairo_source_dir and !File.exist?(rcairo_source_dir)
421
- rcairo_source_dir = nil
422
- end
423
- if rcairo_source_dir.nil?
424
- cairo_gem_spec = find_gem_spec("cairo")
425
- rcairo_source_dir = cairo_gem_spec.full_gem_path if cairo_gem_spec
426
- end
427
-
428
- unless rcairo_source_dir.nil?
429
- options = {}
430
- build_dir = "tmp/#{RUBY_PLATFORM}/cairo/#{RUBY_VERSION}"
431
- if File.exist?(File.join(rcairo_source_dir, build_dir))
432
- options[:target_build_dir] = build_dir
433
- end
434
- add_depend_package("cairo", "ext/cairo", rcairo_source_dir, options)
435
- end
436
-
437
- PKGConfig.have_package("cairo") and have_header("rb_cairo.h")
438
- end
439
-
440
- def install_missing_native_package(native_package_info)
441
- NativePackageInstaller.install(native_package_info)
442
- end
443
-
444
- def required_pkg_config_package(package_info, native_package_info=nil)
445
- if package_info.is_a?(Array)
446
- required_package_info = package_info
447
- else
448
- required_package_info = [package_info]
449
- end
450
- return true if PKGConfig.have_package(*required_package_info)
451
-
452
- native_package_info ||= {}
453
- return false unless install_missing_native_package(native_package_info)
454
-
455
- PKGConfig.have_package(*required_package_info)
456
- end
457
-
458
- add_include_path = Proc.new do |dir_variable|
459
- value = RbConfig::CONFIG[dir_variable]
460
- if value and File.exist?(value)
461
- $INCFLAGS << " -I$(#{dir_variable}) "
462
- end
463
- end
464
-
465
- add_include_path.call("sitearchdir")
466
- add_include_path.call("vendorarchdir")
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
467
16
 
468
- if /mingw/ =~ RUBY_PLATFORM
469
- $ruby.gsub!('\\', '/')
470
- end
17
+ warn("mkmf-gnome2 is deprecated. Use mkmf-gnome instead.")
18
+ require "mkmf-gnome"