#!/bin/make -f
# #(@) Makefile $Revision: 1.6 $ $Date: 2000/03/08 08:24:49 $
#
#  Makefile for building C++ components for SNMP++ Object Library
#
#  SUN/Solaris version derived from HPUX Makefile (rlujo@isrglobal.com)
#  

#
#  Flags: compiler options, search paths
#

COPTIONS = -D__unix__

CXXFLAGS = @CXXFLAGS@

CINCDIRS = -I../include/snmp++ -I./

TEMPOPTS = -I.

CFLAGS	 = $(COPTIONS) $(CINCDIRS) $(CXXFLAGS)

LDFLAGS  = $(CFLAGS)

top_builddir = ../../..
LIBTOOL = @ /bin/sh $(top_builddir)/libtool
C_R_A = @C_R_A@

#
#  Header Files
#
USERHEADERS = ../include/snmp++/address.h ../include/snmp++/counter.h \
	../include/snmp++/ctr64.h ../include/snmp++/gauge.h \
	../include/snmp++/octet.h ../include/snmp++/oid.h \
	../include/snmp++/pdu.h ../include/snmp++/smi.h \
	../include/snmp++/target.h ../include/snmp++/timetick.h \
	../include/snmp++/vb.h ../include/snmp++/snmp_pp.h \
	../include/snmp++/integer.h ../include/snmp++/smival.h \
	../include/snmp++/snmperrs.h ../include/snmp++/collect.h \
	../include/snmp++/oid_def.h ../include/snmp++/asn1.h \
	../include/snmp++/snmpmsg.h

UXHEADERS = ../include/snmp++/msgqueue.h ../include/snmp++/userdefined.h \
	../include/snmp++/usertimeout.h ../include/snmp++/eventlist.h \
	../include/snmp++/msec.h ../include/snmp++/notifyqueue.h


HEADERS = $(USERHEADERS) $(UXHEADERS) 

#
#  Source code
#
PLUSSRC = address.cpp counter.cpp ctr64.cpp gauge.cpp integer.cpp octet.cpp \
	oid.cpp pdu.cpp target.cpp timetick.cpp vb.cpp asn1.cpp snmpmsg.cpp

UXSRC = uxsnmp.cpp eventlist.cpp msgqueue.cpp userdefined.cpp usertimeout.cpp \
	msec.cpp notifyqueue.cpp


#
#  Object Files produced
#
OBJS =	address.lo counter.lo ctr64.lo gauge.lo integer.lo octet.lo oid.lo \
	pdu.lo target.lo timetick.lo vb.lo asn1.lo snmpmsg.lo uxsnmp.lo \
	eventlist.lo msgqueue.lo userdefined.lo usertimeout.lo msec.lo \
	notifyqueue.lo

P1OBJ = test_app.o

#
#  Libraries:  dependencies and produced
#

LIBSNMPPLUS = ../lib/libsnmp++.la

LIBSNMPX11 = ../lib/libsnmpx11.a

#
#  Used to instantiate templates
#
TEMPMAIN = tempmain.C

#
#  Here for a quick sanity check upon completing a build...
#
PROG1 = test_app

#
#  Shar file packages for delivery to our pals...
#
LIBSHARFILE = libsnmp++.sh
LIBSHARFILES = $(LIBSNMPPLUS) $(HEADERS)
#LIBSHARFILES = $(LIBSNMPPLUS) $(LIBSNMPX11) $(HEADERS)

UXCODESHARFILE = snmp++.ux.src.sh
UXCODESHARFILES = $(PLUSSRC) $(UXSRC) $(USERHEADERS) $(UXHEADERS) Makefile

############################################################################
#
# Compilation rules
#
############################################################################
CC = ${CXX}
LD = ld

.SUFFIXES: .cpp .C .lo

.cpp.lo:
	${LIBTOOL} $(CXX) $(CFLAGS) -c $<

.C.o:
	${LIBTOOL} $(CXX) $(CFLAGS) -c $<

#	$(CXX) -DSNMPX11 -I/usr/include/X11R5 $(CFLAGS) -c $< -o ${@:.o=x11.o}

#	$(CXX) -DSNMPX11 -I/usr/include/X11R5 $(CFLAGS) -c $< -o ${@:.o=x11.o}

#
#  Build rules
#
all: $(LIBSNMPPLUS)

#all: $(LIBSNMPPLUS) $(LIBSNMPX11) $(PROG1)


# Compile with debugging turned on
debug:= CXXFLAGS = -g 
debug: all

shar: $(LIBSHARFILE) $(UXCODESHARFILE) $(WINCODESHARFILE)

$(PROG1): $(LIBSNMPPLUS) $(P1OBJ)
	$(CXX) $(LDFLAGS) $(P1OBJ) -L./ -lsnmp @LIBS@ -o $(PROG1)

$(LIBSNMPPLUS): $(OBJS)
	${LIBTOOL} ${CXX} $(OBJS) -o $@ -rpath @libdir@ -version-info ${C_R_A}

$(LIBSNMPX11): $(OBJS:.o=x11.o)
	ar -rv $(LIBSNMPX11) $(OBJS:.o=x11.o)
	# Re-use the instantiated templates created by $(LIBSNMPPLUS)
	ar -rv $(LIBSNMPX11) Templates.DB/*.o

uxsnmp.lo: $(HEADERS)
	${LIBTOOL} $(CXX) $(CFLAGS) -I../../../include -c uxsnmp.cpp

#	$(CXX) -c $(CFLAGS) \
#	-o uxsnmpx11.o uxsnmp.cpp
#	-I/usr/include/X11R5 -DSNMPX11 -o uxsnmpx11.o uxsnmp.cpp


# Fix up delivered files to go into separate directories
$(LIBSHARFILE): $(LIBSHARFILES)
	shar -CZ -b $(LIBSHARFILES) | awk '                                  \
	/^PATH=/ {print; print "\nmkdir -p snmp++/lib snmp++/include"; next} \
	/^chmod /  {                                                         \
	  print;                                                             \
	  if ($$3 ~ /.*\.h$$/) {                                             \
	    printf("mv -f %s snmp++/include/\n", $$3)}                       \
	  else if ($$3 ~ /.*\.a$$/) {                                        \
	    printf("mv -f %s snmp++/lib/\n",     $$3)}                       \
	  next                                                               \
	}                                                                    \
	{print}                                                              \
	' > $(LIBSHARFILE)

$(UXCODESHARFILE): $(UXCODESHARFILES)
	shar -CZ -b $(UXCODESHARFILES) > $(UXCODESHARFILE)

clean:
	-rm -f core  *.o *~ $(LIBSNMPPLUS) $(LIBSNMPX11)
	-rm -rf Templates.DB ../lib/.libs

clobber: clean
	-rm -f $(LIBSNMPPLUS) $(LIBSNMPX11) $(PROG1) \
	       $(LIBSHARFILE) $(UXCODESHARFILE)

install: $(LIBSNMPPLUS)
	${LIBTOOL} ../../../install-sh -c -m 444 $(LIBSNMPPLUS) @libdir@/libsnmp++.la

tarball::
	-@TAR@ -rvf ../../../@PKG_VERSION@_@OSNAME@.tar @libdir@/libsnmp++.a
	if [ -f @libdir@/libsnmp++.la ]; then \
	  . @libdir@/libsnmp++.la ; \
	  for libfile in $$library_names ; do \
	    @TAR@ -uvf ../../../@PKG_VERSION@_@OSNAME@.tar @libdir@/$$libfile ; \
	  done ; \
	fi

#
#  Dependency rules
#
$(P1OBJ): $(HEADERS)

$(OBJS): $(HEADERS)
