mkmf.rb

Path: lib/mkmf.rb
Last Update: Sat Jun 07 08:53:42 +0000 2008

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 543
543: def append_library(libs, lib)
544:   format(LIBARG, lib) + " " + libs
545: end

[Source]

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

[Source]

     # File lib/mkmf.rb, line 287
287: def cc_command(opt="")
288:   conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)
289:   Config::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
290:                  conf)
291: 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 805
805: def check_sizeof(type, headers = nil, &b)
806:   expr = "sizeof(#{type})"
807:   fmt = "%d"
808:   def fmt.%(x)
809:     x ? super : "failed"
810:   end
811:   checking_for checking_message("size of #{type}", headers), fmt do
812:     if size = try_constant(expr, headers, &b)
813:       $defs.push(format("-DSIZEOF_%s=%d", type.upcase.tr_s("^A-Z0-9_", "_"), size))
814:       size
815:     end
816:   end
817: end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

     # File lib/mkmf.rb, line 875
875: def  find_executable0find_executable0(bin, path = nil)
876:   ext = config_string('EXEEXT')
877:   if File.expand_path(bin) == bin
878:     return bin if File.executable?(bin)
879:     ext and File.executable?(file = bin + ext) and return file
880:     return nil
881:   end
882:   if path ||= ENV['PATH']
883:     path = path.split(File::PATH_SEPARATOR)
884:   else
885:     path = %w[/usr/local/bin /usr/ucb /usr/bin /bin]
886:   end
887:   file = nil
888:   path.each do |dir|
889:     return file if File.executable?(file = File.join(dir, bin))
890:     return file if ext and File.executable?(file << ext)
891:   end
892:   nil
893: 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 714
714: def find_header(header, *paths)
715:   header = cpp_include(header)
716:   checking_for header do
717:     if try_cpp(header)
718:       true
719:     else
720:       found = false
721:       paths.each do |dir|
722:         opt = "-I#{dir}".quote
723:         if try_cpp(header, opt)
724:           $INCFLAGS << " " << opt
725:           found = true
726:           break
727:         end
728:       end
729:       found
730:     end
731:   end
732: 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 630
630: def find_library(lib, func, *paths, &b)
631:   func = "main" if !func or func.empty?
632:   lib = with_config(lib+'lib', lib)
633:   paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten
634:   checking_for "#{func}() in #{LIBARG%lib}" do
635:     libpath = $LIBPATH
636:     libs = append_library($libs, lib)
637:     begin
638:       until r = try_func(func, libs, &b) or paths.empty?
639:         $LIBPATH = libpath | [paths.shift]
640:       end
641:       if r
642:         $libs = libs
643:         libpath = nil
644:       end
645:     ensure
646:       $LIBPATH = libpath if libpath
647:     end
648:     r
649:   end
650: 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 660
660: def have_func(func, headers = nil, &b)
661:   checking_for checking_message("#{func}()", headers) do
662:     if try_func(func, $libs, headers, &b)
663:       $defs.push(format("-DHAVE_%s", func.upcase))
664:       true
665:     else
666:       false
667:     end
668:   end
669: 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 697
697: def have_header(header, &b)
698:   checking_for header do
699:     if try_cpp(cpp_include(header), &b)
700:       $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___")))
701:       true
702:     else
703:       false
704:     end
705:   end
706: 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 605
605: def have_library(lib, func = nil, headers = nil, &b)
606:   func = "main" if !func or func.empty?
607:   lib = with_config(lib+'lib', lib)
608:   checking_for checking_message("#{func}()", LIBARG%lib) do
609:     if COMMON_LIBS.include?(lib)
610:       true
611:     else
612:       libs = append_library($libs, lib)
613:       if try_func(func, libs, headers, &b)
614:         $libs = libs
615:         true
616:       else
617:         false
618:       end
619:     end
620:   end
621: 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 588
588: def have_macro(macro, headers = nil, opt = "", &b)
589:   checking_for checking_message(macro, headers, opt) do
590:     macro_defined?(macro, cpp_include(headers), opt, &b)
591:   end
592: 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 745
745: def have_struct_member(type, member, headers = nil, &b)
746:   checking_for checking_message("#{type}.#{member}", headers) do
747:     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)
748:       $defs.push(format("-DHAVE_ST_%s", member.upcase))
749:       true
750:     else
751:       false
752:     end
753:   end
754: 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 776
776: def have_type(type, headers = nil, opt = "", &b)
777:   checking_for checking_message(type, headers, opt) do
778:     headers = cpp_include(headers)
779:     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)
780:       $defs.push(format("-DHAVE_TYPE_%s", type.strip.upcase.tr_s("^A-Z0-9_", "_")))
781:       true
782:     else
783:       false
784:     end
785:   end
786: 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 679
679: def have_var(var, headers = nil, &b)
680:   checking_for checking_message(var, headers) do
681:     if try_var(var, headers, &b)
682:       $defs.push(format("-DHAVE_%s", var.upcase))
683:       true
684:     else
685:       false
686:     end
687:   end
688: end

