Top Level Namespace
Defined Under Namespace
Modules: Logging Classes: Array, String
Constant Summary collapse
- CONFIG =
Config::MAKEFILE_CONFIG
- ORIG_LIBPATH =
ENV['LIB']
- CXX_EXT =
%w[cc cxx cpp]
- SRC_EXT =
%w[c m] << CXX_EXT
- INSTALL_DIRS =
[ [dir_re('commondir'), "$(RUBYCOMMONDIR)"], [dir_re("sitedir"), "$(RUBYCOMMONDIR)"], [dir_re('rubylibdir'), "$(RUBYLIBDIR)"], [dir_re('archdir'), "$(RUBYARCHDIR)"], [dir_re('sitelibdir'), "$(RUBYLIBDIR)"], [dir_re('sitearchdir'), "$(RUBYARCHDIR)"] ]
- OUTFLAG =
- CPPOUTFILE =
- CONFTEST_C =
"conftest.c"- FailedMessage =
<<MESSAGE Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: MESSAGE
- EXPORT_PREFIX =
config_string('EXPORT_PREFIX') {|s| s.strip}
- COMMON_HEADERS =
hdr.join("\n")
- COMMON_LIBS =
config_string('COMMON_LIBS', &split) || []
- COMPILE_RULES =
config_string('COMPILE_RULES', &split) || %w[.%s.%s:]
- RULE_SUBST =
config_string('RULE_SUBST')
- COMPILE_C =
config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<'
- COMPILE_CXX =
config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<'
- TRY_LINK =
config_string('TRY_LINK') || "$(CC) #{OUTFLAG}conftest $(INCFLAGS) $(CPPFLAGS) " \ "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
- LINK_SO =
config_string('LINK_SO') || if CONFIG["DLEXT"] == $OBJEXT "ld $(DLDFLAGS) -r -o $@ $(OBJS)\n" else "$(LDSHARED) $(DLDFLAGS) $(LIBPATH) #{OUTFLAG}$@ " \ "$(OBJS) $(LOCAL_LIBS) $(LIBS)" end
- LIBPATHFLAG =
config_string('LIBPATHFLAG') || ' -L"%s"'
- RPATHFLAG =
config_string('RPATHFLAG') || ''
- LIBARG =
config_string('LIBARG') || '-l%s'
- CLEANINGS =
" clean: @-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) distclean: clean @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep}) realclean: distclean "
Instance Method Summary collapse
- #append_library(libs, lib) ⇒ Object
- #arg_config(config, *defaults, &block) ⇒ Object
- #cc_command(opt = "") ⇒ Object
-
#check_sizeof(type, headers = nil, &b) ⇒ Object
Returns the size of the given
type. - #checking_for(m, fmt = nil) ⇒ Object
- #checking_message(target, place = nil, opt = nil) ⇒ Object
- #config_string(key, config = CONFIG) ⇒ Object
- #configuration(srcdir) ⇒ Object
- #cpp_command(outfile, opt = "") ⇒ Object
- #cpp_include(header) ⇒ Object
- #create_header(header = "extconf.h") ⇒ Object
-
#create_makefile(target, srcprefix = nil) ⇒ Object
Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.
- #create_tmpsrc(src) ⇒ Object
-
#dir_config(target, idefault = nil, ldefault = nil) ⇒ Object
Sets a
targetname that the user can then use to configure various 'with' options with on the command line by using that name. - #dir_re(dir) ⇒ Object
- #dummy_makefile(srcdir) ⇒ Object
- #egrep_cpp(pat, src, opt = "", &b) ⇒ Object
- #enable_config(config, *defaults) ⇒ Object
- #find_executable(bin, path = nil) ⇒ Object
- #find_executable0(bin, path = nil) ⇒ Object
-
#find_header(header, *paths) ⇒ Object
Instructs mkmf to search for the given
headerin any of thepathsprovided, and returns whether or not it was found in those paths. -
#find_library(lib, func, *paths, &b) ⇒ Object
Returns whether or not the entry point
funccan be found within the librarylibin one of thepathsspecified, wherepathsis an array of strings. -
#have_func(func, headers = nil, &b) ⇒ Object
Returns whether or not the function
funccan be found in the common header files, or within anyheadersthat you provide. -
#have_header(header, &b) ⇒ Object
Returns whether or not the given
headerfile can be found on your system. -
#have_library(lib, func = nil, headers = nil, &b) ⇒ Object
Returns whether or not the given entry point
funccan be found withinlib. -
#have_macro(macro, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not
macrois defined either in the common header files or within anyheadersyou provide. -
#have_struct_member(type, member, headers = nil, &b) ⇒ Object
Returns whether or not the struct of type
typecontainsmember. -
#have_type(type, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the static type
typeis defined. -
#have_var(var, headers = nil, &b) ⇒ Object
Returns whether or not the variable
varcan be found in the common header files, or within anyheadersthat you provide. - #init_mkmf(config = CONFIG) ⇒ Object
- #install_dirs(target_prefix = nil) ⇒ Object
- #install_files(mfile, ifiles, map = nil, srcprefix = nil) ⇒ Object
- #install_rb(mfile, dest, srcdir = nil) ⇒ Object
- #libpathflag(libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
- #link_command(ldflags, opt = "", libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
- #log_src(src) ⇒ Object
- #macro_defined?(macro, src, opt = "", &b) ⇒ Boolean
- #map_dir(dir, map = nil) ⇒ Object
- #merge_libs(*libs) ⇒ Object
- #message(*s) ⇒ Object
- #mkmf_failed(path) ⇒ Object
- #modified?(target, times) ⇒ Boolean
- #pkg_config(pkg) ⇒ Object
- #rm_f(*files) ⇒ Object
- #scalar_ptr_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
- #scalar_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
- #try_compile(src, opt = "", &b) ⇒ Object
- #try_constant(const, headers = nil, opt = "", &b) ⇒ Object
- #try_cpp(src, opt = "", &b) ⇒ Object
- #try_do(src, command, &b) ⇒ Object
- #try_func(func, libs, headers = nil, &b) ⇒ Object
- #try_link(src, opt = "", &b) ⇒ Object
- #try_link0(src, opt = "", &b) ⇒ Object
- #try_run(src, opt = "", &b) ⇒ Object
- #try_static_assert(expr, headers = nil, opt = "", &b) ⇒ Object
- #try_var(var, headers = nil, &b) ⇒ Object
- #what_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
- #winsep(s) ⇒ Object
- #with_cflags(flags) ⇒ Object
- #with_config(config, *defaults) ⇒ Object
- #with_cppflags(flags) ⇒ Object
- #with_destdir(dir) ⇒ Object
- #with_ldflags(flags) ⇒ Object
- #xpopen(command, *mode, &block) ⇒ Object
- #xsystem(command) ⇒ Object
Instance Method Details
#append_library(libs, lib) ⇒ Object
526 527 528 |
# File 'lib/mkmf.rb', line 526 def append_library(libs, lib) format(LIBARG, lib) + " " + libs end |
#arg_config(config, *defaults, &block) ⇒ Object
880 881 882 883 884 |
# File 'lib/mkmf.rb', line 880 def arg_config(config, *defaults, &block) $arg_config << [config, *defaults] defaults << nil if !block and defaults.empty? $configure_args.fetch(config.tr('_', '-'), *defaults, &block) end |
#cc_command(opt = "") ⇒ Object
282 283 284 285 |
# File 'lib/mkmf.rb', line 282 def cc_command(opt="") Config::("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}", CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)) end |
#check_sizeof(type, headers = nil, &b) ⇒ Object
Returns the size of the given type. You may optionally specify additional
headers to search in for the type.
If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with 'SIZEOF_', followed by the type name, followed by '=X' where 'X' is the actual size.
For example, if check_sizeof('mystruct') returned 12, then the SIZEOF_MYSTRUCT=12 preprocessor macro would be passed to the compiler.
786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/mkmf.rb', line 786 def check_sizeof(type, headers = nil, &b) expr = "sizeof(#{type})" fmt = "%d" def fmt.%(x) x ? super : "failed" end checking_for ("size of #{type}", headers), fmt do if size = try_constant(expr, headers, &b) $defs.push(format("-DSIZEOF_%s=%d", type.upcase.tr_s("^A-Z0-9_", "_"), size)) size end end end |
#checking_for(m, fmt = nil) ⇒ Object
537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/mkmf.rb', line 537 def checking_for(m, fmt = nil) f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... " "%s", m a = r = nil Logging::postpone do r = yield a = (fmt ? fmt % r : r ? "yes" : "no") << "\n" "#{f}#{m}-------------------- #{a}\n" end (a) Logging:: "--------------------\n\n" r end |
#checking_message(target, place = nil, opt = nil) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/mkmf.rb', line 552 def (target, place = nil, opt = nil) [["in", place], ["with", opt]].inject("#{target}") do |msg, (pre, noun)| if noun [[:to_str], [:join, ","], [:to_s]].each do |meth, *args| if noun.respond_to?(meth) break noun = noun.send(meth, *args) end end msg << " #{pre} #{noun}" unless noun.empty? end msg end end |
#config_string(key, config = CONFIG) ⇒ Object
66 67 68 |
# File 'lib/mkmf.rb', line 66 def config_string(key, config = CONFIG) s = config[key] and !s.empty? and block_given? ? yield(s) : s end |
#configuration(srcdir) ⇒ Object
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
# File 'lib/mkmf.rb', line 1027 def configuration(srcdir) mk = [] vpath = %w[$(srcdir) $(topdir) $(hdrdir)] if !CROSS_COMPILING case CONFIG['build_os'] when 'cygwin' if CONFIG['target_os'] != 'cygwin' vpath.each {|p| p.sub!(/.*/, '$(shell cygpath -u \&)')} end when 'msdosdjgpp', 'mingw32' CONFIG['PATH_SEPARATOR'] = ';' end end mk << %{ SHELL = /bin/sh #### Start of system configuration section. #### srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {CONFIG[$1||$2]}.quote} topdir = #{($extmk ? CONFIG["topdir"] : $topdir).quote} hdrdir = #{$extmk ? CONFIG["hdrdir"].quote : '$(topdir)'} VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])} } if destdir = CONFIG["prefix"][$dest_prefix_pattern, 1] mk << "\nDESTDIR = #{destdir}\n" end CONFIG.each do |key, var| next unless /prefix$/ =~ key mk << "#{key} = #{with_destdir(var)}\n" end CONFIG.each do |key, var| next if /^abs_/ =~ key next unless /^(?:src|top|hdr|(.*))dir$/ =~ key and $1 mk << "#{key} = #{with_destdir(var)}\n" end if !$extmk and !$configure_args.has_key?('--ruby') and sep = config_string('BUILD_FILE_SEPARATOR') sep = ":/=#{sep}" else sep = "" end extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ")<<" " mk << %{ CC = #{CONFIG['CC']} LIBRUBY = #{CONFIG['LIBRUBY']} LIBRUBY_A = #{CONFIG['LIBRUBY_A']} LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC RUBY_EXTCONF_H = #{$extconf_h} CFLAGS = #{$static ? '' : CONFIG['CCDLFLAGS']} #$CFLAGS #$ARCH_FLAG INCFLAGS = -I. #$INCFLAGS CPPFLAGS = #{extconf_h}#{$CPPFLAGS} CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']} DLDFLAGS = #$LDFLAGS #$DLDFLAGS #$ARCH_FLAG LDSHARED = #{CONFIG['LDSHARED']} AR = #{CONFIG['AR']} EXEEXT = #{CONFIG['EXEEXT']} RUBY_INSTALL_NAME = #{CONFIG['RUBY_INSTALL_NAME']} RUBY_SO_NAME = #{CONFIG['RUBY_SO_NAME']} arch = #{CONFIG['arch']} sitearch = #{CONFIG['sitearch']} ruby_version = #{Config::CONFIG['ruby_version']} ruby = #{$ruby} RUBY = $(ruby#{sep}) RM = #{config_string('RM') || '$(RUBY) -run -e rm -- -f'} MAKEDIRS = #{config_string('MAKEDIRS') || '@$(RUBY) -run -e mkdir -- -p'} INSTALL = #{config_string('INSTALL') || '@$(RUBY) -run -e install -- -vp'} INSTALL_PROG = #{config_string('INSTALL_PROG') || '$(INSTALL) -m 0755'} INSTALL_DATA = #{config_string('INSTALL_DATA') || '$(INSTALL) -m 0644'} COPY = #{config_string('CP') || '@$(RUBY) -run -e cp -- -v'} #### End of system configuration section. #### preload = #{$preload ? $preload.join(' ') : ''} } if $nmake == ?b mk.each do |x| x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do "!ifndef " + $1 + "\n" + $& + "!endif\n" end end end mk end |
#cpp_command(outfile, opt = "") ⇒ Object
287 288 289 290 |
# File 'lib/mkmf.rb', line 287 def cpp_command(outfile, opt="") Config::("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)) end |
#cpp_include(header) ⇒ Object
320 321 322 323 324 325 326 327 |
# File 'lib/mkmf.rb', line 320 def cpp_include(header) if header header = [header] unless header.kind_of? Array header.map {|h| "#include <#{h}>\n"}.join else "" end end |
#create_header(header = "extconf.h") ⇒ Object
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 |
# File 'lib/mkmf.rb', line 919 def create_header(header = "extconf.h") "creating %s\n", header sym = header.tr("a-z./\055", "A-Z___") hdr = ["#ifndef #{sym}\n#define #{sym}\n"] for line in $defs case line when /^-D([^=]+)(?:=(.*))?/ hdr << "#define #$1 #{$2 ? Shellwords.shellwords($2)[0] : 1}\n" when /^-U(.*)/ hdr << "#undef #$1\n" end end hdr << "#endif\n" hdr = hdr.join unless (IO.read(header) == hdr rescue false) open(header, "w") do |hfile| hfile.write(hdr) end end $extconf_h = header end |
#create_makefile(target, srcprefix = nil) ⇒ Object
Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.
The target name should correspond the name of the global function name
defined within your C extension, minus the 'Init_'. For example, if your
C extension is defined as 'Init_foo', then your target would simply be 'foo'.
If any '/' characters are present in the target name, only the last name is interpreted as the target name, and the rest are considered toplevel directory names, and the generated Makefile will be altered accordingly to follow that directory structure.
For example, if you pass 'test/foo' as a target name, your extension will be installed under the 'test' directory. This means that in order to load the file within a Ruby program later, that directory structure will have to be followed, e.g. "require 'test/foo'".
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 |
# File 'lib/mkmf.rb', line 1143 def create_makefile(target, srcprefix = nil) $target = target libpath = $DEFLIBPATH|$LIBPATH "creating Makefile\n" rm_f "conftest*" if CONFIG["DLEXT"] == $OBJEXT for lib in libs = $libs.split lib.sub!(/-l(.*)/, %%"lib\\1.#{$LIBEXT}"%) end $defs.push(format("-DEXTLIB='%s'", libs.join(","))) end if target.include?('/') target_prefix, target = File.split(target) target_prefix[0,0] = '/' else target_prefix = "" end srcprefix ||= '$(srcdir)' Config::(srcdir = srcprefix.dup) if not $objs $objs = [] srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] for f in srcs obj = File.basename(f, ".*") << ".o" $objs.push(obj) unless $objs.index(obj) end elsif !(srcs = $srcs) srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')} end $srcs = srcs for i in $objs i.sub!(/\.o\z/, ".#{$OBJEXT}") end $objs = $objs.join(" ") target = nil if $objs == "" if target and EXPORT_PREFIX if File.exist?(File.join(srcdir, target + '.def')) deffile = "$(srcdir)/$(TARGET).def" unless EXPORT_PREFIX.empty? makedef = %{-pe "sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"} end else makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"} end if makedef $distcleanfiles << '$(DEFFILE)' origdef = deffile deffile = "$(TARGET)-$(arch).def" end end origdef ||= '' libpath = libpathflag(libpath) dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : "" staticlib = target ? "$(TARGET).#$LIBEXT" : "" mfile = open("Makefile", "wb") mfile.print configuration(srcprefix) mfile.print " libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")} LIBPATH = #{libpath} DEFFILE = #{deffile} CLEANFILES = #{$cleanfiles.join(' ')} DISTCLEANFILES = #{$distcleanfiles.join(' ')} extout = #{$extout} extout_prefix = #{$extout_prefix} target_prefix = #{target_prefix} LOCAL_LIBS = #{$LOCAL_LIBS} LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS} SRCS = #{srcs.collect(&File.method(:basename)).join(' ')} OBJS = #{$objs} TARGET = #{target} DLLIB = #{dllib} EXTSTATIC = #{$static || ""} STATIC_LIB = #{staticlib unless $static.nil?} #{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""} " install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]} n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET).' mfile.print " TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB) CLEANLIBS = #{n}#{CONFIG['DLEXT']} #{n}il? #{n}tds #{n}map CLEANOBJS = *.#{$OBJEXT} *.#{$LIBEXT} *.s[ol] *.pdb *.exp *.bak all: #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"} static: $(STATIC_LIB)#{$extout ? " install-rb" : ""} " mfile.print CLEANINGS dirs = [] mfile.print "install: install-so install-rb\n\n" sodir = (dir = "$(RUBYARCHDIR)").dup mfile.print("install-so: #{dir}\n") if target f = "$(DLLIB)" dest = "#{dir}/#{f}" mfile.print "install-so: #{dest}\n" unless $extout mfile.print "#{dest}: #{f}\n" if (sep = config_string('BUILD_FILE_SEPARATOR')) f.gsub!("/", sep) dir.gsub!("/", sep) sep = ":/="+sep f.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2} f.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2} dir.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2} dir.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2} end mfile.print "\t$(INSTALL_PROG) #{f} #{dir}\n" if defined?($installed_list) mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n" end end end mfile.print("install-rb: pre-install-rb install-rb-default\n") mfile.print("install-rb-default: pre-install-rb-default\n") mfile.print("pre-install-rb: Makefile\n") mfile.print("pre-install-rb-default: Makefile\n") for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]] files = install_files(mfile, i, nil, srcprefix) or next for dir, *files in files unless dirs.include?(dir) dirs << dir mfile.print "pre-install-rb#{sfx}: #{dir}\n" end files.each do |f| dest = "#{dir}/#{File.basename(f)}" mfile.print("install-rb#{sfx}: #{dest}\n") mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ") sep = config_string('BUILD_FILE_SEPARATOR') if sep f = f.gsub("/", sep) sep = ":/="+sep f = f.gsub(/(\$\(\w+)(\))/) {$1+sep+$2} f = f.gsub(/(\$\{\w+)(\})/) {$1+sep+$2} else sep = "" end mfile.print("#{f} $(@D#{sep})\n") if defined?($installed_list) and !$extout mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n") end end end end dirs.unshift(sodir) if target and !dirs.include?(sodir) dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"} mfile.print <<-SITEINSTALL site-install: site-install-so site-install-rb site-install-so: install-so site-install-rb: install-rb SITEINSTALL return unless target mfile.puts SRC_EXT.collect {|ext| ".path.#{ext} = $(VPATH)"} if $nmake == ?b mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n" mfile.print "\n" CXX_EXT.each do |ext| COMPILE_RULES.each do |rule| mfile.printf(rule, ext, $OBJEXT) mfile.printf("\n\t%s\n\n", COMPILE_CXX) end end %w[c].each do |ext| COMPILE_RULES.each do |rule| mfile.printf(rule, ext, $OBJEXT) mfile.printf("\n\t%s\n\n", COMPILE_C) end end mfile.print "$(RUBYARCHDIR)/" if $extout mfile.print "$(DLLIB): ", (makedef ? "$(DEFFILE) " : ""), "$(OBJS)\n" mfile.print "\t@-$(RM) $@\n" mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout link_so = LINK_SO.gsub(/^/, "\t") mfile.print link_so, "\n\n" unless $static.nil? mfile.print "$(STATIC_LIB): $(OBJS)\n\t" mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)" config_string('RANLIB') do |ranlib| mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true" end end mfile.print "\n\n" if makedef mfile.print "$(DEFFILE): #{origdef}\n" mfile.print "\t$(RUBY) #{makedef} #{origdef} > $@\n\n" end depend = File.join(srcdir, "depend") if File.exist?(depend) suffixes = [] depout = [] open(depend, "r") do |dfile| mfile.printf "###\n" cont = implicit = nil impconv = proc do COMPILE_RULES.each {|rule| depout << (rule % implicit[0]) << implicit[1]} implicit = nil end ruleconv = proc do |line| if implicit if /\A\t/ =~ line implicit[1] << line next else impconv[] end end if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line) suffixes << m[1] << m[2] implicit = [[m[1], m[2]], [m.post_match]] next elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2} end depout << line end while line = dfile.gets() line.gsub!(/\.o\b/, ".#{$OBJEXT}") line.gsub!(/\$\(hdrdir\)\/config.h/, $config_h) if $config_h if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line (cont ||= []) << line next elsif cont line = (cont << line).join cont = nil end ruleconv.call(line) end if cont ruleconv.call(cont.join) elsif implicit impconv.call end end unless suffixes.empty? mfile.print ".SUFFIXES: .", suffixes.uniq.join(" ."), "\n\n" end mfile.print depout else headers = %w[ruby.h defines.h] if RULE_SUBST headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}} end headers << $config_h if $config_h headers << "$(RUBY_EXTCONF_H)" if $extconf_h mfile.print "$(OBJS): ", headers.join(' '), "\n" end $makefile_created = true ensure mfile.close if mfile end |
#create_tmpsrc(src) ⇒ Object
252 253 254 255 256 257 258 259 |
# File 'lib/mkmf.rb', line 252 def create_tmpsrc(src) src = yield(src) if block_given? src = src.gsub(/[ \t]+$/, '').gsub(/\A\n+|^\n+$/, '').sub(/[^\n]\z/, "\\&\n") open(CONFTEST_C, "wb") do |cfile| cfile.print src end src end |
#dir_config(target, idefault = nil, ldefault = nil) ⇒ Object
Sets a target name that the user can then use to configure various 'with'
options with on the command line by using that name. For example, if the
target is set to "foo", then the user could use the --with-foo-dir command
line option.
You may pass along additional 'include' or 'lib' defaults via the idefault
and ldefault parameters, respectively.
Note that dir_config only adds to the list of places to search for libraries and include files. It does not link the libraries into your application.
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
# File 'lib/mkmf.rb', line 952 def dir_config(target, idefault=nil, ldefault=nil) if dir = with_config(target + "-dir", (idefault unless ldefault)) defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR) idefault = ldefault = nil end idir = with_config(target + "-include", idefault) $arg_config.last[1] ||= "${#{target}-dir}/include" ldir = with_config(target + "-lib", ldefault) $arg_config.last[1] ||= "${#{target}-dir}/lib" idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : [] if defaults idirs.concat(defaults.collect {|dir| dir + "/include"}) idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR) end unless idirs.empty? idirs.collect! {|dir| "-I" + dir} idirs -= Shellwords.shellwords($CPPFLAGS) unless idirs.empty? $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ") end end ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : [] if defaults ldirs.concat(defaults.collect {|dir| dir + "/lib"}) ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR) end $LIBPATH = ldirs | $LIBPATH [idir, ldir] end |
#dir_re(dir) ⇒ Object
70 71 72 |
# File 'lib/mkmf.rb', line 70 def dir_re(dir) Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$(?:\(target_prefix\)|\{target_prefix\}))?') end |
#dummy_makefile(srcdir) ⇒ Object
1116 1117 1118 1119 1120 1121 1122 1123 1124 |
# File 'lib/mkmf.rb', line 1116 def dummy_makefile(srcdir) configuration(srcdir) << <<RULES << CLEANINGS CLEANFILES = #{$cleanfiles.join(' ')} DISTCLEANFILES = #{$distcleanfiles.join(' ')} all install static install-so install-rb: Makefile RULES end |
#egrep_cpp(pat, src, opt = "", &b) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/mkmf.rb', line 438 def egrep_cpp(pat, src, opt = "", &b) src = create_tmpsrc(src, &b) xpopen(cpp_command('', opt)) do |f| if Regexp === pat puts(" ruby -ne 'print if #{pat.inspect}'") f.grep(pat) {|l| puts "#{f.lineno}: #{l}" return true } false else puts(" egrep '#{pat}'") begin stdin = $stdin.dup $stdin.reopen(f) system("egrep", pat) ensure $stdin.reopen(stdin) end end end ensure rm_f "conftest*" log_src(src) end |
#enable_config(config, *defaults) ⇒ Object
907 908 909 910 911 912 913 914 915 916 917 |
# File 'lib/mkmf.rb', line 907 def enable_config(config, *defaults) if arg_config("--enable-"+config) true elsif arg_config("--disable-"+config) false elsif block_given? yield(config, *defaults) else return *defaults end end |
#find_executable(bin, path = nil) ⇒ Object
874 875 876 877 878 |
# File 'lib/mkmf.rb', line 874 def find_executable(bin, path = nil) checking_for (bin, path) do find_executable0(bin, path) end end |
#find_executable0(bin, path = nil) ⇒ Object
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/mkmf.rb', line 854 def find_executable0(bin, path = nil) ext = config_string('EXEEXT') if File.(bin) == bin return bin if File.executable?(bin) ext and File.executable?(file = bin + ext) and return file return nil end if path ||= ENV['PATH'] path = path.split(File::PATH_SEPARATOR) else path = %w[/usr/local/bin /usr/ucb /usr/bin /bin] end file = nil path.each do |dir| return file if File.executable?(file = File.join(dir, bin)) return file if ext and File.executable?(file << ext) end nil end |
#find_header(header, *paths) ⇒ Object
Instructs mkmf to search for the given header in any of the paths
provided, and returns whether or not it was found in those paths.
If the header is found then the path it was found on is added to the list of included directories that are sent to the compiler (via the -I switch).
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'lib/mkmf.rb', line 697 def find_header(header, *paths) header = cpp_include(header) checking_for header do if try_cpp(header) true else found = false paths.each do |dir| opt = "-I#{dir}".quote if try_cpp(header, opt) $INCFLAGS << " " << opt found = true break end end found end end end |
#find_library(lib, func, *paths, &b) ⇒ Object
Returns whether or not the entry point func can be found within the library
lib in one of the paths specified, where paths is an array of strings.
If func is nil , then the main() function is used as the entry point.
If lib is found, then the path it was found on is added to the list of
library paths searched and linked against.
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/mkmf.rb', line 613 def find_library(lib, func, *paths, &b) func = "main" if !func or func.empty? lib = with_config(lib+'lib', lib) paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten checking_for "#{func}() in #{LIBARG%lib}" do libpath = $LIBPATH libs = append_library($libs, lib) begin until r = try_func(func, libs, &b) or paths.empty? $LIBPATH = libpath | [paths.shift] end if r $libs = libs libpath = nil end ensure $LIBPATH = libpath if libpath end r end end |
#have_func(func, headers = nil, &b) ⇒ Object
Returns whether or not the function func can be found in the common
header files, or within any headers that you provide. If found, a
macro is passed as a preprocessor constant to the compiler using the
function name, in uppercase, prepended with 'HAVE_'.
For example, if have_func('foo') returned true, then the HAVE_FOO preprocessor macro would be passed to the compiler.
643 644 645 646 647 648 649 650 651 652 |
# File 'lib/mkmf.rb', line 643 def have_func(func, headers = nil, &b) checking_for ("#{func}()", headers) do if try_func(func, $libs, headers, &b) $defs.push(format("-DHAVE_%s", func.upcase)) true else false end end end |
#have_header(header, &b) ⇒ Object
Returns whether or not the given header file can be found on your system.
If found, a macro is passed as a preprocessor constant to the compiler using
the header file name, in uppercase, prepended with 'HAVE_'.
For example, if have_header('foo.h') returned true, then the HAVE_FOO_H preprocessor macro would be passed to the compiler.
680 681 682 683 684 685 686 687 688 689 |
# File 'lib/mkmf.rb', line 680 def have_header(header, &b) checking_for header do if try_cpp(cpp_include(header), &b) $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___"))) true else false end end end |
#have_library(lib, func = nil, headers = nil, &b) ⇒ Object
Returns whether or not the given entry point func can be found within
lib. If func is nil, the 'main()' entry point is used by default.
If found, it adds the library to list of libraries to be used when linking
your extension.
If headers are provided, it will include those header files as the
header files it looks in when searching for func.
Real name of the library to be linked can be altered by '--with-FOOlib' configuration option.
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/mkmf.rb', line 588 def have_library(lib, func = nil, headers = nil, &b) func = "main" if !func or func.empty? lib = with_config(lib+'lib', lib) checking_for ("#{func}()", LIBARG%lib) do if COMMON_LIBS.include?(lib) true else libs = append_library($libs, lib) if try_func(func, libs, headers, &b) $libs = libs true else false end end end end |
#have_macro(macro, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not macro is defined either in the common header
files or within any headers you provide.
Any options you pass to opt are passed along to the compiler.
571 572 573 574 575 |
# File 'lib/mkmf.rb', line 571 def have_macro(macro, headers = nil, opt = "", &b) checking_for (macro, headers, opt) do macro_defined?(macro, cpp_include(headers), opt, &b) end end |
#have_struct_member(type, member, headers = nil, &b) ⇒ Object
Returns whether or not the struct of type type contains member. If
it does not, or the struct type can't be found, then false is returned. You
may optionally specify additional headers in which to look for the struct
(in addition to the common header files).
If found, a macro is passed as a preprocessor constant to the compiler using the member name, in uppercase, prepended with 'HAVE_ST_'.
For example, if have_struct_member('foo', 'bar') returned true, then the HAVE_ST_BAR preprocessor macro would be passed to the compiler.
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
# File 'lib/mkmf.rb', line 728 def have_struct_member(type, member, headers = nil, &b) checking_for ("#{type}.#{member}", headers) do if try_compile(<<"SRC", &b) #{COMMON_HEADERS} #{cpp_include(headers)} /*top*/ int main() { return 0; } int s = (char *)&((#{type}*)0)->#{member} - (char *)0; SRC $defs.push(format("-DHAVE_ST_%s", member.upcase)) true else false end end end |
#have_type(type, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the static type type is defined. You may
optionally pass additional headers to check against in addition to the
common header files.
You may also pass additional flags to opt which are then passed along to
the compiler.
If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with 'HAVE_TYPE_'.
For example, if have_type('foo') returned true, then the HAVE_TYPE_FOO preprocessor macro would be passed to the compiler.
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 |
# File 'lib/mkmf.rb', line 758 def have_type(type, headers = nil, opt = "", &b) checking_for (type, headers, opt) do headers = cpp_include(headers) if try_compile(<<"SRC", opt, &b) #{COMMON_HEADERS} #{headers} /*top*/ typedef #{type} conftest_type; static conftest_type conftestval[sizeof(conftest_type)?1:-1]; SRC $defs.push(format("-DHAVE_TYPE_%s", type.strip.upcase.tr_s("^A-Z0-9_", "_"))) true else false end end end |
#have_var(var, headers = nil, &b) ⇒ Object
Returns whether or not the variable var can be found in the common
header files, or within any headers that you provide. If found, a
macro is passed as a preprocessor constant to the compiler using the
variable name, in uppercase, prepended with 'HAVE_'.
For example, if have_var('foo') returned true, then the HAVE_FOO preprocessor macro would be passed to the compiler.
662 663 664 665 666 667 668 669 670 671 |
# File 'lib/mkmf.rb', line 662 def have_var(var, headers = nil, &b) checking_for (var, headers) do if try_var(var, headers, &b) $defs.push(format("-DHAVE_%s", var.upcase)) true else false end end end |
#init_mkmf(config = CONFIG) ⇒ Object
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 |
# File 'lib/mkmf.rb', line 1409 def init_mkmf(config = CONFIG) $makefile_created = false $arg_config = [] $enable_shared = config['ENABLE_SHARED'] == 'yes' $defs = [] $extconf_h = nil $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup $ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup $LDFLAGS = with_config("ldflags", arg_config("LDFLAGS", config["LDFLAGS"])).dup $INCFLAGS = "-I$(topdir) -I$(hdrdir) -I$(srcdir)" $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup $LIBEXT = config['LIBEXT'].dup $OBJEXT = config["OBJEXT"].dup $LIBS = "#{config['LIBS']} #{config['DLDLIBS']}" $LIBRUBYARG = "" $LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC'] $LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED'] $DEFLIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"] $LIBPATH = [] $INSTALLFILES = nil $objs = nil $srcs = nil $libs = "" if $enable_shared or Config.(config["LIBRUBY"].dup) != Config.(config["LIBRUBY_A"].dup) $LIBRUBYARG = config['LIBRUBYARG'] end $LOCAL_LIBS = "" $cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || [] $distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || [] $extout ||= nil $extout_prefix ||= nil $arg_config.clear dir_config("opt") end |
#install_dirs(target_prefix = nil) ⇒ Object
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 |
# File 'lib/mkmf.rb', line 83 def install_dirs(target_prefix = nil) if $extout dirs = [ ['RUBYCOMMONDIR', '$(extout)/common'], ['RUBYLIBDIR', '$(RUBYCOMMONDIR)$(target_prefix)'], ['RUBYARCHDIR', '$(extout)/$(arch)$(target_prefix)'], ['extout', "#$extout"], ['extout_prefix', "#$extout_prefix"], ] elsif $extmk dirs = [ ['RUBYCOMMONDIR', '$(rubylibdir)'], ['RUBYLIBDIR', '$(rubylibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(archdir)$(target_prefix)'], ] else dirs = [ ['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'], ['RUBYLIBDIR', '$(sitelibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(sitearchdir)$(target_prefix)'], ] end dirs << ['target_prefix', (target_prefix ? "/#{target_prefix}" : "")] dirs end |
#install_files(mfile, ifiles, map = nil, srcprefix = nil) ⇒ Object
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/mkmf.rb', line 485 def install_files(mfile, ifiles, map = nil, srcprefix = nil) ifiles or return srcprefix ||= '$(srcdir)' Config::(srcdir = srcprefix.dup) dirs = [] path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]} ifiles.each do |files, dir, prefix| dir = map_dir(dir, map) prefix = %r|\A#{Regexp.quote(prefix)}/?| if prefix if /\A\.\// =~ files # install files which are in current working directory. files = files[2..-1] len = nil else # install files which are under the $(srcdir). files = File.join(srcdir, files) len = srcdir.size end f = nil Dir.glob(files) do |f| f[0..len] = "" if len d = File.dirname(f) d.sub!(prefix, "") if prefix d = (d.empty? || d == ".") ? dir : File.join(dir, d) f = File.join(srcprefix, f) if len path[d] << f end unless len or f d = File.dirname(files) d.sub!(prefix, "") if prefix d = (d.empty? || d == ".") ? dir : File.join(dir, d) path[d] << files end end dirs end |
#install_rb(mfile, dest, srcdir = nil) ⇒ Object
522 523 524 |
# File 'lib/mkmf.rb', line 522 def install_rb(mfile, dest, srcdir = nil) install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir) end |
#libpathflag(libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
292 293 294 295 296 |
# File 'lib/mkmf.rb', line 292 def libpathflag(libpath=$DEFLIBPATH|$LIBPATH) libpath.map{|x| (x == "$(topdir)" ? LIBPATHFLAG : LIBPATHFLAG+RPATHFLAG) % x.quote }.join end |
#link_command(ldflags, opt = "", libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/mkmf.rb', line 268 def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH) Config::(TRY_LINK.dup, CONFIG.merge('hdrdir' => $hdrdir.quote, 'src' => CONFTEST_C, 'INCFLAGS' => $INCFLAGS, 'CPPFLAGS' => $CPPFLAGS, 'CFLAGS' => "#$CFLAGS", 'ARCH_FLAG' => "#$ARCH_FLAG", 'LDFLAGS' => "#$LDFLAGS #{ldflags}", 'LIBPATH' => libpathflag(libpath), 'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs", 'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS")) end |
#log_src(src) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/mkmf.rb', line 238 def log_src(src) src = src.split(/^/) fmt = "%#{src.size.to_s.size}d: %s" Logging:: <<"EOM" checked program was: /* begin */ EOM src.each_with_index {|line, no| Logging:: fmt, no+1, line} Logging:: <<"EOM" /* end */ EOM end |
#macro_defined?(macro, src, opt = "", &b) ⇒ Boolean
464 465 466 467 468 469 470 471 472 473 |
# File 'lib/mkmf.rb', line 464 def macro_defined?(macro, src, opt = "", &b) src = src.sub(/[^\n]\z/, "\\&\n") try_compile(src + <<"SRC", opt, &b) /*top*/ #ifndef #{macro} # error >>>>>> #{macro} undefined <<<<<< #endif SRC end |
#map_dir(dir, map = nil) ⇒ Object
109 110 111 112 |
# File 'lib/mkmf.rb', line 109 def map_dir(dir, map = nil) map ||= INSTALL_DIRS map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)} end |
#merge_libs(*libs) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/mkmf.rb', line 152 def merge_libs(*libs) libs.inject([]) do |x, y| xy = x & y xn = yn = 0 y = y.inject([]) {|ary, e| ary.last == e ? ary : ary << e} y.each_with_index do |v, yi| if xy.include?(v) xi = [x.index(v), xn].max() x[xi, 1] = y[yn..yi] xn, yn = xi + (yi - yn + 1), yi + 1 end end x.concat(y[yn..-1] || []) end end |
#message(*s) ⇒ Object
530 531 532 533 534 535 |
# File 'lib/mkmf.rb', line 530 def (*s) unless $extmk and not $VERBOSE printf(*s) $stdout.flush end end |
#mkmf_failed(path) ⇒ Object
1458 1459 1460 1461 1462 1463 |
# File 'lib/mkmf.rb', line 1458 def mkmf_failed(path) unless $makefile_created or File.exist?("Makefile") opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"} abort "*** #{path} failed ***\n" + FailedMessage + opts.join end end |
#modified?(target, times) ⇒ Boolean
146 147 148 149 150 |
# File 'lib/mkmf.rb', line 146 def modified?(target, times) (t = File.mtime(target)) rescue return nil Array === times or times = [times] t if times.all? {|n| n <= t} end |
#pkg_config(pkg) ⇒ Object
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/mkmf.rb', line 986 def pkg_config(pkg) if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig) # iff package specific config command is given get = proc {|opt| `#{pkgconfig} --#{opt}`.chomp} elsif ($PKGCONFIG ||= (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) && find_executable0(pkgconfig) && pkgconfig) and system("#{$PKGCONFIG} --exists #{pkg}") # default to pkg-config command get = proc {|opt| `#{$PKGCONFIG} --#{opt} #{pkg}`.chomp} elsif find_executable0(pkgconfig = "#{pkg}-config") # default to package specific config command, as a last resort. get = proc {|opt| `#{pkgconfig} --#{opt}`.chomp} end if get cflags = get['cflags'] ldflags = get['libs'] libs = get['libs-only-l'] ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ") $CFLAGS += " " << cflags $LDFLAGS += " " << ldflags $libs += " " << libs Logging:: "package configuration for %s\n", pkg Logging:: "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs [cflags, ldflags, libs] else Logging:: "package configuration for %s is not found\n", pkg nil end end |
#rm_f(*files) ⇒ Object
142 143 144 |
# File 'lib/mkmf.rb', line 142 def rm_f(*files) FileUtils.rm_f(Dir[files.join("\0")]) end |
#scalar_ptr_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
800 801 802 803 804 805 806 807 808 809 |
# File 'lib/mkmf.rb', line 800 def scalar_ptr_type?(type, member = nil, headers = nil, &b) try_compile(<<"SRC", &b) # pointer #{COMMON_HEADERS} #{cpp_include(headers)} /*top*/ volatile #{type} conftestval; int main() { return 0; } int t() {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));} SRC end |
#scalar_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
811 812 813 814 815 816 817 818 819 820 |
# File 'lib/mkmf.rb', line 811 def scalar_type?(type, member = nil, headers = nil, &b) try_compile(<<"SRC", &b) # pointer #{COMMON_HEADERS} #{cpp_include(headers)} /*top*/ volatile #{type} conftestval; int main() { return 0; } int t() {return (int)(1-(conftestval#{member ? ".#{member}" : ""}));} SRC end |
#try_compile(src, opt = "", &b) ⇒ Object
308 309 310 311 312 |
# File 'lib/mkmf.rb', line 308 def try_compile(src, opt="", &b) try_do(src, cc_command(opt), &b) ensure rm_f "conftest*" end |
#try_constant(const, headers = nil, opt = "", &b) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/mkmf.rb', line 363 def try_constant(const, headers = nil, opt = "", &b) includes = cpp_include(headers) if CROSS_COMPILING if try_static_assert("#{const} > 0", headers, opt) # positive constant elsif try_static_assert("#{const} < 0", headers, opt) neg = true const = "-(#{const})" elsif try_static_assert("#{const} == 0", headers, opt) return 0 else # not a constant return nil end upper = 1 lower = 0 until try_static_assert("#{const} <= #{upper}", headers, opt) lower = upper upper <<= 1 end return nil unless lower while upper > lower + 1 mid = (upper + lower) / 2 if try_static_assert("#{const} > #{mid}", headers, opt) lower = mid else upper = mid end end upper = -upper if neg return upper else src = %{#{COMMON_HEADERS} #{includes} #include <stdio.h> /*top*/ int conftest_const = (int)(#{const}); int main() {printf("%d\\n", conftest_const); return 0;} } if try_link0(src, opt, &b) xpopen("./conftest") do |f| return Integer(f.gets) end end end nil end |
#try_cpp(src, opt = "", &b) ⇒ Object
314 315 316 317 318 |
# File 'lib/mkmf.rb', line 314 def try_cpp(src, opt="", &b) try_do(src, cpp_command(CPPOUTFILE, opt), &b) ensure rm_f "conftest*" end |
#try_do(src, command, &b) ⇒ Object
261 262 263 264 265 266 |
# File 'lib/mkmf.rb', line 261 def try_do(src, command, &b) src = create_tmpsrc(src, &b) xsystem(command) ensure log_src(src) end |
#try_func(func, libs, headers = nil, &b) ⇒ Object
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/mkmf.rb', line 411 def try_func(func, libs, headers = nil, &b) headers = cpp_include(headers) try_link(<<"SRC", libs, &b) or try_link(<<"SRC", libs, &b) #{headers} /*top*/ int main() { return 0; } int t() { #{func}(); return 0; } SRC end |
#try_link(src, opt = "", &b) ⇒ Object
302 303 304 305 306 |
# File 'lib/mkmf.rb', line 302 def try_link(src, opt="", &b) try_link0(src, opt, &b) ensure rm_f "conftest*", "c0x32*" end |
#try_link0(src, opt = "", &b) ⇒ Object
298 299 300 |
# File 'lib/mkmf.rb', line 298 def try_link0(src, opt="", &b) try_do(src, link_command("", opt), &b) end |
#try_run(src, opt = "", &b) ⇒ Object
475 476 477 478 479 480 481 482 483 |
# File 'lib/mkmf.rb', line 475 def try_run(src, opt = "", &b) if try_link0(src, opt, &b) xsystem("./conftest") else nil end ensure rm_f "conftest*" end |
#try_static_assert(expr, headers = nil, opt = "", &b) ⇒ Object
353 354 355 356 357 358 359 360 361 |
# File 'lib/mkmf.rb', line 353 def try_static_assert(expr, headers = nil, opt = "", &b) headers = cpp_include(headers) try_compile(<<SRC, opt, &b) #{COMMON_HEADERS} #{headers} /*top*/ int conftest_const[(#{expr}) ? 1 : -1]; SRC end |
#try_var(var, headers = nil, &b) ⇒ Object
427 428 429 430 431 432 433 434 435 436 |
# File 'lib/mkmf.rb', line 427 def try_var(var, headers = nil, &b) headers = cpp_include(headers) try_compile(<<"SRC", &b) #{COMMON_HEADERS} #{headers} /*top*/ int main() { return 0; } int t() { const volatile void *volatile p; p = (void *)&#{var}; return 0; } SRC end |
#what_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
# File 'lib/mkmf.rb', line 822 def what_type?(type, member = nil, headers = nil, &b) m = "#{type}" name = type if member m << "." << member name = "(((#{type} *)0)->#{member})" end fmt = "seems %s" def fmt.%(x) x ? super : "unknown" end checking_for (m, headers), fmt do if scalar_ptr_type?(type, member, headers, &b) if try_static_assert("sizeof(*#{name}) == 1", headers) "string" end elsif scalar_type?(type, member, headers, &b) if try_static_assert("sizeof(#{name}) > sizeof(long)", headers) "long long" elsif try_static_assert("sizeof(#{name}) > sizeof(int)", headers) "long" elsif try_static_assert("sizeof(#{name}) > sizeof(short)", headers) "int" elsif try_static_assert("sizeof(#{name}) > 1", headers) "short" else "char" end end end end |
#winsep(s) ⇒ Object
1023 1024 1025 |
# File 'lib/mkmf.rb', line 1023 def winsep(s) s.tr('/', '\\') end |
#with_cflags(flags) ⇒ Object
337 338 339 340 341 342 343 |
# File 'lib/mkmf.rb', line 337 def with_cflags(flags) cflags = $CFLAGS $CFLAGS = flags ret = yield ensure $CFLAGS = cflags unless ret end |
#with_config(config, *defaults) ⇒ Object
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 |
# File 'lib/mkmf.rb', line 886 def with_config(config, *defaults) config = config.sub(/^--with[-_]/, '') val = arg_config("--with-"+config) do if arg_config("--without-"+config) false elsif block_given? yield(config, *defaults) else break *defaults end end case val when "yes" true when "no" false else val end end |
#with_cppflags(flags) ⇒ Object
329 330 331 332 333 334 335 |
# File 'lib/mkmf.rb', line 329 def with_cppflags(flags) cppflags = $CPPFLAGS $CPPFLAGS = flags ret = yield ensure $CPPFLAGS = cppflags unless ret end |
#with_destdir(dir) ⇒ Object
1018 1019 1020 1021 |
# File 'lib/mkmf.rb', line 1018 def with_destdir(dir) dir = dir.sub($dest_prefix_pattern, '') /\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir end |
#with_ldflags(flags) ⇒ Object
345 346 347 348 349 350 351 |
# File 'lib/mkmf.rb', line 345 def with_ldflags(flags) ldflags = $LDFLAGS $LDFLAGS = flags ret = yield ensure $LDFLAGS = ldflags unless ret end |