## ----------------------------------------------------------------------------
##                                                                           --
##  Filename        : $Source: /cvsroot/gnade/gnade/Makefile,v $
##  Description     : The top level makefile of GNADE                        --
##  Author          : Michael Erdmann <Michael.Erdmann@snafu.de>             --
##  Created On      : 03-Jan-2001                                            --
##  Last Modified By: $Author: merdmann $                                    --
##  Last Modified On: $Date: 2004/05/31 14:39:14 $                           --
##  Status          : $State: Exp $                                          --
##                                                                           --
##  Copyright (C) 2000-2004 Michael Erdmann                                  --
##                                                                           --
##  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 recursively visits subdirectories for the various GNADE
##  components and performs the make steps there.
##
##  All objects exported by this project are compiled in the source tree
##  and copied into the following export directories:
##
##   <arch>-bin    	- All executables
##   <arch>-lib    	- All libraries
##   <arch>-include	- All includes as for example *.ali, *.ads and *.adb
##			  files.
##   <arch>-doc	        - All documentation
##   <arch>-export	- All package exported by the project. The setup installer
##			  for windows and the rpm files will be stored here.
##   <arch>-libexec	- All tools which are called only from within GNADE
##   shared		- All objects to be installed by the end used localy.
##
##  The Makefile provides the following target:
##
##  make all       - makes the whole GNADE project including  the samples
##		     if configured.
##  make clean     - Removes all compilation product from the GNADE file
##		     tree but leaves the compilation results intact
##  make distclean - Removes all compilation results from the file tree and
##		     the common directories <platform>-bin/-include/...
##  make dist      - Create a distribution based on the information as it
##                   is stored in the VERSION file.
##
##  make createuser- Creates a data base user. This traget has been specified
##                   here, because for some data bases it has to be executed
##                   using a different user id.
##
##  make createdb  - Create the used database
##
##  The behaviour of the Makefiles depends on the parameter COMPLETE. If it is
##  set to any value, the makefiles called from the makefile are compiling 
##  only locally in the working directory and a make install needs to be issued
##  manually to copy the compilation results into the export directories.
##
##  If a make clean is done in one of the called makefiles, the compliation 
##  results are deleted from the export directories.
##
##  The sub makefiles have to process the following targets:
##
##    all build  - To Build the targets of the subproject
##    clean	 - Clean locally all compilation results including the results
##		   in the export directories. If the Variable EXPORT is set
##		   do not delete the results in the export files. 
##    install    - Copy the local compilation results into the export directories
##  
##
##
##
##  Note:
##    The sample database is only generated on systems, where the
##    one of the supported databases is available.
##
##  Restrictions
##  ============
##  None
##
##  References
##  ==========
##  None
##
.PHONY: clean reatedb createuser directories dist-Linux dist-binaries \
	dist-win32 dist distclean documentation install manual publish \
	remove-directories removedb removeuser shared-all shared-clean

sinclude make.conf

ifeq ($(GNADETARGET),)
ROOT=$(prefix)
else
ROOT=$(GNADETARGET)
endif

DISTNAME=gnade-src-$(VERSION)

##
## This line dfines the logging method
##
LOGFILE=build.log

ifneq ($(LOGFILE),)
logging=>>$(LOGFILE)
else
logging=
endif

##
## list of directories which are created by the makefile to export build
## results.
##
exportdirs=$(libdir) 	\
	$(includedir) 	\
	$(bindir) 	\
	$(docdir) 	\
	$(SHARED) 	\
	$(DBPATH) 	\
	$(libexec) 	\
	$(gnadeetcdir)	\
	$(exportdir)


## ############################################################################ ##
##  			Compile the GNADE sources                               ##
## ############################################################################ ##
all clean ::
ifeq ($(BUILDENV),)
	@echo "*** ERROR: run the configure script before trying to build GNADE"
	exit 1
endif
	$(MAKE) core-$@ $(logging)
	$(MAKE) odbc-$@ $(logging)
	$(MAKE) native-$@ $(logging)
	$(MAKE) samples-$@ $(logging)


clean ::
	-$(RM) $(LOGFILE)

##
## core components needed in any configuration
##
core-all core-clean:
	$(MAKE) -C./cfg $(subst core-,,$@)  Target=$(libexec) EXPORT=T
	$(MAKE) -C./etc $(subst core-,,$@)  EXPORT=T
	$(MAKE) -C./support EXPORT=T $(subst core-,,$@)
	$(MAKE) -C./bin     EXPORT=T $(subst core-,,$@)
##
## All odbc related and dependant parts of GNADE
##
odbc-all odbc-clean ::
ifneq ($(OPTODBC),) 
	$(MAKE) -C./dbi     BINDINGS=odbc EXPORT=T $(subst odbc-,,$@)
	$(MAKE) -C./esql    EXPORT=T $(subst odbc-,,$@)
	$(MAKE) -C./tools   EXPORT=T $(subst odbc-,,$@)
	$(MAKE) -C./samples SAMPLES="esql odbc" $(subst odbc-,,$@)
else
	@echo "ODBC Bindings not build"
endif

##
## All native database bindings except for odbc
##
native-all native-clean ::
ifneq ($(NATIVE_BINDINGS),)
	$(MAKE) -C./dbi BINDINGS="$(NATIVE_BINDINGS)" EXPORT=T $(subst native-,,$@)

else
	@echo "Native bindings are not build"
endif

##
## The samples
##
samples-all samples-clean :
	$(MAKE) -C./samples SAMPLES="$(NATIVE_SMAPLES)" $(subst samples-,,$@)

