# Makefile -- makefile for gnucash
# Copyright (C) 1997 Robin Clark                                   
# Copyright (C) 1998 Rob Browning <rlb@cs.utexas.edu>
#                                                                  
# This program is free software; you can redistribute it and/or    
# modify it under the terms of the GNU General Public License as   
# published by the Free Software Foundation; either version 2 of   
# the License, or (at your option) any later version.              
#                                                                  
# This program is distributed in the hope that it will be useful,  
# but WITHOUT 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
# along with this program; if not, write to the Free Software      
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.        
#                                                                  
#   Author: Robin Clark                                            
# Internet: rclark@rush.aero.org                                   
#  Address: 609 8th Street                                         
#           Huntington Beach, CA 92648-4632                        

SHELL=/bin/bash
export SHELL

srcdir  = @srcdir@
VPATH   = @srcdir@

prefix=@prefix@
datadir=@datadir@
  # i.e. /usr/share
localstatedir=@localstatedir@
  # i.e. /var/
sysconfdir=@sysconfdir@
  # i.e. /etc/

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
CPU     = @target_cpu@

LIBS=@LIBS@

######################################################################
# Description of targets:
#
#   default      -- make the application
#   depend       -- generate the dependencies
#   clean        -- remove *.a, *.o, *.bak, and *~
#   distclean    -- get rid of config files too...
#   install      -- installs everything

default:
	@echo " "
	@echo "Please choose one of the following targets:"
	@echo "motif           dynamically linked motif version"
	@echo "motif-static    statically linked motif version"
	@echo "gnome           gnome/gtk version"
	@echo "gnome-static    gnome/gtk statically linked version"
	@echo "qt              kde/qt version"
	@echo " "

# Aliases
motif-static: motif.static
gnome-static: gnome.static

build-flavor:
	@cd lib;    $(MAKE) ${FLAVOR}
	@cd src;    $(MAKE) ${FLAVOR}
	ln -sf gnucash.${FLAVOR} gnucash.bin
	(cd share && ln -sf ../src/scm scm)

motif:
	${MAKE} FLAVOR=motif build-flavor

motif.static:
	${MAKE} FLAVOR=motif.static build-flavor

gnome:
	${MAKE} FLAVOR=gnome build-flavor

gnome.static:
	${MAKE} FLAVOR=gnome.static build-flavor

qt:
	${MAKE} FLAVOR=qt build-flavor

depend:
	@echo make depend is now superfluous.

clean:
	rm -f *~ *.o *.bak
	@cd lib;    $(MAKE) clean
	@cd src;    $(MAKE) clean

distclean: clean
	rm -f *~ *.o *.bak Makefile share/scm gnucash.bin
	rm -f gnucash gnucash.motif gnucash.motif.static \
	gnucash.gnome gnucash.gnome.static gnucash.qt
	rm -f config.cache config.log config.status config.h
	rm -f src/guile/path-defaults.h    
	@cd lib;    $(MAKE) distclean
	@cd src;    $(MAKE) distclean

tagsfiles := $(shell find -name "*.[ch]")

TAGS: ${tagsfiles}
	etags ${tagsfiles}    

install:
	${MAKE} \
    DOCDIR=${prefix}/doc/gnucash \
    BINDIR=${prefix}/bin \
    CONFIGDIR=${sysconfdir}/gnucash \
    SHAREDIR=${datadir}/gnucash \
    install-private

install-opt:
	${MAKE} \
    DOCDIR=${prefix}/doc \
    BINDIR=${prefix}/bin \
    CONFIGDIR=${sysconfdir} \
    SHAREDIR=${datadir} \
    install-private

# We have to re-build the binary here to pick up any modifications to
# the ./configure configuration and to accomodate install vs
# install-opt.  The other option would be to always use a wrapper
# script, even in the install tree, but that's IMO uglier.

