#
# common
#
# This file is the common Makefile for all C/C++ modules in graphlet
#
#------------------------------------------
#
# $Source: /home/br/CVS/graphlet/lib/graphlet/config/common,v $
# $Author: himsolt $
# $Revision: 1.3 $
# $Date: 1999/08/05 16:45:09 $
# $Locker:  $
# $State: Exp $
#
#------------------------------------------
#
# (C) University of Passau 1995-1999, graphlet project
#

it: all

# FORCE:	

##########################################
#
# This module needs the following external names:
# MODULE = Name of the module
# GRAPHLET_BASE_DIR = Directory where graphlet starts, relative
#                e.g. ../..
#
# *Note:* GRAPHLET_BASE_DIR must be set in each Makefile
#
##########################################

#
# Directories
#

include $(GRAPHLET_BASE_DIR)/lib/graphlet/config/config
include $(GRAPHLET_BASE_DIR)/lib/graphlet/config/system-specs
include $(GRAPHLET_BASE_DIR)/lib/graphlet/config/config-details




##########################################
#
# MYFILES are all files generated by the user
#
##########################################


MYFILES= GNUmakefile $(TCLFILES) $(MYCFILES) $(HFILES) $(LFILES) $(YFILES)

# The follwing target is used to output $(MYFILES)

.PHONY:	myfiles
myfiles:
	@echo "MYFILES=$(MYFILES)"



##########################################
#
# The next line generates the names of the object files from the
# source files
#
##########################################


OFILES= $(CFILES:%.cpp=%.o)



##########################################
#
# Generate the module library
#
##########################################

#
# Mangle the path so that libraries can be found
#

ifdef LD_PATH_OPTION
    LDFLAGS += $(LD_PATH_OPTION)$(INSTALL_LIB_DIR)
endif
LDFLAGS += -L$(GRAPHLET_LIB_DIR) 

#
# Name of the library
#

ifndef GT_SUPPORT_SHARED_LIBRARIES
    LIBMODULE = $(GRAPHLET_LIB_DIR)/lib$(MODULE).a
else
    ifeq ($(LINKING),static)
        LIBMODULE = $(GRAPHLET_LIB_DIR)/lib$(MODULE).a
    else
        LIBMODULE = $(GRAPHLET_LIB_DIR)/lib$(MODULE).so
    endif
endif

#
# make_library is the STANDARD target for all modules which
# assemble a library.
#

make_library:	$(LIBMODULE)


#
# Static Libraries
#

$(GRAPHLET_LIB_DIR)/lib$(MODULE).a:	$(OFILES)
	$(MAKE_LIBRARY) $?
ifneq ($(strip $(RANLIB)),)
	$(RANLIB) $@
endif

#
# Shared Libraries
#

$(GRAPHLET_LIB_DIR)/lib$(MODULE).so:	$(OFILES)
	$(MAKE_SHARED_LIBRARY) $(OFILES)


##########################################
#
# CLEANING UP
#
##########################################

CLEANINGDUMMY = cleaning.dummy

CLEANFILES += \
	$(LFILES:%.l=%.cpp) \
	$(YFILES:%.y=%.cpp) $(YFILES:%.y=%.h) \
	*.tmp *~ tclIndex pkgIndex.tcl x xx xxx y yy yyy z zz zzz junk ir.out 

clean:	clean.local
ifneq ($(strip $(SUBDIRS)),)
	$(MAKE) $(SUBDIRS) TARGET=$@
endif

.PHONY: clean.local
clean.local::
	touch $(CLEANINGDUMMY); \
	$(RM) $(CLEANINGDUMMY) $(OFILES) $(GRAPHLET_LIB_DIR)/lib$(MODULE).a $(GRAPHLET_LIB_DIR)/lib$(MODULE).so $(CLEANFILES); \
	if [ -d Templates.DB ]; then \
		$(RM) -r Templates.DB; \
	fi




##########################################
#
# Automatic dependency generation
#
##########################################


depend::
	if [ -n "$(MYCFILES)$(HFILES)$(LFILES)$(YFILES)" ]; then \
		$(MAKE_DEPEND) $(INCLUDES) \
			$(MYCFILES) $(LFILES) $(YFILES) $(DEPENDFILES) \
			> GNUmakefile.depend ; \
	fi
ifneq ($(strip $(SUBDIRS)),)
	$(MAKE) $(SUBDIRS) TARGET=$@
endif



##########################################
#
# Counting ...
#
##########################################


count::
	wc $(MYFILES)



##########################################
#
# Automatic Subdirectory recursion
#
##########################################


.PHONY:	$(SUBDIRS)
$(SUBDIRS)::	
	$(MAKE) -C $@ $(TARGET)



##########################################
#
# Automatic Installation
#
##########################################

