The m4 macro script in m4/gl.m4 has one serious bug, and a few smaller problems that could be fixed.
First of all, the script erases the value of $with_gl_lib when it performs the Darwin Frameworks check, but unconditionally setting:
Additionally, when cross-compiling to a Win32 target (using MinGW32, for instance), the opengl32 and glu32 libraries don't use the cdecl calling convention. Rather, they use stdcall which requires that the functions be prototyped properly to build the proper symbol name (Function@ARGBYTES). For example, glBegin(GLint) becomes glBegin@4 (where 4 means 4 arg bytes).
This patch fixes the Darwin Frameworks problem by only assigning the value of $FRAMEWORKS_OPENGL if the frameworks were detected.
Additionally, the patch modifies the link check so that if it fails to link against the dummy prototype, it will subsequently attempt to link a version that #include's the GL/gl.h or GL/glu.h headers, to see if that succeeds. Only if both checks fail will it set $HAVE_GL to "no".