# We could get rid of some redundant rebuilds with a
# stamp-install-opt-build, but that's somewhat messy too.
gnucash.motif gnucash.motif.static gnucash.gnome gnucash.gnome.static:
	@echo Rebuilding binary to handle install site specific dependencies. 
	rm -f gnucash.${FLAVOR} src/guile/path-defaults.h    
	${MAKE} DOCDIR=${DOCDIR} BINDIR=${BINDIR} CONFIGDIR=${CONFIGDIR} \
          SHAREDIR=${SHAREDIR} ${FLAVOR}
.PHONY: gnucash.motif gnucash.motif.static gnucash.gnome gnucash.gnome.static


install-bin: gnucash.${FLAVOR}
	$(INSTALL) gnucash.${FLAVOR} ${BINDIR}/gnucash.${FLAVOR}
	(cd ${BINDIR} && ln -sf gnucash.${FLAVOR} gnucash)

install-private:
	@mkdir -p ${BINDIR}

  # Put these in the opposite order of precedence.  Final bin/gnucash link will
  # point to the last one that exists...
	-[ -e gnucash.qt ] && ${MAKE} FLAVOR=qt BINDIR=${BINDIR} install-bin
	-[ -e gnucash.gnome.static ] && \
     ${MAKE} FLAVOR=gnome.static BINDIR=${BINDIR} install-bin
	-[ -e gnucash.gnome ] && ${MAKE} FLAVOR=gnome BINDIR=${BINDIR} install-bin
	-[ -e gnucash.motif.static ] && \
     ${MAKE} FLAVOR=motif.static BINDIR=${BINDIR} install-bin
	-[ -e gnucash.motif ] && ${MAKE} FLAVOR=motif BINDIR=${BINDIR} install-bin

  # Make sure at least one succeeded
	[ \
    -e ${BINDIR}/gnucash.motif -o \
    -e ${BINDIR}/gnucash.motif.static -o \
    -e ${BINDIR}/gnucash.gnome -o \
    -e ${BINDIR}/gnucash.gnome.static -o \
    -e ${BINDIR}/gnucash.qt \
  ]

# 	@mkdir -p $(prefix)/toolbar
# 	$(INSTALL_DATA) toolbar/*.xpm $(prefix)/toolbar

	@mkdir -p ${DOCDIR}
	$(INSTALL_DATA) Docs/*.html ${DOCDIR}
	$(INSTALL_DATA) Docs/*.gif ${DOCDIR}
#	$(INSTALL_DATA) Docs/*.jpg ${DOCDIR}
	$(INSTALL_DATA) Docs/*.xpm ${DOCDIR}
	@mkdir -p ${DOCDIR}/logos
	$(INSTALL_DATA) Docs/logos/*.* ${DOCDIR}/logos

  # Config directory
	@mkdir -p ${CONFIGDIR}

  # Try to do this in a platform independent way...
  # Directories
	for dir in `find etc/ -type d`; do \
    dest=`echo $$dir | cut -c 5-` \
		mkdir -p ${CONFIGDIR}/$$dest; \
  done

  # Files
	for file in `find etc/ -type f`; do \
    dest=`echo $$file | cut -c 5-` \
		${INSTALL_DATA} $$file ${CONFIGDIR}/$$dest; \
  done

  # Share directory
	@mkdir -p ${SHAREDIR}

  # Try to do this in a platform independent way...
  # Directories
	for dir in `find share/scm/ -type d`; do \
    dest=`echo $$dir | cut -c 11-` \
		mkdir -p ${SHAREDIR}/scm/$$dest; \
  done

  # Files
	for file in `find share/scm/ -name "*.scm"`; do \
    dest=`echo $$file | cut -c 11-` \
		${INSTALL_DATA} $$file ${SHAREDIR}/scm/$$dest; \
  done

.PHONY: default install-private install motif motif-static gnome gnome-static qt
.PHONY: depend clean distclean

# Local Variables:
# tab-width: 2
# End: