.SUFFIXES:
.SUFFIXES: .c .o .ads .adb .ali
 
.PHONY:
.PHONY: clean-generic mostlyclean-generic \
	clean distclean mostlyclean maintainer-clean

include ../Makefile.common

CFLAGS = @CFLAGS@ -Wall @GTK_CFLAGS@ -I. $(FPIC)
 
SONAME        = libgtkada_gl-$(MAJOR).$(MINOR)$(SO_EXT).$(MICRO)
LIBNAME       = libgtkada_gl$(SO_EXT)
ARCHIVENAME   = libgtkada_gl.a
INSTALL       = @INSTALL@
INSTALL_DATA  = @INSTALL_DATA@

HAVE_OPENGL=@HAVE_OPENGL@
 
ifeq ($(HAVE_OPENGL),True)
OPENGL_C_OBJECTS=gtkglarea.o gdkgl.o
OPENGL_SOURCES=gl_h.adb gdk-gl.adb gtk-glarea.adb
OPENGL_OBJECTS=$(OPENGL_SOURCES:%.adb=%.o)
OPENGL_LIBS=@GL_LIBS@
OPENGL_FLAGS=@GL_CFLAGS@
MESA_SPECS=gl_h.ads glu_h.ads

ifeq ($(BUILD_SHARED),yes)
all: $(LIBNAME) $(ARCHIVENAME)
else
all: $(ARCHIVENAME)
endif

install: all
	$(INSTALL_DATA) $(ARCHIVENAME) $(libdir)
	if [ $(BUILD_SHARED) = yes ]; then \
	  $(INSTALL_DATA) $(SONAME) $(libdir); \
	  $(RM) $(libdir)/$(LIBNAME); \
	  $(LN) $(SONAME) $(libdir)/$(LIBNAME); \
	fi
	$(CP) $(MESA_SPECS) $(incdir)
	$(CP) gdk*.ads gdk*.adb $(incdir)
	$(CP) gtk*.ads gtk*.adb $(incdir)
	$(CP) *.ali $(alidir)
	$(CHMOD) -w $(alidir)/*.ali

else
OPENGL_C_OBJECTS=
OPENGL_SOURCES=
OPENGL_OBJECTS=
OPENGL_LIBS=
OPENGL_FLAGS=
MESA_SPECS=

all:
install:
endif

$(LIBNAME):: $(OPENGL_OBJECTS) $(OPENGL_C_OBJECTS)
	$(CC) -shared $(FPIC) $(OS_SPECIFIC_LINK_OPTIONS) -o $(SONAME) \
	  $(SO_OPTS)$(SONAME) $(OPENGL_OBJECTS) $(OPENGL_C_OBJECTS) \
	  @GTK_LIBS@ -L.. -lgtkada $(OPENGL_LIBS)
	$(RM) $(LIBNAME)
	$(LN) $(SONAME) $(LIBNAME)
	-@if [ ! -f ../.devel ]; then \
	   strip $(LIBNAME); \
	fi
 
$(ARCHIVENAME):: $(OPENGL_OBJECTS) $(OPENGL_C_OBJECTS)
	$(AR) $(ARFLAGS) $(ARCHIVENAME) gdk*.o gtk*.o
	if [ -f /usr/bin/$(RANLIB) -o -f /bin/$(RANLIB) ]; then \
	   $(RANLIB) $(ARCHIVENAME); \
	fi

$(OPENGL_OBJECTS):: force
	@if [ -f ../.devel ]; then \
	   $(GNATMAKE) -I.. -aO../lib-obj $(GNATFLAGS_DEVEL) $(FPIC) -c $(patsubst %.o,%.adb,$@); \
	else \
	   $(GNATMAKE) -I.. -aO../lib-obj $(GNATFLAGS) $(FPIC) -c $(patsubst %.o,%.adb,$@); \
	fi
 
gtkglarea.o: gtkglarea.h gtkglarea.c
	$(CC) -c $(CFLAGS) $(OPENGL_FLAGS) gtkglarea.c
gdkgl.o:     gdkgl.h gdkgl.c
	$(CC) -c $(CFLAGS) $(OPENGL_FLAGS) gdkgl.c

clean-generic:
	-${RM} *.o *.ali *~ b_*.c b~*.ad? core
	-${RM} $(ARCHIVENAME) $(LIBNAME) $(SONAME)
	-${RM} .\#*
 
mostlyclean-generic: clean-generic
	-${RM} Makefile
 
clean: clean-generic
 
distclean: mostlyclean-generic
 
mostlyclean: mostlyclean-generic
 
maintainer-clean: mostlyclean-generic

force:
