mkmf.rb

Path: lib/mkmf.rb
Last Update: Sat Sep 22 12:31:32 +0000 2007

module to create Makefile for extension modules invoke like: ruby -r mkmf extconf.rb

Required files

rbconfig   fileutils   shellwords  

Methods

Constants

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 = CONFIG['OUTFLAG']
CPPOUTFILE = CONFIG['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

Public Instance methods

[Source]

     # File lib/mkmf.rb, line 541
541: def append_library(libs, lib)
542:   format(LIBARG, lib) + " " + libs
543: end

[Source]

     # File lib/mkmf.rb, line 899
899: def arg_config(config, *defaults, &block)
900:   $arg_config << [config, *defaults]
901:   defaults << nil if !block and defaults.empty?
902:   $configure_args.fetch(config.tr('_', '-'), *defaults, &block)
903: end

[Source]

     # File lib/mkmf.rb, line 287
287: def cc_command(opt="")
288:   Config::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
289:                  CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote))
290: end

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.

[Source]

     # File lib/mkmf.rb, line 803
803: def check_sizeof(type, headers = nil, &b)
804:   expr = "sizeof(#{type})"
805:   fmt = "%d"
806:   def fmt.%(x)
807:     x ? super : "failed"
808:   end
809:   checking_for checking_message("size of #{type}", headers), fmt do
810:     if size = try_constant(expr, headers, &b)
811:       $defs.push(format("-DSIZEOF_%s=%d", type.upcase.tr_s("^A-Z0-9_", "_"), size))
812:       size
813:     end
814:   end
815: end

[Source]

     # File lib/mkmf.rb, line 552
552: def checking_for(m, fmt = nil)
553:   f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim
554:   m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... "
555:   message "%s", m
556:   a = r = nil
557:   Logging::postpone do
558:     r = yield
559:     a = (fmt ? fmt % r : r ? "yes" : "no") << "\n"
560:     "#{f}#{m}-------------------- #{a}\n"
561:   end
562:   message(a)
563:   Logging::message "--------------------\n\n"
564:   r
565: end

[Source]

     # File lib/mkmf.rb, line 567
567: def checking_message(target, place = nil, opt = nil)
568:   [["in", place], ["with", opt]].inject("#{target}") do |msg, (pre, noun)|
569:     if noun
570:       [[:to_str], [:join, ","], [:to_s]].each do |meth, *args|
571:         if noun.respond_to?(meth)
572:           break noun = noun.send(meth, *args)
573:         end
574:       end
575:       msg << " #{pre} #{noun}" unless noun.empty?
576:     end
577:     msg
578:   end
579: end

[Source]

    # File lib/mkmf.rb, line 69
69: def config_string(key, config = CONFIG)
70:   s = config[key] and !s.empty? and block_given? ? yield(s) : s
71: end

[Source]

      # File lib/mkmf.rb, line 1046
1046: def configuration(srcdir)
1047:   mk = []
1048:   vpath = %w[$(srcdir) $(topdir) $(hdrdir)]
1049:   if !CROSS_COMPILING
1050:     case CONFIG['build_os']
1051:     when 'cygwin'
1052:       if CONFIG['target_os'] != 'cygwin'
1053:         vpath.each {|p| p.sub!(/.*/, '$(shell cygpath -u \&)')}
1054:       end
1055:     when 'msdosdjgpp', 'mingw32'
1056:       CONFIG['PATH_SEPARATOR'] = ';'
1057:     end
1058:   end
1059:   mk << %{
1060: SHELL = /bin/sh
1061: 
1062: #### Start of system configuration section. ####
1063: 
1064: srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {CONFIG[$1||$2]}.quote}
1065: topdir = #{($extmk ? CONFIG["topdir"] : $topdir).quote}
1066: hdrdir = #{$extmk ? CONFIG["hdrdir"].quote : '$(topdir)'}
1067: VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
1068: }
1069:   if $extmk
1070:     mk << "RUBYLIB = -\nRUBYOPT = -rpurelib.rb\n"
1071:   end
1072:   if destdir = CONFIG["prefix"][$dest_prefix_pattern, 1]
1073:     mk << "\nDESTDIR = #{destdir}\n"
1074:   end
1075:   CONFIG.each do |key, var|
1076:     next unless /prefix$/ =~ key
1077:     mk << "#{key} = #{with_destdir(var)}\n"
1078:   end
1079:   CONFIG.each do |key, var|
1080:     next if /^abs_/ =~ key
1081:     next unless /^(?:src|top|hdr|(.*))dir$/ =~ key and $1
1082:     mk << "#{key} = #{with_destdir(var)}\n"
1083:   end
1084:   if !$extmk and !$configure_args.has_key?('--ruby') and
1085:       sep = config_string('BUILD_FILE_SEPARATOR')
1086:     sep = ":/=#{sep}"
1087:   else
1088:     sep = ""
1089:   end
1090:   extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ")<<" "
1091:   mk << %{
1092: CC = #{CONFIG['CC']}
1093: LIBRUBY = #{CONFIG['LIBRUBY']}
1094: LIBRUBY_A = #{CONFIG['LIBRUBY_A']}
1095: LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED
1096: LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC
1097: 
1098: RUBY_EXTCONF_H = #{$extconf_h}
1099: CFLAGS   = #{$static ? '' : CONFIG['CCDLFLAGS']} #$CFLAGS #$ARCH_FLAG
1100: INCFLAGS = -I. #$INCFLAGS
1101: CPPFLAGS = #{extconf_h}#{$CPPFLAGS}
1102: CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']}
1103: DLDFLAGS = #$LDFLAGS #$DLDFLAGS #$ARCH_FLAG
1104: LDSHARED = #{CONFIG['LDSHARED']}
1105: AR = #{CONFIG['AR']}
1106: EXEEXT = #{CONFIG['EXEEXT']}
1107: 
1108: RUBY_INSTALL_NAME = #{CONFIG['RUBY_INSTALL_NAME']}
1109: RUBY_SO_NAME = #{CONFIG['RUBY_SO_NAME']}
1110: arch = #{CONFIG['arch']}
1111: sitearch = #{CONFIG['sitearch']}
1112: vendorarch = #{CONFIG['vendorarch']}
1113: ruby_version = #{Config::CONFIG['ruby_version']}
1114: ruby = #{$ruby}
1115: RUBY = $(ruby#{sep})
1116: RM = #{config_string('RM') || '$(RUBY) -run -e rm -- -f'}
1117: MAKEDIRS = #{config_string('MAKEDIRS') || '@$(RUBY) -run -e mkdir -- -p'}
1118: INSTALL = #{config_string('INSTALL') || '@$(RUBY) -run -e install -- -vp'}
1119: INSTALL_PROG = #{config_string('INSTALL_PROG') || '$(INSTALL) -m 0755'}
1120: INSTALL_DATA = #{config_string('INSTALL_DATA') || '$(INSTALL) -m 0644'}
1121: COPY = #{config_string('CP') || '@$(RUBY) -run -e cp -- -v'}
1122: 
1123: #### End of system configuration section. ####
1124: 
1125: preload = #{$preload ? $preload.join(' ') : ''}
1126: }
1127:   if $nmake == ?b
1128:     mk.each do |x|
1129:       x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do
1130:         "!ifndef " + $1 + "\n" +
1131:         $& +
1132:         "!endif\n"
1133:       end
1134:     end
1135:   end
1136:   mk
1137: end

[Source]

     # File lib/mkmf.rb, line 292
292: def cpp_command(outfile, opt="")
293:   Config::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
294:                  CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote))
295: end

