# c++-examples/simple/makefile
#
# WARNING: this makefile isn't safe for parallel making!
#
# $Header: /usr/app/odstb/CVS/snacc/c++-examples/simple/makefile,v 1.9 1997/02/16 16:47:58 rj Exp $
# $Log: makefile,v $
# Revision 1.9  1997/02/16 16:47:58  rj
# made return *this after calling abort()'' a compile time option.
#
# Revision 1.8  1995/07/24  15:29:44  rj
# `cd && make' instead of `cd; make'.
#
# changed `_' to `-' in file names.
#
# Revision 1.7  1995/02/20  11:47:37  rj
# build snacc if it doesn't exist.
# some makes leave a trailing slash on $(@D), others don't. this causes some mkdir(1)s to deny their cooperation. therefore, the slash has got to be stripped.
#
# Revision 1.6  1995/02/13  14:58:14  rj
# augment CPPFLAGS, not overwrite
#
# Revision 1.5  1994/10/08  04:35:59  rj
# enhance portability by using standard make capabilities instead of utilies (basename, dirname) not found on every platform.
#
# for the dependencies, generate the snacc compiler if it doesn't exist.
#
# Revision 1.4  1994/09/01  02:26:54  rj
# use CXX instead of CC to get another default linkage
#
# Revision 1.3  1994/08/31  21:40:00  rj
# rebuild the executables when the c++-lib is newer.
# the file good-pr.ber needs to be distributed.
#
# Revision 1.2  1994/08/31  10:31:50  rj
# since .o files get moved, a few more dependencies are needed.
#
# Revision 1.1  1994/08/31  08:48:10  rj
# first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
#

#include ../../makehead

TOP		= /usr

ASN1_SRC_DIR	= $(TOP)/include/snacc/asn1

ASN1_C++_LIB_DIR	= $(TOP)/lib
ASN1_C++_INC_DIR	= $(TOP)/include/snacc/c++
ASN1_C++_LIB		= $(ASN1_C++_LIB_DIR)/libasn1c++.a

COMPILERDIR	= $(TOP)/bin
SNACC		= $(COMPILERDIR)/snacc
USEFUL_TYPES	= $(ASN1_SRC_DIR)/asn-useful.asn1
SNACCFLAGS	= -C $(SNACC_NOVOLAT) -u $(USEFUL_TYPES)

CC		= $(CXX)
CPPFLAGS	+= -g -I$(TOP) -I$(ASN1_C++_INC_DIR) $(LENFLAG)

ASN1FILES	= $(ASN1_SRC_DIR)/p-rec.asn1

# generated by snacc from p-rec.asn1:
ASN1HFILES	= p-rec.h
ASN1CFILES	= p-rec.C

CFILES = \
	genber.C	\
	example.C

DISTFILES = \
	README		\
	makefile	\
	$(CFILES)	\
	good-pr.ber

#-------------------------------------------------------------------------------

all::		genber def indef

$(ASN1HFILES)	\
$(ASN1CFILES):	$(SNACC) $(ASN1FILES)
		$(REASON)
		$(SNACC) $(SNACCFLAGS) $(ASN1FILES)

$(SNACC):
		cd $(@D) && $(MAKE) $(@F)

def-obj		\
indef-obj:
		mkdir $@

def-obj/p-rec.o	\
def-obj/example.o:
		$(REASON)
		$(MAKE) LENFLAG= `echo $(@D) | sed -e 's:/$$::'` $(@F)
		mv $(@F) $@

indef-obj/p-rec.o	\
indef-obj/example.o:
		$(REASON)
		$(MAKE) LENFLAG=-DUSE_INDEF_LEN `echo $(@D) | sed -e 's:/$$::'` $(@F)
		mv $(@F) $@

genber:		def-obj/p-rec.o genber.o
		$(REASON)
		$(CXX) $(LDFLAGS) -o $@ def-obj/p-rec.o genber.o $(ASN1_C++_LIB) $(LIBS)

def: 		def-obj/p-rec.o def-obj/example.o
		$(REASON)
		$(CXX) $(LDFLAGS) -o $@ def-obj/p-rec.o def-obj/example.o $(ASN1_C++_LIB) $(LIBS)

indef:		indef-obj/p-rec.o indef-obj/example.o
		$(REASON)
		$(CXX) $(LDFLAGS) -o $@ indef-obj/p-rec.o indef-obj/example.o $(ASN1_C++_LIB) $(LIBS)

genber	\
def	\
indef:		$(ASN1_C++_LIB)

.PHONY:	check

check::		def indef
		uudecode -o good-pr.ber good-pr.ber.uu
		$(RM) foo.ber bar.ber
		./indef good-pr.ber > foo.ber
		./def foo.ber > bar.ber
		@if cmp -s bar.ber good-pr.ber; then\
		  echo "+++ Passed simple encode/decode tests using p-rec.asn1.";\
		else\
		  echo "--- Failed simple encode/decode tests using p-rec.asn1.";\
		fi
		$(RM) foo.ber bar.ber

clean::
		$(RM) *.o *~ .emacs* core def indef genber pr.ber good-pr.ber $(ASN1HFILES) $(ASN1CFILES)
		$(RM) -r def-obj indef-obj
		$(RM) foo.ber bar.ber

depend::	$(SNACC)

#include ../../maketail

depend::
		cp dependencies deps
		for dir in def-obj indef-obj; do\
		  < dependencies sed -e 's:^\(.*\.o\):'"$$dir"'/\1:' >> deps;\
		done
		mv deps dependencies
