1.  I tried your patch out.  It did not apply cleanly at first, so I had
to do a little editing.  I am attaching an 'svn diff' that represents
the changes actually made.


This patch worked for me on Darwin in the sense that it detected OpenGL
where previously the step class had not:

Determining if your platform supports OpenGL............yes, MacOSX_GLUT 5.

2.  Last night I wrote some tests for this step class along the lines of
those found for other configuration step classes, e.g., testing for
settings of results, testing for verbose output, etc.  However, since
the internals of this class are still under development, I have
temporarily disabled some of those tests so that we don't get spurious
failures.

3.  May I suggest that this code:

        $has_glut = _handle_glut($conf, $self->_evaluate_cc_run($test,
$verbose));

... be rewritten like this:

        my $rv = $self->_evaluate_cc_run($test, $verbose);
        $has_glut = _handle_glut($conf, $rv);

This would be more consistent with the way other config step classes are
coded in that it gives the method call its own statement.

Thank you very much.



Index: runtime/parrot/library/OpenGL.pir
===================================================================
--- runtime/parrot/library/OpenGL.pir   (revision 27056)
+++ runtime/parrot/library/OpenGL.pir   (working copy)
@@ -56,16 +56,19 @@
 
     libnames = new 'ResizableStringArray'
     push libnames, 'libGL'
+    push libnames, '/System/Library/Frameworks/OpenGL.framework/OpenGL'
     libgl = load_lib_with_fallbacks('GL', libnames)
     set_global 'libgl', libgl
 
     libnames = new 'ResizableStringArray'
     push libnames, 'libGLU'
+    push libnames, '/System/Library/Frameworks/OpenGL.framework/OpenGL'
     libglu = load_lib_with_fallbacks('GLU', libnames)
     set_global 'libglu', libglu
 
     libnames = new 'ResizableStringArray'
     push libnames, 'libglut'
+    push libnames, '/System/Library/Frameworks/GLUT.framework/GLUT'
     libglut = load_lib_with_fallbacks('GLUT', libnames)
     set_global 'libglut', libglut
 
Index: config/auto/opengl.pm
===================================================================
--- config/auto/opengl.pm       (revision 27056)
+++ config/auto/opengl.pm       (working copy)
@@ -66,8 +66,7 @@
     eval { $conf->cc_build() };
     if ( !$@ ) {
         my $test = $conf->cc_run();
-        $has_glut = $self->_evaluate_cc_run($test, $verbose);
-        _handle_glut($conf, $has_glut);
+        $has_glut = _handle_glut($conf, $self->_evaluate_cc_run($test, 
$verbose));
     }
     unless ($has_glut) {
         # The Parrot::Configure settings might have changed while class ran
@@ -88,6 +87,9 @@
             $conf->data->add( ' ', libs => 'glut.lib glu.lib gl.lib' );
         }
     }
+    elsif ( $osname =~ /darwin/i ) {
+        $conf->data->add( ' ', libs => '-framework OpenGL -framework GLUT' );
+    }
     else {
         $conf->data->add( ' ', libs => '-lglut -lGLU -lGL' );
     }
@@ -96,25 +98,29 @@
 
 sub _evaluate_cc_run {
     my ($self, $test, $verbose) = @_;
-    chomp $test;
-    my $has_glut = $test;
-    print " (yes, GLUT API $has_glut) " if $verbose;
-    $self->set_result("yes, GLUT $has_glut");
-    return $has_glut;
+    my ($glut_api_version, $glut_brand) = split ' ', $test;
+
+    print " (yes, $glut_brand API version $glut_api_version) " if $verbose;
+    $self->set_result("yes, $glut_brand $glut_api_version");
+
+    return ($glut_api_version, $glut_brand);
 }
 
 sub _handle_glut {
-    my ($conf, $has_glut) = @_;
+    my ($conf, $glut_api_version, $glut_brand) = @_;
+
     $conf->data->set(
         # Completely cargo culted
         opengl     => 'define',
-        has_opengl => $has_glut,
-        HAS_OPENGL => $has_glut,
+        has_opengl => 1,
+        HAS_OPENGL => 1,
 
         glut       => 'define',
-        has_glut   => $has_glut,
-        HAS_GLUT   => $has_glut,
+        glut_brand => $glut_brand,
+        has_glut   => $glut_api_version,
+        HAS_GLUT   => $glut_api_version,
     );
+
     return 1;
 }
 
Index: config/auto/opengl/opengl.in
===================================================================
--- config/auto/opengl/opengl.in        (revision 27056)
+++ config/auto/opengl/opengl.in        (working copy)
@@ -4,9 +4,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-/* XXXX: This location is platform dependent.  What's the preferred
-         way to find headers that move? */
+#ifdef __APPLE_CC__
+#include <GLUT/glut.h>
+#else
 #include <GL/glut.h>
+#endif
 
 
 int main(int argc, char *argv[])
@@ -15,6 +17,16 @@
         printf("glutInit is NULL\n");
         return EXIT_FAILURE;
     }
