Acme-MITHALDU-BleedingOpenGL

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

use strict;
use warnings;
use ExtUtils::MakeMaker;
use ExtUtils::Liblist;
use Data::Dumper;
use Config;
use Try::Tiny;

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.

# Supported windowing interfaces
our $is_valid_interface =
{
  'AGL'       => 'Default GLUT framework on Mac OS X',
  'FREEGLUT'  => 'FreeGLUT, preferred over GLUT',
  'GLUT'      => 'GLUT; often really FreeGLUT on Linux',
  'GLX'       => 'Default GLX+X11 on Linux; use XQuartz on Mac OS X',
  'W32API'    => 'Uses WGL+FreeGLUT on CYGWIN, instead of GLX+FreeGLUT',
  'WGL'       => 'Same as W32API',
};


# Makefile.PL Usage
sub Usage
{
  print "\n@_\n\n";

  print qq
  {
    USAGE: perl Makefile.PL [OPTIONS]


    OPTIONS include:

    help                This help message

    verbose             Display additional status info, can be
                        repeated for more verbosity

    dist=NO_EXCLUSIONS  Build with no OpenGL Extension exclusions

    interface=XFACE     Build for a specific windowing interface
                        Currently supports:
  };

  print "\n";
  foreach my $xface (sort keys %$is_valid_interface)
  {
    print substr("      $xface                  ",0,24).
      "$is_valid_interface->{$xface}\n";
  }
  print "\n";
  exit(0);
}
if (@ARGV and $ARGV[0] =~ m|^([-/]*)?h(elp)?|i)
{
  Usage();
}
else
{
  print "\nrun as `perl Makefile.PL help` to show user options\n";
}

our $verbose = 0;
our $IS_MINGW = 0;
our $IS_STRAWBERRY = 0;
our $IS_CYGWIN;
our $IS_W32API;
my $INCS;