install.target:	install.local
ifneq ($(strip $(SUBDIRS)),)
	$(MAKE) $(SUBDIRS) TARGET=install.target
endif

install.local::


# Automatic library installation

install.library::	 $(GRAPHLET_LIB_DIR)/lib$(MODULE).a
	$(INSTALL_MAKE_DIR) $(INSTALL_LIB_DIR)
	$(INSTALL_FILE) $(GRAPHLET_LIB_DIR)/lib$(MODULE).a $(INSTALL_LIB_DIR)

ifdef GT_SUPPORT_SHARED_LIBRARIES

install.library::	$(GRAPHLET_LIB_DIR)/lib$(MODULE).so
	$(INSTALL_FILE) $(GRAPHLET_LIB_DIR)/lib$(MODULE).so $(INSTALL_LIB_DIR)

else

install.library::	$(GRAPHLET_LIB_DIR)/lib$(MODULE).a
	$(INSTALL_FILE) $(GRAPHLET_LIB_DIR)/lib$(MODULE).a $(INSTALL_LIB_DIR)
ifneq ($(strip $(RANLIB)),)
	$(RANLIB) $(INSTALL_LIB_DIR)/lib$(MODULE).a
endif

endif


.PHONY: install.headers
install.headers:	
	$(INSTALL_MAKE_DIR) $(INSTALL_INCLUDE_DIR)/$(MODULE)
ifneq ($(HFILES),)
	$(INSTALL_FILE) $(HFILES) $(INSTALL_INCLUDE_DIR)/$(MODULE)
else
	$(INSTALL_FILE) $(CFILES:%.cpp=%.h) $(INSTALL_INCLUDE_DIR)/$(MODULE)
endif



##########################################
#
# Utilities
#
##########################################

#
# showversion
#

.PHONY:	showversion
showversion:
	@echo $(VERSION)

#
# html -> text conversion
#

.SUFFIXES: .html
.html:
	$(LYNX) -dump $< > $@



##########################################
#
# C Compiler Stuff
#
##########################################

#
# Add a new rule to understand the ".cpp" ending since most
# Windows compilers use this (aaaarrrrgggghhhh).
#

.SUFFIXES: .cpp

.cpp.o:
	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<


CXX=$(CCC)
CC=$(CCC)

ifndef GT_EXTERNAL
    INCLUDES += -I$(GRAPHLET_BASE_DIR)/src
else
    INCLUDES += -I$(GRAPHLET_BASE_DIR)/include
endif

#
# C Compiler flags
#

CCFLAGS += $(OPT) $(WARN) $(DBX) $(INCLUDES)
CXXFLAGS = $(CCFLAGS)

ifeq ($(strip $(LINKING)),static)
    CCFLAGS += -DGT_STATIC_LINKING
endif


##########################################
#
# Tcl / Tk
#
##########################################


INCLUDES += -I$(TK_INCLUDE_DIR) -I$(TCL_INCLUDE_DIR)

ifeq ($(LINKING),static)
    LDFLAGS += $(START_STATIC_LINKING)
endif

LDFLAGS  += \
    -L$(TK_LIB_DIR)  -l$(TK_LIB) \
    -L$(TCL_LIB_DIR) -l$(TCL_LIB)

ifeq ($(LINKING),static)
    LDFLAGS += $(END_STATIC_LINKING)
endif

LD_PATH += $(LD_PATH_OPTION)$(TK_LIB_DIR) $(LD_PATH_OPTION)$(TCL_LIB_DIR)


##########################################
#
# AGD
#
##########################################

ifneq ($(filter gt_agd,$(EXTENSION_MODULES)),)
    INCLUDES += -I$(AGD_INCLUDE_DIR)
    LDFLAGS += -L$(AGD_LIB_DIR) $(AGD_LIBRARIES)
endif


##########################################
#
# GTL
#
##########################################

INCLUDES += -I$(GTL_INCLUDE_DIR)

ifeq ($(LINKING),static)
    LDFLAGS += $(START_STATIC_LINKING)
endif

LDFLAGS += -L$(GTL_LIB_DIR) $(GTL_LIBRARIES)

ifeq ($(LINKING),static)
    LDFLAGS += $(END_STATIC_LINKING)
endif

LD_PATH += $(LD_PATH_OPTION)$(GTL_LIB_DIR)


##########################################
#
# X11
#
##########################################


INCLUDES += -I$(X11INCLUDE)

LDFLAGS  += -L$(X11LIB) -lX11

LD_PATH  += $(LD_PATH_OPTION)$(X11LIB)


##########################################
#
# Final adjustments
#
##########################################

#
# Add operating system specific libraries + math library
#

LDFLAGS += $(OSLIBS) -lm



##########################################
#
# Set emacs variables
#
##########################################

# ;;; Local Variables: ***
# ;;; mode: makefile ***
# ;;; End: ***
