srcdir=		@srcdir@
VPATH=		@srcdir@
CC=		    @CC@
CXX=        @CXXITSELF@
AR=	 	    @AR@
RANLIB=		@RANLIB@
MACHDEP=    @MACHDEP@
DEFS=		@DEFS@ 
LDFLAGS=    @LDFLAGS@
OPT=        @OPT@
LIBS=       @LIBS@
CXXLD=      @CXXLD@
CONFIG_H_DEST = $(srcdir)/include/utils
SGI_ABI=        @SGI_ABI@
CPPFLAGS =      -I$(srcdir)/include $(DEFS) @CPPFLAGS@ 
CLIBS =         @CLIBS@
INSTALL_DIR = $(RHEX_DIR)
LIB_DEST_DIR =  $(INSTALL_DIR)/@LIB_DEST_DIR@
INSTALL_LIB =   $(LIB_DEST_DIR)/@LIB_INSTALL@
CONFIG_H=       utils_config.h
BISONPP =       @BISONPP@
ECHO =          echo
RM   =          rm

# Modes for directories, executables and data files created by the
# install process.  Default to group-writable directories but
# user-only-writable for executables and data files.
DIRMODE=	775
EXEMODE=	755
FILEMODE=	644

INSTALL         = @INSTALL@
INSTALL_PROGRAM = ${INSTALL} -m $(EXEMODE)
INSTALL_DATA    = ${INSTALL} -m $(FILEMODE)

CFLAGS   = $(OPT) 
CXXFLAGS = $(OPT) 
PURIFY   = purify
PUREOPT  = -chain-length=100 -verbose -windows=no 

LIB_SRC = ConfigFile.cc Dict.cc StringDict.cc List.cc Mutex.cc \
	String.cc Input.cc Output.cc Managed.cc Type.cc Base.cc \
	ConfigParser.cc \
	Generator.cc SymbolTable.cc 
OBJS    = $(LIB_SRC:.cc=.o)
ALL_SRC = $(LIB_SRC) config_test.cc 

all: libutils.a $(CONFIG_H_DEST)/$(CONFIG_H) 

ConfigParser.cc ConfigParser.h: ConfigParser.y
	$(BISONPP) -o ConfigParser.cc --defines ConfigParser.y

libutils.a: $(OBJS) $(CONFIG_H_DEST)/$(CONFIG_H)
	$(RM) -f libutils.a
	$(AR)  cr libutils.a $(OBJS)
	$(RANLIB) libutils.a

config_test: config_test.o $(OBJS)
	$(CXXLD) $(LDFLAGS) config_test.o $(OBJS) -o config_test $(LIBS)

cconfig_test: cconfig_test.o $(OBJS)
	$(CC) $(LDFLAGS) cconfig_test.o $(OBJS) -o cconfig_test $(LIBS) \
		$(CLIBS)

clean: 
#	@echo Cleaning object, dependency and test files...
	@rm -f *.o *.d *.a *_test *_test.pure

distclean: clean
	@echo Cleaning everything...
	@rm -rf config.cache config.status Makefile config.log include/$(MACHDEP)

depend:
	@rm -f *.d

%.d: %.cc $(CONFIG_H_DEST)/$(CONFIG_H)
	@$(ECHO) Finding dependencies for $<
	@$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< \
	              | sed '\''s/\($*\.o\)[ :]*/\1 $@ : /g'\'' > $@ '

%.d: %.c $(CONFIG_H_DEST)/$(CONFIG_H)
	@$(ECHO) Finding dependencies for $<
	@$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
	              | sed '\''s/\($*\.o\)[ :]*/\1 $@ : /g'\'' > $@ '

$(CONFIG_H_DEST)/$(CONFIG_H): $(CONFIG_H)
	cp $(CONFIG_H) $(CONFIG_H_DEST)/$(CONFIG_H)

INCLUDE_DIR = $(INSTALL_DIR)/include/utils
ALL_INCLUDE_DIRS = $(INSTALL_DIR)/include $(INCLUDE_DIR) \
		$(INSTALL_DIR)/include/$(MACHDEP)
CONFIG_DIR = $(INSTALL_DIR)/include

incinstall:
	@if test ! -L $(INSTALL_DIR)/include/utils; then \
		rm -rf $(INSTALL_DIR)/include/utils; \
		echo "Linking $(INSTALL_DIR)/include/utils"; \
		ln -s $(RHEX_DIR)/libutils/include/utils $(INSTALL_DIR)/include/utils; \
	fi; 

install: libutils.a incinstall 

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)

-include $(ALL_SRC:.cc=.d)

endif
endif