##
## Generate the configured basic project file for gnade
##
$(TARGET)gnade.gpr: gnade.gpp
	$(PREP) -s DMLINKEROPT="$(DMLINKEROPT)"  			\
		    NALINKEROPT="$(APP_LINK_FLAGS_NATIVE)"		\
		    ROOT=$(ROOT)	 				\
		    BUILDARCH=$(BUILDARCH)				\
		   gnade.gpp $(TARGET)gnade.gpr

all::
	$(MAKE) gnade.gpr

##
## Generate commonly resources
##
shared-all:
	$(CP) $(subst /,$(PATHSEP),./ide/gps/*.xml)   $(subst /,$(PATHSEP), $(SHARED))
	$(CP) $(subst /,$(PATHSEP),./doc/build/*.xml) $(subst /,$(PATHSEP), $(SHARED)) 
	$(MAKE) GNADETARGET=/usr/local/gnade TARGET=$(SHARED)/ \
		APP_LINK_FLAGS_NATIVE="-L$(SITE_LIBDIR) $(GNADE_LIBS)" \
		$(SHARED)/gnade.gpr 

shared-clean:

##
## create/delete the export directories
##
directories:
	-$(MKDIR) $(subst /,$(PATHSEP),$(exportdirs)) 2> configure.log

remove-directories:
	-$(RMDIR) $(subst /,$(PATHSEP),$(exportdirs)) 2>configure.log

##
## Create the documentation
##
documentation : $(DOCUMENT_PARTS)

manual:
	echo $(DOCUMENT_PARTS)
	$(MAKE) -C doc/build documentation
## ############################################################################ ##
## create a distribution package different operating system.                    ##
## ############################################################################ ##
dist :: all
	$(MAKE) dist-binaries
	$(MAKE) documentation
	$(MAKE) package

package :: 
	$(MAKE) package-$(BUILDENV)
	$(MAKE) package-clean-$(BUILDENV) 

# copy the binries into the lib 
dist-binaries:
	strip $(libexec)/prep$(bin) 
	strip $(wildcard $(bindir)/*$(bin))

## Build all packages which could be build by a GNU development environment
package-gnu: dist-tree $(foreach i,$(PACKAGE_TYPES),package-$i)

dist-tree: clean
	rm -rf $(DISTNAME)
	mkdir -p $(DISTNAME)
	mkdir -p $(DISTNAME)/doc
	mkdir -p $(DISTNAME)/doc/releasenotes
	tar cvf $(DISTNAME)/files.tar --files-from=MANIFEST
	( cd $(DISTNAME) && tar xvf files.tar && rm files.tar )	
	cp -a  ./doc/releasenotes/note_$(VERSION).html $(DISTNAME)/doc/releasenotes
	cp -a  $(docdir)/* $(DISTNAME)/doc

package-gzip:
	tar cvfz $(DISTNAME).tar.gz $(DISTNAME)
	mv $(DISTNAME).tar.gz $(exportdir)
	rm -rf $(DISTNAME)

package-zip:
	zip -r $(exportdir)/$(DISTNAME).zip $(DISTNAME)		

package-rpm:
	@echo "*** Execute the makefile in ./rpm as superuser ****" 

package-clean-gnu:
	$(RM) $(DISTNAME)

## Build a windows/dos distribution
package-win32: clean
	cmd /c "C:\Programme\Inno Setup 4\iscc" win32\gnade.iss >var/build.log
	$(CP) $(subst /,$(PATHSEP),Output/setup.exe $(exportdir)/setup-gnade-$(VERSION).exe)
	$(RMDIR) Output

package-clean-win32:

## ############################################################################ ##
## Create the test database 
## ############################################################################ ##
createdb createuser removeuser removedb:
	$(MAKE) -C./samples/smaple_db DATABASE=$(DATABASE) $@

## ############################################################################ ##
## install the sofware in the system
## ############################################################################ ##
install :: shared-all 
	./bin/gnadeinst.sh --force

## ############################################################################ ##
## CLEANUP SECTION                                                              ##
## ############################################################################ ##

##
## clean up the  distribution
##
distclean :: clean clean-standalone
	$(MAKE) remove-directories
	$(RM) gnade.gpr
	$(RM) make.conf
	$(RM) gnade-*.*.tar.gz
	$(RM) gnade-*.*.zip
	$(RM) config.* *~ .configure configure.log
##
## Cleanup some subdirs but no all!
##
clean ::
ifeq ($(BUILDENV),gnu)
	$(MAKE) -C./autoconf $@
	$(MAKE) -C./pkg-config $@
	$(MAKE) -C./cfg $@
	$(MAKE) -C./bin $@
endif
##
## Perfom a local clean up
##
clean ::
	$(MAKE) -C./cfg clean
	$(RM) *~*~ *~

##
## clean out the standalone example. This example does not know anything
## about the operating system.
##
clean-standalone:
	$(RM) $(subst /,$(PATHSEP),samples/standalone/*.ali)
	$(RM) $(subst /,$(PATHSEP),samples/standalone/*.o)
	$(RM) $(subst /,$(PATHSEP),samples/standalone/*~*~)
	$(RM) $(subst /,$(PATHSEP),samples/standalone/*~)

##
## publish towards sourceforge
##
publish:
	-ncftpput  upload.sourceforge.net  /incoming $(exportdir)/$(DISTNAME).zip
	-ncftpput  upload.sourceforge.net  /incoming $(exportdir)/$(DISTNAME).tar.gz
