summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 06:08:41 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 06:08:41 +0000
commit212e90ce3a056aaf5915a11c061a80e893f8e2fd (patch)
treeae90f1dc6bb7168c5dc80c8f8b1a7f217b852bf0 /ext/socket
parent0d2e8c14bb187e5f5a117f6e37a6b4ab34e540e1 (diff)
* ext/socket/mkconstants.rb: add -o option.
* ext/socket/depend: use mkconstants.rb with -o option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/depend2
-rw-r--r--ext/socket/mkconstants.rb30
2 files changed, 30 insertions, 2 deletions
diff --git a/ext/socket/depend b/ext/socket/depend
index 29bc2f3be38..0a9b8cacefd 100644
--- a/ext/socket/depend
+++ b/ext/socket/depend
@@ -6,4 +6,4 @@ getaddrinfo.o: getaddrinfo.c $(arch_hdrdir)/ruby/config.h addrinfo.h sockport.h
constants.h: $(srcdir)/mkconstants.rb
@echo "generating constants.h"
- @$(RUBY) $(srcdir)/mkconstants.rb > $@
+ @$(RUBY) $(srcdir)/mkconstants.rb -o $@
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index 589e3b2bb36..948eda8be1b 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -1,4 +1,24 @@
-$out ||= $stdout
+require 'optparse'
+
+opt = OptionParser.new
+
+opt.def_option('-h', 'help') {
+ puts opt
+ exit 0
+}
+
+opt_o = nil
+opt.def_option('-o FILE', 'specify output file') {|filename|
+ opt_o = filename
+}
+
+$out = ''
+def $out.puts(str="")
+ str += "\n" if /\n\z/ !~ str
+ self << str
+end
+
+opt.parse!
# workaround for NetBSD, OpenBSD and etc.
$out.puts("#define pseudo_AF_FTIP pseudo_AF_RTIP")
@@ -23,6 +43,14 @@ DATA.each_line do |s|
end
end
+if opt_o
+ File.open(opt_o, 'w') {|f|
+ f << $out
+ }
+else
+ $stdout << $out
+end
+
__END__
SOCK_STREAM