import platform
from .. import Path, Exception, srctree
from .  import Config, StaticLib

class OpenGL:

    def __init__(self, prefix = None):

        test = []
        test_framework = []
        if prefix is None:
            test = ['/usr', '/usr/local']
            if platform.system() == 'Darwin':
                test_framework += ['/System/Library/Frameworks/OpenGL.framework']
        else:
            test = [prefix]
            if platform.system() == 'Darwin':
                test_framework += [prefix]

        searched_file = 'glext.h'
        for path in test:

            p = Path(path)
            if not p.absolute:
                p = srctree() / p

            if (p / 'include/GL' / searched_file).exists():

                self.prefix = path

                self.cfg = Config()
                self.cfg.add_system_include_path('%s/include' % self.prefix)
                self.cfg.lib_path('%s/lib' % self.prefix)
                self.cfg.lib('GL')

                return

        if platform.system() == 'Darwin':
            for path in test_framework:

                p = Path(path)
                if not p.absolute:
                    p = srctree() / p

                if (p / 'Headers' / searched_file).exists():

                    self.prefix = p
                    self.cfg = Config()
                    self.cfg.add_system_include_path(self.prefix / 'Headers')
                    self.cfg.framework_add('Cocoa')
                    self.cfg.framework_add('OpenGL')

                    return

        raise Exception('unable to find %s in %s' % (searched_file, ', '.join(test + test_framework)))

    def config(self):

        return self.cfg

@@ -927,32 +927,154 @@
  %25 self.prefix)%0A
+                if platform.system() == 'Windows':%0A                    self.cfg.lib('opengl32')%0A                else:%0A    
                 

Fix OpenGL library name under windows.