[ruby-opengl-devel] Patch for building on windows
Ronald Pijnacker
pijnacker at dse.nl
Thu Apr 5 07:35:51 EDT 2007
Hi all,
I've attached the patch for making ruby-opengl build on windows.
This includes the patch Jan sent out last week that provides the extra
typedefs.
For now, I've chosen to export the Init_* functions using the dllexport
keyword, that keeps me from having to support -def: in mkrf.
Please have a look and let me know what you think. Or better yet...
commit in svn :-)
The patch requires a patched version of mkrf, which I send to the mkrf
mailing list.
Groeten,
Ronald.
-------------- next part --------------
Index: ext/gl/gl.c
===================================================================
--- ext/gl/gl.c (revision 171)
+++ ext/gl/gl.c (working copy)
@@ -25,6 +25,12 @@
#include "../common/rbogl.h"
#include "../common/gl-enums.h"
+#ifdef WIN32
+#define DLLEXPORT __declspec(dllexport)
+#else
+#define DLLEXPORT
+#endif
+
static VALUE module;
void gl_init_enums(VALUE);
@@ -49,7 +55,7 @@
return Qtrue;
}
-void Init_gl()
+DLLEXPORT void Init_gl()
{
module = rb_define_module("Gl");
gl_init_enums(module);
Index: ext/gl/mkrf_conf.rb
===================================================================
--- ext/gl/mkrf_conf.rb (revision 171)
+++ ext/gl/mkrf_conf.rb (working copy)
@@ -15,12 +15,16 @@
require 'rubygems'
require 'mkrf'
+require 'rbconfig'
Mkrf::Generator.new( 'gl' ) do |g|
- g.objects << '../common/rbogl.o'
+ g.objects << "../common/rbogl.#{Config::CONFIG['OBJEXT']}"
case RUBY_PLATFORM
when /darwin/
g.ldshared << ' -framework OpenGL'
+ when /mswin32/
+ g.cflags << ' -DWIN32'
+ g.include_library( 'opengl32.lib', 'glVertex3d')
else
g.include_library( 'GL', 'glVertex3d')
end
Index: ext/glu/mkrf_conf.rb
===================================================================
--- ext/glu/mkrf_conf.rb (revision 171)
+++ ext/glu/mkrf_conf.rb (working copy)
@@ -17,10 +17,14 @@
require 'mkrf'
Mkrf::Generator.new( 'glu' ) do |g|
- g.objects << '../common/rbogl.o'
+ g.objects << "../common/rbogl.#{Config::CONFIG['OBJEXT']}"
case RUBY_PLATFORM
when /darwin/
g.ldshared << ' -framework OpenGL'
+ when /mswin32/
+ g.cflags << ' -DWIN32'
+ g.include_library( 'opengl32.lib', 'glVertex3d')
+ g.include_library( 'glu32.lib', 'gluLookAt')
else
g.include_library( 'GLU', 'gluLookAt' )
g.include_library( 'GL', 'glVertex3d')
Index: ext/glu/glu.c
===================================================================
--- ext/glu/glu.c (revision 171)
+++ ext/glu/glu.c (working copy)
@@ -33,8 +33,10 @@
#include "../common/rbogl.h"
#ifdef WIN32
+#define DLLEXPORT __declspec(dllexport)
typedef void (CALLBACK*(VOIDFUNC))();
#else
+#define DLLEXPORT
typedef void (*VOIDFUNC)();
#endif
@@ -1448,8 +1450,7 @@
#define GLU_ERROR 100103
#endif
-
-void Init_glu()
+DLLEXPORT void Init_glu()
{
callId = rb_intern("call");
refId = rb_intern("[]");
Index: ext/common/Rakefile
===================================================================
--- ext/common/Rakefile (revision 171)
+++ ext/common/Rakefile (working copy)
@@ -20,20 +20,24 @@
INCLUDES = "-I#{Config::CONFIG['archdir']}"
CFLAGS = "#{Config::CONFIG['CFLAGS']}"
+CC = "#{Config::CONFIG['CC']}"
+O = "#{Config::CONFIG['OBJEXT']}"
case RUBY_PLATFORM
when /darwin/
INCLUDES << ' -F/System/Library/Frameworks'
+when /mswin32/
+ CFLAGS << ' -DWIN32'
end
-CLEAN.include( '*.o' )
+CLEAN.include( '*.#{O}' )
SRC = FileList[ '*.c' ]
-OBJ = SRC.ext( 'o' )
+OBJ = SRC.ext( O )
task :default => OBJ
file 'rbogl.c' => [ 'rbogl.h' ]
-rule '.o' => '.c' do |t|
- sh "cc -c #{CFLAGS} #{INCLUDES} -o #{t.name} #{t.source}"
+rule ".#{O}" => '.c' do |t|
+ sh "#{CC} -c #{CFLAGS} #{INCLUDES} #{t.source}"
end
Index: ext/common/rbogl.c
===================================================================
--- ext/common/rbogl.c (revision 171)
+++ ext/common/rbogl.c (working copy)
@@ -293,13 +293,3 @@
return func_ptr;
}
-
-/* -------------------------------------------------------------------- */
-void Init_gl(void);
-
-void Init_opengl()
-{
- Init_gl(); /* is this needed ? */
- /* RxINC: InitializeGLU(); */
-}
-
Index: ext/common/gl-enums.h
===================================================================
--- ext/common/gl-enums.h (revision 171)
+++ ext/common/gl-enums.h (working copy)
@@ -1,4 +1,42 @@
-/* This file was genereated on Sun Feb 11 01:24:24 +0100 2007 */
+/* GL types - define if system GLheaders are not recent */
+
+/* GL base */
+#ifndef GL_VERSION_1_5
+typedef ptrdiff_t GLintptr;
+typedef ptrdiff_t GLsizeiptr;
+#endif
+
+#ifndef GL_VERSION_2_0
+typedef char GLchar;
+#endif
+
+/* new GL types introduced by ARB extensions */
+#ifndef GL_ARB_half_float_pixel
+typedef unsigned short GLhalfARB;
+#endif
+
+#ifndef GL_ARB_shader_objects
+typedef char GLcharARB;
+typedef unsigned int GLhandleARB;
+#endif
+
+#ifndef GL_ARB_vertex_buffer_object
+typedef ptrdiff_t GLintptrARB;
+typedef ptrdiff_t GLsizeiptrARB;
+#endif
+
+/* new GL types introduced by other extensions */
+#ifndef GL_NV_half_float
+typedef unsigned short GLhalfNV;
+#endif
+
+/* List of GL enumerators */
+
+/* The code below was genereated on Sun Feb 11 01:24:24 +0100 2007
+ source: http://www.opengl.org/registry/api/enum.spec
+ http://www.opengl.org/registry/api/enumext.spec
+*/
+
#ifndef _GLENUMS_H_
#define _GLENUMS_H_
Index: ext/glut/mkrf_conf.rb
===================================================================
--- ext/glut/mkrf_conf.rb (revision 171)
+++ ext/glut/mkrf_conf.rb (working copy)
@@ -20,6 +20,11 @@
case RUBY_PLATFORM
when /darwin/
g.ldshared << ' -framework GLUT -framework OpenGL -framework Cocoa'
+ when /mswin32/
+ g.cflags << ' -DWIN32'
+ g.include_library( 'glut32.lib', 'glutSolidTeapot' )
+ g.include_library( 'glu32.lib', 'gluLookAt' )
+ g.include_library( 'opengl32.lib', 'glVertex3d' )
else
g.include_library( 'glut', 'glutSolidTeapot' )
g.include_library( 'GLU', 'gluLookAt' )
Index: ext/glut/glut.c
===================================================================
--- ext/glut/glut.c (revision 171)
+++ ext/glut/glut.c (working copy)
@@ -35,6 +35,12 @@
#include <ruby.h>
+#ifdef WIN32
+#define DLLEXPORT __declspec(dllexport)
+#else
+#define DLLEXPORT
+#endif
+
static int callId; /* 'call' method id */
/* callback define macro */
@@ -1484,7 +1490,7 @@
static VALUE module;
-void Init_glut()
+DLLEXPORT void Init_glut()
{
module = rb_define_module("Glut");
Index: Rakefile
===================================================================
--- Rakefile (revision 171)
+++ Rakefile (working copy)
@@ -39,7 +39,8 @@
NICE_HTML_DOCS = WEBSITE_MKDN.ext('html')
CLEAN.include("ext/gl*/Rakefile", "ext/*/mkrf.log", "ext/*/*.so",
- "ext/**/*.bundle", "lib/*.so", "lib/*.bundle", "ext/*/*.o",
+ "ext/**/*.bundle", "lib/*.so", "lib/*.bundle", "ext/*/*.o{,bj}",
+ "ext/*/*.lib", "ext/*/*.exp", "ext/*/*.pdb",
"pkg")
CLOBBER.include("*.plain", "doc/*.plain", "doc/*.snip", "*.html",
"doc/*.html", "website/*.html")
@@ -125,7 +126,7 @@
# Define the files that will go into the gem
gem_files = FileList["{lib,ext,doc,examples,test}/**/*"]
-gem_files = gem_files.exclude("**/*.so", "**/*.o", "ext/**/*.log", "ext/gl*/Rakefile")
+gem_files = gem_files.exclude("**/*.so", "**/*.o{,bj}", "ext/**/*.log", "ext/gl*/Rakefile")
spec = Gem::Specification.new do |s|
s.name = "ruby-opengl"
More information about the ruby-opengl-devel
mailing list