[Source]

      # File lib/mkmf.rb, line 1437
1437: def init_mkmf(config = CONFIG)
1438:   $makefile_created = false
1439:   $arg_config = []
1440:   $enable_shared = config['ENABLE_SHARED'] == 'yes'
1441:   $defs = []
1442:   $extconf_h = nil
1443:   $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup
1444:   $ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup
1445:   $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup
1446:   $LDFLAGS = with_config("ldflags", arg_config("LDFLAGS", config["LDFLAGS"])).dup
1447:   $INCFLAGS = "-I$(topdir) -I$(hdrdir) -I$(srcdir)"
1448:   $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup
1449:   $LIBEXT = config['LIBEXT'].dup
1450:   $OBJEXT = config["OBJEXT"].dup
1451:   $LIBS = "#{config['LIBS']} #{config['DLDLIBS']}"
1452:   $LIBRUBYARG = ""
1453:   $LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
1454:   $LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED']
1455:   $DEFLIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"]
1456:   $DEFLIBPATH.unshift(".")
1457:   $LIBPATH = []
1458:   $INSTALLFILES = nil
1459: 
1460:   $objs = nil
1461:   $srcs = nil
1462:   $libs = ""
1463:   if $enable_shared or Config.expand(config["LIBRUBY"].dup) != Config.expand(config["LIBRUBY_A"].dup)
1464:     $LIBRUBYARG = config['LIBRUBYARG']
1465:   end
1466: 
1467:   $LOCAL_LIBS = ""
1468: 
1469:   $cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || []
1470:   $cleanfiles << "mkmf.log"
1471:   $distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || []
1472: 
1473:   $extout ||= nil
1474:   $extout_prefix ||= nil
1475: 
1476:   $arg_config.clear
1477:   dir_config("opt")
1478: 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 502
502: def install_files(mfile, ifiles, map = nil, srcprefix = nil)
503:   ifiles or return
504:   srcprefix ||= '$(srcdir)'
505:   Config::expand(srcdir = srcprefix.dup)
506:   dirs = []
507:   path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]}
508:   ifiles.each do |files, dir, prefix|
509:     dir = map_dir(dir, map)
510:     prefix = %r|\A#{Regexp.quote(prefix)}/?| if prefix
511:     if /\A\.\// =~ files
512:       # install files which are in current working directory.
513:       files = files[2..-1]
514:       len = nil
515:     else
516:       # install files which are under the $(srcdir).
517:       files = File.join(srcdir, files)
518:       len = srcdir.size
519:     end
520:     f = nil
521:     Dir.glob(files) do |f|
522:       f[0..len] = "" if len
523:       d = File.dirname(f)
524:       d.sub!(prefix, "") if prefix
525:       d = (d.empty? || d == ".") ? dir : File.join(dir, d)
526:       f = File.join(srcprefix, f) if len
527:       path[d] << f
528:     end
529:     unless len or f
530:       d = File.dirname(files)
531:       d.sub!(prefix, "") if prefix
532:       d = (d.empty? || d == ".") ? dir : File.join(dir, d)
533:       path[d] << files
534:     end
535:   end
536:   dirs
537: end

