As far as I know there currently is no way to retrieve the stage for which the GLSL compiler is generating code.
Such a feature could ease the development of GLSL libraries whose functions can be evaluated accross multiple stages.
Here's an example of source code which could be included at any stage and is safe to use:
Code :
// check GLSL compiler version
#if (__VERSION__ < 150)
#error Unsupported GLSL version
#endif
 
// some function (shading function for example)
vec3 shade(...) {
#if (__STAGE__ == GL_vertex_stage)
    perform per-vertex operations
#elif (__STAGE__ == GL_fragment_stage)
   per-fragment operations
#else
// either halt compilation...
   #error Invalid stage 
// ... or return something
   return vec3(0);
#endif
}
On the client side, one would simply use
Code :
const GLchar * files[] = {"library.glsl", "main_function.glsl"};
GLuint shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader, 2, load_strings(2, files), NULL);
Granted, this can already be accomplished by including a string in glShaderSource, but having the compiler doing it would save some time and ease the development of safer and more portable GLSL libraries... What do you think ?