## 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
# main/Makefile
#
# Stephane Rehel
# June 29 1996
#
############################################################################

TOPDIR=..
SUBDIRS=
LIBRARY=

include $(TOPDIR)/Makenames

SRCS= main.C

PLUGINS_DEP_LIBS= \
$(shell \
  plugin_dependency_libs="" ; \
  cd $(PLUGIN_DIR) ; \
  for i in `ls *.la` ; \
    do \
    pdl=`. $$i ; \
         if [ "$$dlname" != "" ]; then echo $$dependency_libs; fi` ; \
    plugin_dependency_libs="$$plugin_dependency_libs $$pdl" ; \
    done ; \
  echo $$plugin_dependency_libs ; \
 )

DEP_LA_LIBS= \
$(addprefix $(LIB_DIR)/lib$(LIB_MOON_PREFIX), \
$(addsuffix .la, \
$(sort \
$(shell \
  plugin_dependency_la_libs="" ; \
  cd $(PLUGIN_DIR) ; \
  dep_files="*.la.dep" ; \
  if test "$$dep_files" != "" ; then \
    cat $$dep_files ; \
  fi \
 ) \
)))

#    for j in $$pdl ; \
#      do \
#      if [ "`echo $$plugin_dependency_libs | grep -- $$j`" = "" ]; then \
#        plugin_dependency_libs="$$plugin_dependency_libs $$j" ; \
#      fi ; \
#      done ;

ifeq ($(WINDOWS),yes)
all: windows
else
all: $(PROGRAM_NAME)
endif

LOCAL_DEFINES=
LOCAL_INCLUDES=

include $(MAKERULES)

$(LIB_DIR)/stamp-libs: $(LIBRARIES)

$(PROGRAM_NAME): $(OBJ_DIR) $(OBJS) $(LIB_DIR)/stamp-libs
	@echo --
	@echo ---------- Main executable $(PROGRAM_NAME) ----------
	@echo --
	@echo "PLUGINS_DEP_LIBS: $(PLUGINS_DEP_LIBS)"
	@echo "DEP_LA_LIBS: $(DEP_LA_LIBS)"
	$(LIB_LINK) --mode=link $(CC) -o $(PROGRAM_NAME) $(LDFLAGS) $(LOBJS) \
 $(DEP_LA_LIBS) $(PLUGINS_DEP_LIBS)
	set -e ; \
 CUR_PWD=`pwd` ; \
 mkdir -p $(AI_BIN_DIR) ; \
 cd $(AI_BIN_DIR) ; \
 $(RM) $(ML_BASENAME) ; \
 $(LN_S) $$CUR_PWD/$(PROGRAM_NAME) $(ML_BASENAME)
	@$(INCBUILD) ml

windows: $(OBJ_DIR) $(OBJS) $(LIB_DIR)/stamp-libs
	mkdir -p .libs
	gcc -o .libs/$(PROGRAM_NAME).exe $(OBJS) \
 $(LIB_DIR)/.libs/libmoon_kmodel.a \
 $(LIB_DIR)/.libs/libmoon_scene.a \
 $(LIB_DIR)/.libs/libmoon_koalagui.a \
 $(LIB_DIR)/.libs/libmoon_image.a \
 $(LIB_DIR)/.libs/libmoon_kernel.a \
 $(LIB_DIR)/.libs/libmoon_tools.a \
 -L/usr/local/lib -lgltt -lttf -lz -ltiff -ljpeg \
 -lopengl32 -lglu32 -lkernel32 -luser32 -lgdi32 -lm

distclean: clean
	$(RM) -rf obj .libs $(PROGRAM_NAME) moonlight-*.*.*

############################################################################
#
# main/Makefile end
#
############################################################################
