Top Level Namespace
Defined Under Namespace
Constant Summary collapse
- FileMagic =
Magic
- LIBMAGIC_TAG =
'5.39'
- LIBIMAGE_SHA256 =
'f05d286a76d9556243d0cb05814929c2ecf3a5ba07963f8f70bfaaa70517fad1'
- PACKAGE_ROOT_DIR =
helpful constants
File.(File.join(File.dirname(__FILE__), '..', '..'))
- REQUIRED_MINI_PORTILE_VERSION =
The gem version constraint in the Rakefile is not respected at install time. Keep this version in sync with the one in the Rakefile !
"~> 2.5.0"
- MAGIC_HELP_MESSAGE =
<<~HELP USAGE: ruby #{$0} [options] Flags that are always valid: --use-system-libraries --enable-system-libraries Use system libraries instead of building and using the packaged libraries. --disable-system-libraries Use the packaged libraries, and ignore the system libraries. This is the default on most platforms, and overrides `--use-system-libraries` and the environment variable `RB_MAGIC_USE_SYSTEM_LIBRARIES`. --disable-clean Do not clean out intermediate files after successful build. Flags only used when building and using the packaged libraries: --disable-static Do not statically link packaged libraries, instead use shared libraries. --enable-cross-build Enable cross-build mode. (You probably do not want to set this manually.) Flags only used when using system libraries: Related to libmagic: --with-magic-dir=DIRECTORY Look for libmagic headers and library in DIRECTORY. --with-magic-lib=DIRECTORY Look for libmagic library in DIRECTORY. --with-magic-include=DIRECTORY Look for libmagic headers in DIRECTORY. Environment variables used: CC Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']` CPPFLAGS If this string is accepted by the C preprocessor, add it to the flags passed to the C preprocessor CFLAGS If this string is accepted by the compiler, add it to the flags passed to the compiler LDFLAGS If this string is accepted by the linker, add it to the flags passed to the linker LIBS Add this string to the flags passed to the linker HELP
Instance Method Summary collapse
- #concat_flags(*args) ⇒ Object
-
#config_clean? ⇒ Boolean
utility functions.
- #config_cross_build? ⇒ Boolean
- #config_static? ⇒ Boolean
- #config_system_libraries? ⇒ Boolean
- #darwin? ⇒ Boolean
- #do_clean ⇒ Object
- #do_help ⇒ Object
- #process_recipe(name, version, static_p, cross_p) ⇒ Object
- #truffle? ⇒ Boolean
- #windows? ⇒ Boolean
Instance Method Details
#concat_flags(*args) ⇒ Object
163 164 165 |
# File 'ext/magic/extconf.rb', line 163 def concat_flags(*args) args.compact.join(" ") end |
#config_clean? ⇒ Boolean
utility functions
132 133 134 |
# File 'ext/magic/extconf.rb', line 132 def config_clean? enable_config('clean', true) end |
#config_cross_build? ⇒ Boolean
141 142 143 |
# File 'ext/magic/extconf.rb', line 141 def config_cross_build? enable_config("cross-build") end |
#config_static? ⇒ Boolean
136 137 138 139 |
# File 'ext/magic/extconf.rb', line 136 def config_static? default_static = !truffle? enable_config("static", default_static) end |
#config_system_libraries? ⇒ Boolean
145 146 147 148 149 |
# File 'ext/magic/extconf.rb', line 145 def config_system_libraries? enable_config("system-libraries", ENV.key?("RB_MAGIC_USE_SYSTEM_LIBRARIES")) do |_, default| arg_config('--use-system-libraries', default) end end |
#darwin? ⇒ Boolean
151 152 153 |
# File 'ext/magic/extconf.rb', line 151 def darwin? RbConfig::CONFIG['target_os'] =~ /darwin/ end |
#do_clean ⇒ Object
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 |
# File 'ext/magic/extconf.rb', line 172 def do_clean root = Pathname(PACKAGE_ROOT_DIR) pwd = Pathname(Dir.pwd) # Skip if this is a development work tree unless (root + '.git').exist? ("Cleaning files only used during build.\n") # (root + 'tmp') cannot be removed at this stage because # libmagic.so is yet to be copied to lib. # clean the ports build directory Pathname.glob(pwd.join('tmp', '*', 'ports')) do |dir| FileUtils.rm_rf(dir, verbose: true) end FileUtils.rm_rf(root + 'ports' + 'archives', verbose: true) # Remove everything but share/ directory remove_paths = %w[bin include] remove_paths << 'lib' if config_static? Pathname.glob(File.join(root, 'ports', '*', 'libmagic', '*')) do |dir| remove_paths.each do |path| remove_dir = File.join(dir, path) FileUtils.rm_rf(remove_dir, verbose: true) end end end exit!(0) end |
#do_help ⇒ Object
167 168 169 170 |
# File 'ext/magic/extconf.rb', line 167 def do_help print(MAGIC_HELP_MESSAGE) exit!(0) end |
#process_recipe(name, version, static_p, cross_p) ⇒ Object
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 |
# File 'ext/magic/extconf.rb', line 73 def process_recipe(name, version, static_p, cross_p) require 'rubygems' gem('mini_portile2', REQUIRED_MINI_PORTILE_VERSION) require 'mini_portile2' ("Using mini_portile version #{MiniPortile::VERSION}\n") MiniPortile.new(name, version).tap do |recipe| # 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.target = File.join(PACKAGE_ROOT_DIR, "ports") recipe. << "--libdir=#{File.join(recipe.path, 'lib')}" yield recipe env = Hash.new do |hash, key| hash[key] = (ENV[key]).to_s end recipe..flatten! recipe. = [ "--disable-silent-rules", "--disable-dependency-tracking", "--enable-fsect-man5" ] if static_p recipe. += [ "--disable-shared", "--enable-static", ] env["CFLAGS"] = concat_flags(env["CFLAGS"], "-fPIC") else recipe. += [ "--enable-shared", "--disable-static", ] end if cross_p recipe. += [ "--target=#{recipe.host}", "--host=#{recipe.host}", ] end recipe. += env.map do |key, value| "#{key}=#{value.strip}" end recipe.cook recipe.activate end end |
#truffle? ⇒ Boolean
159 160 161 |
# File 'ext/magic/extconf.rb', line 159 def truffle? ::RUBY_ENGINE == 'truffleruby' end |
#windows? ⇒ Boolean
155 156 157 |
# File 'ext/magic/extconf.rb', line 155 def windows? RbConfig::CONFIG['target_os'] =~ /mswin|mingw32|windows/ end |