[Source]

     # File lib/mkmf.rb, line 330
330: def cpp_include(header)
331:   if header
332:     header = [header] unless header.kind_of? Array
333:     header.map {|h| "#include <#{h}>\n"}.join
334:   else
335:     ""
336:   end
337: end

[Source]

     # File lib/mkmf.rb, line 938
938: def create_header(header = "extconf.h")
939:   message "creating %s\n", header
940:   sym = header.tr("a-z./\055", "A-Z___")
941:   hdr = ["#ifndef #{sym}\n#define #{sym}\n"]
942:   for line in $defs
943:     case line
944:     when /^-D([^=]+)(?:=(.*))?/
945:       hdr << "#define #$1 #{$2 ? Shellwords.shellwords($2)[0] : 1}\n"
946:     when /^-U(.*)/
947:       hdr << "#undef #$1\n"
948:     end
949:   end
950:   hdr << "#endif\n"
951:   hdr = hdr.join
952:   unless (IO.read(header) == hdr rescue false)
953:     open(header, "w") do |hfile|
954:       hfile.write(hdr)
955:     end
956:   end
957:   $extconf_h = header
958: end

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’".

[Source]

      # File lib/mkmf.rb, line 1167
1167: def create_makefile(target, srcprefix = nil)
1168:   $target = target
1169:   libpath = $DEFLIBPATH|$LIBPATH
1170:   message "creating Makefile\n"
1171:   rm_f "conftest*"
1172:   if CONFIG["DLEXT"] == $OBJEXT
1173:     for lib in libs = $libs.split
1174:       lib.sub!(/-l(.*)/, %%"lib\\1.#{$LIBEXT}"%)
1175:     end
1176:     $defs.push(format("-DEXTLIB='%s'", libs.join(",")))
1177:   end
1178: 
1179:   if target.include?('/')
1180:     target_prefix, target = File.split(target)
1181:     target_prefix[0,0] = '/'
1182:   else
1183:     target_prefix = ""
1184:   end
1185: 
1186:   srcprefix ||= '$(srcdir)'
1187:   Config::expand(srcdir = srcprefix.dup)
1188: 
1189:   if not $objs
1190:     $objs = []
1191:     srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
1192:     for f in srcs
1193:       obj = File.basename(f, ".*") << ".o"
1194:       $objs.push(obj) unless $objs.index(obj)
1195:     end
1196:   elsif !(srcs = $srcs)
1197:     srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')}
1198:   end
1199:   $srcs = srcs
1200:   for i in $objs
1201:     i.sub!(/\.o\z/, ".#{$OBJEXT}")
1202:   end
1203:   $objs = $objs.join(" ")
1204: 
1205:   target = nil if $objs == ""
1206: 
1207:   if target and EXPORT_PREFIX
1208:     if File.exist?(File.join(srcdir, target + '.def'))
1209:       deffile = "$(srcdir)/$(TARGET).def"
1210:       unless EXPORT_PREFIX.empty?
1211:         makedef = %{-pe "sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
1212:       end
1213:     else
1214:       makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"}
1215:     end
1216:     if makedef
1217:       $distcleanfiles << '$(DEFFILE)'
1218:       origdef = deffile
1219:       deffile = "$(TARGET)-$(arch).def"
1220:     end
1221:   end
1222:   origdef ||= ''
1223: 
1224:   libpath = libpathflag(libpath)
1225: 
1226:   dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
1227:   staticlib = target ? "$(TARGET).#$LIBEXT" : ""
1228:   mfile = open("Makefile", "wb")
1229:   mfile.print configuration(srcprefix)
1230:   mfile.print "
1231: libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")}
1232: LIBPATH = #{libpath}
1233: DEFFILE = #{deffile}
1234: 
1235: CLEANFILES = #{$cleanfiles.join(' ')}
1236: DISTCLEANFILES = #{$distcleanfiles.join(' ')}
1237: 
1238: extout = #{$extout}
1239: extout_prefix = #{$extout_prefix}
1240: target_prefix = #{target_prefix}
1241: LOCAL_LIBS = #{$LOCAL_LIBS}
1242: LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS}
1243: SRCS = #{srcs.collect(&File.method(:basename)).join(' ')}
1244: OBJS = #{$objs}
1245: TARGET = #{target}
1246: DLLIB = #{dllib}
1247: EXTSTATIC = #{$static || ""}
1248: STATIC_LIB = #{staticlib unless $static.nil?}
1249: #{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""}
1250: "
1251:   install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
1252:   n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET).'
1253:   mfile.print "
1254: TARGET_SO     = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB)
1255: CLEANLIBS     = #{n}#{CONFIG['DLEXT']} #{n}il? #{n}tds #{n}map
1256: CLEANOBJS     = *.#{$OBJEXT} *.#{$LIBEXT} *.s[ol] *.pdb *.exp *.bak
1257: 
1258: all:            #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"}
1259: static:         $(STATIC_LIB)#{$extout ? " install-rb" : ""}
1260: "
1261:   mfile.print CLEANINGS
1262:   dirs = []
1263:   mfile.print "install: install-so install-rb\n\n"
1264:   sodir = (dir = "$(RUBYARCHDIR)").dup
1265:   mfile.print("install-so: #{dir}\n")
1266:   if target
1267:     f = "$(DLLIB)"
1268:     dest = "#{dir}/#{f}"
1269:     mfile.print "install-so: #{dest}\n"
1270:     unless $extout
1271:       mfile.print "#{dest}: #{f}\n"
1272:       if (sep = config_string('BUILD_FILE_SEPARATOR'))
1273:         f.gsub!("/", sep)
1274:         dir.gsub!("/", sep)
1275:         sep = ":/="+sep
1276:         f.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2}
1277:         f.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2}
1278:         dir.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2}
1279:         dir.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2}
1280:       end
1281:       mfile.print "\t$(INSTALL_PROG) #{f} #{dir}\n"
1282:       if defined?($installed_list)
1283:         mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
1284:       end
1285:     end
1286:   end
1287:   mfile.print("install-rb: pre-install-rb install-rb-default\n")
1288:   mfile.print("install-rb-default: pre-install-rb-default\n")
1289:   mfile.print("pre-install-rb: Makefile\n")
1290:   mfile.print("pre-install-rb-default: Makefile\n")
1291:   for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]]
1292:     files = install_files(mfile, i, nil, srcprefix) or next
1293:     for dir, *files in files
1294:       unless dirs.include?(dir)
1295:         dirs << dir
1296:         mfile.print "pre-install-rb#{sfx}: #{dir}\n"
1297:       end
1298:       files.each do |f|
1299:         dest = "#{dir}/#{File.basename(f)}"
1300:         mfile.print("install-rb#{sfx}: #{dest}\n")
1301:         mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
1302:         sep = config_string('BUILD_FILE_SEPARATOR')
1303:         if sep
1304:           f = f.gsub("/", sep)
1305:           sep = ":/="+sep
1306:           f = f.gsub(/(\$\(\w+)(\))/) {$1+sep+$2}
1307:           f = f.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
1308:         else
1309:           sep = ""
1310:         end
1311:         mfile.print("#{f} $(@D#{sep})\n")
1312:         if defined?($installed_list) and !$extout
1313:           mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
1314:         end
1315:       end
1316:     end
1317:   end
1318:   dirs.unshift(sodir) if target and !dirs.include?(sodir)
1319:   dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"}
1320: 
1321:   mfile.print "\nsite-install: site-install-so site-install-rb\nsite-install-so: install-so\nsite-install-rb: install-rb\n\n"
1322: 
1323:   return unless target
1324: 
1325:   mfile.puts SRC_EXT.collect {|ext| ".path.#{ext} = $(VPATH)"} if $nmake == ?b
1326:   mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n"
1327:   mfile.print "\n"
1328: 
1329:   CXX_EXT.each do |ext|
1330:     COMPILE_RULES.each do |rule|
1331:       mfile.printf(rule, ext, $OBJEXT)
1332:       mfile.printf("\n\t%s\n\n", COMPILE_CXX)
1333:     end
1334:   end
1335:   %w[c].each do |ext|
1336:     COMPILE_RULES.each do |rule|
1337:       mfile.printf(rule, ext, $OBJEXT)
1338:       mfile.printf("\n\t%s\n\n", COMPILE_C)
1339:     end
1340:   end
1341: 
1342:   mfile.print "$(RUBYARCHDIR)/" if $extout
1343:   mfile.print "$(DLLIB): ", (makedef ? "$(DEFFILE) " : ""), "$(OBJS)\n"
1344:   mfile.print "\t@-$(RM) $@\n"
1345:   mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout
1346:   link_so = LINK_SO.gsub(/^/, "\t")
1347:   mfile.print link_so, "\n\n"
1348:   unless $static.nil?
1349:     mfile.print "$(STATIC_LIB): $(OBJS)\n\t"
1350:     mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
1351:     config_string('RANLIB') do |ranlib|
1352:       mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true"
1353:     end
1354:   end
1355:   mfile.print "\n\n"
1356:   if makedef
1357:     mfile.print "$(DEFFILE): #{origdef}\n"
1358:     mfile.print "\t$(RUBY) #{makedef} #{origdef} > $@\n\n"
1359:   end
1360: 
1361:   depend = File.join(srcdir, "depend")
1362:   if File.exist?(depend)
1363:     suffixes = []
1364:     depout = []
1365:     open(depend, "r") do |dfile|
1366:       mfile.printf "###\n"
1367:       cont = implicit = nil
1368:       impconv = proc do
1369:         COMPILE_RULES.each {|rule| depout << (rule % implicit[0]) << implicit[1]}
1370:         implicit = nil
1371:       end
1372:       ruleconv = proc do |line|
1373:         if implicit
1374:           if /\A\t/ =~ line
1375:             implicit[1] << line
1376:             next
1377:           else
1378:             impconv[]
1379:           end
1380:         end
1381:         if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line)
1382:           suffixes << m[1] << m[2]
1383:           implicit = [[m[1], m[2]], [m.post_match]]
1384:           next
1385:         elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line
1386:           line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2}
1387:         end
1388:         depout << line
1389:       end
1390:       while line = dfile.gets()
1391:         line.gsub!(/\.o\b/, ".#{$OBJEXT}")
1392:         line.gsub!(/\$\(hdrdir\)\/config.h/, $config_h) if $config_h
1393:         if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line
1394:           (cont ||= []) << line
1395:           next
1396:         elsif cont
1397:           line = (cont << line).join
1398:           cont = nil
1399:         end
1400:         ruleconv.call(line)
1401:       end
1402:       if cont
1403:         ruleconv.call(cont.join)
1404:       elsif implicit
1405:         impconv.call
1406:       end
1407:     end
1408:     unless suffixes.empty?
1409:       mfile.print ".SUFFIXES: .", suffixes.uniq.join(" ."), "\n\n"
1410:     end
1411:     mfile.print depout
1412:   else
1413:     headers = %w[ruby.h defines.h]
1414:     if RULE_SUBST
1415:       headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}}
1416:     end
1417:     headers << $config_h if $config_h
1418:     headers << "$(RUBY_EXTCONF_H)" if $extconf_h
1419:     mfile.print "$(OBJS): ", headers.join(' '), "\n"
1420:   end
1421: 
1422:   $makefile_created = true
1423: ensure
1424:   mfile.close if mfile
1425: end

