##############################################################
# Name: /home/users/otso/official/otso/prepro/SCCS/s.Makefile
# Vers: 5.2    Time: 92/09/10, 10:49:34
#
# Copyright (c) 1992      Technical Research Centre of Finland (VTT)
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that this notice and the reference to this notice appearing in each software
# module be retained unaltered, and that the name of any contributors shall not
# be used in advertising or publicity pertaining to distribution of the software
# without specific written prior permission.  No contributor makes any
# representations about the suitability of this software for any purpose.
# It is provided "as is" without any express or limited warranty.
#
#			NO WARRANTY
#
# ALL CONTRIBUTORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS.  IN NO
# EVENT SHALL ANY CONTRIBUTOR BE LIABLE FOR ANY SPECIAL, PUNITIVE, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA, OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE OR PERFORMANCE
# OF THIS SOFTWARE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THIS
# SOFTWARE IS WITH YOU.  SHOULD THIS SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE
# COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
#
# As used above, "contributor" includes, but is not limited to :
#        The Technical Research Centre of Finland
#############################################################################

###############################################################################
#   Instructions to Make, for compilation of OTSO preprocessor tool
###############################################################################

PREPRO	=	./prepro
LIBES	=	libprepro.a 


##################################################################
# good stuff goes here:
##################################################################

all:		prepro
inst-all:	inst-prepro
install:	inst-all clean


CFILES	=	prepro.l prepro.y classdef.cxx alloca.c

# alloca.o needed on HPUX, not on Sun
OFILES	=	prepro.o classdef.o alloca.o	
#OFILES	=	prepro.o classdef.o 

#
#Some libraries linked twice on purpose! (linker bug?)
#
prepro:		$(OFILES) $(OTSO_LIBES) 
		-echo "compiling prepro"
		$(CXX) $(LDXXFLAGS) $(OFILES) \
			$(OTSO_LIBES) \
			$(OTSO_SIMU) \
			$(LIBDIR)libdvops.a \
			$(SYSTEM_LIBES) \
			-o prepro

inst-prepro:	prepro
		-@rm -f $(BINDIR)prepro
		-ln prepro $(BINDIR)prepro

################################################################
# source code
################################################################

classdef.o:	$(CLASSDEFH) $(HEAPH)
preprovrsn.c:	$(OFILES)
		@$(UTILDIR)version.sh prepro > $@

prepro.o:	$(PREPROH) prepro.inc prepro.cxx $(HEAPH)
		if [ "$(CXX_COMMENT)" = "CC-gcc-hack" ]; then		\
			echo "***";					\
			echo "*** MINOR WARNING : $(CXX_COMMENT) - CC uses gcc !!!" ;			\
			echo "*** Hacking 'extern builtin_alloca' out of generated .c file" ;								\
			echo "***";					\
			cp prepro.cxx prepro_tmp.cxx ;			\
			make prepro_tmp.c ;				\
			cat prepro_tmp.c | sed -e "s/^extern char .*builtin_alloca.*;/\/\*&\ - commented out by jfr\@tel.vtt.fi to make gcc happy *\//" > prepro_tmp_sed.c ;								\
			make prepro_tmp_sed.o ;				\
			mv prepro_tmp_sed.o prepro.o ;			\
			rm prepro_tmp* ;				\
		else							\
			$(CXX) -c $(IFLAGS) prepro.cxx ;		\
		fi
prepro.inc:	prepro.l
		$(LEX) prepro.l; sed -f lex.sed lex.yy.c > prepro.inc
prepro.cxx:	prepro.y $(OBJECTH) $(CHANNELH) $(HEAPH) $(INTH) \
		$(CLASSDEFH) $(DYNDIRH) $(PROCESSH)
		$(YACC) $(YFLAGS) prepro.y
		mv prepro.tab.c prepro.cxx


################################################################
# Documentation
################################################################

DOCS	=	dvops.doc

documents:;	@for i in $(DOCS); \
		  do (echo "---- " $$i " ----" >> $(TOPDIR)/master.doc; \
			cat $$i >> $(TOPDIR)/master.doc); \
		  done
		echo "" >> $(TOPDIR)/master.doc

################################################################
# clean
################################################################

clean:;		-rm -f *yy.c *tab.c y.output *tab.h prepro.cxx \
		prepro.inc $(CLEANSTRINGS)

tar-clean:	clean
		-rm -f prepro