try {

# Get debugging flags
if ( grep { if (m/^verbose/i) { $verbose++; 1; } else { 0; } } @ARGV )

Makefile.PL  view on Meta::CPAN


if ($verbose)
{
  print "found libs:\n";
  foreach my $key (sort keys %$found_libs)
  {
    print "    $key = '$found_libs->{$key}'\n";
  }
}

# Check for OpenGL installation
our $DIST_DEFS = get_extensions($found_libs,$dist_flags->{NO_EXCLUSIONS});

# Don't build Makefile if we cannot compile+run glversion
die "unable to determine extensions or no extensions found\n" if !length $DIST_DEFS;

# Get user-specified interface
my $interface_lib;
if ( grep { m/^interface=/i } @ARGV )
{
  my @my_argv = @ARGV;    # safe copy
  my @interface_opts = ();
  my $fallback = 0;

  foreach my $arg (@my_argv)
  {
    if ($arg =~ m/^interface=(\w+)/i)
    {
      my $interface = uc($1);
      my $valid_type = $is_valid_interface->{$interface};
      if (!$valid_type)
      {
        Usage("Invalid interface: '$interface'");
        next;
      }

      # test if requested interfaces supported
      # !!! Should use lookup table
      if ($interface eq 'W32API' or $interface eq 'WGL')
      {
        if (!$found_libs->{FREEGLUT32} && !$found_libs->{GLUT32})
        {
          print "W32API interface requires GLUT or FreeGLUT\n";
          next;
        }
        if (!$found_libs->{OPENGL32})
        {
          print "W32API interface requires OpenGL32.dll\n";
          next;
        }
        if (!$found_libs->{GLU32})
        {
          print "W32API interface requires GLU32.dll\n";
          next;
        }
      }
      elsif ($interface eq 'AGL')
      {
        if ($^O ne 'darwin' || !$found_libs->{GLUT})
        {
          print "AGL interface requires GLUT.framework\n";
          next;
        }
      }
      elsif ($interface =~ m|GLUT|)
      {
        if ($interface eq 'FREEGLUT')
        {
          if (!$found_libs->{FREEGLUT} && !$found_libs->{FREEGLUT32})
          {
            print "FREEGLUT interface requires FreeGLUT\n";

            if ($found_libs->{GLUT})
            {
              print "Falling back to the GLUT interface\n";
              $interface = 'GLUT';
              $fallback++;
            }
            else
            {
              print "Try installing FREEGLUT first\n";
              next;
            }
          }
        }
        elsif ($interface eq 'GLUT')
        {
          if (!$found_libs->{GLUT} && $found_libs->{FREEGLUT})
          {
            $found_libs->{GLUT} = $found_libs->{FREEGLUT};
          }

          if (!$found_libs->{GLUT32} && $found_libs->{FREEGLUT32})
          {
            $found_libs->{GLUT32} = $found_libs->{FREEGLUT32};
          }

          if ($found_libs->{GLUT})
          {
            delete($found_libs->{FREEGLUT});
          }

          if ($found_libs->{GLUT32})
          {
            delete($found_libs->{FREEGLUT32});
          }

          if (!$found_libs->{GLUT} && !$found_libs->{GLUT32})
          {
            print "GLUT interface requires GLUT or FreeGLUT but libs were not found\n";
            next;
          }
        }
        else
        {
           print "Error in interface argument processing\n";
           next;
        }
      }
      elsif ($interface eq 'GLX')
      {

Makefile.PL  view on Meta::CPAN

my $DYNS = {};
if ($IS_W32API || (($^O eq 'MSWin32') && !$IS_CYGWIN))		# Win32
{
  my $glut_lib = '-lopengl32 -lglu32 ';
  if ($interface_lib eq 'GLUT')
  {
    $glut_lib .= '-lglut32';
  }
  elsif ($interface_lib eq 'FREEGLUT' and $IS_STRAWBERRY)
  {
    $glut_lib .= '-lglut';
  }
  else
  {
    $glut_lib .= '-LFreeGLUT -lfreeglut';
  }

  if ($IS_MINGW)	# MINGW
  {
    $LDFROM = $glut_lib;
  }
  elsif ($IS_W32API)	# CYGWIN W32API
  {
     my $glut = ($found_libs->{FREEGLUT32}) ? $found_libs->{FREEGLUT32} : $found_libs->{GLUT32};

    $LIBS = "-L/usr/lib/w32api $glut_lib";
    $LDFROM = $glut_lib;
    ### $INCS = '-I/usr/include/w32api';
    $INCS = '-I/usr/include/opengl';
    $DEFS .= " -DHAVE_W32API";
    $DYNS = { OTHERLDFLAGS => '-Wl,--exclude-symbols,'."\x7F".$glut.'_NULL_THUNK_DATA' };
  }
  else			# Windows VC6
  {
    $LIBS = $glut_lib;
    $OPTS = "/ogity /GDs";
  }

  # Using a dll as EXES is incorrect for EU::MM, since the EXES here mean
  # perl scripts and not windows binaries or DLLs.  This puts the DLL in
  # blib/bin from whence it should be installed correctly.  It is not
  # clear that this step is even needed since the freeglut.dll is installed
  # by this Makefile.PL if no FreeGLUT is found.
  #
  ## $EXES = ['FreeGLUT/freeglut.dll'];
  {
     system $^X , qw[-MExtUtils::Command -e mkpath --], qw[blib/arch/auto/Acme/MITHALDU/BleedingOpenGL];
     system $^X , qw[-MExtUtils::Command -e cp --], qw[FreeGLUT/freeglut.dll blib/arch/auto/Acme/MITHALDU/BleedingOpenGL/freeglut.dll];
     my @other_installs = grep { -e "$_\\freeglut.dll" } split /;/, $ENV{PATH};
     if(@other_installs) {
      print "\n" ;
      print "XXX Other freeglut.dll installed in $_\n" for @other_installs;
      print "Please verify whether the other found dll(s) are from older OpenGL.pm installs, and delete them if so!\n\n\n";
      sleep 2;
     }
  }

}
elsif ($interface_lib eq 'AGL')					# Mac OS X
{
  $INCS = ""; # no include flags required: Apple gcc will automatically pick up the system frameworks
  $DEFS .= " -DHAVE_AGL_GLUT -Wno-deprecated-declarations ";  # So we know we have glutWMCloseFunc() and glutCheckLoop()
  $DYNS = { OTHERLDFLAGS => "-framework OpenGL -framework GLUT" };
}
else # Everyone else
{
  my @includes = qw
  {
    -I/usr/include
    -I/usr/include
    -I/usr/X11R6/include
    -I/opt/X11/include
    -I/usr/local/include
    -I/usr/openwin/include
    -I/opt/csw/include
    -I/usr/local/freeglut/include
  };
  $INCS = "@includes";


  # Test for obfuscated GLX
  # quite often GLX is in -lGL...  Test for GL/glx.h instead...
  my $out = cfile_text('GL/glx.h');

  # The cpp would not let this macro through. Check for something else
  # that still exists after the cpp pass. a typedef, or type would work
  my $has_glx = ($out =~ m|GLXContext|);

  if ($has_glx)
  {
    #delete($found_libs->{GLX});
    $DEFS .= " -DHAVE_GLX";
  }
  elsif (!$found_libs->{GLX} && $verbose)
  {
    print "GLX not found (neither library, nor headers).";
  }

  # Test for obfuscated Freeglut
  # quite often Freeglut is in -lglut...  Test for GL/freeglut.h instead...
  $out = cfile_text('GL/freeglut.h');

  # The cpp would not let this macro through. Check for something else
  # that still exists after the cpp pass. a typedef, or type would work
  my $has_freeglut = ($out =~ m|glutMainLoopEvent|);

  if ($has_freeglut)
  {
    #delete($found_libs->{GLX});
    $DEFS .= " -DHAVE_FREEGLUT -DHAVE_FREEGLUT_H";
    $found_libs->{FREEGLUT}="glut";
  }

  # Marshall libs
  my $libs = ' -l'.join(' -l',values(%$found_libs));
  my @more_libs = qw
  {
    -lXext
    -lXmu
    -lXi
    -lICE
    -lX11
    -lstdc++

Makefile.PL  view on Meta::CPAN

  },
  'EXE_FILES'	=> $EXES,
  'OPTIMIZE'	=> $OPTS,
  'clean'       =>
  {
    FILES =>
      "Config.pm ".
      "utils/glversion.txt ".
      "utils/glversion$Config{exe_ext} ".
      "utils/glversion$Config{obj_ext}"
  }
};

print "\nMakeMaker configuration:\n" if $verbose;

close(CONF) if (open(CONF,">Config.pm"));	# Generate place-holder Config.pm
WriteMakefile( %$build_config );       		# Generate the Makefile
WriteConfigPM( $build_config );			# Regenerate final Config.pm

if ($found_libs->{GLX} && $ENV{TERM} ne 'xterm')
{
  print "\nThis configuration should be built under an X11 shell\n\n";
}

exit 0;

}
catch {
  warn $_;
  die "OS unsupported\n";
};



# test header files for extensions
sub cfile_text
{
  my($filename) = @_;

  # Use $Config{cpprun}, instead of $Config{cpp}. cpp is simply set to
  # 'cpp' after Configure has run, which is not useful, since it lives
  # in /lib/ on many systems, which is normally not on the path.  This
  # is documented, but silly behaviour.  $Config{cpprun} is what is
  # documented to be set to a cpp that will take stuff on stdin

  my $cmd = "echo '\#include \"$filename\"' | ".
    "$Config{cpprun} $INCS $Config{cppflags} $Config{cppminus} 2>&1";

  return `$cmd`;
}


# Find OpenGL-related Libs
sub get_libs
{
  my @glx_libs = @_;
  my $found = {};
  my $libs;

  # Mac OS X
  if ($^O eq 'darwin' && -d '/System/Library/Frameworks/OpenGL.framework')
  {
    $found->{GL} = 'OpenGL.framework';
    $found->{GLU} = 'AGL.framework';
    if (-e '/opt/X11/lib/libglut.3.dylib')
    {
      $found->{FREEGLUT} = 'glut';
    }
    else
    {
      $found->{GLUT} = 'GLUT.framework';
    }
    return $found;
  }

  # Win32
  if ($IS_STRAWBERRY)
  {
     # libs for strawberry perl go here
     $found->{FREEGLUT} = 'glut';
     $found->{OPENGL32} = 'opengl32';
     $found->{GLU32} = 'glu32';
  }
  elsif (($^O eq 'MSWin32') || $IS_W32API)
  {
    my $paths = $ENV{PATH};
    $paths =~ s|\\|/|g;
    my $sep = $IS_W32API ? ':' : ';';
    my @paths = split($sep.'\s*',$paths);

    my $sysroot = $ENV{'SYSTEMROOT'};
    @paths = ("$sysroot/system32",@paths) if ($sysroot);

    $libs = {OPENGL32=>'opengl32.dll',GLU32=>'glu32.dll',GLUT32=>'glut32.dll',FREEGLUT32=>'freeglut.dll'};
    foreach my $key (sort keys %$libs)
    {
      foreach my $path (@paths)
      {
        $path =~ s|/$||;
        my $lib = $libs->{$key};
        next if (!-e "$path/$lib");
        $lib =~ s/\.dll$//i;
        if ( $lib eq "freeglut" ) {
          my @p = split m@[/\\]@, $Config{installsitebin};
          next if $path eq join "/", @p or $path eq join "\\", @p;
        }
        # print "  $key: $lib\n";
        $found->{$key} = $lib;
        last;
      }
    }

    # Install FreeGLUT if not found
    if (!$found->{FREEGLUT32} and !$IS_STRAWBERRY)
    {
      my $dll_dir = "utils";

      my $exec;
      if ($IS_W32API)
      {
        $dll_dir = '/usr/local/bin' if ($dll_dir eq '/usr/bin');
        $exec = "cp FreeGLUT/freeglut.dll $dll_dir";
      }
      else
      {
        $exec = "copy FreeGLUT\\freeglut.dll $dll_dir";
      }
      `$exec`;

      if (! -x "$dll_dir/freeglut.dll")
      {



( run in 0.788 second using v1.01-cache-2.11-cpan-df04353d9ac )