From: nobu@... Date: 2006-05-21T17:30:12+09:00 Subject: [ruby-dev:28660] Re: create header (Re: Re: ossl_cipher.c:124: warning: control reaches end of non-void function) なかだです。 At Sun, 21 May 2006 01:52:01 +0900, Tanaka Akira wrote in [ruby-dev:28659]: > どうやら、 > > gcc -fPIC -g -O2 -DHAVE_CONFIG_H -I../../.././ext/digest/md5/.. -I. -I../../.. -I../../../. -I../../.././ext/digest/md5 -DRUBY_EXTCONF_H=\"extconf.h\" -c md5init.c > gcc -fPIC -g -O2 -DHAVE_CONFIG_H -I../../.././ext/digest/md5/.. -I. -I../../.. -I../../../. -I../../.././ext/digest/md5 -DRUBY_EXTCONF_H=\"extconf.h\" -c md5ossl.c > > というようコンパイルして、openssl を使おうと判断して md5ossl.c > を使ったが、md5init.c をコンパイルした時に > -I../../.././ext/digest/md5/.. が -I. より先にあるので > digest/md5/extconf.h でなく digest/extconf.h を読んだあげく > にそこには HAVE_OPENSSL_MD5_H がないので問題が起こる、という > ことのようです。うぅむ。 手元では再現しないと思ったら、ソースとは別のディレクトリでコン パイルしているため、ext/digestのソースディレクトリにはextconf.h が作られないからでした。 作り直したパッチです。 Index: ruby.h =================================================================== RCS file: /cvs/ruby/src/ruby/ruby.h,v retrieving revision 1.134 diff -p -U2 -r1.134 ruby.h --- ruby.h 2 Mar 2006 05:22:30 -0000 1.134 +++ ruby.h 11 May 2006 14:46:59 -0000 @@ -23,4 +23,7 @@ extern "C" { #include "config.h" +#ifdef RUBY_EXTCONF_H +#include RUBY_EXTCONF_H +#endif #define NORETURN_STYLE_NEW 1 Index: ext/extmk.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/extmk.rb,v retrieving revision 1.88 diff -p -U2 -r1.88 extmk.rb --- ext/extmk.rb 17 May 2006 15:41:31 -0000 1.88 +++ ext/extmk.rb 19 May 2006 15:39:06 -0000 @@ -125,4 +125,5 @@ def extmake(target) begin if (!(ok &&= extract_makefile(makefile)) || + !$extconf_h || !File.exist?($extconf_h) || !(t = modified?(makefile, MTIMES)) || %W"#{$srcdir}/makefile.rb #{$srcdir}/extconf.rb #{$srcdir}/depend".any? {|f| modified?(f, [t])}) Index: ext/dbm/extconf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/dbm/extconf.rb,v retrieving revision 1.16 diff -p -U2 -r1.16 extconf.rb --- ext/dbm/extconf.rb 24 Jul 2003 07:41:36 -0000 1.16 +++ ext/dbm/extconf.rb 21 May 2006 00:54:24 -0000 @@ -34,5 +34,5 @@ def db_check(db) for hdr in $dbm_conf_headers.fetch(db, ["ndbm.h"]) if have_header(hdr.dup) and have_type("DBM", hdr.dup, hsearch) - $CFLAGS += " " + hsearch + '-DDBM_HDR="<'+hdr+'>"' + $defs << hsearch << '-DDBM_HDR="<'+hdr+'>"' return true end Index: ext/digest/md5/extconf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/digest/md5/extconf.rb,v retrieving revision 1.6 diff -p -U2 -r1.6 extconf.rb --- ext/digest/md5/extconf.rb 21 Jan 2004 09:05:25 -0000 1.6 +++ ext/digest/md5/extconf.rb 21 May 2006 00:41:53 -0000 @@ -4,5 +4,6 @@ require "mkmf" -$CFLAGS << " -DHAVE_CONFIG_H -I#{File.dirname(__FILE__)}/.." +$defs << "-DHAVE_CONFIG_H" +$INCFLAGS << " -I$(srcdir)/.." $objs = [ "md5init.#{$OBJEXT}" ] Index: ext/digest/rmd160/extconf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/digest/rmd160/extconf.rb,v retrieving revision 1.6 diff -p -U2 -r1.6 extconf.rb --- ext/digest/rmd160/extconf.rb 21 Jan 2004 07:01:31 -0000 1.6 +++ ext/digest/rmd160/extconf.rb 21 May 2006 00:42:20 -0000 @@ -4,5 +4,6 @@ require "mkmf" -$CFLAGS << " -DHAVE_CONFIG_H -I#{File.dirname(__FILE__)}/.." +$defs << "-DNDEBUG" << "-DHAVE_CONFIG_H" +$INCFLAGS << " -I$(srcdir)/.." $objs = [ "rmd160init.#{$OBJEXT}" ] Index: ext/digest/sha1/extconf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/digest/sha1/extconf.rb,v retrieving revision 1.6 diff -p -U2 -r1.6 extconf.rb --- ext/digest/sha1/extconf.rb 7 Jan 2004 22:06:38 -0000 1.6 +++ ext/digest/sha1/extconf.rb 21 May 2006 00:42:46 -0000 @@ -4,5 +4,6 @@ require "mkmf" -$CFLAGS << " -DHAVE_CONFIG_H -I#{File.dirname(__FILE__)}/.." +$defs << "-DHAVE_CONFIG_H" +$INCFLAGS << " -I$(srcdir)/.." $objs = [ "sha1init.#{$OBJEXT}" ] Index: ext/digest/sha2/extconf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/digest/sha2/extconf.rb,v retrieving revision 1.10 diff -p -U2 -r1.10 extconf.rb --- ext/digest/sha2/extconf.rb 6 Sep 2005 23:22:39 -0000 1.10 +++ ext/digest/sha2/extconf.rb 21 May 2006 00:42:59 -0000 @@ -4,5 +4,6 @@ require "mkmf" -$CPPFLAGS << " -DHAVE_CONFIG_H -I#{File.dirname(__FILE__)}/.." +$defs << "-DHAVE_CONFIG_H" +$INCFLAGS << " -I$(srcdir)/.." $objs = [ Index: ext/readline/readline.c =================================================================== RCS file: /cvs/ruby/src/ruby/ext/readline/readline.c,v retrieving revision 1.27 diff -p -U2 -r1.27 readline.c --- ext/readline/readline.c 24 Sep 2005 00:17:43 -0000 1.27 +++ ext/readline/readline.c 13 May 2006 13:09:08 -0000 @@ -2,4 +2,6 @@ Copyright (C) 1997-2001 Shugo Maeda */ +#include "ruby.h" + #include #include @@ -16,5 +18,4 @@ #endif -#include "ruby.h" #include "rubyio.h" #include "rubysig.h" Index: ext/socket/extconf.rb =================================================================== RCS file: /cvs/ruby/src/ruby/ext/socket/extconf.rb,v retrieving revision 1.45 diff -p -U2 -r1.45 extconf.rb --- ext/socket/extconf.rb 21 Oct 2005 06:46:41 -0000 1.45 +++ ext/socket/extconf.rb 21 Oct 2005 15:43:45 -0000 @@ -27,5 +27,5 @@ if /solaris/ =~ RUBY_PLATFORM and !try_c end -$ipv6 = false +ipv6 = false default_ipv6 = /cygwin/ !~ RUBY_PLATFORM if enable_config("ipv6", default_ipv6) @@ -38,61 +38,43 @@ main() } EOF - $CPPFLAGS+=" -DENABLE_IPV6" - $ipv6 = true + $defs << "-DENABLE_IPV6" << "-DINET6" + ipv6 = true end end -$ipv6type = nil -$ipv6lib = nil -$ipv6libdir = nil -$ipv6trylibc = nil -if $ipv6 - if have_macro("IPV6_INRIA_VERSION", "netinet/in.h") - $ipv6type = "inria" - $CPPFLAGS="-DINET6 "+$CPPFLAGS - elsif have_macro("__KAME__", "netinet/in.h") - $ipv6type = "kame" - $ipv6lib="inet6" - $ipv6libdir="/usr/local/v6/lib" - $ipv6trylibc=true - $CPPFLAGS="-DINET6 "+$CPPFLAGS - elsif File.directory? "/usr/inet6" - $ipv6type = "linux" - $ipv6lib="inet6" - $ipv6libdir="/usr/inet6/lib" - $CPPFLAGS="-DINET6 -I/usr/inet6/include "+$CPPFLAGS - elsif have_macro("_TOSHIBA_INET6", "sys/param.h") - $ipv6type = "toshiba" - $ipv6lib="inet6" - $ipv6libdir="/usr/local/v6/lib" - $CPPFLAGS="-DINET6 "+$CPPFLAGS - elsif have_macro("__V6D__", "/usr/local/v6/include/sys/v6config.h") - $ipv6type = "v6d" - $ipv6lib="v6" - $ipv6libdir="/usr/local/v6/lib" - $CFLAGS="-I/usr/local/v6/include "+$CFLAGS - $CPPFLAGS="-DINET6 "+$CPPFLAGS - elsif have_macro("_ZETA_MINAMI_INET6", "sys/param.h") - $ipv6type = "zeta" - $ipv6lib="inet6" - $ipv6libdir="/usr/local/v6/lib" - $CPPFLAGS="-DINET6 "+$CPPFLAGS - else - $ipv6lib=with_config("ipv6-lib", nil) - $ipv6libdir=with_config("ipv6-libdir", nil) - $CPPFLAGS="-DINET6 "+$CPPFLAGS - end - - if $ipv6lib - if File.directory? $ipv6libdir and File.exist? "#{$ipv6libdir}/lib#{$ipv6lib}.a" - $LOCAL_LIBS = " -L#$ipv6libdir -l#$ipv6lib" - elsif !$ipv6trylibc - abort < $hdrdir.quote)) + RbConfig::expand("$(CC) -c #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} #{CONFTEST_C}", + CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)) end def cpp_command(outfile, opt="") - RbConfig::expand("$(CPP) #$INCFLAGS -I$(hdrdir) " \ - "#$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", - CONFIG.merge('hdrdir' => $hdrdir.quote)) + RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", + CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote)) end @@ -829,18 +827,25 @@ end def create_header(header = "extconf.h") message "creating %s\n", header - if $defs.length > 0 + unless $defs.empty? sym = header.tr("a-z./\055", "A-Z___") - open(header, "w") do |hfile| - hfile.print "#ifndef #{sym}\n#define #{sym}\n" - for line in $defs - case line - when /^-D([^=]+)(?:=(.*))?/ - hfile.print "#define #$1 #{$2 || 1}\n" - when /^-U(.*)/ - hfile.print "#undef #$1\n" - end + hdr = ["#ifndef #{sym}\n#define #{sym}\n"] + for line in $defs + case line + when /^-D([^=]+)(?:=(.*))?/ + hdr << "#define #$1 #{$2 ? Shellwords.shellwords($2)[0] : 1}\n" + when /^-U(.*)/ + hdr << "#undef #$1\n" + end + end + hdr << "#endif\n" + hdr = hdr.join + open(header, "w+") do |hfile| + unless hfile.read == hdr + hfile.rewind + hfile.truncate(0) + hfile.write(hdr) end - hfile.print "#endif\n" end + $extconf_h = header end end @@ -952,4 +957,5 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARA sep = "" end + extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"#{$extconf_h}\\\" " : "" mk << %{ CC = #{CONFIG['CC']} @@ -961,5 +967,6 @@ LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC CFLAGS = #{CONFIG['CCDLFLAGS'] unless $static} #$CFLAGS #$ARCH_FLAG -CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) #{$defs.join(" ")} #{$CPPFLAGS} +INCFLAGS = -I. #$INCFLAGS +CPPFLAGS = #{extconf_h}#{$CPPFLAGS} CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']} DLDFLAGS = #$LDFLAGS #$DLDFLAGS #$ARCH_FLAG @@ -1064,4 +1071,8 @@ def create_makefile(target, srcprefix = end + unless $extconf_h + create_header + end + libpath = libpathflag(libpath) @@ -1260,4 +1271,5 @@ site-install-rb: install-rb end headers << $config_h if $config_h + headers << $extconf_h if $extconf_h mfile.print "$(OBJS): ", headers.join(' '), "\n" end @@ -1273,9 +1285,10 @@ def init_mkmf(config = CONFIG) $enable_shared = config['ENABLE_SHARED'] == 'yes' $defs = [] + $extconf_h = nil $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup $ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup $LDFLAGS = (with_config("ldflags") || "").dup - $INCFLAGS = "-I$(topdir)" + $INCFLAGS = "-I$(topdir) -I$(hdrdir) -I$(srcdir)" $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup $LIBEXT = config['LIBEXT'].dup @@ -1368,8 +1381,8 @@ COMMON_LIBS = config_string('COMMON_LIBS 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 $<' +COMPILE_C = config_string('COMPILE_C') || '$(CC) -c $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $<' +COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) -c $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $<' TRY_LINK = config_string('TRY_LINK') || - "$(CC) #{OUTFLAG}conftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS) " \ + "$(CC) #{OUTFLAG}conftest $(INCFLAGS) $(CPPFLAGS) " \ "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)" LINK_SO = config_string('LINK_SO') || @@ -1390,5 +1403,5 @@ clean: distclean: clean - @-$(RM) Makefile extconf.h conftest.* mkmf.log + @-$(RM) Makefile #{$extconf_h} conftest.* mkmf.log @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep}) -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