# This file has been generated automatically.  Modify at your own risk!

# Makefile for STELLA.
# Uses various constructs only supported by GNU make!

# Template version: Makefile.in,v 1.10 2006/05/16 06:39:08 hans Exp

SYSTEMS-ROOT = ..
STELLA-ROOT = ../stella

# g++ settings:
CXX    = g++
CC     = gcc
CFLAGS = -w -g -O2 -fno-common

# Some versions of Unix and/or gcc need special switches; see what we have:
OS = $(shell if gcc --version | grep -iq "CYGWIN"; then echo "CYGWIN"; \
             elif gcc --version | grep -iq "MINGW"; then echo "MINGW"; \
             elif uname | grep -iq "DARWIN"; then echo "DARWIN"; \
             elif uname | grep -iq "SUNOS"; then echo "SUNOS"; \
             else echo "UNIX"; fi)

# Should be one of `static' or `dynamic'.  Dynamic linking under CygWin &
# MinGW doesn't seem to work (easily), so we force static linking there:
LINK-MODE =  $(shell if [ $(OS) = CYGWIN -o $(OS) = MINGW ]; \
                   then echo static; \
                   else echo dynamic; fi)

# Comment GC-SWITCHES and GC-LIBS (or reset them from the `make' command line)
# to not use the garbage collector.  This also requires a recompilation of
# all systems that use STELLA with the same settings.
GC-DIR = $(STELLA-ROOT)/cpp-lib/gc
GC-SWITCHES = -DSTELLA_USE_GC
GC-CFLAGS = $(GC-SWITCHES) -I$(GC-DIR)/include
GC-LIBS = -lgc $(shell if [ $(LINK-MODE) = dynamic ]; then echo -ldl; fi)
GC-LIB-DIR = $(GC-DIR)/.libs
GC-LDFLAGS = -L$(GC-LIB-DIR)

override INCLUDE += -I$(SYSTEMS-ROOT)

LDFLAGS = # -pg
MINGW-LIBS = $(shell if [ $(OS) = MINGW ]; then echo -liberty; fi)
OTHER-LIBS = -lm $(MINGW-LIBS)

# Leave this as is if one of the system source files has a `defmain' entry.
# Otherwise, or if you want to use your own `main' function, supply the .cc
# file here that defines `main':
MAIN =    main.cc
PROG =    stella

LIB-DIR  = $(SYSTEMS-ROOT)/lib
# Would need .dll for dynamic libraries under Windows: 
LIB-TYPE = $(shell if [ $(LINK-MODE) = static ]; \
	           then echo .a; \
                   elif [ $(OS) = "DARWIN" ]; \
                   then echo .dylib; \
                   else echo .so; fi)
LIB-FILE = $(LIB-DIR)/libstella$(LIB-TYPE)
LIB      = -L$(LIB-DIR) -lstella

# Linker flags to generate a shared library.
# The incantation below works with g++ on Linux, MacOS X and SunOS.
LIB-SHARED-FLAGS = $(shell if [ $(OS) = "SUNOS" ]; \
                           then echo -Xlinker -G; \
                           elif [ $(OS) = "DARWIN" ]; \
		           then echo -dynamiclib; \
                           else echo -shared; fi)

# For dynamic linking, tell the runtime linker where the libraries are via an
# rpath option; we use a relative and an absolute location to be able to move
# around a bit (for the absolute version we have to worry about spaces, etc.);
# if everything fails we can still set LD_LIBRARY_PATH at runtime:
RPATH  = $(LIB-DIR):$(shell cd $(LIB-DIR); pwd):$(GC-LIB-DIR):$(shell cd $(GC-LIB-DIR); pwd)
# Linker flags to define shared library path (covers Linux, MacOS X and SunOS):
RPATH-FLAGS = $(shell if [ $(OS) = "SUNOS" ]; \
                      then echo -Xlinker -R -Xlinker \'$(RPATH)\'; \
	              elif [ $(OS) = "DARWIN" ]; \
	              then echo ""; \
                      else echo -Xlinker -rpath -Xlinker \'$(RPATH)\'; fi)

LIB-SRCS =   hierarchy.cc streams.cc taxonomies.cc primal.cc type-predicates.cc conses.cc lists.cc collections.cc iterators.cc symbols.cc literals.cc classes.cc methods.cc defclass.cc date-time.cc date-time-parser.cc stella-in.cc foreach.cc walk.cc cl-translate.cc cl-translate-file.cc dynamic-slots.cc dynamic-literal-slots.cc modules.cc contexts.cc read.cc xml.cc macros.cc memoize.cc demons.cc more-demons.cc name-utility.cc translate-file.cc systems.cc describe.cc cpp-translate-file.cc cpp-translate.cc cpp-class-out.cc cpp-output.cc java-translate-file.cc java-translate.cc java-class-out.cc java-output.cc idl-translate.cc idl-class-out.cc idl-translate-file.cc idl-output.cc tools.cc startup.cc startup-system.cc 
CPP-LIB =    cpp-lib/*.o
LIB-OBJS =   $(LIB-SRCS:.cc=.o) $(CPP-LIB)

PROG-SRCS =  $(MAIN)
PROG-OBJS =  $(MAIN:.cc=.o)

HEADERS =  $(PROG-SRCS:.cc=.hh) $(LIB-SRCS:.cc=.hh)


all: $(PROG)
lib: $(LIB-FILE)

$(PROG): $(PROG-OBJS) $(LIB-FILE)
	$(CXX) -$(LINK-MODE) $(LDFLAGS) $(GC-LDFLAGS) $(RPATH-FLAGS) \
	       $(PROG-OBJS) -o $(PROG) $(LIB) $(GC-LIBS) $(OTHER-LIBS)

$(LIB-FILE): $(LIB-OBJS) $(LIB-DIR)
	if [ $(LINK-MODE) = dynamic ]; \
	then $(CXX) $(LIB-SHARED-FLAGS) $(LDFLAGS) $(GC-LDFLAGS) $(LIB-OBJS) \
	            -o $(LIB-FILE) $(GC-LIBS) $(OTHER-LIBS); \
	else ar r $(LIB-FILE) $(LIB-OBJS); \
             ranlib $(LIB-FILE); \
	fi

$(LIB-DIR):
	mkdir -p $(LIB-DIR)

.PHONY: $(CPP-LIB)
$(CPP-LIB):
	cd cpp-lib; $(MAKE) $(MFLAGS) CC=$(CC) CXX=$(CXX) OS=$(OS)

#
# Default rules
# 

.cc.o: $(HEADERS)
	$(CXX) $(CFLAGS) $(GC-CFLAGS) -c $(INCLUDE) $<

#
# Cleaning up
#

.PHONY: clean extraclean

clean:
	/bin/rm -f *.o core \#*
	cd cpp-lib; $(MAKE) $(MFLAGS) clean

extraclean: clean
	/bin/rm -f $(LIB-FILE) $(PROG) *~ .*~ \#* .\#*
	cd cpp-lib; $(MAKE) $(MFLAGS) extraclean