-    printf("%d\n", GLUT_API_VERSION);
+
+#ifdef OPENGLUT
+    printf("%d OpenGLUT\n",    GLUT_API_VERSION);
+#elif  FREEGLUT
+    printf("%d freeglut\n",    GLUT_API_VERSION);
+#elif  GLUT_MACOSX_IMPLEMENTATION
+    printf("%d MacOSX_GLUT\n", GLUT_API_VERSION);
+#else
+    printf("%d GLUT\n",        GLUT_API_VERSION);
+#endif
+
     return EXIT_SUCCESS;
 }
Index: config/gen/opengl.pm
===================================================================
--- config/gen/opengl.pm        (revision 27056)
+++ config/gen/opengl.pm        (working copy)
@@ -60,18 +60,25 @@
 );
 
 my @GLUT_4_CALLBACKS = (
-    [ 'Close',            'void' ],
-    [ 'Menu Destroy',     'void' ],
-    [ 'WM Close',         'void' ],
     [ 'Window Status',    'int state' ],
     [ 'Keyboard Up',      'unsigned char key, int x, int y' ],
     [ 'Special Up',       'int key, int x, int y' ],
-    [ 'Mouse Wheel',      'int wheel, int direction, int x, int y' ],
 
     # NOTE: Hardcoded because of special arguments
     # [ 'Joystick',         'int buttons, int xaxis, int yaxis, int zaxis' ],
 );
 
+my @MACOSXGLUT_CALLBACKS = (
+    # Also works in freeglut
+    [ 'WM Close',         'void' ],
+);
+
+my @FREEGLUT_CALLBACKS = (
+    [ 'Close',            'void' ],
+    [ 'Menu Destroy',     'void' ],
+    [ 'Mouse Wheel',      'int wheel, int direction, int x, int y' ],
+);
+
 my $MACRO_FILE = 'runtime/parrot/include/opengl_defines.pasm';
 my $C_FILE     = 'src/glut_callbacks.c';
 
@@ -93,23 +100,29 @@
         return 1;
     }
 
-    $self->gen_opengl_defines($conf);
+    my @header_globs = (
+        '/usr/include/GL/*.h',
+        '/System/Library/Frameworks/OpenGL.framework/Headers/*.h',
+        '/System/Library/Frameworks/GLUT.framework/Headers/*.h',
+    );
+                 
+    my @header_files = sort map {glob} @header_globs;
+
+    $self->gen_opengl_defines($conf, [EMAIL PROTECTED]);
     $self->gen_glut_callbacks($conf);
 
     return 1;
 }
 
 sub gen_opengl_defines {
-    my ( $self, $conf ) = @_;
+    my ( $self, $conf, $header_files ) = @_;
 
     my $verbose = $conf->options->get('verbose');
 
-    my @header_files = glob '/usr/include/GL/*.h';
-
     my (%defs, @macros);
     my $max_len = 0;
 
-    foreach my $file (@header_files) {
+    foreach my $file (@$header_files) {
         open my $header, '<', $file
         or die "Could not open header '$file': $!";
 
@@ -157,7 +170,7 @@
 #
 HEADER
 
-    print $macros "# $_\n" foreach sort @header_files;
+    print $macros "# $_\n" foreach @$header_files;
     print $macros "\n\n";
 
     foreach my $api (sort keys %defs) {
@@ -177,12 +190,22 @@
 sub gen_glut_callbacks {
     my ( $self, $conf ) = @_;
 
-    my   $glut_api       = $conf->data->get('has_glut');
+    my $glut_api   = $conf->data->get('has_glut');
+    my $glut_brand = $conf->data->get('glut_brand');
+
     my   @glut_callbacks = @GLUT_1_CALLBACKS;
-    push @glut_callbacks,  @GLUT_2_CALLBACKS if $glut_api >= 2;
-    push @glut_callbacks,  @GLUT_3_CALLBACKS if $glut_api >= 3;
-    push @glut_callbacks,  @GLUT_4_CALLBACKS if $glut_api >= 4;
+    push @glut_callbacks,  @GLUT_2_CALLBACKS     if $glut_api   >= 2;
+    push @glut_callbacks,  @GLUT_3_CALLBACKS     if $glut_api   >= 3;
+    push @glut_callbacks,  @GLUT_4_CALLBACKS     if $glut_api   >= 4;
+    push @glut_callbacks,  @FREEGLUT_CALLBACKS   if $glut_brand eq 'freeglut';
+    push @glut_callbacks,  @MACOSXGLUT_CALLBACKS if $glut_brand eq 'freeglut'
+                                                 or $glut_brand eq 
'MacOSX_GLUT';
 
+    my $glut_header = $glut_brand eq 'MacOSX_GLUT' ? 'GLUT/glut.h'   :
+                      $glut_brand eq 'OpenGLUT'    ? 'GL/openglut.h' :
+                      $glut_brand eq 'freeglut'    ? 'GL/freeglut.h' :
+                                                     'GL/glut.h'     ;
+
     my @callbacks;
     foreach my $raw (@glut_callbacks) {
         my ($friendly, $params) = @$raw;
@@ -263,7 +286,7 @@
 #ifdef WIN32
 #include <GL/glut.h>
 #else
-#include <GL/freeglut.h>
+#include <$glut_header>
 #endif
 #include "parrot/parrot.h"
 

Reply via email to