#*************************************************************************
# COPYRIGHT  (c)  1997 
# THE REGENTS OF THE UNIVERSITY OF MICHIGAN
# ALL RIGHTS RESERVED
# 
# PERMISSION IS GRANTED TO USE, COPY, CREATE DERIVATIVE WORKS 
# AND REDISTRIBUTE THIS SOFTWARE AND SUCH DERIVATIVE WORKS FOR 
# ANY PURPOSE, SO LONG AS NO FEE IS CHARGED, AND SO LONG AS 
# THE COPYRIGHT NOTICE ABOVE, THIS GRANT OF PERMISSION, AND 
# THE DISCLAIMER BELOW APPEAR IN ALL COPIES MADE; AND SO LONG 
# AS THE NAME OF THE UNIVERSITY OF MICHIGAN IS NOT USED IN ANY 
# ADVERTISING OR PUBLICITY PERTAINING TO THE USE OR 
# DISTRIBUTION OF THIS SOFTWARE WITHOUT SPECIFIC, WRITTEN 
# PRIOR AUTHORIZATION.
# 
# THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION 
# FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS 
# FOR ANY PURPOSE, AND WITHOUT WARRANTY BY THE 
# UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR 
# IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES 
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE 
# REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE 
# FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR 
# CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT 
# HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH 
# DAMAGES.
#*************************************************************************

#*************************************************************************
#
# File: Makefile
#
# Purpose: top-level makefile for the hparse hspice parser
#
# Author: Michael Riepe
#
# History: 03/18/97 - MAR - initial implementation
#
# Instructions:
#      'make' - makes top level executable
#      'make pure' - instruments the appliction with purify
#      'make includes' - makes links to .hh files in 'includes' directory
#      'make stats' - prints out number of lines of code in source tree
#      'make clean' - removes all non-source files from all directories
#      'make <target> FLAGS='-DDEBUG_0' to enable debug level 0
#      'make <target> FLAGS='-DDEBUG_1' to enable debug level 1
#      'make <target> FLAGS='-DCHCK' to enable run-time error checking
#
# Note: this makefile depends heavily on the capabilities of gnu make
#
# RCS Version:
#     $Id: Makefile,v 1.1.1.1 2002/05/01 14:23:27 mguthaus Exp $
#
#*************************************************************************

# get the path to the directory in which the top-level make is called, and
# export to recursive makefiles
export SRCHOME = $(shell pwd)

# Include common definitions
include make.include

#*************************************************************************
#
# Modify the following section to customize makefile
#     LIBS - a list of the subdirectories containing library modules
#     TARGET - the name of the target executable
# CAUTION: the order of $LIBS is very important at link time!
#
#*************************************************************************

LIBS = Netlist Parse/hspice Parse Util
TARGET = hparse

#*************************************************************************
#
# implicit rules
#
#*************************************************************************
%.o : %.cc
	$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -I$(SRCHOME)/includes $< -o $@

#*************************************************************************
#
# Build rules
#*******************************************

#******************************
# build target executable
$(TARGET): % : %.o subdirs
	$(CXX) $(CXXFLAGS) ${addsuffix .o, $@} \
            ${addprefix -L,$(LIBS)} ${addprefix -L,$(SYSLIB_DIRS)} \
            ${addprefix -l,$(notdir $(LIBS))} ${addprefix -l,$(SYSLIBS)} -o $@

# target built with standard GDB debugging
debug: % : %.o subdirs
	$(CXX) $(CXXFLAGS) -g ${addsuffix .o, $@} \
            ${addprefix -L,$(LIBS)} ${addprefix -L,$(SYSLIB_DIRS)} \
            ${addprefix -l,$(notdir $(LIBS))} ${addprefix -l,$(SYSLIBS)} -o $@

# target built with purify(tm) for debugging
pure: ${addsuffix .o, $(TARGET)} subdirs
	$(PURIFY) $(CXX) $(CXXFLAGS) ${addsuffix .o, $(TARGET)} \
            ${addprefix -L,$(LIBS)} ${addprefix -L,$(SYSLIB_DIRS)} \
            ${addprefix -l,$(notdir $(LIBS))} ${addprefix -l,$(SYSLIBS)} -o $(TARGET)

# forces processing of subdirectories
.PHONY: subdirs
subdirs:
	for dir in $(LIBS); do $(CD) $$dir ; $(MAKE) $(MAKEFLAGS); $(CD) $(SRCHOME) ; done

# this target finds all include files in subdirectories and creates links 
# to them in the 'includes' directory
.PHONY: includes
includes:
	$(RM) -f includes/*.h
	$(RM) -f includes/*.hh
	$(CD) includes; $(LN) -s -n `$(FIND) $(SRCHOME) -name '*.h' -o -name '*.hh'` .

# this target prints out interesting statistics about the source tree
.PHONY: stats
stats:
	$(WC) -l `$(FIND) $(SRCHOME) -name includes -prune -type f -o -name '*.h' -o -name '*.hh' -o -name '*.cc'`

# cause .o files to depend on the .d (dependency) files
${addsuffix .o, $(TARGET)}: %.o : %.d

# include all dependency files
include ${addsuffix .d, $(TARGET)} 

#*************************************************************************
#
# Clean rules
#
#*************************************************************************

# this target deleted all temporary files to create a clean distribution
.PHONY: clean
clean:
	$(RM) ${addsuffix .o, $(TARGET)} ${addsuffix .d, $(TARGET)} $(TARGET)
	for dir in $(LIBS) ; do $(CD) $$dir; $(MAKE) $(MAKEFLAGS) clean; $(CD) $(SRCHOME) ; done
	$(RM) $(TARGET)_pure_*.o
	$(RM) -f includes/*.h
	$(RM) -f includes/*.hh

