Small usability improvement for main generator interface: --help message, auto-fetch.
[cl-glfw.git] / generators / make-opengl-bindings.rb
blobd4e910695ccccd77492aa5ff2ad39fb8299d3e55
1 #!/usr/bin/env ruby
3 require 'fileutils'
5 BASE=File::dirname($0)+'/..'
6 #Dir::chdir(BASE+'/work')
8 def check_ok
9   unless $?.success?
10     puts "Process returned #{$?.inspect}"
11     exit
12   end
13 end
15 def fetch_specs
16   puts `wget -P #{BASE}/src -N http://www.opengl.org/registry/api/gl.tm http://www.opengl.org/registry/api/gl.spec  http://www.opengl.org/registry/api/enum.spec  http://www.opengl.org/registry/api/enumext.spec`
17   check_ok
18 end
20 while arg=ARGV.shift
21   case arg
22   when '--fetch-specs'
23     fetch_specs
24   when '--help'
25     puts "Re-generates OpenGL bindings from specifications."
26     puts "Use --fetch-specs to force re-download of spec files from http://www.opengl.org/registry"
27     exit
28   end
29 end
31 fetch_specs unless File::exists?("#{BASE}/src/gl.tm") and
32     File::exists?("#{BASE}/src/gl.spec") and
33     File::exists?("#{BASE}/src/enum.spec") and
34     File::exists?("#{BASE}/src/enumext.spec")
36 puts `ruby #{BASE}/generators/sexpize-gl-spec.rb`
37 check_ok
38 puts `sbcl --load #{BASE}/generators/make-bindings-from-spec.lisp --eval "(sb-ext:quit)"`
39 check_ok
41 open("#{BASE}/src/opengl-template.lisp") do |tf|
42   open("#{BASE}/lib/opengl.lisp","w") do |of|
43     puts "ok, writing #{BASE}/lib/opengl.lisp"
44     of.write(tf.read.sub('@EXPORTS@',open("#{BASE}/src/opengl-exports.lisp"){|i|i.read}).sub("@BODY@",open("#{BASE}/src/opengl-body.lisp"){|i|i.read}).sub("@TYPE_MAPS@",open("#{BASE}/src/opengl-type-maps.lisp"){|i|i.read}))
45   end
46 end