Module: MakeMakefile
Overview
mkmf.rb is used by Ruby C extensions to generate a Makefile which will correctly compile and link the C extension to Ruby and a third-party library.
Defined Under Namespace
Modules: Logging
Constant Summary collapse
- CONFIG =
The makefile configuration using the defaults from when Ruby was built.
RbConfig::MAKEFILE_CONFIG
- ORIG_LIBPATH =
ENV['LIB']
- C_EXT =
Extensions for files compiled with a C compiler
%w[c m]
- CXX_EXT =
Extensions for files complied with a C++ compiler
%w[cc mm cxx cpp]
- SRC_EXT =
Extensions for source files
C_EXT + CXX_EXT
- HDR_EXT =
Extensions for header files
%w[h hpp]
- INSTALL_DIRS =
[ [dir_re('commondir'), "$(RUBYCOMMONDIR)"], [dir_re('sitedir'), "$(RUBYCOMMONDIR)"], [dir_re('vendordir'), "$(RUBYCOMMONDIR)"], [dir_re('rubylibdir'), "$(RUBYLIBDIR)"], [dir_re('archdir'), "$(RUBYARCHDIR)"], [dir_re('sitelibdir'), "$(RUBYLIBDIR)"], [dir_re('vendorlibdir'), "$(RUBYLIBDIR)"], [dir_re('sitearchdir'), "$(RUBYARCHDIR)"], [dir_re('vendorarchdir'), "$(RUBYARCHDIR)"], [dir_re('rubyhdrdir'), "$(RUBYHDRDIR)"], [dir_re('sitehdrdir'), "$(SITEHDRDIR)"], [dir_re('vendorhdrdir'), "$(VENDORHDRDIR)"], [dir_re('bindir'), "$(BINDIR)"], ]
- CONFTEST =
"conftest".freeze
- CONFTEST_C =
"#{CONFTEST}.c"
- OUTFLAG =
CONFIG['OUTFLAG']
- COUTFLAG =
CONFIG['COUTFLAG']
- CPPOUTFILE =
config_string('CPPOUTFILE') {|str| str.sub(/\bconftest\b/, CONFTEST)}
- STRING_OR_FAILED_FORMAT =
:stopdoc:
"%s"
- 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
Class Method Summary collapse
-
.config_string(key, config = CONFIG) ⇒ Object
:stopdoc:.
- .dir_re(dir) ⇒ Object
- .rm_f(*files) ⇒ Object
- .rm_rf(*files) ⇒ Object
Instance Method Summary collapse
- #append_cflags(flags, *opts) ⇒ Object
- #append_cppflags(flags, *opts) ⇒ Object
- #append_ldflags(flags, *opts) ⇒ Object
-
#append_library(libs, lib) ⇒ Object
:no-doc:.
-
#arg_config(config, default = nil, &block) ⇒ Object
:stopdoc:.
- #cc_command(opt = "") ⇒ Object
-
#check_signedness(type, headers = nil, opts = nil, &b) ⇒ Object
Returns the signedness of the given
type
. -
#check_sizeof(type, headers = nil, opts = "", &b) ⇒ Object
Returns the size of the given
type
. -
#checking_for(m, fmt = nil) ⇒ Object
This emits a string to stdout that allows users to see the results of the various have* and find* methods as they are tested.
- #checking_message(target, place = nil, opt = nil) ⇒ Object
- #configuration(srcdir) ⇒ Object
-
#convertible_int(type, headers = nil, opts = nil, &b) ⇒ Object
Returns the convertible integer type of the given
type
. - #cpp_command(outfile, opt = "") ⇒ Object
- #cpp_include(header) ⇒ Object
-
#create_header(header = "extconf.h") ⇒ Object
Generates a header file consisting of the various macro definitions generated by other methods such as have_func and have_header.
-
#create_makefile(target, srcprefix = nil) ⇒ Object
Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.
- #create_tmpsrc(src) ⇒ Object
-
#depend_rules(depend) ⇒ Object
Processes the data contents of the “depend” file.
-
#dir_config(target, idefault = nil, ldefault = nil) ⇒ Object
call-seq: dir_config(target) dir_config(target, prefix) dir_config(target, idefault, ldefault).
-
#dummy_makefile(srcdir) ⇒ Object
creates a stub Makefile.
-
#each_compile_rules ⇒ Object
:nodoc:.
-
#egrep_cpp(pat, src, opt = "", &b) ⇒ Object
Returns whether or not the
src
can be preprocessed with the C preprocessor and matches withpat
. -
#enable_config(config, default = nil) ⇒ Object
Tests for the presence of an
--enable-
config or--disable-
config option. -
#find_executable(bin, path = nil) ⇒ Object
Searches for the executable
bin
onpath
. -
#find_executable0(bin, path = nil) ⇒ Object
This method is used internally by the find_executable method.
-
#find_header(header, *paths) ⇒ Object
Instructs mkmf to search for the given
header
in any of thepaths
provided, and returns whether or not it was found in those paths. -
#find_library(lib, func, *paths, &b) ⇒ Object
Returns whether or not the entry point
func
can be found within the librarylib
in one of thepaths
specified, wherepaths
is an array of strings. -
#find_type(type, opt, *headers, &b) ⇒ Object
Returns where the static type
type
is defined. -
#have_const(const, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the constant
const
is defined. - #have_devel? ⇒ Boolean
-
#have_framework(fw, &b) ⇒ Object
Returns whether or not the given
framework
can be found on your system. -
#have_func(func, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the function
func
can be found in the common header files, or within anyheaders
that you provide. -
#have_header(header, preheaders = nil, opt = "", &b) ⇒ Object
Returns whether or not the given
header
file can be found on your system. -
#have_library(lib, func = nil, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the given entry point
func
can be found withinlib
. -
#have_macro(macro, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not
macro
is defined either in the common header files or within anyheaders
you provide. -
#have_struct_member(type, member, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the struct of type
type
containsmember
. -
#have_type(type, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the static type
type
is defined. -
#have_typeof? ⇒ Boolean
Used internally by the what_type? method to check if the typeof GCC extension is available.
-
#have_var(var, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the variable
var
can be found in the common header files, or within anyheaders
that you provide. -
#init_mkmf(config = CONFIG, rbconfig = RbConfig::CONFIG) ⇒ Object
:stopdoc:.
- #install_dirs(target_prefix = nil) ⇒ Object
- #install_files(mfile, ifiles, map = nil, srcprefix = nil) ⇒ Object
- #install_rb(mfile, dest, srcdir = nil) ⇒ Object
- #libpath_env ⇒ Object
- #libpathflag(libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
- #link_command(ldflags, opt = "", libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
- #log_src(src, heading = "checked program was") ⇒ Object
-
#macro_defined?(macro, src, opt = "", &b) ⇒ Boolean
This is used internally by the have_macro? method.
- #map_dir(dir, map = nil) ⇒ Object
- #merge_libs(*libs) ⇒ Object
- #message(*s) ⇒ Object
- #mkintpath(path) ⇒ Object
-
#mkmf_failed(path) ⇒ Object
Returns whether or not the Makefile was successfully generated.
-
#modified?(target, times) ⇒ Boolean
Returns time stamp of the
target
file if it exists and is newer than or equal to all oftimes
. -
#pkg_config(pkg, option = nil) ⇒ Object
Returns compile/link information about an installed library in a tuple of
[cflags, ldflags, libs]
, by using the command found first in the following commands:. - #relative_from(path, base) ⇒ Object
-
#scalar_ptr_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
Used internally by the what_type? method to determine if
type
is a scalar pointer. -
#scalar_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
Used internally by the what_type? method to determine if
type
is a scalar pointer. - #split_libs(*strs) ⇒ Object
- #timestamp_file(name, target_prefix = nil) ⇒ Object
- #try_cflags(flags, opts = {}) ⇒ Object
-
#try_compile(src, opt = "", *opts, &b) ⇒ Object
Returns whether or not the
src
can be compiled as a C source. -
#try_const(const, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the constant
const
is defined. - #try_constant(const, headers = nil, opt = "", &b) ⇒ Object
-
#try_cpp(src, opt = "", *opts, &b) ⇒ Object
Returns whether or not the
src
can be preprocessed with the C preprocessor. - #try_cppflags(flags, opts = {}) ⇒ Object
- #try_do(src, command, *opts, &b) ⇒ Object
-
#try_func(func, libs, headers = nil, opt = "", &b) ⇒ Object
You should use
have_func
rather thantry_func
. - #try_ldflags(flags, opts = {}) ⇒ Object
-
#try_link(src, opt = "", *opts, &b) ⇒ Object
Returns whether or not the
src
can be compiled as a C source and linked with its depending libraries successfully. -
#try_link0(src, opt = "", *opts, &b) ⇒ Object
:nodoc:.
-
#try_run(src, opt = "", &b) ⇒ Object
Returns whether or not: * the
src
can be compiled as a C source, * the result object can be linked with its depending libraries successfully, * the linked file can be invoked as an executable * and the executable exits successfully. - #try_signedness(type, member, headers = nil, opts = nil) ⇒ Object
- #try_static_assert(expr, headers = nil, opt = "", &b) ⇒ Object
-
#try_type(type, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the static type
type
is defined. -
#try_var(var, headers = nil, opt = "", &b) ⇒ Object
You should use
have_var
rather thantry_var
. - #typedef_expr(type, headers) ⇒ Object
- #what_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
-
#winsep(s) ⇒ Object
Converts forward slashes to backslashes.
- #with_cflags(flags) ⇒ Object
-
#with_config(config, default = nil) ⇒ Object
Tests for the presence of a
--with-
config or--without-
config option. - #with_cppflags(flags) ⇒ Object
-
#with_destdir(dir) ⇒ Object
:stopdoc:.
- #with_ldflags(flags) ⇒ Object
- #with_werror(opt, opts = nil) ⇒ Object
- #xpopen(command, *mode, &block) ⇒ Object
- #xsystem(command, opts = nil) ⇒ Object
Class Method Details
.config_string(key, config = CONFIG) ⇒ Object
:stopdoc:
143 144 145 |
# File 'lib/mkmf.rb', line 143 def config_string(key, config = CONFIG) s = config[key] and !s.empty? and block_given? ? yield(s) : s end |
.dir_re(dir) ⇒ Object
148 149 150 |
# File 'lib/mkmf.rb', line 148 def dir_re(dir) Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$(?:\(target_prefix\)|\{target_prefix\}))?') end |
.rm_f(*files) ⇒ Object
255 256 257 258 |
# File 'lib/mkmf.rb', line 255 def rm_f(*files) opt = (Hash === files.last ? [files.pop] : []) FileUtils.rm_f(Dir[*files.flatten], *opt) end |
.rm_rf(*files) ⇒ Object
261 262 263 264 |
# File 'lib/mkmf.rb', line 261 def rm_rf(*files) opt = (Hash === files.last ? [files.pop] : []) FileUtils.rm_rf(Dir[*files.flatten], *opt) end |
Instance Method Details
#append_cflags(flags, *opts) ⇒ Object
638 639 640 641 642 643 644 645 646 |
# File 'lib/mkmf.rb', line 638 def append_cflags(flags, *opts) Array(flags).each do |flag| if checking_for("whether #{flag} is accepted as CFLAGS") { try_cflags(flag, *opts) } $CFLAGS << " " << flag end end end |
#append_cppflags(flags, *opts) ⇒ Object
616 617 618 619 620 621 622 623 624 |
# File 'lib/mkmf.rb', line 616 def append_cppflags(flags, *opts) Array(flags).each do |flag| if checking_for("whether #{flag} is accepted as CPPFLAGS") { try_cppflags(flag, *opts) } $CPPFLAGS << " " << flag end end end |
#append_ldflags(flags, *opts) ⇒ Object
660 661 662 663 664 665 666 667 668 |
# File 'lib/mkmf.rb', line 660 def append_ldflags(flags, *opts) Array(flags).each do |flag| if checking_for("whether #{flag} is accepted as LDFLAGS") { try_ldflags(flag, *opts) } $LDFLAGS << " " << flag end end end |
#append_library(libs, lib) ⇒ Object
:no-doc:
920 921 922 |
# File 'lib/mkmf.rb', line 920 def append_library(libs, lib) # :no-doc: format(LIBARG, lib) + " " + libs end |
#arg_config(config, default = nil, &block) ⇒ Object
:stopdoc:
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 |
# File 'lib/mkmf.rb', line 1581 def arg_config(config, default=nil, &block) $arg_config << [config, default] defaults = [] if default defaults << default elsif !block defaults << nil end $configure_args.fetch(config.tr('_', '-'), *defaults, &block) end |
#cc_command(opt = "") ⇒ Object
487 488 489 490 491 492 493 |
# File 'lib/mkmf.rb', line 487 def cc_command(opt="") conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote, 'arch_hdrdir' => $arch_hdrdir.quote, 'top_srcdir' => $top_srcdir.quote) RbConfig::("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}", conf) end |
#check_signedness(type, headers = nil, opts = nil, &b) ⇒ Object
Returns the signedness of the given type
. You may optionally specify additional headers
to search in for the type
.
If the type
is found and is a numeric type, a macro is passed as a preprocessor constant to the compiler using the type
name, in uppercase, prepended with SIGNEDNESS_OF_
, followed by the type
name, followed by =X
where “X” is positive integer if the type
is unsigned and a negative integer if the type
is signed.
For example, if size_t
is defined as unsigned, then check_signedness('size_t')
would return 1 and the SIGNEDNESS_OF_SIZE_T=
1 preprocessor macro would be passed to the compiler. The SIGNEDNESS_OF_INT=-1
macro would be set for check_signedness('int')
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 |
# File 'lib/mkmf.rb', line 1355 def check_signedness(type, headers = nil, opts = nil, &b) typedef, member, prelude = typedef_expr(type, headers) signed = nil checking_for("signedness of #{type}", STRING_OR_FAILED_FORMAT) do signed = try_signedness(typedef, member, [prelude], opts, &b) or next nil $defs.push("-DSIGNEDNESS_OF_%s=%+d" % [type.tr_cpp, signed]) signed < 0 ? "signed" : "unsigned" end signed end |
#check_sizeof(type, headers = nil, opts = "", &b) ⇒ Object
Returns the size of the given type
. You may optionally specify additional headers
to search in for the type
.
If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with SIZEOF_
, followed by the type name, followed by =X
where “X” is the actual size.
For example, if check_sizeof('mystruct')
returned 12, then the SIZEOF_MYSTRUCT=12
preprocessor macro would be passed to the compiler.
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 |
# File 'lib/mkmf.rb', line 1326 def check_sizeof(type, headers = nil, opts = "", &b) typedef, member, prelude = typedef_expr(type, headers) prelude << "#{typedef} *rbcv_ptr_;\n" prelude = [prelude] expr = "sizeof((*rbcv_ptr_)#{"." << member if member})" fmt = STRING_OR_FAILED_FORMAT checking_for ("size of #{type}", headers), fmt do if size = try_constant(expr, prelude, opts, &b) $defs.push(format("-DSIZEOF_%s=%s", type.tr_cpp, size)) size end end end |
#checking_for(m, fmt = nil) ⇒ Object
This emits a string to stdout that allows users to see the results of the various have* and find* methods as they are tested.
Internal use only.
936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
# File 'lib/mkmf.rb', line 936 def checking_for(m, fmt = nil) f = caller[0][/in `([^<].*)'$/, 1] and f << ": " #` for vim #' m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... " "%s", m a = r = nil Logging::postpone do r = yield a = (fmt ? "#{fmt % r}" : r ? "yes" : "no") << "\n" "#{f}#{m}-------------------- #{a}\n" end (a) Logging:: "--------------------\n\n" r end |
#checking_message(target, place = nil, opt = nil) ⇒ Object
951 952 953 954 955 956 957 958 959 960 961 962 963 |
# File 'lib/mkmf.rb', line 951 def (target, place = nil, opt = nil) [["in", place], ["with", opt]].inject("#{target}") do |msg, (pre, noun)| if noun [[:to_str], [:join, ","], [:to_s]].each do |meth, *args| if noun.respond_to?(meth) break noun = noun.send(meth, *args) end end msg << " #{pre} #{noun}" unless noun.empty? end msg end end |
#configuration(srcdir) ⇒ Object
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 |
# File 'lib/mkmf.rb', line 1887 def configuration(srcdir) mk = [] vpath = $VPATH.dup CONFIG["hdrdir"] ||= $hdrdir mk << %{ SHELL = /bin/sh # V=0 quiet, V=1 verbose. other values don't work. V = 0 Q1 = $(V:1=) Q = $(Q1:0=@) ECHO1 = $(V:1=@#{CONFIG['NULLCMD']}) ECHO = $(ECHO1:0=@echo) NULLCMD = #{CONFIG['NULLCMD']} #### Start of system configuration section. #### #{"top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/") if $extmk} srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2]).unspace}} topdir = #{mkintpath(topdir = $extmk ? CONFIG["topdir"] : $topdir).unspace} hdrdir = #{(hdrdir = CONFIG["hdrdir"]) == topdir ? "$(topdir)" : mkintpath(hdrdir).unspace} arch_hdrdir = #{$arch_hdrdir.quote} PATH_SEPARATOR = #{CONFIG['PATH_SEPARATOR']} VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])} } if $extmk mk << "RUBYLIB =\n""RUBYOPT = -\n" end prefix = mkintpath(CONFIG["prefix"]) if destdir = prefix[$dest_prefix_pattern, 1] mk << "\nDESTDIR = #{destdir}\n" prefix = prefix[destdir.size..-1] end mk << "prefix = #{with_destdir(prefix).unspace}\n" CONFIG.each do |key, var| mk << "#{key} = #{with_destdir(mkintpath(var)).unspace}\n" if /.prefix$/ =~ key end CONFIG.each do |key, var| next if /^abs_/ =~ key next if /^(?:src|top(?:_src)?|build|hdr)dir$/ =~ key next unless /dir$/ =~ key mk << "#{key} = #{with_destdir(var)}\n" end if !$extmk and !$configure_args.has_key?('--ruby') and sep = config_string('BUILD_FILE_SEPARATOR') sep = ":/=#{sep}" else sep = "" end possible_command = (proc {|s| s if /top_srcdir/ !~ s} unless $extmk) extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ") << " " headers = %w[ $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h ] if RULE_SUBST headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))} end headers << $config_h headers << '$(RUBY_EXTCONF_H)' if $extconf_h mk << %{ CC = #{CONFIG['CC']} CXX = #{CONFIG['CXX']} LIBRUBY = #{CONFIG['LIBRUBY']} LIBRUBY_A = #{CONFIG['LIBRUBY_A']} LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC empty = OUTFLAG = #{OUTFLAG}$(empty) COUTFLAG = #{COUTFLAG}$(empty) RUBY_EXTCONF_H = #{$extconf_h} cflags = #{CONFIG['cflags']} cxxflags = #{CONFIG['cxxflags']} optflags = #{CONFIG['optflags']} debugflags = #{CONFIG['debugflags']} warnflags = #{$warnflags} CCDLFLAGS = #{$static ? '' : CONFIG['CCDLFLAGS']} CFLAGS = $(CCDLFLAGS) #$CFLAGS $(ARCH_FLAG) INCFLAGS = -I. #$INCFLAGS DEFS = #{CONFIG['DEFS']} CPPFLAGS = #{extconf_h}#{$CPPFLAGS} CXXFLAGS = $(CCDLFLAGS) #$CXXFLAGS $(ARCH_FLAG) ldflags = #{$LDFLAGS} dldflags = #{$DLDFLAGS} #{CONFIG['EXTDLDFLAGS']} ARCH_FLAG = #{$ARCH_FLAG} DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG) LDSHARED = #{CONFIG['LDSHARED']} LDSHAREDXX = #{config_string('LDSHAREDXX') || '$(LDSHARED)'} AR = #{CONFIG['AR']} EXEEXT = #{CONFIG['EXEEXT']} } CONFIG.each do |key, val| mk << "#{key} = #{val}\n" if /^RUBY.*NAME/ =~ key end mk << %{ arch = #{CONFIG['arch']} sitearch = #{CONFIG['sitearch']} ruby_version = #{RbConfig::CONFIG['ruby_version']} ruby = #{$ruby.sub(%r[\A#{Regexp.quote(RbConfig::CONFIG['bindir'])}(?=/|\z)]) {'$(bindir)'}} RUBY = $(ruby#{sep}) ruby_headers = #{headers.join(' ')} RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'} RM_RF = #{'$(RUBY) -run -e rm -- -rf'} RMDIRS = #{config_string('RMDIRS', &possible_command) || '$(RUBY) -run -e rmdir -- -p'} MAKEDIRS = #{config_string('MAKEDIRS', &possible_command) || '@$(RUBY) -run -e mkdir -- -p'} INSTALL = #{config_string('INSTALL', &possible_command) || '@$(RUBY) -run -e install -- -vp'} INSTALL_PROG = #{config_string('INSTALL_PROG') || '$(INSTALL) -m 0755'} INSTALL_DATA = #{config_string('INSTALL_DATA') || '$(INSTALL) -m 0644'} COPY = #{config_string('CP', &possible_command) || '@$(RUBY) -run -e cp -- -v'} TOUCH = exit > #### End of system configuration section. #### preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''} } if $nmake == ?b mk.each do |x| x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do "!ifndef " + $1 + "\n" + $& + "!endif\n" end end end mk end |
#convertible_int(type, headers = nil, opts = nil, &b) ⇒ Object
Returns the convertible integer type of the given type
. You may optionally specify additional headers
to search in for the type
. convertible means actually the same type, or typedef’d from the same type.
If the type
is a integer type and the convertible type is found, the following macros are passed as preprocessor constants to the compiler using the type
name, in uppercase.
-
TYPEOF_
, followed by thetype
name, followed by=X
where “X” is the found convertible type name. -
TYP2NUM
andNUM2TYP
, whereTYP
is thetype
name in uppercase with replacing an_t
suffix with “T”, followed by=X
where “X” is the macro name to converttype
to an Integer object, and vice versa.
For example, if foobar_t
is defined as unsigned long, then convertible_int("foobar_t")
would return “unsigned long”, and define these macros:
#define TYPEOF_FOOBAR_T unsigned long
#define FOOBART2NUM ULONG2NUM
#define NUM2FOOBART NUM2ULONG
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 |
# File 'lib/mkmf.rb', line 1390 def convertible_int(type, headers = nil, opts = nil, &b) type, macname = *type checking_for("convertible type of #{type}", STRING_OR_FAILED_FORMAT) do if UNIVERSAL_INTS.include?(type) type else typedef, member, prelude = typedef_expr(type, headers, &b) if member prelude << "static rbcv_typedef_ rbcv_var;" compat = UNIVERSAL_INTS.find {|t| try_static_assert("sizeof(rbcv_var.#{member}) == sizeof(#{t})", [prelude], opts, &b) } else next unless signed = try_signedness(typedef, member, [prelude]) u = "unsigned " if signed > 0 prelude << "extern rbcv_typedef_ foo();" compat = UNIVERSAL_INTS.find {|t| try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b) } end if compat macname ||= type.sub(/_(?=t\z)/, '').tr_cpp conv = (compat == "long long" ? "LL" : compat.upcase) compat = "#{u}#{compat}" typename = type.tr_cpp $defs.push(format("-DSIZEOF_%s=SIZEOF_%s", typename, compat.tr_cpp)) $defs.push(format("-DTYPEOF_%s=%s", typename, compat.quote)) $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv)) conv = (u ? "U" : "") + conv $defs.push(format("-D%s2NUM=%s2NUM", macname, conv)) $defs.push(format("-DNUM2%s=NUM2%s", macname, conv)) compat end end end end |
#cpp_command(outfile, opt = "") ⇒ Object
495 496 497 498 499 500 501 502 503 504 |
# File 'lib/mkmf.rb', line 495 def cpp_command(outfile, opt="") conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote, 'arch_hdrdir' => $arch_hdrdir.quote, 'top_srcdir' => $top_srcdir.quote) if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty? conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '') end RbConfig::("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", conf) end |
#cpp_include(header) ⇒ Object
595 596 597 598 599 600 601 602 |
# File 'lib/mkmf.rb', line 595 def cpp_include(header) if header header = [header] unless header.kind_of? Array header.map {|h| String === h ? "#include <#{h}>\n" : h}.join else "" end end |
#create_header(header = "extconf.h") ⇒ Object
Generates a header file consisting of the various macro definitions generated by other methods such as have_func and have_header. These are then wrapped in a custom #ifndef
based on the header
file name, which defaults to “extconf.h”.
For example:
# extconf.rb
require 'mkmf'
have_func('realpath')
have_header('sys/utime.h')
create_header
create_makefile('foo')
The above script would generate the following extconf.h file:
#ifndef EXTCONF_H
#define EXTCONF_H
#define HAVE_REALPATH 1
#define HAVE_SYS_UTIME_H 1
#endif
Given that the create_header method generates a file based on definitions set earlier in your extconf.rb file, you will probably want to make this one of the last methods you call in your script.
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 |
# File 'lib/mkmf.rb', line 1681 def create_header(header = "extconf.h") "creating %s\n", header sym = header.tr_cpp hdr = ["#ifndef #{sym}\n#define #{sym}\n"] for line in $defs case line when /^-D([^=]+)(?:=(.*))?/ hdr << "#define #$1 #{$2 ? Shellwords.shellwords($2)[0].gsub(/(?=\t+)/, "\\\n") : 1}\n" when /^-U(.*)/ hdr << "#undef #$1\n" end end hdr << "#endif\n" hdr = hdr.join("") log_src(hdr, "#{header} is") unless (IO.read(header) == hdr rescue false) open(header, "wb") do |hfile| hfile.write(hdr) end end $extconf_h = header end |
#create_makefile(target, srcprefix = nil) ⇒ Object
Generates the Makefile for your extension, passing along any options and preprocessor constants that you may have generated through other methods.
The target
name should correspond the name of the global function name defined within your C extension, minus the Init_
. For example, if your C extension is defined as Init_foo
, then your target would simply be “foo”.
If any “/” characters are present in the target name, only the last name is interpreted as the target name, and the rest are considered toplevel directory names, and the generated Makefile will be altered accordingly to follow that directory structure.
For example, if you pass “test/foo” as a target name, your extension will be installed under the “test” directory. This means that in order to load the file within a Ruby program later, that directory structure will have to be followed, e.g. require 'test/foo'
.
The srcprefix
should be used when your source files are not in the same directory as your build script. This will not only eliminate the need for you to manually copy the source files into the same directory as your build script, but it also sets the proper target_prefix
in the generated Makefile.
Setting the target_prefix
will, in turn, install the generated binary in a directory under your RbConfig::CONFIG['sitearchdir']
that mimics your local filesystem when you run make install
.
For example, given the following file tree:
ext/
extconf.rb
test/
foo.c
And given the following code:
create_makefile('test/foo', 'test')
That will set the target_prefix
in the generated Makefile to “test”. That, in turn, will create the following file tree when installed via the make install
command:
/path/to/ruby/sitearchdir/test/foo.so
It is recommended that you use this approach to generate your makefiles, instead of copying files around manually, because some third party libraries may depend on the target_prefix
being set properly.
The srcprefix
argument can be used to override the default source directory, i.e. the current directory. It is included as part of the VPATH
and added to the list of INCFLAGS
.
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 |
# File 'lib/mkmf.rb', line 2180 def create_makefile(target, srcprefix = nil) $target = target libpath = $DEFLIBPATH|$LIBPATH "creating Makefile\n" MakeMakefile.rm_f "#{CONFTEST}*" if CONFIG["DLEXT"] == $OBJEXT for lib in libs = $libs.split lib.sub!(/-l(.*)/, %%"lib\\1.#{$LIBEXT}"%) end $defs.push(format("-DEXTLIB='%s'", libs.join(","))) end if target.include?('/') target_prefix, target = File.split(target) target_prefix[0,0] = '/' else target_prefix = "" end srcprefix ||= "$(srcdir)/#{srcprefix}".chomp('/') RbConfig.(srcdir = srcprefix.dup) ext = ".#{$OBJEXT}" orig_srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] if not $objs srcs = $srcs || orig_srcs objs = srcs.inject(Hash.new {[]}) {|h, f| h[File.basename(f, ".*") << ext] <<= f; h} $objs = objs.keys unless objs.delete_if {|b, f| f.size == 1}.empty? dups = objs.sort.map {|b, f| "#{b[/.*\./]}{#{f.collect {|n| n[/([^.]+)\z/]}.join(',')}}" } abort "source files duplication - #{dups.join(", ")}" end else $objs.collect! {|o| File.basename(o, ".*") << ext} unless $OBJEXT == "o" srcs = $srcs || $objs.collect {|o| o.chomp(ext) << ".c"} end $srcs = srcs hdrs = Dir[File.join(srcdir, "*.{#{HDR_EXT.join(%q{,})}}")] target = nil if $objs.empty? if target and EXPORT_PREFIX if File.exist?(File.join(srcdir, target + '.def')) deffile = "$(srcdir)/$(TARGET).def" unless EXPORT_PREFIX.empty? makedef = %{$(RUBY) -pe "$$_.sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i" #{deffile}} end else makedef = %{(echo EXPORTS && echo $(TARGET_ENTRY))} end if makedef $cleanfiles << '$(DEFFILE)' origdef = deffile deffile = "$(TARGET)-$(arch).def" end end origdef ||= '' if $extout and $INSTALLFILES $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))}) $distcleandirs.concat($INSTALLFILES.collect {|files, dir| dir}) end if $extmk and $static $defs << "-DRUBY_EXPORT=1" end if $extmk and not $extconf_h create_header end libpath = libpathflag(libpath) dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : "" staticlib = target ? "$(TARGET).#$LIBEXT" : "" mfile = open("Makefile", "wb") conf = configuration(srcprefix) conf = yield(conf) if block_given? mfile.puts(conf) mfile.print " libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")} LIBPATH = #{libpath} DEFFILE = #{deffile} CLEANFILES = #{$cleanfiles.join(' ')} DISTCLEANFILES = #{$distcleanfiles.join(' ')} DISTCLEANDIRS = #{$distcleandirs.join(' ')} extout = #{$extout && $extout.quote} extout_prefix = #{$extout_prefix} target_prefix = #{target_prefix} LOCAL_LIBS = #{$LOCAL_LIBS} LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS} ORIG_SRCS = #{orig_srcs.collect(&File.method(:basename)).join(' ')} SRCS = $(ORIG_SRCS) #{(srcs - orig_srcs).collect(&File.method(:basename)).join(' ')} OBJS = #{$objs.join(" ")} HDRS = #{hdrs.map{|h| '$(srcdir)/' + File.basename(h)}.join(' ')} TARGET = #{target} TARGET_NAME = #{target && target[/\A\w+/]} TARGET_ENTRY = #{EXPORT_PREFIX || ''}Init_$(TARGET_NAME) DLLIB = #{dllib} EXTSTATIC = #{$static || ""} STATIC_LIB = #{staticlib unless $static.nil?} #{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""} TIMESTAMP_DIR = #{$extout ? '$(extout)/.timestamp' : '.'} " #" # TODO: fixme install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]} n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET)' mfile.print " TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB) CLEANLIBS = #{n}.#{CONFIG['DLEXT']} #{config_string('cleanlibs') {|t| t.gsub(/\$\*/) {n}}} CLEANOBJS = *.#{$OBJEXT} #{config_string('cleanobjs') {|t| t.gsub(/\$\*/, "$(TARGET)#{deffile ? '-$(arch)': ''}")} if target} *.bak all: #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"} static: #{$extmk && !$static ? "all" : "$(STATIC_LIB)#{!$extmk ? " install-rb" : ""}"} .PHONY: all install static install-so install-rb .PHONY: clean clean-so clean-static clean-rb " mfile.print CLEANINGS fsep = config_string('BUILD_FILE_SEPARATOR') {|s| s unless s == "/"} if fsep sep = ":/=#{fsep}" fseprepl = proc {|s| s = s.gsub("/", fsep) s = s.gsub(/(\$\(\w+)(\))/) {$1+sep+$2} s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2} } rsep = ":#{fsep}=/" else fseprepl = proc {|s| s} sep = "" rsep = "" end dirs = [] mfile.print "install: install-so install-rb\n\n" sodir = (dir = "$(RUBYARCHDIR)").dup mfile.print("install-so: ") if target f = "$(DLLIB)" dest = "#{dir}/#{f}" stamp = (dir, target_prefix) if $extout mfile.puts dest mfile.print "clean-so::\n" mfile.print "\t-$(Q)$(RM) #{fseprepl[dest]} #{fseprepl[stamp]}\n" mfile.print "\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n" else mfile.print "#{f} #{stamp}\n" mfile.print "\t$(INSTALL_PROG) #{fseprepl[f]} #{dir}\n" if defined?($installed_list) mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n" end end mfile.print "clean-static::\n" mfile.print "\t-$(Q)$(RM) $(STATIC_LIB)\n" else mfile.puts "Makefile" end mfile.print("install-rb: pre-install-rb install-rb-default\n") mfile.print("install-rb-default: pre-install-rb-default\n") mfile.print("pre-install-rb: Makefile\n") mfile.print("pre-install-rb-default: Makefile\n") for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]] files = install_files(mfile, i, nil, srcprefix) or next for dir, *files in files unless dirs.include?(dir) dirs << dir mfile.print "pre-install-rb#{sfx}: #{(dir, target_prefix)}\n" end for f in files dest = "#{dir}/#{File.basename(f)}" mfile.print("install-rb#{sfx}: #{dest}\n") mfile.print("#{dest}: #{f} #{(dir, target_prefix)}\n") mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D)\n") if defined?($installed_list) and !$extout mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n") end if $extout mfile.print("clean-rb#{sfx}::\n") mfile.print("\t-$(Q)$(RM) #{fseprepl[dest]}\n") end end end mfile.print "pre-install-rb#{sfx}:\n" if files.empty? mfile.print("\t@$(NULLCMD)\n") else mfile.print("\t$(ECHO) installing#{sfx.sub(/^-/, " ")} #{target} libraries\n") end if $extout dirs.uniq! unless dirs.empty? mfile.print("clean-rb#{sfx}::\n") for dir in dirs.sort_by {|d| -d.count('/')} stamp = (dir, target_prefix) mfile.print("\t-$(Q)$(RM) #{fseprepl[stamp]}\n") mfile.print("\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n") end end end end dirs.unshift(sodir) if target and !dirs.include?(sodir) dirs.each do |d| t = (d, target_prefix) mfile.print "#{t}:\n\t$(Q) $(MAKEDIRS) $(@D) #{d}\n\t$(Q) $(TOUCH) $@\n" end mfile.print <<-SITEINSTALL site-install: site-install-so site-install-rb site-install-so: install-so site-install-rb: install-rb SITEINSTALL return unless target mfile.puts SRC_EXT.collect {|e| ".path.#{e} = $(VPATH)"} if $nmake == ?b mfile.print ".SUFFIXES: .#{(SRC_EXT + [$OBJEXT, $ASMEXT]).compact.join(' .')}\n" mfile.print "\n" compile_command = "\n\t$(ECHO) compiling $(<#{rsep})\n\t$(Q) %s\n\n" command = compile_command % COMPILE_CXX asm_command = compile_command.sub(/compiling/, 'translating') % ASSEMBLE_CXX CXX_EXT.each do |e| each_compile_rules do |rule| mfile.printf(rule, e, $OBJEXT) mfile.print(command) mfile.printf(rule, e, $ASMEXT) mfile.print(asm_command) end end command = compile_command % COMPILE_C asm_command = compile_command.sub(/compiling/, 'translating') % ASSEMBLE_C C_EXT.each do |e| each_compile_rules do |rule| mfile.printf(rule, e, $OBJEXT) mfile.print(command) mfile.printf(rule, e, $ASMEXT) mfile.print(asm_command) end end mfile.print "$(RUBYARCHDIR)/" if $extout mfile.print "$(DLLIB): " mfile.print "$(DEFFILE) " if makedef mfile.print "$(OBJS) Makefile" mfile.print " #{('$(RUBYARCHDIR)', target_prefix)}" if $extout mfile.print "\n" mfile.print "\t$(ECHO) linking shared-object #{target_prefix.sub(/\A\/(.*)/, '\1/')}$(DLLIB)\n" mfile.print "\t-$(Q)$(RM) $(@#{sep})\n" link_so = LINK_SO.gsub(/^/, "\t$(Q) ") if srcs.any?(&%r"\.(?:#{CXX_EXT.join('|')})\z".method(:===)) link_so = link_so.sub(/\bLDSHARED\b/, '\&XX') end mfile.print link_so, "\n\n" unless $static.nil? mfile.print "$(STATIC_LIB): $(OBJS)\n\t-$(Q)$(RM) $(@#{sep})\n\t" mfile.print "$(ECHO) linking static-library $(@#{rsep})\n\t$(Q) " mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)" config_string('RANLIB') do |ranlib| mfile.print "\n\t-$(Q)#{ranlib} $(@) 2> /dev/null || true" end end mfile.print "\n\n" if makedef mfile.print "$(DEFFILE): #{origdef}\n" mfile.print "\t$(ECHO) generating $(@#{rsep})\n" mfile.print "\t$(Q) #{makedef} > $@\n\n" end depend = File.join(srcdir, "depend") if File.exist?(depend) mfile.print("###\n", *depend_rules(File.read(depend))) else mfile.print "$(OBJS): $(HDRS) $(ruby_headers)\n" end $makefile_created = true ensure mfile.close if mfile end |
#create_tmpsrc(src) ⇒ Object
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/mkmf.rb', line 426 def create_tmpsrc(src) src = "#{COMMON_HEADERS}\n#{src}" src = yield(src) if block_given? src.gsub!(/[ \t]+$/, '') src.gsub!(/\A\n+|^\n+$/, '') src.sub!(/[^\n]\z/, "\\&\n") count = 0 begin open(CONFTEST_C, "wb") do |cfile| cfile.print src end rescue Errno::EACCES if (count += 1) < 5 sleep 0.2 retry end end src end |
#depend_rules(depend) ⇒ Object
Processes the data contents of the “depend” file. Each line of this file is expected to be a file name.
Returns the output of findings, in Makefile format.
2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 |
# File 'lib/mkmf.rb', line 2067 def depend_rules(depend) suffixes = [] depout = [] cont = implicit = nil impconv = proc do each_compile_rules {|rule| depout << (rule % implicit[0]) << implicit[1]} implicit = nil end ruleconv = proc do |line| if implicit if /\A\t/ =~ line implicit[1] << line next else impconv[] end end if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line) suffixes << m[1] << m[2] implicit = [[m[1], m[2]], [m.post_match]] next elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line line.sub!(/\s*\#.*$/, '') comment = $& line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2} line = line.chomp + comment + "\n" if comment end depout << line end depend.each_line do |line| line.gsub!(/\.o\b/, ".#{$OBJEXT}") line.gsub!(/\{\$\(VPATH\)\}/, "") unless $nmake line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h) line.gsub!(%r"\$\(hdrdir\)/(?!ruby(?![^:;/\s]))(?=[-\w]+\.h)", '\&ruby/') if $nmake && /\A\s*\$\(RM|COPY\)/ =~ line line.gsub!(%r"[-\w\./]{2,}"){$&.tr("/", "\\")} line.gsub!(/(\$\((?!RM|COPY)[^:)]+)(?=\))/, '\1:/=\\') end if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line (cont ||= []) << line next elsif cont line = (cont << line).join cont = nil end ruleconv.call(line) end if cont ruleconv.call(cont.join) elsif implicit impconv.call end unless suffixes.empty? depout.unshift(".SUFFIXES: ." + suffixes.uniq.join(" .") + "\n\n") end depout.unshift("$(OBJS): $(RUBY_EXTCONF_H)\n\n") if $extconf_h depout.flatten! depout end |
#dir_config(target, idefault = nil, ldefault = nil) ⇒ Object
call-seq:
dir_config(target)
dir_config(target, prefix)
dir_config(target, idefault, ldefault)
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=prefix
, --with-foo-include=dir
and --with-foo-lib=dir
command line options to tell where to search for header/library files.
You may pass along additional parameters to specify default values. If one is given it is taken as default prefix
, and if two are given they are taken as “include” and “lib” defaults in that order.
In any case, the return value will be an array of determined “include” and “lib” directories, either of which can be nil if no corresponding command line option is given when no default value is specified.
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.
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 |
# File 'lib/mkmf.rb', line 1731 def dir_config(target, idefault=nil, ldefault=nil) if dir = with_config(target + "-dir", (idefault unless ldefault)) defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR) idefault = ldefault = nil end idir = with_config(target + "-include", idefault) $arg_config.last[1] ||= "${#{target}-dir}/include" ldir = with_config(target + "-lib", ldefault) $arg_config.last[1] ||= "${#{target}-dir}/#{_libdir_basename}" idirs = idir ? Array === idir ? idir.dup : idir.split(File::PATH_SEPARATOR) : [] if defaults idirs.concat(defaults.collect {|d| d + "/include"}) idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR) end unless idirs.empty? idirs.collect! {|d| "-I" + d} idirs -= Shellwords.shellwords($CPPFLAGS) unless idirs.empty? $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ") end end ldirs = ldir ? Array === ldir ? ldir.dup : ldir.split(File::PATH_SEPARATOR) : [] if defaults ldirs.concat(defaults.collect {|d| "#{d}/#{_libdir_basename}"}) ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR) end $LIBPATH = ldirs | $LIBPATH [idir, ldir] end |
#dummy_makefile(srcdir) ⇒ Object
creates a stub Makefile.
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 |
# File 'lib/mkmf.rb', line 2037 def dummy_makefile(srcdir) configuration(srcdir) << <<RULES << CLEANINGS CLEANFILES = #{$cleanfiles.join(' ')} DISTCLEANFILES = #{$distcleanfiles.join(' ')} all install static install-so install-rb: Makefile .PHONY: all install static install-so install-rb .PHONY: clean clean-so clean-static clean-rb RULES end |
#each_compile_rules ⇒ Object
:nodoc:
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
# File 'lib/mkmf.rb', line 2049 def each_compile_rules # :nodoc: vpath_splat = /\$\(\*VPATH\*\)/ COMPILE_RULES.each do |rule| if vpath_splat =~ rule $VPATH.each do |path| yield rule.sub(vpath_splat) {path} end else yield rule end end end |
#egrep_cpp(pat, src, opt = "", &b) ⇒ Object
Returns whether or not the src
can be preprocessed with the C preprocessor and matches with pat
.
If a block given, it is called with the source before compilation. You can modify the source in the block.
pat
-
a Regexp or a String
src
-
a String which contains a C source
opt
-
a String which contains preprocessor options
NOTE: When pat is a Regexp the matching will be checked in process, otherwise egrep(1) will be invoked to check it.
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
# File 'lib/mkmf.rb', line 806 def egrep_cpp(pat, src, opt = "", &b) src = create_tmpsrc(src, &b) xpopen(cpp_command('', opt)) do |f| if Regexp === pat puts(" ruby -ne 'print if #{pat.inspect}'") f.grep(pat) {|l| puts "#{f.lineno}: #{l}" return true } false else puts(" egrep '#{pat}'") begin stdin = $stdin.dup $stdin.reopen(f) system("egrep", pat) ensure $stdin.reopen(stdin) end end end ensure MakeMakefile.rm_f "#{CONFTEST}*" log_src(src) end |
#enable_config(config, default = nil) ⇒ Object
Tests for the presence of an --enable-
config or --disable-
config option. Returns true
if the enable option is given, false
if the disable option is given, and the default value otherwise.
This can be useful for adding custom definitions, such as debug information.
Example:
if enable_config("debug")
$defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
end
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 |
# File 'lib/mkmf.rb', line 1643 def enable_config(config, default=nil) if arg_config("--enable-"+config) true elsif arg_config("--disable-"+config) false elsif block_given? yield(config, default) else return default end end |
#find_executable(bin, path = nil) ⇒ Object
Searches for the executable bin
on path
. The default path is your PATH
environment variable. If that isn’t defined, it will resort to searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.
If found, it will return the full path, including the executable name, of where it was found.
Note that this method does not actually affect the generated Makefile.
1573 1574 1575 1576 1577 |
# File 'lib/mkmf.rb', line 1573 def find_executable(bin, path = nil) checking_for (bin, path) do find_executable0(bin, path) end end |
#find_executable0(bin, path = nil) ⇒ Object
This method is used internally by the find_executable method.
Internal use only.
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 |
# File 'lib/mkmf.rb', line 1529 def find_executable0(bin, path = nil) executable_file = proc do |name| begin stat = File.stat(name) rescue SystemCallError else next name if stat.file? and stat.executable? end end exts = config_string('EXECUTABLE_EXTS') {|s| s.split} || config_string('EXEEXT') {|s| [s]} if File.(bin) == bin return bin if executable_file.call(bin) if exts exts.each {|ext| executable_file.call(file = bin + ext) and return file} end return nil end if path ||= ENV['PATH'] path = path.split(File::PATH_SEPARATOR) else path = %w[/usr/local/bin /usr/ucb /usr/bin /bin] end file = nil path.each do |dir| return file if executable_file.call(file = File.join(dir, bin)) if exts exts.each {|ext| executable_file.call(ext = file + ext) and return ext} end end nil end |
#find_header(header, *paths) ⇒ Object
Instructs mkmf to search for the given header
in any of the paths
provided, and returns whether or not it was found in those paths.
If the header is found then the path it was found on is added to the list of included directories that are sent to the compiler (via the -I
switch).
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 |
# File 'lib/mkmf.rb', line 1140 def find_header(header, *paths) = (header, paths) header = cpp_include(header) checking_for do if try_header(header) true else found = false paths.each do |dir| opt = "-I#{dir}".quote if try_header(header, opt) $INCFLAGS << " " << opt found = true break end end found end end end |
#find_library(lib, func, *paths, &b) ⇒ Object
Returns whether or not the entry point func
can be found within the library lib
in one of the paths
specified, where paths
is an array of strings. If func
is nil
, then the main()
function is used as the entry point.
If lib
is found, then the path it was found on is added to the list of library paths searched and linked against.
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 |
# File 'lib/mkmf.rb', line 1015 def find_library(lib, func, *paths, &b) func = "main" if !func or func.empty? lib = with_config(lib+'lib', lib) paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten checking_for (func.funcall_style, LIBARG%lib) do libpath = $LIBPATH libs = append_library($libs, lib) begin until r = try_func(func, libs, &b) or paths.empty? $LIBPATH = libpath | [paths.shift] end if r $libs = libs libpath = nil end ensure $LIBPATH = libpath if libpath end r end end |
#find_type(type, opt, *headers, &b) ⇒ Object
Returns where the static type type
is defined.
You may also pass additional flags to opt
which are then passed along to the compiler.
See also have_type
.
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 |
# File 'lib/mkmf.rb', line 1237 def find_type(type, opt, *headers, &b) opt ||= "" fmt = "not found" def fmt.%(x) x ? x.respond_to?(:join) ? x.join(",") : x : self end checking_for (type, nil, opt), fmt do headers.find do |h| try_type(type, h, opt, &b) end end end |
#have_const(const, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the constant const
is defined. You may optionally pass the type
of const
as [const, type]
, such as:
have_const(%w[PTHREAD_MUTEX_INITIALIZER pthread_mutex_t], "pthread.h")
You may also pass additional headers
to check against in addition to the common header files, and 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_CONST_
.
For example, if have_const('foo')
returned true, then the HAVE_CONST_FOO
preprocessor macro would be passed to the compiler.
1285 1286 1287 1288 1289 |
# File 'lib/mkmf.rb', line 1285 def have_const(const, headers = nil, opt = "", &b) checking_for ([*const].compact.join(' '), headers, opt) do try_const(const, headers, opt, &b) end end |
#have_devel? ⇒ Boolean
446 447 448 449 450 451 452 |
# File 'lib/mkmf.rb', line 446 def have_devel? unless defined? $have_devel $have_devel = true $have_devel = try_link(MAIN_DOES_NOTHING) end $have_devel end |
#have_framework(fw, &b) ⇒ Object
Returns whether or not the given framework
can be found on your system. If found, a macro is passed as a preprocessor constant to the compiler using the framework name, in uppercase, prepended with HAVE_FRAMEWORK_
.
For example, if have_framework('Ruby')
returned true, then the HAVE_FRAMEWORK_RUBY
preprocessor macro would be passed to the compiler.
If fw
is a pair of the framework name and its header file name that header file is checked, instead of the normally used header file which is named same as the framework.
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
# File 'lib/mkmf.rb', line 1111 def have_framework(fw, &b) if Array === fw fw, header = *fw else header = "#{fw}.h" end checking_for fw do src = cpp_include("#{fw}/#{header}") << "\n" "int main(void){return 0;}" opt = " -framework #{fw}" if try_link(src, opt, &b) or (objc = try_link(src, "-ObjC#{opt}", &b)) $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp)) # TODO: non-worse way than this hack, to get rid of separating # option and its argument. $LDFLAGS << " -ObjC" if objc and /(\A|\s)-ObjC(\s|\z)/ !~ $LDFLAGS $LIBS << opt true else false end end end |
#have_func(func, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the function func
can be found in the common header files, or within any headers
that you provide. If found, a macro is passed as a preprocessor constant to the compiler using the function name, in uppercase, prepended with HAVE_
.
To check functions in an additional library, you need to check that library first using have_library()
. The func
shall be either mere function name or function name with arguments.
For example, if have_func('foo')
returned true
, then the HAVE_FOO
preprocessor macro would be passed to the compiler.
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/mkmf.rb', line 1049 def have_func(func, headers = nil, opt = "", &b) checking_for (func.funcall_style, headers, opt) do if try_func(func, $libs, headers, opt, &b) $defs << "-DHAVE_#{func.sans_arguments.tr_cpp}" true else false end end end |
#have_header(header, preheaders = nil, opt = "", &b) ⇒ Object
Returns whether or not the given header
file can be found on your system. If found, a macro is passed as a preprocessor constant to the compiler using the header file name, in uppercase, prepended with HAVE_
.
For example, if have_header('foo.h')
returned true, then the HAVE_FOO_H
preprocessor macro would be passed to the compiler.
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 |
# File 'lib/mkmf.rb', line 1089 def have_header(header, preheaders = nil, opt = "", &b) checking_for header do if try_header(cpp_include(preheaders)+cpp_include(header), opt, &b) $defs.push(format("-DHAVE_%s", header.tr_cpp)) true else false end end end |
#have_library(lib, func = nil, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the given entry point func
can be found within lib
. If func
is nil
, the main()
entry point is used by default. If found, it adds the library to list of libraries to be used when linking your extension.
If headers
are provided, it will include those header files as the header files it looks in when searching for func
.
The real name of the library to be linked can be altered by --with-FOOlib
configuration option.
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
# File 'lib/mkmf.rb', line 989 def have_library(lib, func = nil, headers = nil, opt = "", &b) func = "main" if !func or func.empty? lib = with_config(lib+'lib', lib) checking_for (func.funcall_style, LIBARG%lib, opt) do if COMMON_LIBS.include?(lib) true else libs = append_library($libs, lib) if try_func(func, libs, headers, opt, &b) $libs = libs true else false end end end end |
#have_macro(macro, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not macro
is defined either in the common header files or within any headers
you provide.
Any options you pass to opt
are passed along to the compiler.
972 973 974 975 976 |
# File 'lib/mkmf.rb', line 972 def have_macro(macro, headers = nil, opt = "", &b) checking_for (macro, headers, opt) do macro_defined?(macro, cpp_include(headers), opt, &b) end end |
#have_struct_member(type, member, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the struct of type type
contains member
. If it does not, or the struct type can’t be found, then false is returned. You may optionally specify additional headers
in which to look for the struct (in addition to the common header files).
If found, a macro is passed as a preprocessor constant to the compiler using the type name and the member name, in uppercase, prepended with HAVE_
.
For example, if have_struct_member('struct foo', 'bar')
returned true, then the HAVE_STRUCT_FOO_BAR
preprocessor macro would be passed to the compiler.
HAVE_ST_BAR
is also defined for backward compatibility.
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
# File 'lib/mkmf.rb', line 1176 def have_struct_member(type, member, headers = nil, opt = "", &b) checking_for ("#{type}.#{member}", headers) do if try_compile(<<"SRC", opt, &b) #{cpp_include(headers)} /*top*/ int s = (char *)&((#{type}*)0)->#{member} - (char *)0; #{MAIN_DOES_NOTHING} SRC $defs.push(format("-DHAVE_%s_%s", type.tr_cpp, member.tr_cpp)) $defs.push(format("-DHAVE_ST_%s", member.tr_cpp)) # backward compatibility true else false end end end |
#have_type(type, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the static type type
is defined. You may optionally pass additional headers
to check against in addition to the common header files.
You may also pass additional flags to opt
which are then passed along to the compiler.
If found, a macro is passed as a preprocessor constant to the compiler using the type name, in uppercase, prepended with HAVE_TYPE_
.
For example, if have_type('foo')
returned true, then the HAVE_TYPE_FOO
preprocessor macro would be passed to the compiler.
1224 1225 1226 1227 1228 |
# File 'lib/mkmf.rb', line 1224 def have_type(type, headers = nil, opt = "", &b) checking_for (type, headers, opt) do try_type(type, headers, opt, &b) end end |
#have_typeof? ⇒ Boolean
Used internally by the what_type? method to check if the typeof GCC extension is available.
1456 1457 1458 1459 1460 1461 1462 1463 1464 |
# File 'lib/mkmf.rb', line 1456 def have_typeof? return $typeof if defined?($typeof) $typeof = %w[__typeof__ typeof].find do |t| try_compile(<<SRC) int rbcv_foo; #{t}(rbcv_foo) rbcv_bar; SRC end end |
#have_var(var, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the variable var
can be found in the common header files, or within any headers
that you provide. If found, a macro is passed as a preprocessor constant to the compiler using the variable name, in uppercase, prepended with HAVE_
.
To check variables in an additional library, you need to check that library first using have_library()
.
For example, if have_var('foo')
returned true, then the HAVE_FOO
preprocessor macro would be passed to the compiler.
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 |
# File 'lib/mkmf.rb', line 1071 def have_var(var, headers = nil, opt = "", &b) checking_for (var, headers, opt) do if try_var(var, headers, opt, &b) $defs.push(format("-DHAVE_%s", var.tr_cpp)) true else false end end end |
#init_mkmf(config = CONFIG, rbconfig = RbConfig::CONFIG) ⇒ Object
:stopdoc:
2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 |
# File 'lib/mkmf.rb', line 2469 def init_mkmf(config = CONFIG, rbconfig = RbConfig::CONFIG) $makefile_created = false $arg_config = [] $enable_shared = config['ENABLE_SHARED'] == 'yes' $defs = [] $extconf_h = nil if $warnflags = CONFIG['warnflags'] and CONFIG['GCC'] == 'yes' # turn warnings into errors only for bundled extensions. config['warnflags'] = $warnflags.gsub(/(\A|\s)-Werror[-=]/, '\1-W') if /icc\z/ =~ config['CC'] config['warnflags'].gsub!(/(\A|\s)-W(?:division-by-zero|deprecated-declarations)/, '\1') end RbConfig.(rbconfig['warnflags'] = config['warnflags'].dup) config.each do |key, val| RbConfig.(rbconfig[key] = val.dup) if /warnflags/ =~ val end $warnflags = config['warnflags'] unless $extmk end $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup $CXXFLAGS = (with_config("cxxflags", arg_config("CXXFLAGS", config["CXXFLAGS"]))||'').dup $ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup $LDFLAGS = with_config("ldflags", arg_config("LDFLAGS", config["LDFLAGS"])).dup $INCFLAGS = "-I$(arch_hdrdir)" $INCFLAGS << " -I$(hdrdir)/ruby/backward" unless $extmk $INCFLAGS << " -I$(hdrdir) -I$(srcdir)" $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup $LIBEXT = config['LIBEXT'].dup $OBJEXT = config["OBJEXT"].dup $EXEEXT = config["EXEEXT"].dup $ASMEXT = config_string('ASMEXT', &:dup) || 'S' $LIBS = "#{config['LIBS']} #{config['DLDLIBS']}" $LIBRUBYARG = "" $LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC'] $LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED'] $DEFLIBPATH = [$extmk ? "$(topdir)" : "$(#{config["libdirname"] || "libdir"})"] $DEFLIBPATH.unshift(".") $LIBPATH = [] $INSTALLFILES = [] $NONINSTALLFILES = [/~\z/, /\A#.*#\z/, /\A\.#/, /\.bak\z/i, /\.orig\z/, /\.rej\z/, /\.l[ao]\z/, /\.o\z/] $VPATH = %w[$(srcdir) $(arch_hdrdir)/ruby $(hdrdir)/ruby] $objs = nil $srcs = nil $libs = "" if $enable_shared or RbConfig.(config["LIBRUBY"].dup) != RbConfig.(config["LIBRUBY_A"].dup) $LIBRUBYARG = config['LIBRUBYARG'] end $LOCAL_LIBS = "" $cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || [] $cleanfiles << "mkmf.log" $distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || [] $distcleandirs = config_string('DISTCLEANDIRS') {|s| Shellwords.shellwords(s)} || [] $extout ||= nil $extout_prefix ||= nil $arg_config.clear dir_config("opt") end |
#install_dirs(target_prefix = nil) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/mkmf.rb', line 178 def install_dirs(target_prefix = nil) if $extout dirs = [ ['BINDIR', '$(extout)/bin'], ['RUBYCOMMONDIR', '$(extout)/common'], ['RUBYLIBDIR', '$(RUBYCOMMONDIR)$(target_prefix)'], ['RUBYARCHDIR', '$(extout)/$(arch)$(target_prefix)'], ['HDRDIR', '$(extout)/include/ruby$(target_prefix)'], ['ARCHHDRDIR', '$(extout)/include/$(arch)/ruby$(target_prefix)'], ['extout', "#$extout"], ['extout_prefix', "#$extout_prefix"], ] elsif $extmk dirs = [ ['BINDIR', '$(bindir)'], ['RUBYCOMMONDIR', '$(rubylibdir)'], ['RUBYLIBDIR', '$(rubylibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(archdir)$(target_prefix)'], ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'], ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'], ] elsif $configure_args.has_key?('--vendor') dirs = [ ['BINDIR', '$(bindir)'], ['RUBYCOMMONDIR', '$(vendordir)$(target_prefix)'], ['RUBYLIBDIR', '$(vendorlibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(vendorarchdir)$(target_prefix)'], ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'], ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'], ] else dirs = [ ['BINDIR', '$(bindir)'], ['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'], ['RUBYLIBDIR', '$(sitelibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(sitearchdir)$(target_prefix)'], ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'], ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'], ] end dirs << ['target_prefix', (target_prefix ? "/#{target_prefix}" : "")] dirs end |
#install_files(mfile, ifiles, map = nil, srcprefix = nil) ⇒ Object
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
# File 'lib/mkmf.rb', line 873 def install_files(mfile, ifiles, map = nil, srcprefix = nil) ifiles or return ifiles.empty? and return srcprefix ||= "$(srcdir)/#{srcprefix}".chomp('/') RbConfig::(srcdir = srcprefix.dup) dirs = [] path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]} ifiles.each do |files, dir, prefix| dir = map_dir(dir, map) prefix &&= %r|\A#{Regexp.quote(prefix)}/?| if /\A\.\// =~ files # install files which are in current working directory. files = files[2..-1] len = nil else # install files which are under the $(srcdir). files = File.join(srcdir, files) len = srcdir.size end f = nil Dir.glob(files) do |fx| f = fx f[0..len] = "" if len case File.basename(f) when *$NONINSTALLFILES next end d = File.dirname(f) d.sub!(prefix, "") if prefix d = (d.empty? || d == ".") ? dir : File.join(dir, d) f = File.join(srcprefix, f) if len path[d] << f end unless len or f d = File.dirname(files) d.sub!(prefix, "") if prefix d = (d.empty? || d == ".") ? dir : File.join(dir, d) path[d] << files end end dirs end |
#install_rb(mfile, dest, srcdir = nil) ⇒ Object
916 917 918 |
# File 'lib/mkmf.rb', line 916 def install_rb(mfile, dest, srcdir = nil) install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir) end |
#libpath_env ⇒ Object
366 367 368 369 370 371 372 373 374 375 |
# File 'lib/mkmf.rb', line 366 def libpath_env # used only if native compiling if libpathenv = config_string("LIBPATHENV") pathenv = ENV[libpathenv] libpath = RbConfig.($DEFLIBPATH.join(File::PATH_SEPARATOR)) {libpathenv => [libpath, pathenv].compact.join(File::PATH_SEPARATOR)} else {} end end |
#libpathflag(libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
506 507 508 509 510 511 512 513 514 515 |
# File 'lib/mkmf.rb', line 506 def libpathflag(libpath=$DEFLIBPATH|$LIBPATH) libpath.map{|x| case x when "$(topdir)", /\A\./ LIBPATHFLAG else LIBPATHFLAG+RPATHFLAG end % x.quote }.join end |
#link_command(ldflags, opt = "", libpath = $DEFLIBPATH|$LIBPATH) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/mkmf.rb', line 470 def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH) librubyarg = $extmk ? $LIBRUBYARG_STATIC : "$(LIBRUBYARG)" conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'src' => "#{CONFTEST_C}", 'arch_hdrdir' => $arch_hdrdir.quote, 'top_srcdir' => $top_srcdir.quote, 'INCFLAGS' => "#$INCFLAGS", 'CPPFLAGS' => "#$CPPFLAGS", 'CFLAGS' => "#$CFLAGS", 'ARCH_FLAG' => "#$ARCH_FLAG", 'LDFLAGS' => "#$LDFLAGS #{ldflags}", 'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs", 'LIBS' => "#{librubyarg} #{opt} #$LIBS") conf['LIBPATH'] = libpathflag(libpath.map {|s| RbConfig::(s.dup, conf)}) RbConfig::(TRY_LINK.dup, conf) end |
#log_src(src, heading = "checked program was") ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/mkmf.rb', line 412 def log_src(src, heading="checked program was") src = src.split(/^/) fmt = "%#{src.size.to_s.size}d: %s" Logging:: <<"EOM" #{heading}: /* begin */ EOM src.each_with_index {|line, no| Logging:: fmt, no+1, line} Logging:: <<"EOM" /* end */ EOM end |
#macro_defined?(macro, src, opt = "", &b) ⇒ Boolean
This is used internally by the have_macro? method.
833 834 835 836 837 838 839 840 841 842 |
# File 'lib/mkmf.rb', line 833 def macro_defined?(macro, src, opt = "", &b) src = src.sub(/[^\n]\z/, "\\&\n") try_compile(src + <<"SRC", opt, &b) /*top*/ #ifndef #{macro} # error |:/ === #{macro} undefined === /:| #endif SRC end |
#map_dir(dir, map = nil) ⇒ Object
222 223 224 225 |
# File 'lib/mkmf.rb', line 222 def map_dir(dir, map = nil) map ||= INSTALL_DIRS map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)} end |
#merge_libs(*libs) ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/mkmf.rb', line 279 def merge_libs(*libs) libs.inject([]) do |x, y| y = y.inject([]) {|ary, e| ary.last == e ? ary : ary << e} y.each_with_index do |v, yi| if xi = x.rindex(v) x[(xi+1)..-1] = merge_libs(y[(yi+1)..-1], x[(xi+1)..-1]) x[xi, 0] = y[0...yi] break end end and x.concat(y) x end end |
#message(*s) ⇒ Object
924 925 926 927 928 929 |
# File 'lib/mkmf.rb', line 924 def (*s) unless Logging.quiet and not $VERBOSE printf(*s) $stdout.flush end end |
#mkintpath(path) ⇒ Object
1882 1883 1884 |
# File 'lib/mkmf.rb', line 1882 def mkintpath(path) path end |
#mkmf_failed(path) ⇒ Object
Returns whether or not the Makefile was successfully generated. If not, the script will abort with an error message.
Internal use only.
2545 2546 2547 2548 2549 2550 |
# File 'lib/mkmf.rb', line 2545 def mkmf_failed(path) unless $makefile_created or File.exist?("Makefile") opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"} abort "*** #{path} failed ***\n" + FailedMessage + opts.join end end |
#modified?(target, times) ⇒ Boolean
Returns time stamp of the target
file if it exists and is newer than or equal to all of times
.
269 270 271 272 273 |
# File 'lib/mkmf.rb', line 269 def modified?(target, times) (t = File.mtime(target)) rescue return nil Array === times or times = [times] t if times.all? {|n| n <= t} end |
#pkg_config(pkg, option = nil) ⇒ Object
Returns compile/link information about an installed library in a tuple of [cflags, ldflags, libs]
, by using the command found first in the following commands:
-
If
--with-{pkg}-config={command}
is given via command line option:{command} {option}
-
{pkg}-config {option}
-
pkg-config {option} {pkg}
Where option is, for instance, --cflags
.
The values obtained are appended to $CFLAGS, $LDFLAGS and $libs.
If an option
argument is given, the config command is invoked with the option and a stripped output string is returned without modifying any of the global values mentioned above.
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 |
# File 'lib/mkmf.rb', line 1784 def pkg_config(pkg, option=nil) if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig) # iff package specific config command is given elsif ($PKGCONFIG ||= (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) && find_executable0(pkgconfig) && pkgconfig) and system("#{$PKGCONFIG} --exists #{pkg}") # default to pkg-config command pkgconfig = $PKGCONFIG get = proc {|opt| opt = xpopen("#{$PKGCONFIG} --#{opt} #{pkg}", err:[:child, :out], &:read) Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}} opt.strip if $?.success? } elsif find_executable0(pkgconfig = "#{pkg}-config") # default to package specific config command, as a last resort. else pkgconfig = nil end if pkgconfig get ||= proc {|opt| opt = xpopen("#{pkgconfig} --#{opt}", err:[:child, :out], &:read) Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}} opt.strip if $?.success? } end orig_ldflags = $LDFLAGS if get and option get[option] elsif get and try_ldflags(ldflags = get['libs']) if incflags = get['cflags-only-I'] $INCFLAGS << " " << incflags cflags = get['cflags-only-other'] else cflags = get['cflags'] end libs = get['libs-only-l'] if cflags $CFLAGS += " " << cflags $CXXFLAGS += " " << cflags end if libs ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ") else libs, ldflags = Shellwords.shellwords(ldflags).partition {|s| s =~ /-l([^ ]+)/ }.map {|l|l.quote.join(" ")} end $libs += " " << libs $LDFLAGS = [orig_ldflags, ldflags].join(' ') Logging:: "package configuration for %s\n", pkg Logging:: "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs [cflags, ldflags, libs] else Logging:: "package configuration for %s is not found\n", pkg nil end end |
#relative_from(path, base) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/mkmf.rb', line 153 def relative_from(path, base) dir = File.join(path, "") if File.(dir) == File.(dir, base) path else File.join(base, path) end end |
#scalar_ptr_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
Used internally by the what_type? method to determine if type
is a scalar pointer.
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/mkmf.rb', line 1430 def scalar_ptr_type?(type, member = nil, headers = nil, &b) try_compile(<<"SRC", &b) # pointer #{cpp_include(headers)} /*top*/ volatile #{type} conftestval; extern int t(void); #{MAIN_DOES_NOTHING 't'} int t(void) {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));} SRC end |
#scalar_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
Used internally by the what_type? method to determine if type
is a scalar pointer.
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
# File 'lib/mkmf.rb', line 1443 def scalar_type?(type, member = nil, headers = nil, &b) try_compile(<<"SRC", &b) # pointer #{cpp_include(headers)} /*top*/ volatile #{type} conftestval; extern int t(void); #{MAIN_DOES_NOTHING 't'} int t(void) {return (int)(1-(conftestval#{member ? ".#{member}" : ""}));} SRC end |
#split_libs(*strs) ⇒ Object
275 276 277 |
# File 'lib/mkmf.rb', line 275 def split_libs(*strs) strs.map {|s| s.split(/\s+(?=-|\z)/)}.flatten end |
#timestamp_file(name, target_prefix = nil) ⇒ Object
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 |
# File 'lib/mkmf.rb', line 2022 def (name, target_prefix = nil) if target_prefix pat = [] install_dirs.each do |n, d| pat << n if /\$\(target_prefix\)\z/ =~ d end name = name.gsub(/\$\((#{pat.join("|")})\)/) {$&+target_prefix} end name = name.gsub(/(\$[({]|[})])|(\/+)|[^-.\w]+/) {$1 ? "" : $2 ? ".-." : "_"} "$(TIMESTAMP_DIR)/.#{name}.time" end |
#try_cflags(flags, opts = {}) ⇒ Object
634 635 636 |
# File 'lib/mkmf.rb', line 634 def try_cflags(flags, opts = {}) try_compile(MAIN_DOES_NOTHING, flags, {:werror => true}.update(opts)) end |
#try_compile(src, opt = "", *opts, &b) ⇒ Object
Returns whether or not the src
can be compiled as a C source. opt
is passed to the C compiler as options. Note that $CFLAGS is also passed to the compiler.
If a block given, it is called with the source before compilation. You can modify the source in the block.
src
-
a String which contains a C source
opt
-
a String which contains compiler options
570 571 572 573 574 575 |
# File 'lib/mkmf.rb', line 570 def try_compile(src, opt="", *opts, &b) with_werror(opt, *opts) {|_opt, *| try_do(src, cc_command(_opt), *opts, &b)} and File.file?("#{CONFTEST}.#{$OBJEXT}") ensure MakeMakefile.rm_f "#{CONFTEST}*" end |
#try_const(const, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the constant const
is defined.
See also have_const
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 |
# File 'lib/mkmf.rb', line 1254 def try_const(const, headers = nil, opt = "", &b) const, type = *const if try_compile(<<"SRC", opt, &b) #{cpp_include(headers)} /*top*/ typedef #{type || 'int'} conftest_type; conftest_type conftestval = #{type ? '' : '(int)'}#{const}; SRC $defs.push(format("-DHAVE_CONST_%s", const.tr_cpp)) true else false end end |
#try_constant(const, headers = nil, opt = "", &b) ⇒ Object
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
# File 'lib/mkmf.rb', line 679 def try_constant(const, headers = nil, opt = "", &b) includes = cpp_include(headers) neg = try_static_assert("#{const} < 0", headers, opt) if CROSS_COMPILING if neg const = "-(#{const})" elsif try_static_assert("#{const} > 0", headers, opt) # positive constant elsif try_static_assert("#{const} == 0", headers, opt) return 0 else # not a constant return nil end upper = 1 until try_static_assert("#{const} <= #{upper}", headers, opt) lower = upper upper <<= 1 end return nil unless lower while upper > lower + 1 mid = (upper + lower) / 2 if try_static_assert("#{const} > #{mid}", headers, opt) lower = mid else upper = mid end end upper = -upper if neg return upper else src = %{#{includes} #include <stdio.h> /*top*/ typedef#{neg ? '' : ' unsigned'} #ifdef PRI_LL_PREFIX #define PRI_CONFTEST_PREFIX PRI_LL_PREFIX LONG_LONG #else #define PRI_CONFTEST_PREFIX "l" long #endif conftest_type; conftest_type conftest_const = (conftest_type)(#{const}); int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const); return 0;} } begin if try_link0(src, opt, &b) xpopen("./#{CONFTEST}") do |f| return Integer(f.gets) end end ensure MakeMakefile.rm_f "#{CONFTEST}*" end end nil end |
#try_cpp(src, opt = "", *opts, &b) ⇒ Object
Returns whether or not the src
can be preprocessed with the C preprocessor. opt
is passed to the preprocessor as options. Note that $CFLAGS is also passed to the preprocessor.
If a block given, it is called with the source before preprocessing. You can modify the source in the block.
src
-
a String which contains a C source
opt
-
a String which contains preprocessor options
586 587 588 589 590 591 |
# File 'lib/mkmf.rb', line 586 def try_cpp(src, opt="", *opts, &b) try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b) and File.file?("#{CONFTEST}.i") ensure MakeMakefile.rm_f "#{CONFTEST}*" end |
#try_cppflags(flags, opts = {}) ⇒ Object
612 613 614 |
# File 'lib/mkmf.rb', line 612 def try_cppflags(flags, opts = {}) try_header(MAIN_DOES_NOTHING, flags, {:werror => true}.update(opts)) end |
#try_do(src, command, *opts, &b) ⇒ Object
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/mkmf.rb', line 454 def try_do(src, command, *opts, &b) unless have_devel? raise <<MSG The compiler failed to generate an executable file. You have to install development tools first. MSG end begin src = create_tmpsrc(src, &b) xsystem(command, *opts) ensure log_src(src) MakeMakefile.rm_rf "#{CONFTEST}.dSYM" end end |
#try_func(func, libs, headers = nil, opt = "", &b) ⇒ Object
You should use have_func
rather than try_func
.
func
-
a String which contains a symbol name
libs
-
a String which contains library names.
headers
-
a String or an Array of strings which contains names of header files.
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
# File 'lib/mkmf.rb', line 744 def try_func(func, libs, headers = nil, opt = "", &b) headers = cpp_include(headers) case func when /^&/ decltype = proc {|x|"const volatile void *#{x}"} when /\)$/ call = func else call = "#{func}()" decltype = proc {|x| "void ((*#{x})())"} end if opt and !opt.empty? [[:to_str], [:join, " "], [:to_s]].each do |meth, *args| if opt.respond_to?(meth) break opt = opt.send(meth, *args) end end opt = "#{opt} #{libs}" else opt = libs end decltype && try_link(<<"SRC", opt, &b) or call && try_link(<<"SRC", opt, &b) #{headers} /*top*/ extern int t(void); #{MAIN_DOES_NOTHING 't'} #{"extern void #{call};" if decltype} int t(void) { #{call}; return 0; } SRC end |
#try_ldflags(flags, opts = {}) ⇒ Object
656 657 658 |
# File 'lib/mkmf.rb', line 656 def try_ldflags(flags, opts = {}) try_link(MAIN_DOES_NOTHING, flags, {:werror => true}.update(opts)) end |
#try_link(src, opt = "", *opts, &b) ⇒ Object
Returns whether or not the src
can be compiled as a C source and linked with its depending libraries successfully. opt
is passed to the linker as options. Note that $CFLAGS and $LDFLAGS are also passed to the linker.
If a block given, it is called with the source before compilation. You can modify the source in the block.
src
-
a String which contains a C source
opt
-
a String which contains linker options
555 556 557 558 559 |
# File 'lib/mkmf.rb', line 555 def try_link(src, opt="", *opts, &b) try_link0(src, opt, *opts, &b) ensure MakeMakefile.rm_f "#{CONFTEST}*", "c0x32*" end |
#try_link0(src, opt = "", *opts, &b) ⇒ Object
:nodoc:
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/mkmf.rb', line 528 def try_link0(src, opt="", *opts, &b) # :nodoc: cmd = link_command("", opt) if $universal require 'tmpdir' Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir| begin ENV["TMPDIR"] = tmpdir try_do(src, cmd, *opts, &b) ensure ENV["TMPDIR"] = oldtmpdir end end else try_do(src, cmd, *opts, &b) end and File.executable?(CONFTEST+$EXEEXT) end |
#try_run(src, opt = "", &b) ⇒ Object
Returns whether or not:
-
the
src
can be compiled as a C source, -
the result object can be linked with its depending libraries successfully,
-
the linked file can be invoked as an executable
-
and the executable exits successfully
opt
is passed to the linker as options. Note that $CFLAGS and $LDFLAGS are also passed to the linker.
If a block given, it is called with the source before compilation. You can modify the source in the block.
src
-
a String which contains a C source
opt
-
a String which contains linker options
Returns true when the executable exits successfully, false when it fails, or nil when preprocessing, compilation or link fails.
862 863 864 865 866 867 868 869 870 871 |
# File 'lib/mkmf.rb', line 862 def try_run(src, opt = "", &b) raise "cannot run test program while cross compiling" if CROSS_COMPILING if try_link0(src, opt, &b) xsystem("./#{CONFTEST}") else nil end ensure MakeMakefile.rm_f "#{CONFTEST}*" end |
#try_signedness(type, member, headers = nil, opts = nil) ⇒ Object
1304 1305 1306 1307 1308 1309 1310 1311 |
# File 'lib/mkmf.rb', line 1304 def try_signedness(type, member, headers = nil, opts = nil) raise ArgumentError, "don't know how to tell signedness of members" if member if try_static_assert("(#{type})-1 < 0", headers, opts) return -1 elsif try_static_assert("(#{type})-1 > 0", headers, opts) return +1 end end |
#try_static_assert(expr, headers = nil, opt = "", &b) ⇒ Object
670 671 672 673 674 675 676 677 |
# File 'lib/mkmf.rb', line 670 def try_static_assert(expr, headers = nil, opt = "", &b) headers = cpp_include(headers) try_compile(<<SRC, opt, &b) #{headers} /*top*/ int conftest_const[(#{expr}) ? 1 : -1]; SRC end |
#try_type(type, headers = nil, opt = "", &b) ⇒ Object
Returns whether or not the static type type
is defined.
See also have_type
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'lib/mkmf.rb', line 1197 def try_type(type, headers = nil, opt = "", &b) if try_compile(<<"SRC", opt, &b) #{cpp_include(headers)} /*top*/ typedef #{type} conftest_type; int conftestval[sizeof(conftest_type)?1:-1]; SRC $defs.push(format("-DHAVE_TYPE_%s", type.tr_cpp)) true else false end end |
#try_var(var, headers = nil, opt = "", &b) ⇒ Object
You should use have_var
rather than try_var
.
783 784 785 786 787 788 789 790 791 792 |
# File 'lib/mkmf.rb', line 783 def try_var(var, headers = nil, opt = "", &b) headers = cpp_include(headers) try_compile(<<"SRC", opt, &b) #{headers} /*top*/ extern int t(void); #{MAIN_DOES_NOTHING 't'} int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return !p; } SRC end |
#typedef_expr(type, headers) ⇒ Object
1297 1298 1299 1300 1301 1302 |
# File 'lib/mkmf.rb', line 1297 def typedef_expr(type, headers) typename, member = type.split('.', 2) prelude = cpp_include(headers).split(/$/) prelude << "typedef #{typename} rbcv_typedef_;\n" return "rbcv_typedef_", member, prelude end |
#what_type?(type, member = nil, headers = nil, &b) ⇒ Boolean
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 |
# File 'lib/mkmf.rb', line 1466 def what_type?(type, member = nil, headers = nil, &b) m = "#{type}" var = val = "*rbcv_var_" func = "rbcv_func_(void)" if member m << "." << member else type, member = type.split('.', 2) end if member val = "(#{var}).#{member}" end prelude = [cpp_include(headers).split(/^/)] prelude << ["typedef #{type} rbcv_typedef_;\n", "extern rbcv_typedef_ *#{func};\n", "rbcv_typedef_ #{var};\n", ] type = "rbcv_typedef_" fmt = member && !(typeof = have_typeof?) ? "seems %s" : "%s" if typeof var = "*rbcv_member_" func = "rbcv_mem_func_(void)" member = nil type = "rbcv_mem_typedef_" prelude[-1] << "typedef #{typeof}(#{val}) #{type};\n" prelude[-1] << "extern #{type} *#{func};\n" prelude[-1] << "#{type} #{var};\n" val = var end def fmt.%(x) x ? super : "unknown" end checking_for (m, headers), fmt do if scalar_ptr_type?(type, member, prelude, &b) if try_static_assert("sizeof(*#{var}) == 1", prelude) return "string" end ptr = "*" elsif scalar_type?(type, member, prelude, &b) unless member and !typeof or try_static_assert("(#{type})-1 < 0", prelude) unsigned = "unsigned" end ptr = "" else next end type = UNIVERSAL_INTS.find do |t| pre = prelude unless member pre += [["#{unsigned} #{t} #{ptr}#{var};\n", "extern #{unsigned} #{t} #{ptr}*#{func};\n"]] end try_static_assert("sizeof(#{ptr}#{val}) == sizeof(#{unsigned} #{t})", pre) end type or next [unsigned, type, ptr].join(" ").strip end end |
#winsep(s) ⇒ Object
Converts forward slashes to backslashes. Aimed at MS Windows.
Internal use only.
1854 1855 1856 |
# File 'lib/mkmf.rb', line 1854 def winsep(s) s.tr('/', '\\') end |
#with_cflags(flags) ⇒ Object
626 627 628 629 630 631 632 |
# File 'lib/mkmf.rb', line 626 def with_cflags(flags) cflags = $CFLAGS $CFLAGS = flags ret = yield ensure $CFLAGS = cflags unless ret end |
#with_config(config, default = nil) ⇒ Object
Tests for the presence of a --with-
config or --without-
config option. Returns true
if the with option is given, false
if the without option is given, and the default value otherwise.
This can be useful for adding custom definitions, such as debug information.
Example:
if with_config("debug")
$defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
end
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 |
# File 'lib/mkmf.rb', line 1608 def with_config(config, default=nil) config = config.sub(/^--with[-_]/, '') val = arg_config("--with-"+config) do if arg_config("--without-"+config) false elsif block_given? yield(config, default) else break default end end case val when "yes" true when "no" false else val end end |
#with_cppflags(flags) ⇒ Object
604 605 606 607 608 609 610 |
# File 'lib/mkmf.rb', line 604 def with_cppflags(flags) cppflags = $CPPFLAGS $CPPFLAGS = flags ret = yield ensure $CPPFLAGS = cppflags unless ret end |
#with_destdir(dir) ⇒ Object
:stopdoc:
1845 1846 1847 1848 |
# File 'lib/mkmf.rb', line 1845 def with_destdir(dir) dir = dir.sub($dest_prefix_pattern, '') /\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir end |
#with_ldflags(flags) ⇒ Object
648 649 650 651 652 653 654 |
# File 'lib/mkmf.rb', line 648 def with_ldflags(flags) ldflags = $LDFLAGS $LDFLAGS = flags ret = yield ensure $LDFLAGS = ldflags unless ret end |
#with_werror(opt, opts = nil) ⇒ Object
517 518 519 520 521 522 523 524 525 526 |
# File 'lib/mkmf.rb', line 517 def with_werror(opt, opts = nil) if opts if opts[:werror] and config_string("WERRORFLAG") {|flag| opt = opt ? "#{opt} #{flag}" : flag} (opts = opts.dup).delete(:werror) end yield(opt, opts) else yield(opt) end end |
#xpopen(command, *mode, &block) ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/mkmf.rb', line 400 def xpopen command, *mode, &block Logging::open do case mode[0] when nil, /^r/ puts "#{command} |" else puts "| #{command}" end IO.popen(libpath_env, command, *mode, &block) end end |
#xsystem(command, opts = nil) ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/mkmf.rb', line 377 def xsystem command, opts = nil varpat = /\$\((\w+)\)|\$\{(\w+)\}/ if varpat =~ command vars = Hash.new {|h, k| h[k] = ENV[k]} command = command.dup nil while command.gsub!(varpat) {vars[$1||$2]} end Logging::open do puts command.quote if opts and opts[:werror] result = nil Logging.postpone do |log| output = IO.popen(libpath_env, command, &:read) result = ($?.success? and File.zero?(log.path)) output end result else system(libpath_env, command) end end end |