## This file is part of Moonlight Creator
##   Copyright (C) 1996-1998  Stephane Rehel
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU Library 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
## Library General Public License for more details.
##
## You should have received a copy of the GNU Library General Public
## License along with this library; if not, write to the Free
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


############################################################################
# ML
# Global Makefile
#
# Stephane Rehel
# Created: June 28, 1996
#
############################################################################

ifneq (,)
This makefile requires GNU Make.
endif

TOPDIR=.

include $(TOPDIR)/Makenames

KERNEL_SUBDIRS=tools image kernel

SUBDIRS=$(KERNEL_SUBDIRS) koalagui 3D kbuilder photo
# tcl oom

all: $(LIB_DIR) ml

$(LIB_DIR):
	mkdir -p $(LIB_DIR)

subdirs:
	@set -e; for i in $(SUBDIRS) ; do $(MAKE) -C $$i ; done

_ml:
	$(MAKE) -C main

ml: subdirs _ml

# clean up objects and dependency files
clean:
	@set -e; for i in $(SUBDIRS) ; do $(MAKE) -C $$i $@ ; done

# clean up objects, dependency files, libraries, executables
realclean:
	$(RM) `find . -name .depend -print`
	$(RM) `find . -name .depend-opt -print`
	$(RM) `find . \( -name '#*#' -o -name '*~' \
               -o -name '*.o' -o -name '*.lo' \) -print`
	$(RM) -rf $(BIN_DIR)
	$(RM) -rf $(LIB_DIR)

# same as realclean for all targets
distclean: realclean
	$(RM) -rf $(AI_BIN_DIR)
	$(RM) -rf $(AI_LIB_DIR)
	$(MAKE) -C main $@
	$(MAKE) -C koalagui/tests $@
	$(MAKE) config-clean

config-clean:
	$(RM) config.h config.status config.log config.cache \
       Makeconfig libtool conftests.subs version.h moonlightrc

mkconf-clean: config-clean
	$(RM) config.h.in libtool configure aclocal.m4

dep:
	@set -e; for i in $(SUBDIRS) ; do $(MAKE) -C $$i $@ ; done

depend: dep

lines:
	wc `find . \(      -name \*.[Cch] \
              -a \! -name \*Dlg.C \
              -a \! -name mllogo1.C \
              -a \! -name mllogo2.C \
              -a \! -name Cosmic10Font.C \
            \) -print`

mlines:
	@TOTAL=0 ; \
	dirs="$(SUBDIRS) tcl photo oom" ; \
	dirs=`ls -1d $$dirs | while read line ; do basename $$line ; done | sort | uniq` ;\
	for i in $$dirs ; \
	  do \
	  FILES=`find $$i/. \(      -name \*.[Cch] \
	                      -a \! -name \*Dlg.C \
	                      -a \! -name mllogo1.C \
	                      -a \! -name mllogo2.C \
	                      -a \! -name Cosmic10Font.C \
	                    \) -print` ; \
	  LINES=`wc -l $$FILES | tail -1 | awk '{ print $$1 }'` ; \
	  printf "%6d %s\n" $$LINES $$i ; \
	  TOTAL=`expr $$TOTAL + $$LINES` ; \
	  done ; \
	  printf "%6d total\n" $$TOTAL

LIBS_TO_INSTALL=$(sort $(wildcard $(LIB_DIR)/*.la $(PLUGIN_DIR)/*.la))

install-libs-plugins:
ifneq ($(WINDOWS),yes)
	$(mkinstalldirs) $(ml_libdir)
	set -e ; \
 for i in $(LIBS_TO_INSTALL) ; \
   do \
   $(LIBTOOL) --mode=install $(INSTALL) $$i $(ml_libdir) ; \
   done
endif
	$(LIBTOOL) --mode=finish $(ml_libdir)

install-program:
	$(mkinstalldirs) $(bindir)
ifeq ($(WINDOWS),yes)
	set -e ; cd main ; \
	$(INSTALL_PROGRAM) .libs/$(PROGRAM_NAME).exe $(bindir)
else
	set -e ; cd main ; \
 $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $(PROGRAM_NAME) $(bindir)
	$(RM) $(bindir)/$(ML_BASENAME)
	cd $(bindir) ; \
 $(LN_S) $(ML_BASENAME)-$(VERSION) $(ML_BASENAME)
endif

install-data:
	$(mkinstalldirs) $(sysconfdir)
	$(INSTALL_DATA) moonlightrc $(sysconfdir)
	$(mkinstalldirs) $(datadir)/moonlight/database
	$(mkinstalldirs) $(datadir)/moonlight/database/GEOMETRIES
	$(mkinstalldirs) $(datadir)/moonlight/database/HIERARCHIES
	$(mkinstalldirs) $(datadir)/moonlight/database/IMAGES
	$(mkinstalldirs) $(datadir)/moonlight/database/MATERIALS
	$(mkinstalldirs) $(datadir)/moonlight/database/PROJECTS
	$(mkinstalldirs) $(datadir)/moonlight/database/SCENES
	$(mkinstalldirs) $(datadir)/moonlight/database/TT_FONTS
	$(INSTALL_DATA) ../tt_fonts/* $(datadir)/moonlight/database/TT_FONTS

install: $(ML_NAME) install-libs-plugins install-program install-data

############################################################################
#
# Global Makefile end
#
############################################################################
