Browse files

Bring in extensions and platform stuff from shotgun

  • Loading branch information...
1 parent d8b6f6b commit 93747ebb37750a5566d7bff64a1f657e63a8bfe2 @drbrain drbrain committed Oct 1, 2008
Showing with 569 additions and 644 deletions.
  1. +2 −27 Rakefile
  2. +43 −28 rakelib/extensions.rake
  3. +524 −589 rakelib/platform.rake
View
29 Rakefile
@@ -10,9 +10,6 @@ RUBINIUS_BASE = File.expand_path(File.dirname(__FILE__))
# require 'tsort'
# require 'rakelib/rubinius'
-# require 'rakelib/struct_generator'
-# require 'rakelib/const_generator'
-# require 'rakelib/types_generator'
task :default => %w[build vm:test spec:compiler]
@@ -88,14 +85,6 @@ task :run_ruby => %w[kernel:build vm/vm] # HACK argument + dependency is broken
# end
# end
-# Rake::StructGeneratorTask.new do |t|
-# t.dest = "lib/etc.rb"
-# end
-
-# Rake::StructGeneratorTask.new do |t|
-# t.dest = 'lib/zlib.rb'
-# end
-
# AllPreCompiled = Core.output + Bootstrap.output + PlatformFiles.output
# AllPreCompiled << "runtime/loader.rbc"
@@ -104,10 +93,8 @@ task :build => %w[
vm
kernel:build
lib/rbconfig.rb
+ extensions
]
-# build:rbc
-# lib/etc.rb
-# extensions
namespace :build do
@@ -197,24 +184,12 @@ desc "Recompile all ruby system files"
task :rebuild => %w[clean build]
desc 'Remove rubinius build files'
-task :clean => %w[vm:clean kernel:clean clean:crap]
+task :clean => %w[vm:clean kernel:clean clean:crap extension:clean]
desc 'Remove rubinius build files and external library build files'
task :distclean => %w[vm:distclean]
namespace :clean do
-# desc "Cleans all compiled extension files (lib/ext)"
-# task :extensions do
-# Dir["lib/ext/**/*#{$dlext}"].each do |f|
-# rm_f f, :verbose => $verbose
-# end
-# end
-
-# desc "Cleans up generated files"
-# task :generated do
-# rm_f Dir["shotgun/lib/grammar.c"], :verbose => $verbose
-# end
-
desc "Cleans up editor files and other misc crap"
task :crap do
files = (Dir["*~"] + Dir["**/*~"]).uniq
View
71 rakelib/extensions.rake
@@ -1,91 +1,106 @@
+require 'lib/ffi/generator_task'
+
desc "Build extensions from lib/ext"
task :extensions => %w[
- build:shotgun
- build:rbc
-
- extension:digest_rmd160
- extension:digest_md5
- extension:digest_sha1
- extension:digest_sha2
-
- extension:zlib
- extension:readline
+ vm/vm
+ kernel:build
+
+ lib/etc.rb
+ lib/fcntl.rb
+ lib/openssl/digest.rb
+ lib/syslog.rb
+ lib/zlib.rb
]
+# extension:digest_rmd160
+# extension:digest_md5
+# extension:digest_sha1
+# extension:digest_sha2
+#
+# extension:readline
namespace :extension do
+ desc "Cleans all compiled extension files (lib/ext)"
+ task :clean do
+ Dir["lib/ext/**/*#{$dlext}"].each do |f|
+ rm_f f, :verbose => $verbose
+ end
+ end
+
+ FFI::Generator::Task.new %w[
+ lib/etc.rb
+ lib/fcntl.rb
+ lib/openssl/digest.rb
+ lib/syslog.rb
+ lib/zlib.rb
+ ]
+
task :digest_md5 => "lib/ext/digest/md5/md5.#{$dlext}"
file "lib/ext/digest/md5/md5.#{$dlext}" => FileList[
+ 'shotgun/lib/subtend/*',
'lib/ext/digest/md5/build.rb',
'lib/ext/digest/md5/*.c',
'lib/ext/digest/md5/*.h',
'lib/ext/digest/defs.h',
] do
- compile 'lib/ext/digest/md5'
+ compile_ruby 'lib/ext/digest/md5'
end
task :digest_rmd160 => "lib/ext/digest/rmd160/rmd160.#{$dlext}"
file "lib/ext/digest/rmd160/rmd160.#{$dlext}" => FileList[
+ 'shotgun/lib/subtend/*',
'lib/ext/digest/rmd160/build.rb',
'lib/ext/digest/rmd160/*.c',
'lib/ext/digest/rmd160/*.h',
'lib/ext/digest/defs.h',
] do
- compile 'lib/ext/digest/rmd160'
+ compile_ruby 'lib/ext/digest/rmd160'
end
task :digest_sha1 => "lib/ext/digest/sha1/sha1.#{$dlext}"
file "lib/ext/digest/sha1/sha1.#{$dlext}" => FileList[
+ 'shotgun/lib/subtend/*',
'lib/ext/digest/sha1/build.rb',
'lib/ext/digest/sha1/*.c',
'lib/ext/digest/sha1/*.h',
'lib/ext/digest/defs.h',
] do
- compile 'lib/ext/digest/sha1'
+ compile_ruby 'lib/ext/digest/sha1'
end
task :digest_sha2 => "lib/ext/digest/sha2/sha2.#{$dlext}"
file "lib/ext/digest/sha2/sha2.#{$dlext}" => FileList[
+ 'shotgun/lib/subtend/*',
'lib/ext/digest/sha2/build.rb',
'lib/ext/digest/sha2/*.c',
'lib/ext/digest/sha2/*.h',
'lib/ext/digest/defs.h',
] do
- compile 'lib/ext/digest/sha2'
+ compile_ruby 'lib/ext/digest/sha2'
end
task :mongrel => "lib/ext/mongrel/http11.#{$dlext}"
file "lib/ext/mongrel/http11.#{$dlext}" => FileList[
- 'shotgun/lib/subtend/ruby.h',
+ 'shotgun/lib/subtend/*',
'lib/ext/mongrel/build.rb',
'lib/ext/mongrel/*.c',
'lib/ext/mongrel/*.h',
] do
- compile "lib/ext/mongrel"
- end
-
- task :zlib => %W[lib/ext/zlib/zlib.#{$dlext} lib/zlib.rb]
-
- file "lib/ext/zlib/zlib.#{$dlext}" => FileList[
- 'shotgun/lib/subtend/ruby.h',
- 'lib/ext/zlib/build.rb',
- 'lib/ext/zlib/*.c'
- ] do
- compile "lib/ext/zlib"
+ compile_ruby "lib/ext/mongrel"
end
task :readline => %W[lib/ext/readline/readline.#{$dlext} lib/readline.rb]
file "lib/ext/readline/readline.#{$dlext}" => FileList[
- 'shotgun/lib/subtend/ruby.h',
+ 'shotgun/lib/subtend/*',
'lib/ext/readline/build.rb',
'lib/ext/readline/*.c'
] do
- compile "lib/ext/readline"
+ compile_ruby "lib/ext/readline"
end
end
View
1,113 rakelib/platform.rake
@@ -1,611 +1,546 @@
-require 'rakelib/const_generator'
-require 'rakelib/struct_generator'
-require 'rakelib/types_generator'
-
-file 'runtime/platform.conf' => %w[
- Rakefile
- rakelib/platform.rake
- rakelib/struct_generator.rb
- rakelib/types_generator.rb
- rakelib/const_generator.rb
- ] do |task|
- addrinfo = StructGenerator.new
- addrinfo.include 'sys/socket.h'
- addrinfo.include 'netdb.h'
- addrinfo.name 'struct addrinfo'
- addrinfo.field :ai_flags, :int
- addrinfo.field :ai_family, :int
- addrinfo.field :ai_socktype, :int
- addrinfo.field :ai_protocol, :int
- addrinfo.field :ai_addrlen, :int
- addrinfo.field :ai_addr, :pointer
- addrinfo.field :ai_canonname, :string
- addrinfo.field :ai_next, :pointer
- addrinfo.calculate
-
- dirent = StructGenerator.new
- dirent.include "sys/types.h"
- dirent.include "dirent.h"
- dirent.name 'struct dirent'
- dirent.field :d_ino, :ino_t
- dirent.field :d_reclen, :ushort
- dirent.field :d_name, :char_array
- dirent.calculate
-
- timeval = StructGenerator.new
- timeval.include "sys/time.h"
- timeval.name 'struct timeval'
- timeval.field :tv_sec, :time_t
- timeval.field :tv_usec, :suseconds_t
- timeval.calculate
-
- sockaddr_in = StructGenerator.new
- sockaddr_in.include "netinet/in.h"
- sockaddr_in.include "fcntl.h"
- sockaddr_in.include "sys/socket.h"
- sockaddr_in.include "sys/stat.h"
- sockaddr_in.name 'struct sockaddr_in'
- sockaddr_in.field :sin_family, :sa_family_t
- sockaddr_in.field :sin_port, :ushort
- sockaddr_in.field :sin_addr
- sockaddr_in.field :sin_zero, :char_array
- sockaddr_in.calculate
-
- sockaddr_un = StructGenerator.new
- sockaddr_un.include "sys/un.h"
- sockaddr_un.name 'struct sockaddr_un'
- sockaddr_un.field :sun_family, :sa_family_t
- sockaddr_un.field :sun_path, :char_array
- sockaddr_un.calculate
-
- servent = StructGenerator.new
- servent.include "netdb.h"
- servent.name 'struct servent'
- servent.field :s_name, :pointer
- servent.field :s_aliases, :pointer
- servent.field :s_port, :int
- servent.field :s_proto, :pointer
- servent.calculate
-
- stat = StructGenerator.new
- stat.include "sys/types.h"
- stat.include "sys/stat.h"
- stat.name 'struct stat'
- stat.field :st_dev, :dev_t
- stat.field :st_ino, :ino_t
- stat.field :st_mode, :mode_t
- stat.field :st_nlink, :nlink_t
- stat.field :st_uid, :uid_t
- stat.field :st_gid, :gid_t
- stat.field :st_rdev, :dev_t
- stat.field :st_size, :off_t
- stat.field :st_blksize
- stat.field :st_blocks
- stat.field :st_atime, :time_t
- stat.field :st_mtime, :time_t
- stat.field :st_ctime, :time_t
- stat.calculate
-
- rlimit = StructGenerator.new
- rlimit.include "sys/types.h"
- rlimit.include "sys/time.h"
- rlimit.include "sys/resource.h"
- rlimit.name 'struct rlimit'
- rlimit.field :rlim_cur, :rlim_t
- rlimit.field :rlim_max, :rlim_t
- rlimit.calculate
-
- # FIXME these constants don't have standard names.
- # LOCK_SH == Linux, O_SHLOCK on Bsd/Darwin, etc.
- # Binary doesn't exist at all in many non-Unix variants.
- # This should come out of something like config.h
+require 'lib/ffi/struct_generator'
+require 'lib/ffi/const_generator'
+require 'lib/ffi/types_generator'
+
+deps = %w[Rakefile] + Dir['lib/ffi/*rb']
+
+file 'runtime/platform.conf' => deps do |task|
+ addrinfo = FFI::StructGenerator.new 'addrinfo' do |s|
+ s.include 'sys/socket.h'
+ s.include 'netdb.h'
+ s.name 'struct addrinfo'
+ s.field :ai_flags, :int
+ s.field :ai_family, :int
+ s.field :ai_socktype, :int
+ s.field :ai_protocol, :int
+ s.field :ai_addrlen, :int
+ s.field :ai_addr, :pointer
+ s.field :ai_canonname, :string
+ s.field :ai_next, :pointer
+ end
+
+ dirent = FFI::StructGenerator.new 'dirent' do |s|
+ s.include "sys/types.h"
+ s.include "dirent.h"
+ s.name 'struct dirent'
+ s.field :d_ino, :ino_t
+ s.field :d_reclen, :ushort
+ s.field :d_name, :char_array
+ end
+
+ timeval = FFI::StructGenerator.new 'timeval' do |s|
+ s.include "sys/time.h"
+ s.name 'struct timeval'
+ s.field :tv_sec, :time_t
+ s.field :tv_usec, :suseconds_t
+ end
+
+ sockaddr_in = FFI::StructGenerator.new 'sockaddr_in' do |s|
+ s.include "netinet/in.h"
+ s.include "fcntl.h"
+ s.include "sys/socket.h"
+ s.include "sys/stat.h"
+ s.name 'struct sockaddr_in'
+ s.field :sin_family, :sa_family_t
+ s.field :sin_port, :ushort
+ s.field :sin_addr
+ s.field :sin_zero, :char_array
+ end
+
+ sockaddr_un = FFI::StructGenerator.new 'sockaddr_un' do |s|
+ s.include "sys/un.h"
+ s.name 'struct sockaddr_un'
+ s.field :sun_family, :sa_family_t
+ s.field :sun_path, :char_array
+ end
+
+ servent = FFI::StructGenerator.new 'servent' do |s|
+ s.include "netdb.h"
+ s.name 'struct servent'
+ s.field :s_name, :pointer
+ s.field :s_aliases, :pointer
+ s.field :s_port, :int
+ s.field :s_proto, :pointer
+ end
+
+ stat = FFI::StructGenerator.new 'stat' do |s|
+ s.include "sys/types.h"
+ s.include "sys/stat.h"
+ s.name 'struct stat'
+ s.field :st_dev, :dev_t
+ s.field :st_ino, :ino_t
+ s.field :st_mode, :mode_t
+ s.field :st_nlink, :nlink_t
+ s.field :st_uid, :uid_t
+ s.field :st_gid, :gid_t
+ s.field :st_rdev, :dev_t
+ s.field :st_size, :off_t
+ s.field :st_blksize
+ s.field :st_blocks
+ s.field :st_atime, :time_t
+ s.field :st_mtime, :time_t
+ s.field :st_ctime, :time_t
+ end
+
+ rlimit = FFI::StructGenerator.new 'rlimit' do |s|
+ s.include "sys/types.h"
+ s.include "sys/time.h"
+ s.include "sys/resource.h"
+ s.name 'struct rlimit'
+ s.field :rlim_cur, :rlim_t
+ s.field :rlim_max, :rlim_t
+ end
+
+ # FIXME these constants don't have standard names. LOCK_SH == Linux,
+ # O_SHLOCK on Bsd/Darwin, etc. Binary doesn't exist at all in many non-Unix
+ # variants. This should come out of something like config.h
+
fixme_constants = %w{
LOCK_SH
LOCK_EX
LOCK_NB
LOCK_UN
BINARY
}
-
- syslog_constants = %w{
- LOG_PID
- LOG_EMERG
- LOG_ALERT
- LOG_ERR
- LOG_CRIT
- LOG_WARNING
- LOG_NOTICE
- LOG_INFO
- LOG_DEBUG
- LOG_CONS
- LOG_ODELAY
- LOG_NODELAY
- LOG_NOWAIT
- LOG_PERROR
- LOG_AUTH
- LOG_AUTHPRIV
- LOG_CONSOLE
- LOG_CRON
- LOG_DAEMON
- LOG_FTP
- LOG_KERN
- LOG_LPR
- LOG_MAIL
- LOG_NEWS
- LOG_NTP
- LOG_SECURITY
- LOG_SYSLOG
- LOG_USER
- LOG_UUCP
- LOG_LOCAL0
- LOG_LOCAL1
- LOG_LOCAL2
- LOG_LOCAL3
- LOG_LOCAL4
- LOG_LOCAL5
- LOG_LOCAL6
- LOG_LOCAL7
- }
- file_constants = %w{
- O_RDONLY
- O_WRONLY
- O_RDWR
- O_CREAT
- O_EXCL
- O_NOCTTY
- O_TRUNC
- O_APPEND
- O_NONBLOCK
- O_SYNC
- S_IRUSR
- S_IWUSR
- S_IXUSR
- S_IRGRP
- S_IWGRP
- S_IXGRP
- S_IROTH
- S_IWOTH
- S_IXOTH
- S_IFMT
- S_IFIFO
- S_IFCHR
- S_IFDIR
- S_IFBLK
- S_IFREG
- S_IFLNK
- S_IFSOCK
- S_IFWHT
- S_ISUID
- S_ISGID
- }
+ file_cg = FFI::ConstGenerator.new 'rbx.platform.file' do |cg|
+ cg.include 'stdio.h'
+ cg.include 'fcntl.h'
+ cg.include 'sys/stat.h'
+
+ file_constants = %w[
+ O_RDONLY
+ O_WRONLY
+ O_RDWR
+ O_CREAT
+ O_EXCL
+ O_NOCTTY
+ O_TRUNC
+ O_APPEND
+ O_NONBLOCK
+ O_SYNC
+ S_IRUSR
+ S_IWUSR
+ S_IXUSR
+ S_IRGRP
+ S_IWGRP
+ S_IXGRP
+ S_IROTH
+ S_IWOTH
+ S_IXOTH
+ S_IFMT
+ S_IFIFO
+ S_IFCHR
+ S_IFDIR
+ S_IFBLK
+ S_IFREG
+ S_IFLNK
+ S_IFSOCK
+ S_IFWHT
+ S_ISUID
+ S_ISGID
+ ]
+
+ file_constants.each { |c| cg.const c }
+ end
- io_constants = %w{
- SEEK_SET
- SEEK_CUR
- SEEK_END
- }
+ io_cg = FFI::ConstGenerator.new 'rbx.platform.io' do |cg|
+ cg.include 'stdio.h'
- fcntl_constants = %w{
- F_DUPFD
- F_GETFD
- F_GETLK
- F_SETFD
- F_GETFL
- F_SETFL
- F_SETLK
- F_SETLKW
- FD_CLOEXEC
- F_RDLCK
- F_UNLCK
- F_WRLCK
- O_CREAT
- O_EXCL
- O_NOCTTY
- O_TRUNC
- O_APPEND
- O_NONBLOCK
- O_NDELAY
- O_RDONLY
- O_RDWR
- O_WRONLY
- O_ACCMODE
- }
+ io_constants = %w[
+ SEEK_SET
+ SEEK_CUR
+ SEEK_END
+ ]
- socket_constants = %w[
- AF_APPLETALK
- AF_ATM
- AF_AX25
- AF_CCITT
- AF_CHAOS
- AF_CNT
- AF_COIP
- AF_DATAKIT
- AF_DEC
- AF_DLI
- AF_E164
- AF_ECMA
- AF_HYLINK
- AF_IMPLINK
- AF_INET
- AF_INET6
- AF_IPX
- AF_ISDN
- AF_ISO
- AF_LAT
- AF_LINK
- AF_LOCAL
- AF_MAX
- AF_NATM
- AF_NDRV
- AF_NETBIOS
- AF_NETGRAPH
- AF_NS
- AF_OSI
- AF_PPP
- AF_PUP
- AF_ROUTE
- AF_SIP
- AF_SNA
- AF_SYSTEM
- AF_UNIX
- AF_UNSPEC
-
- AI_ADDRCONFIG
- AI_ALL
- AI_CANONNAME
- AI_DEFAULT
- AI_MASK
- AI_NUMERICHOST
- AI_PASSIVE
- AI_V4MAPPED
- AI_V4MAPPED_CFG
-
- EAI_ADDRFAMILY
- EAI_AGAIN
- EAI_BADFLAGS
- EAI_BADHINTS
- EAI_FAIL
- EAI_FAMILY
- EAI_MAX
- EAI_MEMORY
- EAI_NODATA
- EAI_NONAME
- EAI_PROTOCOL
- EAI_SERVICE
- EAI_SOCKTYPE
- EAI_SYSTEM
-
- INADDR_ALLHOSTS_GROUP
- INADDR_ANY
- INADDR_BROADCAST
- INADDR_LOOPBACK
- INADDR_MAX_LOCAL_GROUP
- INADDR_NONE
- INADDR_UNSPEC_GROUP
-
- IPPORT_RESERVED
- IPPORT_USERRESERVED
-
- IPPROTO_BIP
- IPPROTO_EGP
- IPPROTO_EON
- IPPROTO_GGP
- IPPROTO_HELLO
- IPPROTO_ICMP
- IPPROTO_IDP
- IPPROTO_IGMP
- IPPROTO_IP
- IPPROTO_MAX
- IPPROTO_ND
- IPPROTO_PUP
- IPPROTO_RAW
- IPPROTO_TCP
- IPPROTO_TP
- IPPROTO_UDP
- IPPROTO_XTP
-
- IPX_TYPE
-
- IP_ADD_MEMBERSHIP
- IP_DEFAULT_MULTICAST_LOOP
- IP_DEFAULT_MULTICAST_TTL
- IP_DROP_MEMBERSHIP
- IP_HDRINCL
- IP_MAX_MEMBERSHIPS
- IP_MULTICAST_IF
- IP_MULTICAST_LOOP
- IP_MULTICAST_TTL
- IP_OPTIONS
- IP_RECVDSTADDR
- IP_RECVOPTS
- IP_RECVRETOPTS
- IP_RETOPTS
- IP_TOS
- IP_TTL
-
- MSG_COMPAT
- MSG_CTRUNC
- MSG_DONTROUTE
- MSG_DONTWAIT
- MSG_EOF
- MSG_EOR
- MSG_FLUSH
- MSG_HAVEMORE
- MSG_HOLD
- MSG_OOB
- MSG_PEEK
- MSG_RCVMORE
- MSG_SEND
- MSG_TRUNC
- MSG_WAITALL
-
- NI_DGRAM
- NI_MAXHOST
- NI_MAXSERV
- NI_NAMEREQD
- NI_NOFQDN
- NI_NUMERICHOST
- NI_NUMERICSERV
-
- PF_APPLETALK
- PF_AX25
- PF_CCITT
- PF_CHAOS
- PF_CNT
- PF_COIP
- PF_DATAKIT
- PF_DLI
- PF_ECMA
- PF_HYLINK
- PF_IMPLINK
- PF_INET
- PF_INET6
- PF_IPX
- PF_ISDN
- PF_ISO
- PF_KEY
- PF_LAT
- PF_LINK
- PF_LOCAL
- PF_MAX
- PF_NATM
- PF_NDRV
- PF_NETBIOS
- PF_NETGRAPH
- PF_NS
- PF_OSI
- PF_PIP
- PF_PPP
- PF_PUP
- PF_ROUTE
- PF_RTIP
- PF_SIP
- PF_SNA
- PF_SYSTEM
- PF_UNIX
- PF_UNSPEC
- PF_XTP
-
- SHUT_RD
- SHUT_RDWR
- SHUT_WR
-
- SOCK_DGRAM
- SOCK_PACKET
- SOCK_RAW
- SOCK_RDM
- SOCK_SEQPACKET
- SOCK_STREAM
-
- SOL_ATALK
- SOL_AX25
- SOL_IP
- SOL_IPX
- SOL_SOCKET
- SOL_TCP
- SOL_UDP
-
- SOPRI_BACKGROUND
- SOPRI_INTERACTIVE
- SOPRI_NORMAL
-
- SO_ACCEPTCONN
- SO_ACCEPTFILTER
- SO_ATTACH_FILTER
- SO_BINDTODEVICE
- SO_BROADCAST
- SO_DEBUG
- SO_DETACH_FILTER
- SO_DONTROUTE
- SO_DONTTRUNC
- SO_ERROR
- SO_KEEPALIVE
- SO_LINGER
- SO_NKE
- SO_NOSIGPIPE
- SO_NO_CHECK
- SO_NREAD
- SO_OOBINLINE
- SO_PASSCRED
- SO_PEERCRED
- SO_PEERNAME
- SO_PRIORITY
- SO_RCVBUF
- SO_RCVLOWAT
- SO_RCVTIMEO
- SO_REUSEADDR
- SO_REUSEPORT
- SO_SECURITY_AUTHENTICATION
- SO_SECURITY_ENCRYPTION_NETWORK
- SO_SECURITY_ENCRYPTION_TRANSPORT
- SO_SNDBUF
- SO_SNDLOWAT
- SO_SNDTIMEO
- SO_TIMESTAMP
- SO_TYPE
- SO_USELOOPBACK
- SO_WANTMORE
- SO_WANTOOBFLAG
-
- TCP_MAXSEG
- TCP_NODELAY
- ]
-
- process_constants = %w{
- WNOHANG
- WUNTRACED
- PRIO_PROCESS
- PRIO_PGRP
- PRIO_USER
- RLIMIT_CPU
- RLIMIT_FSIZE
- RLIMIT_DATA
- RLIMIT_STACK
- RLIMIT_CORE
- RLIMIT_RSS
- RLIMIT_NPROC
- RLIMIT_NOFILE
- RLIMIT_MEMLOCK
- RLIMIT_AS
- RLIMIT_SBSIZE
- }
+ io_constants.each { |c| cg.const c }
+ end
- long_process_constants = %w{
- RLIM_INFINITY
- RLIM_SAVED_MAX
- RLIM_SAVED_CUR
- }
+ # Only constants needed by core are added here
+ fcntl_cg = FFI::ConstGenerator.new 'rbx.platform.fcntl' do |cg|
+ cg.include 'fcntl.h'
+
+ fcntl_constants = %w[
+ F_GETFL
+ F_SETFL
+ O_ACCMODE
+ ]
+
+ fcntl_constants.each { |c| cg.const c }
+ end
+
+ socket_cg = FFI::ConstGenerator.new 'rbx.platform.socket' do |cg|
+ cg.include 'sys/types.h'
+ cg.include 'sys/socket.h'
+ cg.include 'netdb.h'
+ cg.include 'netinet/tcp.h'
+ cg.include 'netinet/in.h'
+
+ socket_constants = %w[
+ AF_APPLETALK
+ AF_ATM
+ AF_AX25
+ AF_CCITT
+ AF_CHAOS
+ AF_CNT
+ AF_COIP
+ AF_DATAKIT
+ AF_DEC
+ AF_DLI
+ AF_E164
+ AF_ECMA
+ AF_HYLINK
+ AF_IMPLINK
+ AF_INET
+ AF_INET6
+ AF_IPX
+ AF_ISDN
+ AF_ISO
+ AF_LAT
+ AF_LINK
+ AF_LOCAL
+ AF_MAX
+ AF_NATM
+ AF_NDRV
+ AF_NETBIOS
+ AF_NETGRAPH
+ AF_NS
+ AF_OSI
+ AF_PPP
+ AF_PUP
+ AF_ROUTE
+ AF_SIP
+ AF_SNA
+ AF_SYSTEM
+ AF_UNIX
+ AF_UNSPEC
+
+ AI_ADDRCONFIG
+ AI_ALL
+ AI_CANONNAME
+ AI_DEFAULT
+ AI_MASK
+ AI_NUMERICHOST
+ AI_PASSIVE
+ AI_V4MAPPED
+ AI_V4MAPPED_CFG
+
+ EAI_ADDRFAMILY
+ EAI_AGAIN
+ EAI_BADFLAGS
+ EAI_BADHINTS
+ EAI_FAIL
+ EAI_FAMILY
+ EAI_MAX
+ EAI_MEMORY
+ EAI_NODATA
+ EAI_NONAME
+ EAI_PROTOCOL
+ EAI_SERVICE
+ EAI_SOCKTYPE
+ EAI_SYSTEM
+
+ INADDR_ALLHOSTS_GROUP
+ INADDR_ANY
+ INADDR_BROADCAST
+ INADDR_LOOPBACK
+ INADDR_MAX_LOCAL_GROUP
+ INADDR_NONE
+ INADDR_UNSPEC_GROUP
+
+ IPPORT_RESERVED
+ IPPORT_USERRESERVED
+
+ IPPROTO_BIP
+ IPPROTO_EGP
+ IPPROTO_EON
+ IPPROTO_GGP
+ IPPROTO_HELLO
+ IPPROTO_ICMP
+ IPPROTO_IDP
+ IPPROTO_IGMP
+ IPPROTO_IP
+ IPPROTO_MAX
+ IPPROTO_ND
+ IPPROTO_PUP
+ IPPROTO_RAW
+ IPPROTO_TCP
+ IPPROTO_TP
+ IPPROTO_UDP
+ IPPROTO_XTP
+
+ IPX_TYPE
+
+ IP_ADD_MEMBERSHIP
+ IP_DEFAULT_MULTICAST_LOOP
+ IP_DEFAULT_MULTICAST_TTL
+ IP_DROP_MEMBERSHIP
+ IP_HDRINCL
+ IP_MAX_MEMBERSHIPS
+ IP_MULTICAST_IF
+ IP_MULTICAST_LOOP
+ IP_MULTICAST_TTL
+ IP_OPTIONS
+ IP_RECVDSTADDR
+ IP_RECVOPTS
+ IP_RECVRETOPTS
+ IP_RETOPTS
+ IP_TOS
+ IP_TTL
+
+ MSG_COMPAT
+ MSG_CTRUNC
+ MSG_DONTROUTE
+ MSG_DONTWAIT
+ MSG_EOF
+ MSG_EOR
+ MSG_FLUSH
+ MSG_HAVEMORE
+ MSG_HOLD
+ MSG_OOB
+ MSG_PEEK
+ MSG_RCVMORE
+ MSG_SEND
+ MSG_TRUNC
+ MSG_WAITALL
+
+ NI_DGRAM
+ NI_MAXHOST
+ NI_MAXSERV
+ NI_NAMEREQD
+ NI_NOFQDN
+ NI_NUMERICHOST
+ NI_NUMERICSERV
+
+ PF_APPLETALK
+ PF_AX25
+ PF_CCITT
+ PF_CHAOS
+ PF_CNT
+ PF_COIP
+ PF_DATAKIT
+ PF_DLI
+ PF_ECMA
+ PF_HYLINK
+ PF_IMPLINK
+ PF_INET
+ PF_INET6
+ PF_IPX
+ PF_ISDN
+ PF_ISO
+ PF_KEY
+ PF_LAT
+ PF_LINK
+ PF_LOCAL
+ PF_MAX
+ PF_NATM
+ PF_NDRV
+ PF_NETBIOS
+ PF_NETGRAPH
+ PF_NS
+ PF_OSI
+ PF_PIP
+ PF_PPP
+ PF_PUP
+ PF_ROUTE
+ PF_RTIP
+ PF_SIP
+ PF_SNA
+ PF_SYSTEM
+ PF_UNIX
+ PF_UNSPEC
+ PF_XTP
+
+ SHUT_RD
+ SHUT_RDWR
+ SHUT_WR
+
+ SOCK_DGRAM
+ SOCK_PACKET
+ SOCK_RAW
+ SOCK_RDM
+ SOCK_SEQPACKET
+ SOCK_STREAM
+
+ SOL_ATALK
+ SOL_AX25
+ SOL_IP
+ SOL_IPX
+ SOL_SOCKET
+ SOL_TCP
+ SOL_UDP
+
+ SOPRI_BACKGROUND
+ SOPRI_INTERACTIVE
+ SOPRI_NORMAL
+
+ SO_ACCEPTCONN
+ SO_ACCEPTFILTER
+ SO_ATTACH_FILTER
+ SO_BINDTODEVICE
+ SO_BROADCAST
+ SO_DEBUG
+ SO_DETACH_FILTER
+ SO_DONTROUTE
+ SO_DONTTRUNC
+ SO_ERROR
+ SO_KEEPALIVE
+ SO_LINGER
+ SO_NKE
+ SO_NOSIGPIPE
+ SO_NO_CHECK
+ SO_NREAD
+ SO_OOBINLINE
+ SO_PASSCRED
+ SO_PEERCRED
+ SO_PEERNAME
+ SO_PRIORITY
+ SO_RCVBUF
+ SO_RCVLOWAT
+ SO_RCVTIMEO
+ SO_REUSEADDR
+ SO_REUSEPORT
+ SO_SECURITY_AUTHENTICATION
+ SO_SECURITY_ENCRYPTION_NETWORK
+ SO_SECURITY_ENCRYPTION_TRANSPORT
+ SO_SNDBUF
+ SO_SNDLOWAT
+ SO_SNDTIMEO
+ SO_TIMESTAMP
+ SO_TYPE
+ SO_USELOOPBACK
+ SO_WANTMORE
+ SO_WANTOOBFLAG
+
+ TCP_MAXSEG
+ TCP_NODELAY
+ ]
+
+ socket_constants.each { |c| cg.const c }
+ end
+
+ process_cg = FFI::ConstGenerator.new 'rbx.platform.process' do |cg|
+ cg.include 'sys/wait.h'
+ cg.include 'sys/resource.h'
+
+ process_constants = %w{
+ WNOHANG
+ WUNTRACED
+ PRIO_PROCESS
+ PRIO_PGRP
+ PRIO_USER
+ RLIMIT_CPU
+ RLIMIT_FSIZE
+ RLIMIT_DATA
+ RLIMIT_STACK
+ RLIMIT_CORE
+ RLIMIT_RSS
+ RLIMIT_NPROC
+ RLIMIT_NOFILE
+ RLIMIT_MEMLOCK
+ RLIMIT_AS
+ RLIMIT_SBSIZE
+ }
+
+ process_constants.each { |c| cg.const c }
+
+ long_process_constants = %w[
+ RLIM_INFINITY
+ RLIM_SAVED_MAX
+ RLIM_SAVED_CUR
+ ]
+
+ long_process_constants.each { |c|
+ cg.const c, "%llu", "(unsigned long long)"
+ }
+ end
# The constants come from MRI's signal.c. This means that some of them might
# be missing.
- signal_constants = %w{
- SIGHUP
- SIGINT
- SIGQUIT
- SIGILL
- SIGTRAP
- SIGIOT
- SIGABRT
- SIGEMT
- SIGFPE
- SIGKILL
- SIGBUS
- SIGSEGV
- SIGSYS
- SIGPIPE
- SIGALRM
- SIGTERM
- SIGURG
- SIGSTOP
- SIGTSTP
- SIGCONT
- SIGCHLD
- SIGCLD
- SIGCHLD
- SIGTTIN
- SIGTTOU
- SIGIO
- SIGXCPU
- SIGXFSZ
- SIGVTALRM
- SIGPROF
- SIGWINCH
- SIGUSR1
- SIGUSR2
- SIGLOST
- SIGMSG
- SIGPWR
- SIGPOLL
- SIGDANGER
- SIGMIGRATE
- SIGPRE
- SIGGRANT
- SIGRETRACT
- SIGSOUND
- SIGINFO
- }
- cg = ConstGenerator.new
- cg.include "stdio.h"
- cg.include "fcntl.h"
- cg.include "sys/types.h"
- cg.include "sys/socket.h"
- cg.include "netdb.h"
- cg.include "sys/stat.h"
- cg.include "sys/resource.h"
- cg.include "netinet/tcp.h"
- cg.include "signal.h"
- cg.include "netinet/in.h"
- cg.include "syslog.h"
-
- file_constants.each { |c| cg.const c }
- io_constants.each { |c| cg.const c }
- fcntl_constants.each {|c| cg.const c }
- socket_constants.each { |c| cg.const c }
- process_constants.each { |c| cg.const c }
- long_process_constants.each { |c|
- cg.const c, "%llu", "(unsigned long long)"
- }
- signal_constants.each { |c| cg.const c }
- fcntl_constants.each { |c| cg.const c }
- syslog_constants.each { |c| cg.const c }
+ signal_cg = FFI::ConstGenerator.new 'rbx.platform.signal' do |cg|
+ cg.include 'signal.h'
+ cg.include 'sys/signal.h'
+
+ signal_constants = %w{
+ SIGHUP
+ SIGINT
+ SIGQUIT
+ SIGILL
+ SIGTRAP
+ SIGIOT
+ SIGABRT
+ SIGEMT
+ SIGFPE
+ SIGKILL
+ SIGBUS
+ SIGSEGV
+ SIGSYS
+ SIGPIPE
+ SIGALRM
+ SIGTERM
+ SIGURG
+ SIGSTOP
+ SIGTSTP
+ SIGCONT
+ SIGCHLD
+ SIGCLD
+ SIGCHLD
+ SIGTTIN
+ SIGTTOU
+ SIGIO
+ SIGXCPU
+ SIGXFSZ
+ SIGVTALRM
+ SIGPROF
+ SIGWINCH
+ SIGUSR1
+ SIGUSR2
+ SIGLOST
+ SIGMSG
+ SIGPWR
+ SIGPOLL
+ SIGDANGER
+ SIGMIGRATE
+ SIGPRE
+ SIGGRANT
+ SIGRETRACT
+ SIGSOUND
+ SIGINFO
+ }
+
+ signal_constants.each { |c| cg.const c }
+ end
- cg.calculate
+ zlib_cg = FFI::ConstGenerator.new 'rbx.platform.zlib' do |cg|
+ cg.include 'zlib.h'
- puts "Generating #{task.name}..."
+ zlib_constants = %w[ZLIB_VERSION]
+
+ zlib_constants.each { |c| cg.const c, "%s", "(char *)" }
+ end
+
+ puts "Generating #{task.name}..." if $verbose
File.open task.name, "w" do |f|
- f.puts addrinfo.generate_config('addrinfo')
- f.puts dirent.generate_config('dirent')
- f.puts timeval.generate_config('timeval')
- f.puts sockaddr_in.generate_config('sockaddr_in')
- f.puts sockaddr_un.generate_config('sockaddr_un') if sockaddr_un.found?
- f.puts servent.generate_config('servent')
- f.puts stat.generate_config('stat')
- f.puts rlimit.generate_config('rlimit')
-
- file_constants.each do | name |
- const = cg.constants[name]
- f.puts "rbx.platform.file.#{name} = #{const.converted_value}"
- end
-
- io_constants.each do |name|
- const = cg.constants[name]
- f.puts "rbx.platform.io.#{name} = #{const.converted_value}"
- end
-
- fcntl_constants.each do |name|
- const = cg.constants[name]
- next if const.converted_value.nil?
- f.puts "rbx.platform.fcntl.#{name} = #{const.converted_value}"
- end
-
- socket_constants.each do |name|
- const = cg.constants[name]
- next if const.converted_value.nil?
- f.puts "rbx.platform.socket.#{name} = #{const.converted_value}"
- end
-
- (process_constants + long_process_constants).each do |name|
- const = cg.constants[name]
- next if const.converted_value.nil?
- f.puts "rbx.platform.process.#{name} = #{const.converted_value}"
- end
-
- signal_constants.each do |name|
- const = cg.constants[name]
- next if const.converted_value.nil?
- f.puts "rbx.platform.signal.#{name} = #{const.converted_value}"
- end
-
- syslog_constants.each do |name|
- const = cg.constants[name]
- f.puts "rbx.platform.syslog.#{name} = #{const.converted_value}"
- end
-
- f.puts TypesGenerator.generate
-
+ addrinfo.dump_config f
+ dirent.dump_config f
+ timeval.dump_config f
+ sockaddr_in.dump_config f
+ sockaddr_un.dump_config f if sockaddr_un.found?
+ servent.dump_config f
+ stat.dump_config f
+ rlimit.dump_config f
+
+ file_cg.dump_constants f
+ io_cg.dump_constants f
+ fcntl_cg.dump_constants f
+ socket_cg.dump_constants f
+ process_cg.dump_constants f
+ signal_cg.dump_constants f
+ zlib_cg.dump_constants f
+
+ f.puts FFI::TypesGenerator.generate
end
-end
+end

0 comments on commit 93747eb

Please sign in to comment.