#!/bin/sh

# This is a config file for OpenGL based on glib-config/gtk-config. I wrote this
# to help me do my halfassed hacks a little easier.
#
# initial creation: aug 1999
# last update:      jun 2000
#
# Copyright (C) 1999-2000 Erik Greenwald <erik@smluc.org>
# Released under the GNU General Purpose License, available at
# http://www.gnu.org/copyleft/gpl.html
#
# If this should be under the LGPL for some reason, email me at erik@smluc.org
# and tell me why. :) It would be nice if this were moved into the mesa3d
# distribution. GTK+/GDK/GNOME and SDL have embraced this and it simplifies
# not only quick compilation, but making sure code compiles anywhere. Automake
# and autoconf can only do so much... (at a mere 100k)

prefix=/usr		# you may need to change this to /usr/local or /opt
			# or /usr/X11R6

			# these need to be changed per version.
ogl_version="1.2"	# mesa 3.4 conforms to the OpenGL 1.2 spec
lib_version="Mesa 3.4"	# this is... mesa 3.4.


########### you probably don't need to edit below this line. ###########

			# these should be fine on most X systems.
			# if yours doesn't like it, let me know the flags that
			# do work, and I'll see about smartening this up :)
gl_libs="-L${prefix}/lib -lGL -L/usr/X11R6/lib -lX11 -lXmu -lXi -lXext -lm"
glu_libs="-L${prefix}/lib -lGL -lGLU -L/usr/X11R6/lib -lX11 -lXmu -lXi -lXext -lm"
glut_libs="-L${prefix}/lib -lGL -lGLU -lglut -L/usr/X11R6/lib -lX11 -lXmu -lXi -lXext -lm"

			# again, these should work on any system.
gl_cflags="-I${prefix}/include -I${prefix}/include/GL"

##################### don't edit below this line. ###########################

exec_prefix=${prefix}
exec_prefix_set=no

usage()
{
	cat <<EOF
Usage: gl-config [OPTIONS] [LIBRARIES]
Options:
	[--prefix[=DIR]]
	[--exec-prefix[=DIR]]
	[--version]
	[--libs]
	[--cflags]
Libraries:
	gl
	glu
	glut
EOF
	exit $1
}

if test $# -eq 0; then
	usage 1 1>&2
fi

lib_gl=yes

while test $# -gt 0; do
  case "$1" in
  -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  *) optarg= ;;
  esac

  case $1 in
    --prefix=*)
      prefix=$optarg
      if test $exec_prefix_set = no ; then
        exec_prefix=$optarg
      fi
      ;;
    --prefix)
      echo_prefix=yes
      ;;
    --exec-prefix=*)
      exec_prefix=$optarg
      exec_prefix_set=yes
      ;;
    --exec-prefix)
      echo_exec_prefix=yes
      ;;
    --version)
      echo "$ogl_version ($lib_version)"
      ;;
    --cflags)
      echo_cflags=yes
      ;;
    --libs)
      echo_libs=yes
      ;;
    gl)
      lib_gl=yes
      ;;
    glu)
      lib_glu=yes
      ;;
    glut)
      lib_glut=yes
      ;;
    *)
      usage 1 1>&2
      ;;
  esac
  shift
done

if test "$echo_prefix" = "yes"; then
	echo $prefix
fi

if test "$echo_exec_prefix" = "yes"; then
	echo $exec_prefix
fi

if test "$echo_cflags" = "yes"; then
      if test ${prefix}/include != /usr/include ; then
        includes=-I${prefix}/include
        for i in $gl_cflags ; do
          if test $i = -I${prefix}/include ; then
            includes=""
          fi
        done
      fi
      echo $includes $gl_cflags
fi

if test "$echo_libs" = "yes"; then
	if test "$lib_gl" = "yes"; then
		my_gl_libs=$gl_libs
	fi
	if test "$lib_glu" = "yes"; then
		my_gl_libs=$glu_libs
	fi
	if test "$lib_glut" = "yes"; then
		my_gl_libs=$glut_libs
	fi
	echo $my_gl_libs
fi      

