Acme-MITHALDU-BleedingOpenGL
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
# Detect MINGW
if ($^O eq 'MSWin32' && $Config{cc} =~ /\bgcc/i)
{
$IS_MINGW = 1;
print "Build platform \$IS_MINGW==1" if $verbose;
}
# Detect Strawberry Perl
if ($IS_MINGW)
{
$IS_STRAWBERRY = ($Config{cf_by} =~ m/strawberry-perl/i);
print "Build platform \$IS_STRAWBERRY==$IS_STRAWBERRY\n" if $IS_STRAWBERRY and $verbose;
}
# Look for available libs
our @libdirs = qw
{
-L/usr/lib
-L/usr/lib/i386-linux-gnu
-L/usr/X11R6/lib
-L/opt/X11/lib
-L/usr/local/lib
-L/usr/openwin/lib
-L/opt/csw/lib
-L/usr/local/freeglut/lib
};
our @check_libs = qw
{
-lGL
-lopengl
-lMesaGL
-lGLU
-lglu
-lMesaGLU
-lfreeglut
-lglut3
-lglut
-lGLUT
-lMesaGLUT
};
our $found_libs = get_libs(@libdirs,@check_libs);
die "No OpenGL related libs found\n" if (!scalar($found_libs));
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";
Makefile.PL view on Meta::CPAN
}
elsif ($lib =~ m|([\w]*gl)$|i)
{
$found->{GL} = $1;
}
if ($lib =~ m|([\w]*mesa(gl)?.*)|i)
{
$found->{MESA} = $1;
}
}
return $found;
}
# Test for available OpenGL Extensions
sub get_extensions
{
my($found,$no_excl) = @_;
print "Testing for OpenGL Extensions\n" if ($verbose);
# clean up previous output files
my $exc_file = 'gl_exclude.h';
unlink($exc_file) if (-e $exc_file);
my $glv_file = 'utils/glversion.txt';
unlink($glv_file) if (-e $glv_file);
# Only run the rest if GLUT is installed
print "Testing GLUT version\n" if ($verbose);
my($lib,$def);
if ($found->{FREEGLUT32} || $found->{FREEGLUT})
{
$lib = $found->{FREEGLUT32} || $found->{FREEGLUT};
$def = "HAVE_FREEGLUT";
}
elsif ($found->{GLUT32} || $found->{GLUT})
{
$lib = $found->{GLUT32} || $found->{GLUT};
$def = "HAVE_GLUT";
}
elsif ($verbose)
{
print "GLUT not found\n";
}
# Platform-specific makefiles for glversion
my $make_ver;
if ($IS_STRAWBERRY)
{
$make_ver = "&strawberry.bat";
print "strawberry glversion: '$make_ver'\n" if $verbose>1;
}
elsif ($IS_MINGW)
{
$make_ver = "&mingw.bat";
print "mingw glversion: '$make_ver'\n" if $verbose>1;
}
elsif ($IS_W32API)
{
$make_ver = ";make -f Makefile.cygwin " . (length($lib) ? "GLUT_LIB=$lib " : "") . (length($def) ? "GLUT_DEF=$def " : "");
print "cygwin glversion: '$make_ver'\n" if $verbose>1;
}
elsif ($^O eq 'MSWin32')
{
$make_ver = '&nmake -f makefile.mak ' . (length($def) ? "GLUT_DEF=$def " : "");
print "MSWin32 glversion: '$make_ver'\n" if $verbose>1;
}
elsif ($^O eq 'darwin')
{
$make_ver = ";make -f Makefile.macosx " . (length($lib) ? "GLUT_LIB=$lib " : "") . (length($def) ? "GLUT_DEF=$def " : "");
print "MacOSX glversion: '$make_ver'\n" if $verbose>1;
}
else
{
if ($ENV{TERM} ne 'xterm')
{
print "\nIn order to test your GPU's capabilities, run this make under an X11 shell\n\n";
}
$make_ver = ";make -f Makefile " . (length($lib) ? "GLUT_LIB=$lib " : "") . (length($def) ? "GLUT_DEF=$def " : "");
print "glversion: '$make_ver'\n" if $verbose>1;
}
my $exec = 'cd utils'."$make_ver clean".$make_ver;
print "glversion: $exec\n" if ($verbose);
my $stat = `$exec`;
print "\n$stat\n\n" if ($verbose);
unlink "utils/freeglut.dll" or die "could not remove temporary freeglut: $!" if -f "utils/freeglut.dll";
# Parse glversion.txt file
open GLDATA, $glv_file or die "get_extensions: could not open $glv_file: $!\n";
my $gldata = {};
my @gldata = <GLDATA>;
close(GLDATA);
foreach my $line (@gldata)
{
$line =~ s|[\r\n]+||;
my($key,$val) = split('=',$line);
$gldata->{$key} = $val;
}
die "get_extensions: no extensions found in $glv_file\n" if !keys %$gldata;
print "This looks like OpenGL Version: $gldata->{VERSION}\n";
# Parse glext_procs.h file
open GLEXT, "glext_procs.h" or die "get_extensions: could not open glext_procs.h: $!\n";
my @lines = <GLEXT>;
close(GLEXT);
my $no_ext = {};
foreach my $line (@lines)
{
next if ($line !~ m|\#ifndef NO_([^\s]+)|);
my $ext = $1;
next if ($ext =~ m|^GL_VERSION_|);
$no_ext->{$ext}++;
}
# Create gl_exclude.h
die "Unable to write to $exc_file\n" if (!open(GLEXC,">$exc_file"));
print GLEXC "// OpenGL Extension Exclusions - may be modified before building.\n";
print GLEXC "//\n";
print GLEXC "// Generated for ".$gldata->{VENDOR}.", ".$gldata->{RENDERER}."\n";
print GLEXC "// OpenGL v".$gldata->{VERSION}.", using ";
# Fix GLUT flags based on results
if ($gldata->{FREEGLUT})
{
print 'Found FreeGLUT v'.$gldata->{FREEGLUT}."\n";
print GLEXC 'FreeGLUT v'.$gldata->{FREEGLUT}."\n";
if (!$found->{FREEGLUT} && !$found->{FREEGLUT32})
{
$found->{FREEGLUT} = $lib;
}
}
elsif ($gldata->{GLUT})
{
print "Found GLUT - Version: $gldata->{GLUT}\n";
( run in 0.971 second using v1.01-cache-2.11-cpan-5837b0d9d2c )