[Source]

     # File lib/mkmf.rb, line 257
257: def create_tmpsrc(src)
258:   src = yield(src) if block_given?
259:   src = src.gsub(/[ \t]+$/, '').gsub(/\A\n+|^\n+$/, '').sub(/[^\n]\z/, "\\&\n")
260:   open(CONFTEST_C, "wb") do |cfile|
261:     cfile.print src
262:   end
263:   src
264: end

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.

[Source]

      # File lib/mkmf.rb, line 971
 971: def dir_config(target, idefault=nil, ldefault=nil)
 972:   if dir = with_config(target + "-dir", (idefault unless ldefault))
 973:     defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR)
 974:     idefault = ldefault = nil
 975:   end
 976: 
 977:   idir = with_config(target + "-include", idefault)
 978:   $arg_config.last[1] ||= "${#{target}-dir}/include"
 979:   ldir = with_config(target + "-lib", ldefault)
 980:   $arg_config.last[1] ||= "${#{target}-dir}/lib"
 981: 
 982:   idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : []
 983:   if defaults
 984:     idirs.concat(defaults.collect {|dir| dir + "/include"})
 985:     idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
 986:   end
 987:   unless idirs.empty?
 988:     idirs.collect! {|dir| "-I" + dir}
 989:     idirs -= Shellwords.shellwords($CPPFLAGS)
 990:     unless idirs.empty?
 991:       $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
 992:     end
 993:   end
 994: 
 995:   ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : []
 996:   if defaults
 997:     ldirs.concat(defaults.collect {|dir| dir + "/lib"})
 998:     ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
 999:   end