[Source]

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

[Source]

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

[Source]

     # File lib/mkmf.rb, line 273
273: def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
274:   conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote,
275:                               'src' => CONFTEST_C,
276:                               'INCFLAGS' => $INCFLAGS,
277:                               'CPPFLAGS' => $CPPFLAGS,
278:                               'CFLAGS' => "#$CFLAGS",
279:                               'ARCH_FLAG' => "#$ARCH_FLAG",
280:                               'LDFLAGS' => "#$LDFLAGS #{ldflags}",
281:                               'LIBPATH' => libpathflag(libpath),
282:                               'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
283:                               'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS")
284:   Config::expand(TRY_LINK.dup, conf)
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 480
480: def macro_defined?(macro, src, opt = "", &b)
481:   src = src.sub(/[^\n]\z/, "\\&\n")
482:   try_compile(src + "/*top*/\n#ifndef \#{macro}\n# error\n>>>>>> \#{macro} undefined <<<<<<\n#endif\n", opt, &b)
483: 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 547
547: def message(*s)
548:   unless $extmk and not $VERBOSE
549:     printf(*s)
550:     $stdout.flush
551:   end
552: end

[Source]

      # File lib/mkmf.rb, line 1489
1489: def mkmf_failed(path)
1490:   unless $makefile_created or File.exist?("Makefile")
1491:     opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"}
1492:     abort "*** #{path} failed ***\n" + FailedMessage + opts.join
1493:   end
1494: 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 1007
1007: def pkg_config(pkg)
1008:   if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
1009:     # iff package specific config command is given
1010:     get = proc {|opt| `#{pkgconfig} --#{opt}`.chomp}
1011:   elsif ($PKGCONFIG ||= 
1012:          (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) &&
1013:          find_executable0(pkgconfig) && pkgconfig) and
1014:       system("#{$PKGCONFIG} --exists #{pkg}")
1015:     # default to pkg-config command
1016:     get = proc {|opt| `#{$PKGCONFIG} --#{opt} #{pkg}`.chomp}
1017:   elsif find_executable0(pkgconfig = "#{pkg}-config")
1018:     # default to package specific config command, as a last resort.
1019:     get = proc {|opt| `#{pkgconfig} --#{opt}`.chomp}
1020:   end
1021:   if get
1022:     cflags = get['cflags']
1023:     ldflags = get['libs']
1024:     libs = get['libs-only-l']
1025:     ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
1026:     $CFLAGS += " " << cflags
1027:     $LDFLAGS += " " << ldflags
1028:     $libs += " " << libs
1029:     Logging::message "package configuration for %s\n", pkg
1030:     Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n",
1031:                      cflags, ldflags, libs
1032:     [cflags, ldflags, libs]
1033:   else
1034:     Logging::message "package configuration for %s is not found\n", pkg
1035:     nil
1036:   end
1037: 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 819
819: def  scalar_ptr_type?scalar_ptr_type?(type, member = nil, headers = nil, &b)
820:   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
821: end

[Source]

     # File lib/mkmf.rb, line 831
831: def scalar_type?(type, member = nil, headers = nil, &b)
832:   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
833: end

[Source]

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

[Source]

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

[Source]

     # File lib/mkmf.rb, line 326
326: def try_cpp(src, opt="", &b)
327:   try_do(src, cpp_command(CPPOUTFILE, opt), &b)
328: ensure
329:   rm_f "conftest*"
330: 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 424
424: def try_func(func, libs, headers = nil, &b)
425:   headers = cpp_include(headers)
426:   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)
427: end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

     # File lib/mkmf.rb, line 442
442: def try_var(var, headers = nil, &b)
443:   headers = cpp_include(headers)
444:   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)
445: end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

     # File lib/mkmf.rb, line 357
357: def with_ldflags(flags)
358:   ldflags = $LDFLAGS
359:   $LDFLAGS = flags
360:   ret = yield
361: ensure
362:   $LDFLAGS = ldflags unless ret
363: 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]