mkmf.rb
| Path: | mkmf.rb |
| Last Update: | Mon Nov 28 00:22:53 GMT 2005 |
module to create Makefile for extension modules invoke like: ruby -r mkmf extconf.rb
Required files
rbconfig
fileutils
shellwords
Methods
append_library
arg_config
cc_command
check_sizeof
checking_for
config_string
configuration
cpp_command
cpp_include
create_header
create_makefile
create_tmpsrc
dir_config
dir_re
dummy_makefile
egrep_cpp
enable_config
find_executable
find_executable0
find_header
find_library
have_func
have_header
have_library
have_macro
have_struct_member
have_type
have_var
init_mkmf
install_dirs
install_files
install_rb
libpathflag
link_command
log_src
macro_defined?
map_dir
merge_libs
message
mkmf_failed
modified?
pkg_config
rm_f
scalar_ptr_type?
scalar_type?
try_compile
try_constant
try_cpp
try_do
try_func
try_link
try_link0
try_run
try_static_assert
try_var
what_type?
winsep
with_cflags
with_config
with_cppflags
with_destdir
with_ldflags
xpopen
xsystem
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") unless hdr.empty?) |
| 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) $(CFLAGS) $(CPPFLAGS) -c $<' |
| COMPILE_CXX | = | config_string('COMPILE_CXX') || '$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<' |
| TRY_LINK | = | config_string('TRY_LINK') || "$(CC) #{OUTFLAG}conftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS) " \ "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)" |
| LINK_SO | = | config_string('LINK_SO') || if CONFIG["DLEXT"] == $OBJEXT |
Public Instance methods
# File mkmf.rb, line 531
531: def append_library(libs, lib)
532: format(LIBARG, lib) + " " + libs
533: end
# File mkmf.rb, line 801
801: def arg_config(config, *defaults, &block)
802: $arg_config << [config, *defaults]
803: defaults << nil if !block and defaults.empty?
804: $configure_args.fetch(config.tr('_', '-'), *defaults, &block)
805: end
# File mkmf.rb, line 276
276: def cc_command(opt="")
277: Config::expand("$(CC) -c #$INCFLAGS -I$(hdrdir) " \
278: "#$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} #{CONFTEST_C}",
279: CONFIG.merge('hdrdir' => $hdrdir.quote))
280: end
# File mkmf.rb, line 699
699: def check_sizeof(type, header = nil, &b)
700: expr = "sizeof(#{type})"
701: m = "checking size of #{type}... "
702: message "%s", m
703: a = size = nil
704: Logging::postpone do
705: if size = try_constant(expr, header, &b)
706: $defs.push(format("-DSIZEOF_%s=%d", type.upcase.tr_s("^A-Z0-9_", "_"), size))
707: a = "#{size}\n"
708: else
709: a = "failed\n"
710: end
711: "check_sizeof: #{m}-------------------- #{a}\n"
712: end
713: message(a)
714: Logging::message "--------------------\n\n"
715: size
716: end
# File mkmf.rb, line 542
542: def checking_for(m, fmt = nil)
543: f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim
544: m = "checking for #{m}... "
545: message "%s", m
546: a = r = nil
547: Logging::postpone do
548: r = yield
549: a = (fmt ? fmt % r : r ? "yes" : "no") << "\n"
550: "#{f}#{m}-------------------- #{a}\n"
551: end
552: message(a)
553: Logging::message "--------------------\n\n"
554: r
555: end
# File mkmf.rb, line 64
64: def config_string(key, config = CONFIG)
65: s = config[key] and !s.empty? and block_given? ? yield(s) : s
66: end
# File mkmf.rb, line 923
923: def configuration(srcdir)
924: mk = []
925: vpath = %w[$(srcdir) $(topdir) $(hdrdir)]
926: if !CROSS_COMPILING
927: case CONFIG['build_os']
928: when 'cygwin'
929: if CONFIG['target_os'] != 'cygwin'
930: vpath.each {|p| p.sub!(/.*/, '$(shell cygpath -u \&)')}
931: end
932: when 'msdosdjgpp', 'mingw32'
933: CONFIG['PATH_SEPARATOR'] = ';'
934: end
935: end
936: mk << %{
937: SHELL = /bin/sh
938:
939: #### Start of system configuration section. ####
940:
941: srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {CONFIG[$1||$2]}.quote}
942: topdir = #{($extmk ? CONFIG["topdir"] : $topdir).quote}
943: hdrdir = #{$extmk ? CONFIG["hdrdir"].quote : '$(topdir)'}
944: VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
945: }
946: drive = File::PATH_SEPARATOR == ';' ? /\A\w:/ : /\A/
947: if destdir = CONFIG["prefix"].scan(drive)[0] and !destdir.empty?
948: mk << "\nDESTDIR = #{destdir}\n"
949: end
950: CONFIG.each do |key, var|
951: next unless /prefix$/ =~ key
952: mk << "#{key} = #{with_destdir(var.sub(drive, ''))}\n"
953: end
954: CONFIG.each do |key, var|
955: next if /^abs_/ =~ key
956: next unless /^(?:src|top|hdr|(.*))dir$/ =~ key and $1
957: mk << "#{key} = #{with_destdir(var.sub(drive, ''))}\n"
958: end
959: if !$extmk and !$configure_args.has_key?('--ruby') and
960: sep = config_string('BUILD_FILE_SEPARATOR')
961: sep = ":/=#{sep}"
962: else
963: sep = ""
964: end
965: mk << %{
966: CC = #{CONFIG['CC']}
967: LIBRUBY = #{CONFIG['LIBRUBY']}
968: LIBRUBY_A = #{CONFIG['LIBRUBY_A']}
969: LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED
970: LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC
971:
972: CFLAGS = #{CONFIG['CCDLFLAGS'] unless $static} #$CFLAGS #$ARCH_FLAG
973: CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) #{$defs.join(" ")} #{$CPPFLAGS}
974: CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']}
975: DLDFLAGS = #$LDFLAGS #$DLDFLAGS #$ARCH_FLAG
976: LDSHARED = #{CONFIG['LDSHARED']}
977: AR = #{CONFIG['AR']}
978: EXEEXT = #{CONFIG['EXEEXT']}
979:
980: RUBY_INSTALL_NAME = #{CONFIG['RUBY_INSTALL_NAME']}
981: RUBY_SO_NAME = #{CONFIG['RUBY_SO_NAME']}
982: arch = #{CONFIG['arch']}
983: sitearch = #{CONFIG['sitearch']}
984: ruby_version = #{Config::CONFIG['ruby_version']}
985: ruby = #{$ruby}
986: RUBY = $(ruby#{sep})
987: RM = #{config_string('RM') || '$(RUBY) -run -e rm -- -f'}
988: MAKEDIRS = #{config_string('MAKEDIRS') || '@$(RUBY) -run -e mkdir -- -p'}
989: INSTALL = #{config_string('INSTALL') || '@$(RUBY) -run -e install -- -vp'}
990: INSTALL_PROG = #{config_string('INSTALL_PROG') || '$(INSTALL) -m 0755'}
991: INSTALL_DATA = #{config_string('INSTALL_DATA') || '$(INSTALL) -m 0644'}
992: COPY = #{config_string('CP') || '@$(RUBY) -run -e cp -- -v'}
993:
994: #### End of system configuration section. ####
995:
996: preload = #{$preload.join(" ") if $preload}
997: }
998: if $nmake == ?b
999: mk.each do |x|
1000: x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do
1001: "!ifndef " + $1 + "\n" +
1002: $& +
1003: "!endif\n"
1004: end
1005: end
1006: end
1007: mk
1008: end
# File mkmf.rb, line 282
282: def cpp_command(outfile, opt="")
283: Config::expand("$(CPP) #$INCFLAGS -I$(hdrdir) " \
284: "#$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
285: CONFIG.merge('hdrdir' => $hdrdir.quote))
286: end
# File mkmf.rb, line 316
316: def cpp_include(header)
317: if header
318: header = [header] unless header.kind_of? Array
319: header.map {|h| "#include <#{h}>\n"}.join
320: else
321: ""
322: end
323: end
# File mkmf.rb, line 840
840: def create_header(header = "extconf.h")
841: message "creating %s\n", header
842: if $defs.length > 0
843: sym = header.tr("a-z./\055", "A-Z___")
844: open(header, "w") do |hfile|
845: hfile.print "#ifndef #{sym}\n#define #{sym}\n"
846: for line in $defs
847: case line
848: when /^-D([^=]+)(?:=(.*))?/
849: hfile.print "#define #$1 #{$2 || 1}\n"
850: when /^-U(.*)/
851: hfile.print "#undef #$1\n"
852: end
853: end
854: hfile.print "#endif\n"
855: end
856: end
857: end
# File mkmf.rb, line 1021
1021: def create_makefile(target, srcprefix = nil)
1022: $target = target
1023: libpath = $LIBPATH
1024: message "creating Makefile\n"
1025: rm_f "conftest*"
1026: if CONFIG["DLEXT"] == $OBJEXT
1027: for lib in libs = $libs.split
1028: lib.sub!(/-l(.*)/, %%"lib\\1.#{$LIBEXT}"%)
1029: end
1030: $defs.push(format("-DEXTLIB='%s'", libs.join(",")))
1031: end
1032:
1033: if target.include?('/')
1034: target_prefix, target = File.split(target)
1035: target_prefix[0,0] = '/'
1036: else
1037: target_prefix = ""
1038: end
1039:
1040: srcprefix ||= '$(srcdir)'
1041: Config::expand(srcdir = srcprefix.dup)
1042:
1043: if not $objs
1044: $objs = []
1045: srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
1046: for f in srcs
1047: obj = File.basename(f, ".*") << ".o"
1048: $objs.push(obj) unless $objs.index(obj)
1049: end
1050: elsif !(srcs = $srcs)
1051: srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')}
1052: end
1053: for i in $objs
1054: i.sub!(/\.o\z/, ".#{$OBJEXT}")
1055: end
1056: $objs = $objs.join(" ")
1057:
1058: target = nil if $objs == ""
1059:
1060: if target and EXPORT_PREFIX
1061: if File.exist?(File.join(srcdir, target + '.def'))
1062: deffile = "$(srcdir)/$(TARGET).def"
1063: unless EXPORT_PREFIX.empty?
1064: makedef = %{-pe "sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
1065: end
1066: else
1067: makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"}
1068: end
1069: if makedef
1070: $distcleanfiles << '$(DEFFILE)'
1071: origdef = deffile
1072: deffile = "$(TARGET)-$(arch).def"
1073: end
1074: end
1075:
1076: libpath = libpathflag(libpath)
1077:
1078: dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
1079: staticlib = target ? "$(TARGET).#$LIBEXT" : ""
1080: mfile = open("Makefile", "wb")
1081: mfile.print configuration(srcprefix)
1082: mfile.print %{
1083: libpath = #{$LIBPATH.join(" ")}
1084: LIBPATH = #{libpath}
1085: DEFFILE = #{deffile}
1086:
1087: CLEANFILES = #{$cleanfiles.join(' ')}
1088: DISTCLEANFILES = #{$distcleanfiles.join(' ')}
1089:
1090: extout = #{$extout}
1091: extout_prefix = #{$extout_prefix}
1092: target_prefix = #{target_prefix}
1093: LOCAL_LIBS = #{$LOCAL_LIBS}
1094: LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS}
1095: SRCS = #{srcs.collect(&File.method(:basename)).join(' ')}
1096: OBJS = #{$objs}
1097: TARGET = #{target}
1098: DLLIB = #{dllib}
1099: STATIC_LIB = #{staticlib unless $static.nil?}
1100:
1101: }
1102: install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
1103: n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET).'
1104: mfile.print %{
1105: TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB)
1106: CLEANLIBS = #{n}#{CONFIG['DLEXT']} #{n}il? #{n}tds #{n}map
1107: CLEANOBJS = *.#{$OBJEXT} *.#{$LIBEXT} *.s[ol] *.pdb *.exp *.bak
1108:
1109: all: #{target ? $extout ? "install" : "$(DLLIB)" : "Makefile"}
1110: static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
1111: }
1112: mfile.print CLEANINGS
1113: dirs = []
1114: mfile.print "install: install-so install-rb\n\n"
1115: sodir = (dir = "$(RUBYARCHDIR)").dup
1116: mfile.print("install-so: #{dir}\n")
1117: if target
1118: f = "$(DLLIB)"
1119: dest = "#{dir}/#{f}"
1120: mfile.print "install-so: #{dest}\n"
1121: unless $extout
1122: mfile.print "#{dest}: #{f}\n"
1123: if (sep = config_string('BUILD_FILE_SEPARATOR'))
1124: f.gsub!("/", sep)
1125: dir.gsub!("/", sep)
1126: sep = ":/="+sep
1127: f.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2}
1128: f.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2}
1129: dir.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2}
1130: dir.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2}
1131: end
1132: mfile.print "\t$(INSTALL_PROG) #{f} #{dir}\n"
1133: end
1134: end
1135: mfile.print("install-rb: pre-install-rb install-rb-default\n")
1136: mfile.print("install-rb-default: pre-install-rb-default\n")
1137: mfile.print("pre-install-rb: Makefile\n")
1138: mfile.print("pre-install-rb-default: Makefile\n")
1139: for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]]
1140: files = install_files(mfile, i, nil, srcprefix) or next
1141: for dir, *files in files
1142: unless dirs.include?(dir)
1143: dirs << dir
1144: mfile.print "pre-install-rb#{sfx}: #{dir}\n"
1145: end
1146: files.each do |f|
1147: dest = "#{dir}/#{File.basename(f)}"
1148: mfile.print("install-rb#{sfx}: #{dest}\n")
1149: mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
1150: sep = config_string('BUILD_FILE_SEPARATOR')
1151: if sep
1152: f = f.gsub("/", sep)
1153: sep = ":/="+sep
1154: f = f.gsub(/(\$\(\w+)(\))/) {$1+sep+$2}
1155: f = f.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
1156: else
1157: sep = ""
1158: end
1159: mfile.print("#{f} $(@D#{sep})\n")
1160: end
1161: end
1162: end
1163: dirs.unshift(sodir) if target and !dirs.include?(sodir)
1164: dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"}
1165:
1166: mfile.print "\nsite-install: site-install-so site-install-rb\nsite-install-so: install-so\nsite-install-rb: install-rb\n\n"
1167:
1168: return unless target
1169:
1170: mfile.puts SRC_EXT.collect {|ext| ".path.#{ext} = $(VPATH)"} if $nmake == ?b
1171: mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n"
1172: mfile.print "\n"
1173:
1174: CXX_EXT.each do |ext|
1175: COMPILE_RULES.each do |rule|
1176: mfile.printf(rule, ext, $OBJEXT)
1177: mfile.printf("\n\t%s\n\n", COMPILE_CXX)
1178: end
1179: end
1180: %w[c].each do |ext|
1181: COMPILE_RULES.each do |rule|
1182: mfile.printf(rule, ext, $OBJEXT)
1183: mfile.printf("\n\t%s\n\n", COMPILE_C)
1184: end
1185: end
1186:
1187: mfile.print "$(RUBYARCHDIR)/" if $extout
1188: mfile.print "$(DLLIB): ", (makedef ? "$(DEFFILE) " : ""), "$(OBJS)\n\t"
1189: mfile.print "@-$(RM) $@\n\t"
1190: mfile.print "@-$(MAKEDIRS) $(@D)\n\t" if $extout
1191: mfile.print LINK_SO, "\n\n"
1192: unless $static.nil?
1193: mfile.print "$(STATIC_LIB): $(OBJS)\n\t"
1194: mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
1195: config_string('RANLIB') do |ranlib|
1196: mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true"
1197: end
1198: end
1199: mfile.print "\n\n"
1200: if makedef
1201: mfile.print "$(DEFFILE): #{origdef}\n"
1202: mfile.print "\t$(RUBY) #{makedef} #{origdef} > $@\n\n"
1203: end
1204:
1205: depend = File.join(srcdir, "depend")
1206: if File.exist?(depend)
1207: suffixes = []
1208: depout = []
1209: open(depend, "r") do |dfile|
1210: mfile.printf "###\n"
1211: cont = implicit = nil
1212: impconv = proc do
1213: COMPILE_RULES.each {|rule| depout << (rule % implicit[0]) << implicit[1]}
1214: implicit = nil
1215: end
1216: ruleconv = proc do |line|
1217: if implicit
1218: if /\A\t/ =~ line
1219: implicit[1] << line
1220: next
1221: else
1222: impconv[]
1223: end
1224: end
1225: if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line)
1226: suffixes << m[1] << m[2]
1227: implicit = [[m[1], m[2]], [m.post_match]]
1228: next
1229: elsif RULE_SUBST and /\A[$\w][^#]*:/ =~ line
1230: line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2}
1231: end
1232: depout << line
1233: end
1234: while line = dfile.gets()
1235: line.gsub!(/\.o\b/, ".#{$OBJEXT}")
1236: line.gsub!(/\$\(hdrdir\)\/config.h/, $config_h) if $config_h
1237: if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line
1238: (cont ||= []) << line
1239: next
1240: elsif cont
1241: line = (cont << line).join
1242: cont = nil
1243: end
1244: ruleconv.call(line)
1245: end
1246: if cont
1247: ruleconv.call(cont.join)
1248: elsif implicit
1249: impconv.call
1250: end
1251: end
1252: unless suffixes.empty?
1253: mfile.print ".SUFFIXES: .", suffixes.uniq.join(" ."), "\n\n"
1254: end
1255: mfile.print depout
1256: else
1257: headers = %w[ruby.h defines.h]
1258: if RULE_SUBST
1259: headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}}
1260: end
1261: headers << $config_h if $config_h
1262: mfile.print "$(OBJS): ", headers.join(' '), "\n"
1263: end
1264:
1265: $makefile_created = true
1266: ensure
1267: mfile.close if mfile
1268: end
# File mkmf.rb, line 246
246: def create_tmpsrc(src)
247: src = yield(src) if block_given?
248: src = src.sub(/[^\n]\z/, "\\&\n")
249: open(CONFTEST_C, "wb") do |cfile|
250: cfile.print src
251: end
252: src
253: end
# File mkmf.rb, line 859
859: def dir_config(target, idefault=nil, ldefault=nil)
860: if dir = with_config(target + "-dir", (idefault unless ldefault))
861: defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR)
862: idefault = ldefault = nil
863: end
864:
865: idir = with_config(target + "-include", idefault)
866: $arg_config.last[1] ||= "${#{target}-dir}/include"
867: ldir = with_config(target + "-lib", ldefault)
868: $arg_config.last[1] ||= "${#{target}-dir}/lib"
869:
870: idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : []
871: if defaults
872: idirs.concat(defaults.collect {|dir| dir + "/include"})
873: idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
874: end
875: unless idirs.empty?
876: idirs.collect! {|dir| "-I" + dir}
877: idirs -= Shellwords.shellwords($CPPFLAGS)
878: unless idirs.empty?
879: $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
880: end
881: end
882:
883: ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : []
884: if defaults
885: ldirs.concat(defaults.collect {|dir| dir + "/lib"})
886: ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
887: end
888: $LIBPATH = ldirs | $LIBPATH
889:
890: [idir, ldir]
891: end
# File mkmf.rb, line 68
68: def dir_re(dir)
69: Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$\(target_prefix\)|\{target_prefix\})?')
70: end
# File mkmf.rb, line 1010
1010: def dummy_makefile(srcdir)
1011: configuration(srcdir) << "CLEANFILES = \#{$cleanfiles.join(' ')}\nDISTCLEANFILES = \#{$distcleanfiles.join(' ')}\n\nall install static install-so install-rb: Makefile\n\n" << CLEANINGS
1012: end
# File mkmf.rb, line 442
442: def egrep_cpp(pat, src, opt = "", &b)
443: src = create_tmpsrc(src, &b)
444: xpopen(cpp_command('', opt)) do |f|
445: if Regexp === pat
446: puts(" ruby -ne 'print if #{pat.inspect}'")
447: f.grep(pat) {|l|
448: puts "#{f.lineno}: #{l}"
449: return true
450: }
451: false
452: else
453: puts(" egrep '#{pat}'")
454: begin
455: stdin = $stdin.dup
456: $stdin.reopen(f)
457: system("egrep", pat)
458: ensure
459: $stdin.reopen(stdin)
460: end
461: end
462: end
463: ensure
464: rm_f "conftest*"
465: log_src(src)
466: end
# File mkmf.rb, line 828
828: def enable_config(config, *defaults)
829: if arg_config("--enable-"+config)
830: true
831: elsif arg_config("--disable-"+config)
832: false
833: elsif block_given?
834: yield(config, *defaults)
835: else
836: return *defaults
837: end
838: end
# File mkmf.rb, line 795
795: def find_executable(bin, path = nil)
796: checking_for bin do
797: find_executable0(bin, path)
798: end
799: end
# File mkmf.rb, line 775
775: def find_executable0find_executable0(bin, path = nil)
776: ext = config_string('EXEEXT')
777: if File.expand_path(bin) == bin
778: return bin if File.executable?(bin)
779: return file if ext and File.executable?(file = bin + ext)
780: return nil
781: end
782: if path ||= ENV['PATH']
783: path = path.split(File::PATH_SEPARATOR)
784: else
785: path = %w[/usr/local/bin /usr/ucb /usr/bin /bin]
786: end
787: file = nil
788: path.each do |dir|
789: return file if File.executable?(file = File.join(dir, bin))
790: return file if ext and File.executable?(file << ext)
791: end
792: nil
793: end
# File mkmf.rb, line 638
638: def find_header(header, *paths)
639: checking_for header do
640: if try_cpp(cpp_include(header))
641: true
642: else
643: found = false
644: paths.each do |dir|
645: opt = "-I#{dir}".quote
646: if try_cpp(cpp_include(header), opt)
647: $INCFLAGS << " " << opt
648: found = true
649: break
650: end
651: end
652: found
653: end
654: end
655: end
# File mkmf.rb, line 583
583: def find_library(lib, func, *paths, &b)
584: func = "main" if !func or func.empty?
585: lib = with_config(lib+'lib', lib)
586: paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten
587: checking_for "#{func}() in #{LIBARG%lib}" do
588: libpath = $LIBPATH
589: libs = append_library($libs, lib)
590: begin
591: until r = try_func(func, libs, &b) or paths.empty?
592: $LIBPATH = libpath | [paths.shift]
593: end
594: if r
595: $libs = libs
596: libpath = nil
597: end
598: ensure
599: $LIBPATH = libpath if libpath
600: end
601: r
602: end
603: end
# File mkmf.rb, line 605
605: def have_func(func, headers = nil, &b)
606: checking_for "#{func}()" do
607: if try_func(func, $libs, headers, &b)
608: $defs.push(format("-DHAVE_%s", func.upcase))
609: true
610: else
611: false
612: end
613: end
614: end
# File mkmf.rb, line 627
627: def have_header(header, &b)
628: checking_for header do
629: if try_cpp(cpp_include(header), &b)
630: $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___")))
631: true
632: else
633: false
634: end
635: end
636: end
# File mkmf.rb, line 565
565: def have_library(lib, func = nil, header=nil, &b)
566: func = "main" if !func or func.empty?
567: lib = with_config(lib+'lib', lib)
568: checking_for "#{func}() in #{LIBARG%lib}" do
569: if COMMON_LIBS.include?(lib)
570: true
571: else
572: libs = append_library($libs, lib)
573: if try_func(func, libs, header, &b)
574: $libs = libs
575: true
576: else
577: false
578: end
579: end
580: end
581: end
# File mkmf.rb, line 557
557: def have_macro(macro, headers = nil, opt = "", &b)
558: m = "#{macro}"
559: m << " in #{headers.inspect}" if headers
560: checking_for m do
561: macro_defined?(macro, cpp_include(headers), opt, &b)
562: end
563: end
# File mkmf.rb, line 657
657: def have_struct_member(type, member, header = nil, &b)
658: checking_for "#{type}.#{member}" do
659: if try_compile("\#{COMMON_HEADERS}\n\#{cpp_include(header)}\n/*top*/\nint main() { return 0; }\nint s = (char *)&((\#{type}*)0)->\#{member} - (char *)0;\n", &b)
660: $defs.push(format("-DHAVE_ST_%s", member.upcase))
661: true
662: else
663: false
664: end
665: end
666: end
# File mkmf.rb, line 675
675: def have_type(type, header = nil, opt = "", &b)
676: checking_for type do
677: header = cpp_include(header)
678: if try_compile("\#{COMMON_HEADERS}\n\#{header}\n/*top*/\nstatic \#{type} t;\n", opt, &b) or (/\A\w+\z/n =~ type && try_compile("\#{COMMON_HEADERS}\n\#{header}\n/*top*/\nstatic \#{type} *t;\n", opt, &b))
679: $defs.push(format("-DHAVE_TYPE_%s", type.strip.upcase.tr_s("^A-Z0-9_", "_")))
680: true
681: else
682: false
683: end
684: end
685: end
# File mkmf.rb, line 616
616: def have_var(var, headers = nil, &b)
617: checking_for "#{var}" do
618: if try_var(var, headers, &b)
619: $defs.push(format("-DHAVE_%s", var.upcase))
620: true
621: else
622: false
623: end
624: end
625: end
# File mkmf.rb, line 1277
1277: def init_mkmf(config = CONFIG)
1278: $makefile_created = false
1279: $arg_config = []
1280: $enable_shared = config['ENABLE_SHARED'] == 'yes'
1281: $defs = []
1282: $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup
1283: $ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup
1284: $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup
1285: $LDFLAGS = (with_config("ldflags") || "").dup
1286: $INCFLAGS = "-I$(topdir)"
1287: $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup
1288: $LIBEXT = config['LIBEXT'].dup
1289: $OBJEXT = config["OBJEXT"].dup
1290: $LIBS = "#{config['LIBS']} #{config['DLDLIBS']}"
1291: $LIBRUBYARG = ""
1292: $LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
1293: $LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED']
1294: $LIBPATH = $extmk ? ["$(topdir)"] : CROSS_COMPILING ? [] : ["$(libdir)"]
1295: $INSTALLFILES =