1000:   $LIBPATH = ldirs | $LIBPATH
1001: 
1002:   [idir, ldir]
1003: end

[Source]

    # File lib/mkmf.rb, line 73
73: def dir_re(dir)
74:   Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$(?:\(target_prefix\)|\{target_prefix\}))?')
75: end

[Source]

      # File lib/mkmf.rb, line 1139
1139: def dummy_makefile(srcdir)
1140:   configuration(srcdir) << "CLEANFILES = \#{$cleanfiles.join(' ')}\nDISTCLEANFILES = \#{$distcleanfiles.join(' ')}\n\nall install static install-so install-rb: Makefile\n\n" << CLEANINGS
1141: end

[Source]

     # File lib/mkmf.rb, line 452
452: def egrep_cpp(pat, src, opt = "", &b)
453:   src = create_tmpsrc(src, &b)
454:   xpopen(cpp_command('', opt)) do |f|
455:     if Regexp === pat
456:       puts("    ruby -ne 'print if #{pat.inspect}'")
457:       f.grep(pat) {|l|
458:         puts "#{f.lineno}: #{l}"
459:         return true
460:       }
461:       false
462:     else
463:       puts("    egrep '#{pat}'")
464:       begin
465:         stdin = $stdin.dup
466:         $stdin.reopen(f)
467:         system("egrep", pat)
468:       ensure
469:         $stdin.reopen(stdin)
470:       end
471:     end
472:   end
473: ensure
474:   rm_f "conftest*"
475:   log_src(src)
476: end

[Source]

     # File lib/mkmf.rb, line 926
926: def enable_config(config, *defaults)
927:   if arg_config("--enable-"+config)
928:     true
929:   elsif arg_config("--disable-"+config)
930:     false
931:   elsif block_given?
932:     yield(config, *defaults)
933:   else
934:     return *defaults
935:   end
936: end

[Source]

     # File lib/mkmf.rb, line 893
893: def find_executable(bin, path = nil)
894:   checking_for checking_message(bin, path) do
895:     find_executable0(bin, path)
896:   end
897: end

[Source]

     # File lib/mkmf.rb, line 873
