## This file is part of Moonlight Creator
##   Copyright (C) 1996-1998  Stephane Rehel
##
## This library 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 library 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

KSUBDIRS=$(TOOLS_DIR) $(IMAGE_DIR) $(GRAPHICS_DIR) $(KOALA_DIR) $(KW_DIR)

SUBDIRS=$(KSUBDIRS) \
        $(INTERFACE_DIR) \
        $(MODS_DIR)

all: dirs libs _ml

dirs: $(BIN_DIR) $(LIB_DIR)

$(BIN_DIR):
	mkdir -p $(BIN_DIR)

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

klibs:
	@set -e; for i in $(KSUBDIRS); do $(MAKE) -C $$i || exit 1; done

libs:
	@set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i || exit 1; done

relibs:
	@set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i libs || exit 1; done

ml: libs
	$(MAKE) -C $(MAIN_DIR)

_ml:
	$(MAKE) -C $(MAIN_DIR)

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

realclean: clean
	$(RM) -rf $(BIN_DIR)/*
	$(RM) -rf $(LIB_DIR)/*

mrproper:
	$(RM) -rf $(AI_BIN_DIR)/
	$(RM) -rf $(AI_LIB_DIR)/
	@set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i $@; done
	$(MAKE) -C $(MAIN_DIR) $@

dep: depend

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

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 ; \
	for i in ./GL $(SUBDIRS) ./tests ; \
	  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

#config:
#	@echo "/* config.h: Automatically generated by make config: don't edit */" > $(CONFIG_FILE)
#	@echo >> $(CONFIG_FILE)
#	@echo "#ifndef __ML_CONFIG_H" >> $(CONFIG_FILE)
#	@echo "#define __ML_CONFIG_H" >> $(CONFIG_FILE)
#	@echo >> $(CONFIG_FILE)
#	@echo " #define __$(CONFIG_NAME)__" >> $(CONFIG_FILE)
#	@echo " #define __X11__" >> $(CONFIG_FILE)
#	@echo >> $(CONFIG_FILE)
#	@echo "#endif /* ifndef __ML_CONFIG_H */" >> $(CONFIG_FILE)
#	@echo Configured for:
#	@cat $(CONFIG_FILE) | grep " #define"

install:
	if [ ! -d $(INSTALL_DIR)/$(VERSION) ] ; then \
	 mkdir $(INSTALL_DIR)/$(VERSION) ; \
	 fi
	if [ ! -d $(INSTALL_DIR)/$(VERSION)/bin ] ; then \
	 mkdir $(INSTALL_DIR)/$(VERSION)/bin ; \
	 fi
	cp $(INTERFACE_NAME) $(INSTALL_DIR)/$(VERSION)/bin/
	rm -f $(INSTALL_DIR)/current
	ln -s $(INSTALL_DIR)/$(VERSION) $(INSTALL_DIR)/current

INSTALL_PROGRAMS1=ml dxf2ml asc2ml off2ml
INSTALL_PROGRAMS=$(addprefix ../bin/system/O1/,$(INSTALL_PROGRAMS1))

distrib:
	$(SBIN_DIR)/make_distrib $(TOPDIR) \
                          $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) \
                          $(AI_BIN_DIR)/$(OSARCH)/O1

distclean: mrproper
	$(RM) config.h config.status config.log config.cache \
       Makeconfig libtool conftests.subs version.h


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