1 file 'runtime/platform.conf' => %w[Rakefile rakelib/platform.rake rakelib/struct_generator.rb] do |task|
2 addrinfo = StructGenerator.new
3 addrinfo.include 'sys/socket.h'
4 addrinfo.include 'netdb.h'
5 addrinfo.name 'struct addrinfo'
6 addrinfo.field :ai_flags, :int
7 addrinfo.field :ai_family, :int
8 addrinfo.field :ai_socktype, :int
9 addrinfo.field :ai_protocol, :int
10 addrinfo.field :ai_addrlen, :int
11 addrinfo.field :ai_addr, :pointer
12 addrinfo.field :ai_canonname, :string
13 addrinfo.field :ai_next, :pointer
16 dirent = StructGenerator.new
17 dirent.include "sys/types.h"
18 dirent.include "dirent.h"
19 dirent.name 'struct dirent'
20 dirent.field :d_ino, :ino_t
21 dirent.field :d_reclen, :ushort
22 dirent.field :d_name, :char_array
25 timeval = StructGenerator.new
26 timeval.include "sys/time.h"
27 timeval.name 'struct timeval'
28 timeval.field :tv_sec, :time_t
29 timeval.field :tv_usec, :suseconds_t
32 sockaddr_in = StructGenerator.new
33 sockaddr_in.include "netinet/in.h"
34 sockaddr_in.include "fcntl.h"
35 sockaddr_in.include "sys/socket.h"
36 sockaddr_in.include "sys/stat.h"
37 sockaddr_in.name 'struct sockaddr_in'
38 sockaddr_in.field :sin_family, :sa_family_t
39 sockaddr_in.field :sin_port, :ushort
40 sockaddr_in.field :sin_addr
41 sockaddr_in.field :sin_zero, :char_array
44 sockaddr_un = StructGenerator.new
45 sockaddr_un.include "sys/un.h"
46 sockaddr_un.name 'struct sockaddr_un'
47 sockaddr_un.field :sun_family, :sa_family_t
48 sockaddr_un.field :sun_path, :char_array
51 servent = StructGenerator.new
52 servent.include "netdb.h"
53 servent.name 'struct servent'
54 servent.field :s_name, :pointer
55 servent.field :s_aliases, :pointer
56 servent.field :s_port, :int
57 servent.field :s_proto, :pointer
60 stat = StructGenerator.new
61 stat.include "sys/types.h"
62 stat.include "sys/stat.h"
63 stat.name 'struct stat'
64 stat.field :st_dev, :dev_t
65 stat.field :st_ino, :ino_t
66 stat.field :st_mode, :mode_t
67 stat.field :st_nlink, :nlink_t
68 stat.field :st_uid, :uid_t
69 stat.field :st_gid, :gid_t
70 stat.field :st_rdev, :dev_t
71 stat.field :st_size, :off_t
72 stat.field :st_blksize
74 stat.field :st_atime, :time_t
75 stat.field :st_mtime, :time_t
76 stat.field :st_ctime, :time_t
79 rlimit = StructGenerator.new
80 rlimit.include "sys/types.h"
81 rlimit.include "sys/time.h"
82 rlimit.include "sys/resource.h"
83 rlimit.name 'struct rlimit'
84 rlimit.field :rlim_cur, :rlim_t
85 rlimit.field :rlim_max, :rlim_t
88 evp_md = StructGenerator.new
89 evp_md.include "openssl/ossl_typ.h"
90 evp_md.include "openssl/evp.h"
91 evp_md.name 'struct env_md_st'
92 evp_md.field :type, :int
93 evp_md.field :pkey_type, :int
94 evp_md.field :md_size, :int
95 evp_md.field :flags, :ulong
96 evp_md.field :init, :pointer
97 evp_md.field :update, :pointer
98 evp_md.field :final, :pointer
99 evp_md.field :copy, :pointer
100 evp_md.field :cleanup, :pointer
101 evp_md.field :sign, :pointer
102 evp_md.field :verify, :pointer
103 # int required_pkey[5] goes here but we don't care
104 evp_md.field :block_size, :int
105 evp_md.field :ctx_size, :int
108 evp_md_ctx = StructGenerator.new
109 evp_md_ctx.include "openssl/ossl_typ.h"
110 evp_md_ctx.include "openssl/evp.h"
111 evp_md_ctx.name 'struct env_md_ctx_st'
112 evp_md_ctx.field :digest, :pointer
113 evp_md_ctx.field :engine, :pointer
114 evp_md_ctx.field :flags, :ulong
115 evp_md_ctx.field :md_data, :pointer
118 # FIXME these constants don't have standard names.
119 # LOCK_SH == Linux, O_SHLOCK on Bsd/Darwin, etc.
120 # Binary doesn't exist at all in many non-Unix variants.
121 # This should come out of something like config.h
122 fixme_constants = %w{
130 syslog_constants = %w{
209 fcntl_constants = %w{
235 socket_constants = %w[
299 INADDR_ALLHOSTS_GROUP
303 INADDR_MAX_LOCAL_GROUP
331 IP_DEFAULT_MULTICAST_LOOP
332 IP_DEFAULT_MULTICAST_TTL
459 SO_SECURITY_AUTHENTICATION
460 SO_SECURITY_ENCRYPTION_NETWORK
461 SO_SECURITY_ENCRYPTION_TRANSPORT
475 process_constants = %w{
494 long_process_constants = %w{
500 # The constants come from MRI's signal.c. This means that some of them might
502 signal_constants = %w{
549 cg = ConstGenerator.new
552 cg.include "sys/types.h"
553 cg.include "sys/socket.h"
555 cg.include "sys/stat.h"
556 cg.include "sys/resource.h"
557 cg.include "netinet/tcp.h"
558 cg.include "signal.h"
559 cg.include "netinet/in.h"
560 cg.include "syslog.h"
562 file_constants.each { |c| cg.const c }
563 io_constants.each { |c| cg.const c }
564 fcntl_constants.each {|c| cg.const c }
565 socket_constants.each { |c| cg.const c }
566 process_constants.each { |c| cg.const c }
567 long_process_constants.each { |c|
568 cg.const c, "%llu", "(unsigned long long)"
570 signal_constants.each { |c| cg.const c }
571 fcntl_constants.each { |c| cg.const c }
572 syslog_constants.each { |c| cg.const c }
576 puts "Generating #{task.name}..."
578 File.open task.name, "w" do |f|
579 f.puts addrinfo.generate_config('addrinfo')
580 f.puts dirent.generate_config('dirent')
581 f.puts timeval.generate_config('timeval')
582 f.puts sockaddr_in.generate_config('sockaddr_in')
583 f.puts sockaddr_un.generate_config('sockaddr_un') if sockaddr_un.found?
584 f.puts servent.generate_config('servent')
585 f.puts stat.generate_config('stat')
586 f.puts rlimit.generate_config('rlimit')
587 f.puts evp_md.generate_config('evp_md')
588 f.puts evp_md_ctx.generate_config('evp_md_ctx')
590 file_constants.each do | name |
591 const = cg.constants[name]
592 f.puts "rbx.platform.file.#{name} = #{const.converted_value}"
595 io_constants.each do |name|
596 const = cg.constants[name]
597 f.puts "rbx.platform.io.#{name} = #{const.converted_value}"
600 fcntl_constants.each do |name|
601 const = cg.constants[name]
602 next if const.converted_value.nil?
603 f.puts "rbx.platform.fcntl.#{name} = #{const.converted_value}"
606 socket_constants.each do |name|
607 const = cg.constants[name]
608 next if const.converted_value.nil?
609 f.puts "rbx.platform.socket.#{name} = #{const.converted_value}"
612 (process_constants + long_process_constants).each do |name|
613 const = cg.constants[name]
614 next if const.converted_value.nil?
615 f.puts "rbx.platform.process.#{name} = #{const.converted_value}"
618 signal_constants.each do |name|
619 const = cg.constants[name]
620 next if const.converted_value.nil?
621 f.puts "rbx.platform.signal.#{name} = #{const.converted_value}"
624 syslog_constants.each do |name|
625 const = cg.constants[name]
626 f.puts "rbx.platform.syslog.#{name} = #{const.converted_value}"
629 f.puts TypesGenerator.generate