# $Id: Makefile,v 1.5 1998/08/30 01:23:18 taylorj Exp $
# -----------------------------------------------------------------------------
#
#	Copyright (C) 1997 by The GGI Project
#
# -----------------------------------------------------------------------------
#
#	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, or 
#	(at your option) any later version.
#
#	You should have received a copy of the GNU Library General Public 
#	License	along with this program; see the file COPYING.LGPL .  
#	If not, write to the Free Software Foundation, 675 Mass Ave, 
#	Cambridge, MA 02139, USA.
#
# ----------------------------------------------------------------------------

VERSION=$(shell cat ./.version)
SOMAJOR=$(shell cat ./.version | cut -d. -f1)
SOMINOR=$(shell cat ./.version | cut -d. -f2-)
SHLIB=libggi3d.$(DLLEXT).$(SOMAJOR).$(SOMINOR)
SONAME=libggi3d.$(DLLEXT).$(SOMAJOR)
BINNAME=libggi3d-$(SOMAJOR).$(SOMINOR)
LIBGGI3DCONF=libggi3d.conf
TARBALL=$(BINNAME)-bin.tar
BINPACKAGE=$(BINNAME).install
FINDDLLS=find $(BINNAME)/ -name \*.so -path \*dll/\*

SUBDIRS=display default

SOURCES=main.c gc.c stubs.c 
#debug.c

LIBGGI_TOPLEVEL=$(shell pwd)
LIBGGI3D_TOPLEVEL=$(shell pwd)
TOPLEVEL=$(shell cd ../../ ; pwd)
CONFLEVEL=$(LIBGGI_TOPLEVEL)/../../config

include $(CONFLEVEL)/rules/defs

MFLAGS += GGILIBS=$(GGILIBS)

# make config the default target if no configuration file exists

ifeq ($(LIBGGI_TOPLEVEL)/.config,$(wildcard $(LIBGGI_TOPLEVEL)/.config))
include $(LIBGGI_TOPLEVEL)/.config
else
default-target: config
endif

include Makerules

$(LIBGGI3DCONF):: templates/libggi3d.conf.templ
	cat templates/libggi3d.conf.templ | sed -e "s|CONFDIR|$(CONFDIR)|g" -e "s|GGIDIR|$(PREFIX)/lib/ggi|g" > libggi3d.conf

install::
	$(MKDIRTREE) $(INST_CONFIG)
	$(MKDIRTREE) $(INST_LIB)
	$(MKDIRTREE) $(INST_INCLUDE)
	install libggi3d.conf $(INST_CONFIG)
	$(INSTALL) $(SHLIB) $(INST_LIB)
	ln -sf $(SHLIB)  $(INST_LIB)/$(SONAME)
	ln -sf $(SONAME) $(INST_LIB)/libggi3d.$(DLLEXT)
	$(INSTALL) -m 0644 include/ggi/ggi3d.h $(INST_INCLUDE)
	$(LDCONFIG)

$(SHLIBGGI3D):: $(SHLIBOBJECTS)
	$(SHLIBLINKER) $(_SHLIBLDFLAGS) -o $@ $(SHLIBOBJECTS)
	rm -f $(SONAME) libggi3d.$(DLLEXT)
	ln -s $@ $(SONAME)
	ln -s $@ libggi3d.$(DLLEXT)

demos:
	$(MAKE) -C demos $(MFLAGS)

config:
	./configure

