## ----------------------------------------------------------------------------
##                                                                           --
##                      GNADE  : GNu Ada Database Environment                --
##                                                                           --
##  Filename        : $Source: /var/cvs/gnuada/gnade/dbi/mysql/Makefile,v $
##  Description     : Makefile for the direct mySQL binding
##  Author          : Juergen Pfeifer <juergen.pfeifer@gmx.net> 
##  Created On      : 03-Jan-2001
##  Last Modified By: $Author: jp $
##  Last Modified On: $Date: 2001/08/08 20:10:12 $
##  Status          : $State: Exp $
##
##  Copyright (C) 2000-2001
##
##  GNADE is copyrighted by the persons and institutions enumerated in the   --
##  AUTHORS file. This file is located in the root directory of the          --
##  GNADE distribution.                                                      --
##                                                                           --
##  GNADE is free software;  you can redistribute it  and/or modify it under --
##  terms of the  GNU General Public License as published  by the Free Soft- --
##  ware  Foundation;  either version 2,  or (at your option) any later ver- --
##  sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
##  OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
##  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
##  for  more details.  You should have  received  a copy of the GNU General --
##  Public License  distributed with GNAT;  see file COPYING.  If not, write --
##  to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
##  MA 02111-1307, USA.                                                      --
##                                                                           --
##  As a special exception,  if other files  instantiate  generics from      --
##  GNADE Ada units, or you link GNADE Ada units or libraries with other     --
##  files  to produce an executable, these  units or libraries do not by     --
##  itself cause the resulting  executable  to  be covered  by the  GNU      --
##  General  Public  License.  This exception does not however invalidate    --
##  any other reasons why  the executable file  might be covered by the      --
##  GNU Public License.                                                      --
##                                                                           --
##  GNADE is implemented to work with GNAT, the GNU Ada compiler.            --
##                                                                           --
## ----------------------------------------------------------------------------
##
##  Functional Description
##  ======================
##  This makefile builds the direct binding to the MySQL database and
##  stores the package and object files in the proper include resp. lib
##  directories.
##
##  Restrictions
##  ============
##
##  References
##  ==========
##
include ../../make.conf
#
CALLCONVENTION=C        
#
SO_MAJOR=$(GNADE_MAJOR)
SO_MINOR=$(GNADE_MINOR)
BASE=gnu-db-mysql
LIBID=adamysql
LIBNAME=lib$(LIBID)

PREPROCESSED_SOURCES = \
	gnu-db-mysql.adb

.SUFFIXES: .gpb .adb

.gpb.adb:
	$(ADAPREP) -DCALLCONVENTION=$(CALLCONVENTION) -DLIBID=\"-l$(LIBID)\" $*.gpb $*.adb

all::	\
	$(ADALIB)/$(LIBNAME).a	 		\
	$(ADALIB)/$(LIBNAME).so 		\
	$(libdir)/$(LIBNAME).so.$(SO_MAJOR)	\
	headers

objects :: makelib.adb gnu-db-mysql.adb
	@-mkdir -p ./obj
	(cd obj && gnatmake -c -I.. $(ADAFLAGS) makelib) 

shared_objects :: makelib.adb
	@-mkdir -p ./obj_shared
	(cd obj_shared && gnatmake -c -I.. $(ADAFLAGS) makelib -cargs -fPIC) 

$(ADALIB)/$(LIBNAME).a: objects
	$(AR) cr $@ obj/$(BASE)*.o
	ranlib $@
	chmod 0444 $@

$(libdir)/$(LIBNAME).so.$(SO_MAJOR).$(SO_MINOR): shared_objects
	gnatgcc -shared -o $@ -Wl,-soname,$(LIBNAME).so.$(SO_MAJOR) \
		obj_shared/$(BASE)*.o
	chmod 0555 $@

$(libdir)/$(LIBNAME).so.$(SO_MAJOR) : $(libdir)/$(LIBNAME).so.$(SO_MAJOR).$(SO_MINOR)
	ln -sf $(LIBNAME).so.$(SO_MAJOR).$(SO_MINOR) $@

$(ADALIB)/$(LIBNAME).so : $(libdir)/$(LIBNAME).so.$(SO_MAJOR).$(SO_MINOR)
	ln -sf ../../$(LIBNAME).so.$(SO_MAJOR).$(SO_MINOR) $@

headers : $(ADALIB)/$(LIBNAME).so
	@rm -f $(ADAINCLUDE)/$(BASE)*.ad[bs]
	@rm -f $(ADALIB)/$(BASE)*.ali
	$(CP) $(BASE)*.ad[bs] $(ADAINCLUDE)
	$(CP) obj_shared/$(BASE)*.ali $(ADALIB)
	chmod 0444 $(ADAINCLUDE)/$(BASE)*.ad[bs]
	chmod 0444 $(ADALIB)/$(BASE)*.ali

modules.lst ::
	@rm -f modules.tmp
	@for f in $(BASE)*.ads ; do \
	  g=`basename $$f .ads` ;\
	  p=`grep -i "package GNU.DB.MYSQL.* is" $${f} | awk '{print $$2;}'` ;\
	  if [ "$$p" != "" ]; then echo "$$p" >> modules.tmp ; fi ;\
	done
	if [ -e modules.lst ]; then diff -q $@ modules.tmp 2>&1 >/dev/null ;\
	if [ $$? -ne 0 ]; then cp modules.tmp $@ ; fi ;\
	else cp modules.tmp $@ ; fi ;
	rm -f modules.tmp

makelib.adb : modules.lst
	rm -f $@
	for f in `cat modules.lst` ; do \
	  if [ "$$f" != "" ]; then echo "with $$f;" >> $@ ; fi ;\
	done ;\
	echo "" >> $@ ;\
	echo "procedure MakeLib is begin null; end MakeLib;" >> $@

clean:
	rm -f *.o *.ali core b~*.ad? $(libdir)/$(LIBNAME).* \
		$(ADALIB)/$(LIBNAME).*
	rm -f $(ADALIB)/$(BASE)*.ali \
		$(ADAINCLUDE)/$(BASE)*.ad[bs]
	rm -f makelib.* modules.lst *.tmp gnu-db-mysql.adb 
	rm -rf obj obj_shared
	rm -rf *~


install ::

distclean :: clean