873: def  find_executable0find_executable0(bin, path = nil)
874:   ext = config_string('EXEEXT')
875:   if File.expand_path(bin) == bin
876:     return bin if File.executable?(bin)
877:     ext and File.executable?(file = bin + ext) and return file
878:     return nil
879:   end
880:   if path ||= ENV['PATH']
881:     path = path.split(File::PATH_SEPARATOR)
882:   else
883:     path = %w[/usr/local/bin /usr/ucb /usr/bin /bin]
884:   end
885:   file = nil
886:   path.each do |dir|
887:     return file if File.executable?(file = File.join(dir, bin))
888:     return file if ext and File.executable?(file << ext)
889:   end
890:   nil
891: end

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).

[Source]

     # File lib/mkmf.rb, line 712
712: def find_header(header, *paths)
713:   header = cpp_include(header)
714:   checking_for header do
715:     if try_cpp(header)
716:       true
717:     else
718:       found = false
719:       paths.each do |dir|
720:         opt = "-I#{dir}".quote
721:         if try_cpp(header, opt)
722:           $INCFLAGS << " " << opt
723:           found = true
724:           break
725:         end
726:       end
727:       found
728:     end
729:   end
730: end

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.

[Source]

     # File lib/mkmf.rb, line 628
628: def find_library(lib, func, *paths, &b)
629:   func = "main" if !func or func.empty?
630:   lib = with_config(lib+'lib', lib)
631:   paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten
632:   checking_for "#{func}() in #{LIBARG%lib}" do
633:     libpath = $LIBPATH
634:     libs = append_library($libs, lib)
635:     begin
636:       until r = try_func(func, libs, &b) or paths.empty?
637:         $LIBPATH = libpath | [paths.shift]
638:       end
639:       if r
640:         $libs = libs
641:         libpath = nil
642:       end
643:     ensure
644:       $LIBPATH = libpath if libpath
645:     end
646:     r
647:   end
648: end

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.

[Source]

     # File lib/mkmf.rb, line 658
658: def have_func(func, headers = nil, &b)
659:   checking_for checking_message("#{func}()", headers) do
660:     if try_func(func, $libs, headers, &b)
661:       $defs.push(format("-DHAVE_%s", func.upcase))
662:       true
663:     else
664:       false
665:     end
666:   end
667: end

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.

[Source]

     # File lib/mkmf.rb, line 695
695: def have_header(header, &b)
696:   checking_for header do
697:     if try_cpp(cpp_include(header), &b)
698:       $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___")))
699:       true
700:     else
701:       false
702:     end
703:   end
704: end

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.

[Source]

     # File lib/mkmf.rb, line 603
603: def have_library(lib, func = nil, headers = nil, &b)
604:   func = "main" if !func or func.empty?
605:   lib = with_config(lib+'lib', lib)
606:   checking_for checking_message("#{func}()", LIBARG%lib) do
607:     if COMMON_LIBS.include?(lib)
608:       true
609:     else
610:       libs = append_library($libs, lib)
611:       if try_func(func, libs, headers, &b)
612:         $libs = libs
613:         true
614:       else
615:         false
616:       end
617:     end
618:   end
619: end

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.

[Source]

     # File lib/mkmf.rb, line 586
586: def have_macro(macro, headers = nil, opt = "", &b)
587:   checking_for checking_message(macro, headers, opt) do
588:     macro_defined?(macro, cpp_include(headers), opt, &b)
589:   end
590: end

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.

[Source]

     # File lib/mkmf.rb, line 743
743: def have_struct_member(type, member, headers = nil, &b)
744:   checking_for checking_message("#{type}.#{member}", headers) do
745:     if try_compile("\#{COMMON_HEADERS}\n\#{cpp_include(headers)}\n/*top*/\nint main() { return 0; }\nint s = (char *)&((\#{type}*)0)->\#{member} - (char *)0;\n", &b)
746:       $defs.push(format("-DHAVE_ST_%s", member.upcase))
747:       true
748:     else
749:       false
750:     end
751:   end
752: end

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.

[Source]

     # File lib/mkmf.rb, line 774
774: def have_type(type, headers = nil, opt = "", &b)
775:   checking_for checking_message(type, headers, opt) do
776:     headers = cpp_include(headers)
777:     if try_compile("\#{COMMON_HEADERS}\n\#{headers}\n/*top*/\ntypedef \#{type} conftest_type;\nstatic conftest_type conftestval[sizeof(conftest_type)?1:-1];\n", opt, &b)
778:       $defs.push(format("-DHAVE_TYPE_%s", type.strip.upcase.tr_s("^A-Z0-9_", "_")))
779:       true
780:     else
781:       false
782:     end
783:   end
784: end

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.

[Source]

     # File lib/mkmf.rb, line 677
677: def have_var(var, headers = nil, &b)
678:   checking_for checking_message(var, headers) do
679:     if try_var(var, headers, &b)
680:       $defs.push(format("-DHAVE_%s", var.upcase))
681:       true
682:     else
683:       false
684:     end
685:   end
686: end

[Source]

      # File lib/mkmf.rb, line 1434
1434: def init_mkmf(config = CONFIG)
1435:   $makefile_created = false
1436:   $arg_config = []
1437:   $enable_shared = config['ENABLE_SHARED'] == 'yes'
1438:   $defs = []
1439:   $extconf_h = nil
1440:   $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup
1441:   $ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup
1442:   $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup
1443:   $LDFLAGS = with_config("ldflags", arg_config("LDFLAGS", config["LDFLAGS"])).dup
1444:   $INCFLAGS = "-I$(topdir) -I$(hdrdir) -I$(srcdir)"
1445:   $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup
1446:   $LIBEXT = config['LIBEXT'].dup
1447:   $OBJEXT = config["OBJEXT"].dup
1448:   $LIBS = "#{config['LIBS']} #{config['DLDLIBS']}"
1449:   $LIBRUBYARG = ""
1450:   $LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
1451:   $LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED']
1452:   $DEFLIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"]
1453:   $DEFLIBPATH.unshift(".")
1454:   $LIBPATH = []
1455:   $INSTALLFILES = nil
1456: 
1457:   $objs = nil
1458:   $srcs = nil
1459:   $libs = ""
1460:   if $enable_shared or Config.expand(config["LIBRUBY"].dup) != Config.expand(config["LIBRUBY_A"].dup)
1461:     $LIBRUBYARG = config['LIBRUBYARG']
1462:   end
1463: 
1464:   $LOCAL_LIBS = ""
1465: 
1466:   $cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || []
1467:   $distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || []
1468: 
1469:   $extout ||= nil
1470:   $extout_prefix ||= nil
1471: 
1472:   $arg_config.clear
1473:   dir_config("opt")
1474: end

[Source]

     # File lib/mkmf.rb, line 86
 86: def install_dirs(target_prefix = nil)
 87:   if $extout
 88:     dirs = [
 89:       ['RUBYCOMMONDIR', '$(extout)/common'],
 90:       ['RUBYLIBDIR',    '$(RUBYCOMMONDIR)$(target_prefix)'],
 91:       ['RUBYARCHDIR',   '$(extout)/$(arch)$(target_prefix)'],
 92:       ['extout',        "#$extout"],
 93:       ['extout_prefix', "#$extout_prefix"],
 94:     ]
 95:   elsif $extmk
 96:     dirs = [
 97:       ['RUBYCOMMONDIR', '$(rubylibdir)'],
 98:       ['RUBYLIBDIR',    '$(rubylibdir)$(target_prefix)'],
 99:       ['RUBYARCHDIR',   '$(archdir)$(target_prefix)'],
100:     ]
101:   else
102:     dirs = [
103:       ['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'],
104:       ['RUBYLIBDIR',    '$(sitelibdir)$(target_prefix)'],
105:       ['RUBYARCHDIR',   '$(sitearchdir)$(target_prefix)'],
106:     ]
107:   end
108:   dirs << ['target_prefix', (target_prefix ? "/#{target_prefix}" : "")]
109:   dirs
110: end

[Source]

     # File lib/mkmf.rb, line 500
500: def install_files(mfile, ifiles, map = nil, srcprefix = nil)
501:   ifiles or return
502:   srcprefix ||= '$(srcdir)'
503:   Config::expand(srcdir = srcprefix.dup)
504:   dirs = []
505:   path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]}
506:   ifiles.each do |files, dir, prefix|
507:     dir = map_dir(dir, map)
508:     prefix = %r|\A#{Regexp.quote(prefix)}/?| if prefix
509:     if /\A\.\// =~ files
510:       # install files which are in current working directory.
511:       files = files[2..-1]
512:       len = nil
513:     else
514:       # install files which are under the $(srcdir).
515:       files = File.join(srcdir, files)
516:       len = srcdir.size
517:     end
518:     f = nil
519:     Dir.glob(files) do |f|
520:       f[0..len] = "" if len
521:       d = File.dirname(f)
522:       d.sub!(prefix, "") if prefix
523:       d = (d.empty? || d == ".") ? dir : File.join(dir, d)
524:       f = File.join(srcprefix, f) if len
525:       path[d] << f
526:     end
527:     unless len or f
528:       d = File.dirname(files)
529:       d.sub!(prefix, "") if prefix
530:       d = (d.empty? || d == ".") ? dir : File.join(dir, d)
531:       path[d] << files
532:     end
533:   end
534:   dirs
535: end

[Source]

     # File lib/mkmf.rb, line 537
537: def install_rb(mfile, dest, srcdir = nil)
538:   install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir)
539: end

[Source]

     # File lib/mkmf.rb, line 297
297: def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
298:   libpath.map{|x|
299:     case x
300:     when "$(topdir)", /\A\./
301:       LIBPATHFLAG
302:     else
303:       LIBPATHFLAG+RPATHFLAG
304:     end % x.quote
305:   }.join
306: end

[Source]

     # File lib/mkmf.rb, line 273
273: def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
274:   Config::expand(TRY_LINK.dup,
275:                  CONFIG.merge('hdrdir' => $hdrdir.quote,
276:                               'src' => CONFTEST_C,
277:                               'INCFLAGS' => $INCFLAGS,
278:                               'CPPFLAGS' => $CPPFLAGS,
279:                               'CFLAGS' => "#$CFLAGS",
280:                               'ARCH_FLAG' => "#$ARCH_FLAG",
281:                               'LDFLAGS' => "#$LDFLAGS #{ldflags}",
282:                               'LIBPATH' => libpathflag(libpath),
283:                               'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
284:                               'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS"))
285: end

[Source]

     # File lib/mkmf.rb, line 241
241: def log_src(src)
242:   src = src.split(/^/)
243:   fmt = "%#{src.size.to_s.size}d: %s"
244:   Logging::message "checked program was:\n/* begin */\n"
245:   src.each_with_index {|line, no| Logging::message fmt, no+1, line}
246:   Logging::message "/* end */\n\n"
247: end

[Source]

     # File lib/mkmf.rb, line 478
478: def macro_defined?(macro, src, opt = "", &b)
479:   src = src.sub(/[^\n]\z/, "\\&\n")
480:   try_compile(src + "/*top*/\n#ifndef \#{macro}\n# error\n>>>>>> \#{macro} undefined <<<<<<\n#endif\n", opt, &b)
481: end

[Source]

     # File lib/mkmf.rb, line 112
112: def map_dir(dir, map = nil)
113:   map ||= INSTALL_DIRS
114:   map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)}
115: end

[Source]

     # File lib/mkmf.rb, line 155
155: def merge_libs(*libs)
156:   libs.inject([]) do |x, y|
157:     xy = x & y
158:     xn = yn = 0
159:     y = y.inject([]) {|ary, e| ary.last == e ? ary : ary << e}
160:     y.each_with_index do |v, yi|
161:       if xy.include?(v)
162:         xi = [x.index(v), xn].max()
163:         x[xi, 1] = y[yn..yi]
164:         xn, yn = xi + (yi - yn + 1), yi + 1
165:       end
166:     end
167:     x.concat(y[yn..-1] || [])
168:   end
169: end

[Source]

     # File lib/mkmf.rb, line 545
545: def message(*s)
546:   unless $extmk and not $VERBOSE
547:     printf(*s)
548:     $stdout.flush
549:   end
550: end

[Source]

      # File lib/mkmf.rb, line 1485
1485: def mkmf_failed(path)
1486:   unless $makefile_created or File.exist?("Makefile")
1487:     opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"}
1488:     abort "*** #{path} failed ***\n" + FailedMessage + opts.join
1489:   end
1490: end

[Source]

     # File lib/mkmf.rb, line 149
149: def modified?(target, times)
150:   (t = File.mtime(target)) rescue return nil
151:   Array === times or times = [times]
152:   t if times.all? {|n| n <= t}
153: end

[Source]

      # File lib/mkmf.rb, line 1005
1005: def pkg_config(pkg)
1006:   if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
1007:     # iff package specific config command is given
1008:     get = proc {|opt| `#{pkgconfig} --#{opt}`.chomp}
1009:   elsif ($PKGCONFIG ||= 
1010:          (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) &&
1011:          find_executable0(pkgconfig) && pkgconfig) and
1012:       system("#{$PKGCONFIG} --exists #{pkg}")
1013:     # default to pkg-config command
1014:     get = proc {|opt| `#{$PKGCONFIG} --#{opt} #{pkg}`.chomp}
1015:   elsif find_executable0(pkgconfig = "#{pkg}-config")
1016:     # default to package specific config command, as a last resort.
1017:     get = proc {|opt| `#{pkgconfig} --#{opt}`.chomp}
1018:   end
1019:   if get
1020:     cflags = get['cflags']
1021:     ldflags = get['libs']
1022:     libs = get['libs-only-l']
1023:     ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
1024:     $CFLAGS += " " << cflags
1025:     $LDFLAGS += " " << ldflags
1026:     $libs += " " << libs
1027:     Logging::message "package configuration for %s\n", pkg
1028:     Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n",
1029:                      cflags, ldflags, libs
1030:     [cflags, ldflags, libs]
1031:   else
1032:     Logging::message "package configuration for %s is not found\n", pkg
1033:     nil
1034:   end
1035: end

[Source]

     # File lib/mkmf.rb, line 145
145: def rm_f(*files)
146:   FileUtils.rm_f(Dir[files.join("\0")])
147: end

[Source]

     # File lib/mkmf.rb, line 817
817: def  scalar_ptr_type?scalar_ptr_type?(type, member = nil, headers = nil, &b)
818:   try_compile("\#{COMMON_HEADERS}\n\#{cpp_include(headers)}\n/*top*/\nvolatile \#{type} conftestval;\nint main() { return 0; }\nint t() {return (int)(1-*(conftestval\#{member ? \".\#{member}\" : \"\"}));}\n", &b)   # pointer
819: end

[Source]

     # File lib/mkmf.rb, line 829
829: def scalar_type?(type, member = nil, headers = nil, &b)
830:   try_compile("\#{COMMON_HEADERS}\n\#{cpp_include(headers)}\n/*top*/\nvolatile \#{type} conftestval;\nint main() { return 0; }\nint t() {return (int)(1-(conftestval\#{member ? \".\#{member}\" : \"\"}));}\n", &b)   # pointer
831: end

[Source]

     # File lib/mkmf.rb, line 318
318: def try_compile(src, opt="", &b)
319:   try_do(src, cc_command(opt), &b)
320: ensure
321:   rm_f "conftest*"
322: end

[Source]

     # File lib/mkmf.rb, line 374
374: def try_constant(const, headers = nil, opt = "", &b)
375:   includes = cpp_include(headers)
376:   if CROSS_COMPILING
377:     if try_static_assert("#{const} > 0", headers, opt)
378:       # positive constant
379:     elsif try_static_assert("#{const} < 0", headers, opt)
380:       neg = true
381:       const = "-(#{const})"
382:     elsif try_static_assert("#{const} == 0", headers, opt)
383:       return 0
384:     else
385:       # not a constant
386:       return nil
387:     end
388:     upper = 1
389:     lower = 0
390:     until try_static_assert("#{const} <= #{upper}", headers, opt)
391:       lower = upper
392:       upper <<= 1
393:     end
394:     return nil unless lower
395:     while upper > lower + 1
396:       mid = (upper + lower) / 2
397:       if try_static_assert("#{const} > #{mid}", headers, opt)
398:         lower = mid
399:       else
400:         upper = mid
401:       end
402:     end
403:     upper = -upper if neg
404:     return upper
405:   else
406:     src = %{#{COMMON_HEADERS}
407: #{includes}
408: #include <stdio.h>
409: /*top*/
410: int conftest_const = (int)(#{const});
411: int main() {printf("%d\\n", conftest_const); return 0;}
412: }
413:     if try_link0(src, opt, &b)
414:       xpopen("./conftest") do |f|
415:         return Integer(f.gets)
416:       end
417:     end
418:   end
419:   nil
420: end

[Source]

     # File lib/mkmf.rb, line 324
324: def try_cpp(src, opt="", &b)
325:   try_do(src, cpp_command(CPPOUTFILE, opt), &b)
326: ensure
327:   rm_f "conftest*"
328: end

[Source]

     # File lib/mkmf.rb, line 266
266: def try_do(src, command, &b)
267:   src = create_tmpsrc(src, &b)
268:   xsystem(command)
269: ensure
270:   log_src(src)
271: end

[Source]

     # File lib/mkmf.rb, line 422
422: def try_func(func, libs, headers = nil, &b)
423:   headers = cpp_include(headers)
424:   try_link("\#{COMMON_HEADERS}\n\#{headers}\n/*top*/\nint main() { return 0; }\nint t() { void ((*volatile p)()); p = (void ((*)()))\#{func}; return 0; }\n", libs, &b) or try_link("\#{headers}\n/*top*/\nint main() { return 0; }\nint t() { \#{func}(); return 0; }\n", libs, &b)
425: end

[Source]

     # File lib/mkmf.rb, line 312
312: def try_link(src, opt="", &b)
313:   try_link0(src, opt, &b)
314: ensure
315:   rm_f "conftest*", "c0x32*"
316: end

[Source]

     # File lib/mkmf.rb, line 308
308: def try_link0(src, opt="", &b)
309:   try_do(src, link_command("", opt), &b)
310: end

[Source]

     # File lib/mkmf.rb, line 490
490: def try_run(src, opt = "", &b)
491:   if try_link0(src, opt, &b)
492:     xsystem("./conftest")
493:   else
494:     nil
495:   end
496: ensure
497:   rm_f "conftest*"
498: end

[Source]

     # File lib/mkmf.rb, line 363
363: def try_static_assert(expr, headers = nil, opt = "", &b)
364:   headers = cpp_include(headers)
365:   try_compile("\#{COMMON_HEADERS}\n\#{headers}\n/*top*/\nint conftest_const[(\#{expr}) ? 1 : -1];\n", opt, &b)
366: end

[Source]

     # File lib/mkmf.rb, line 440
440: def try_var(var, headers = nil, &b)
441:   headers = cpp_include(headers)
442:   try_compile("\#{COMMON_HEADERS}\n\#{headers}\n/*top*/\nint main() { return 0; }\nint t() { const volatile void *volatile p; p = (void *)&\#{var}; return 0; }\n", &b)
443: end

[Source]

     # File lib/mkmf.rb, line 841
841: def what_type?(type, member = nil, headers = nil, &b)
842:   m = "#{type}"
843:   name = type
844:   if member
845:     m << "." << member
846:     name = "(((#{type} *)0)->#{member})"
847:   end
848:   fmt = "seems %s"
849:   def fmt.%(x)
850:     x ? super : "unknown"
851:   end
852:   checking_for checking_message(m, headers), fmt do
853:     if scalar_ptr_type?(type, member, headers, &b)
854:       if try_static_assert("sizeof(*#{name}) == 1", headers)
855:         "string"
856:       end
857:     elsif scalar_type?(type, member, headers, &b)
858:       if try_static_assert("sizeof(#{name}) > sizeof(long)", headers)
859:         "long long"
860:       elsif try_static_assert("sizeof(#{name}) > sizeof(int)", headers)
861:         "long"
862:       elsif try_static_assert("sizeof(#{name}) > sizeof(short)", headers)
863:         "int"
864:       elsif try_static_assert("sizeof(#{name}) > 1", headers)
865:         "short"
866:       else
867:         "char"
868:       end
869:     end
870:   end
871: end

[Source]

      # File lib/mkmf.rb, line 1042
1042: def winsep(s)
1043:   s.tr('/', '\\')
1044: end

[Source]

     # File lib/mkmf.rb, line 347
347: def with_cflags(flags)
348:   cflags = $CFLAGS
349:   $CFLAGS = flags
350:   ret = yield
351: ensure
352:   $CFLAGS = cflags unless ret
353: end

[Source]

     # File lib/mkmf.rb, line 905
905: def with_config(config, *defaults)
906:   config = config.sub(/^--with[-_]/, '')
907:   val = arg_config("--with-"+config) do
908:     if arg_config("--without-"+config)
909:       false
910:     elsif block_given?
911:       yield(config, *defaults)
912:     else
913:       break *defaults
914:     end
915:   end
916:   case val
917:   when "yes"
918:     true
919:   when "no"
920:     false
921:   else
922:     val
923:   end
924: end

[Source]

     # File lib/mkmf.rb, line 339
339: def with_cppflags(flags)
340:   cppflags = $CPPFLAGS
341:   $CPPFLAGS = flags
342:   ret = yield
343: ensure
344:   $CPPFLAGS = cppflags unless ret
345: end

[Source]

      # File lib/mkmf.rb, line 1037
1037: def with_destdir(dir)
1038:   dir = dir.sub($dest_prefix_pattern, '')
1039:   /\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir
1040: end

[Source]

     # File lib/mkmf.rb, line 355
355: def with_ldflags(flags)
356:   ldflags = $LDFLAGS
357:   $LDFLAGS = flags
358:   ret = yield
359: ensure
360:   $LDFLAGS = ldflags unless ret
361: end

[Source]

     # File lib/mkmf.rb, line 229
229: def xpopen command, *mode, &block
230:   Logging::open do
231:     case mode[0]
232:     when nil, /^r/
233:       puts "#{command} |"
234:     else
235:       puts "| #{command}"
236:     end
237:     IO.popen(command, *mode, &block)
238:   end
239: end

[Source]

     # File lib/mkmf.rb, line 222
222: def xsystem command
223:   Logging::open do
224:     puts command.quote
225:     system(command)
226:   end
227: end

[Validate]