#
#	DISTRIBUTION: HNMS v2.0g2
#	FILE: Makefile
#
#	Makefile for HNMS: NAS Hierarchical Network Management System
#
#	Authors:	Leslie Schlecht
#			Computer Sciences Corporation
#			schlecht@nas.nasa.gov
#
#			Jude George
#			Computer Sciences Corporation
#			heyjude@netcom.com jude@nas.nasa.gov
#
#			M/S 258-6
#			Numerical Aerodynamic Simulation (NAS) Facility
#			NASA Ames Research Center
#			Moffett Field, CA 94035-1000
#
#	Copyright (c) 1994 Jude George
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 1, or (at your option)
#	any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


#	The following should be installed before building HNMS:
#	+ ISODE 7.0's libisode.a (required)
#	+ X11R4 (required)
#	+ Motif widget set (required)
#	+ ISODE 7.0's xpepy/xposy (if you wish to do development on
#	  the HNMP protocol)
#
#	The following should be installed before running HNMS:
#	+ tcpdump (required)
#	+ SMIC MIB compiler (if you wish to add your own MIB variables)
#
#	This makefile expects the HNMS sources to be in the
#	following subdirectories in the same directory as itself:
#
#	asn1/		hnmsd/		hnmstool/
#	gen/		hnmslib/	ui/
#
#	All files in the gen/ directory are machine-generated and should
#	not be edited.  If you blow them away, you will need one or
#	more of the following tools to re-create them: xpepy, xposy, smic.


#		---- CONFIGURATION FOR BUILD -------------------------------*
#
#		HNMS was developed primarily for the Silicon Graphics Iris
#		running Irix 4.x.  The code for this release has not been
#		tested on other CPU types.  It should run on the Sparc
#		platform (running SunOS 4.1.x) with minimal porting.
#
#		On what CPU type am I compiling?  Uncomment one of the
#		following.

CPU=		mips
#CPU=		sparc

#		The $(BIN) directory should have a subdirectory for each
#		CPU type, named after that CPU type.
#
#		Fill in the following path to indicate where I am building
#		HNMS.

SRC=		/r/wk106/u/wk/jude/hnms2
BIN=		$(SRC)/bin/$(CPU)
CONF=		$(SRC)/home

#		You MUST install ISODE 7.0 before going any further!
#		It's not necessary to build the whole package, just
#		libisode.a (well that's most of it, isn't it).  HNMS
#		uses the library and its header files.
#
#		Fill in the path for the top level of your ISODE-7.0
#		distribution.  It is expected that the library lives
#		here, and that the headers are in the h/ subdirectory.

ISODETOP=	/r/wk106/u/wk/jude/isode-7.0
ISODELIB=	$(ISODETOP)
ISODEINC=	$(ISODETOP)/h

#		If any of the gen/*.{c,h,py} files in this distribution
#		have been clobbered for any reason, you will also need
#		the programs xpepy and xposy from ISODE 7.0.

PEPY=		$(ISODETOP)/pepy/xpepy
POSY=		$(ISODETOP)/pepy/xposy

#		If the file gen/mibtable has been clobbered, you must
#		install SMIC as well.

SMIC=		/r/wk106/u/wk/jude/smic/bin/smic

#		Your ISODE-7.0 distribution may not be set up properly
#		for development work.  To ensure that it is, cd to
#		the directory isode-7.0/h and do the following:
#		ln -s . isode
#		ln -s . pepy

#		Now, also fill in the paths at the top of the following
#		files, in this distribution: asn1/makeoids, ui/Makefile.

#		Compilation flags.

CC=		cc
#CC=		gcc
CFLAGS=		-g -I$(ISODEINC) -I$(SRC) -I$(SRC)/hnmslib -I$(SRC)/gen
#CFLAGS=	-g -I$(ISODEINC) -I$(SRC) -I$(SRC)/hnmslib -I$(SRC)/gen \
#		-O -Olimit 2048
LDFLAGS=	-L $(ISODELIB) -L $(BIN)
LIBS=		-lhnms -lisode -lmalloc -lXm_s -lXt_s -lX11_s -lm -lc_s -lPW
#
#		That is all that you need to configure.  You shouldn't
#		need to edit anything below this line.

#		---- FILE LISTS --------------------------------------------*
#
STDINC=		hnmslib/hnmpdefs.h \
		hnmslib/hnmsdefs.h \
		gen/HNMP-types.h \
		gen/oids.h \
		hnmslib/alloc.h \
		hnmslib/peer.h \
		hnmslib/session.h \
		hnmslib/presentation.h \
		hnmslib/hnms.h \
		hnmslib/obj.h \
		hnmslib/mib.h \
		hnmslib/constants.h \
		hnmslib/param.h \
		hnmslib/aux.h
LIBOBJ=		$(BIN)/HNMP-types.o \
		$(BIN)/oids.o \
		$(BIN)/alloc.o \
		$(BIN)/peer.o \
		$(BIN)/session.o \
		$(BIN)/presentation.o \
       		$(BIN)/hnms.o \
       		$(BIN)/obj.o \
		$(BIN)/mib.o \
		$(BIN)/constants.o \
		$(BIN)/param.o \
		$(BIN)/aux.o
HNMSDOBJ=	$(BIN)/hnmsd.o \
		$(BIN)/server.o \
		$(BIN)/io.o \
		$(BIN)/rbip.o \
		$(BIN)/sync.o \
		$(BIN)/icmp.o \
		$(BIN)/snmp.o \
		$(BIN)/ll2.o \
		$(BIN)/SNMP-types.o
HNMSTOOLOBJ=	$(BIN)/hnmstool.o
HNMSLIB=	$(BIN)/libhnms.a
EXECUTABLES=	$(BIN)/hnmsd $(BIN)/hnmstool $(BIN)/hnms

#		Several machine-generated C source files and a table-format
#		mib get created in the gen/ directory.  They are generated
#		from asn.1 source in the asn1/ directory.

GENSRC=		gen/HNMP-types.c gen/HNMP-types.h gen/HNMP-types.py \
		gen/SNMP-types.c gen/SNMP-types.h gen/SNMP-types.py \
		gen/oids.c gen/oids.h gen/mibtable

#			---- BUILD EVERYTHING ------------------------------*
#
all:			gen/mibtable $(EXECUTABLES)

#			---- HNMS LIBRARY ----------------------------------*
#
$(HNMSLIB):		$(LIBOBJ)
			rm -f $@; ar r $@ $(LIBOBJ)

hnmslib/stdhnms.h:	$(STDINC)

#			---- HNMS EXECUTABLES ------------------------------*
#
#			hnms:		graphical ui module
#			hnmsd:		server module
#					io module
#					rbip module
#			hnmstool:	plaintext ui module
#
$(BIN)/hnms:		
			cd $(SRC)/ui; make; mv hnms $(BIN)

$(BIN)/hnmsd:		$(HNMSDOBJ) $(HNMSLIB)
			cd $(SRC)/hnmsd; \
			$(CC) $(LDFLAGS) -o $@ $(HNMSDOBJ) $(LIBS)

$(BIN)/hnmstool:	$(HNMSTOOLOBJ) $(HNMSLIB)
			cd $(SRC)/hnmstool; \
			$(CC) $(LDFLAGS) -o $@ $(HNMSTOOLOBJ) $(LIBS)

#			---- OBJECTS FOR HNMS LIBRARY ----------------------*
#
$(BIN)/hnms.o:		$(STDINC) hnmslib/stdhnms.h hnmslib/hnms.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/hnms.c
$(BIN)/obj.o:		$(STDINC) hnmslib/stdhnms.h hnmslib/obj.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/obj.c
$(BIN)/peer.o:		$(STDINC) hnmslib/stdhnms.h hnmslib/peer.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/peer.c
$(BIN)/session.o:	$(STDINC) hnmslib/stdhnms.h hnmslib/session.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/session.c
$(BIN)/presentation.o:	$(STDINC) hnmslib/stdhnms.h hnmslib/presentation.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/presentation.c
$(BIN)/constants.o:	$(STDINC) hnmslib/stdhnms.h hnmslib/constants.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/constants.c
$(BIN)/mib.o:		$(STDINC) hnmslib/stdhnms.h hnmslib/mib.h hnmslib/mib.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/mib.c
$(BIN)/param.o:		$(STDINC) hnmslib/stdhnms.h hnmslib/param.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/param.c
$(BIN)/alloc.o:		$(STDINC) hnmslib/stdhnms.h hnmslib/alloc.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/alloc.c
$(BIN)/aux.o:		$(STDINC) hnmslib/stdhnms.h hnmslib/aux.c
			$(CC) $(CFLAGS) -o $@ -c hnmslib/aux.c
$(BIN)/oids.o:		$(STDINC) hnmslib/stdhnms.h gen/oids.c
			$(CC) $(CFLAGS) -o $@ -c gen/oids.c
$(BIN)/HNMP-types.o:	gen/HNMP-types.c gen/HNMP-types.h
			cd gen; \
			$(CC) $(CFLAGS) -o $@ -c HNMP-types.c

#			---- OBJECTS FOR HNMSD -----------------------------*
#
$(BIN)/hnmsd.o:		$(STDINC) hnmslib/stdhnms.h hnmsd/hnmsd.c \
			hnmsd/sync.h hnmsd/snmp.h hnmsd/icmp.h hnmsd/ll2.h \
			hnmsd/server.h hnmsd/io.h
			$(CC) $(CFLAGS) -o $@ -c hnmsd/hnmsd.c
$(BIN)/server.o:	$(STDINC) hnmslib/stdhnms.h hnmsd/server.c
			$(CC) $(CFLAGS) -o $@ -c hnmsd/server.c
$(BIN)/sync.o:		$(STDINC) hnmslib/stdhnms.h hnmsd/sync.c
			$(CC) $(CFLAGS) -o $@ -c hnmsd/sync.c
$(BIN)/rbip.o:		$(STDINC) hnmslib/stdhnms.h hnmsd/rbip.c
			$(CC) $(CFLAGS) -o $@ -c hnmsd/rbip.c
$(BIN)/io.o:		$(STDINC) hnmslib/stdhnms.h hnmsd/io.c
			$(CC) $(CFLAGS) -o $@ -c hnmsd/io.c
$(BIN)/ll2.o:		$(STDINC) hnmslib/stdhnms.h hnmsd/ll2.c
			$(CC) $(CFLAGS) -o $@ -c hnmsd/ll2.c
$(BIN)/icmp.o:		$(STDINC) hnmslib/stdhnms.h hnmsd/icmp.c
			$(CC) $(CFLAGS) -o $@ -c hnmsd/icmp.c
$(BIN)/snmp.o:		$(STDINC) hnmslib/stdhnms.h hnmsd/snmp.c \
			gen/SNMP-types.h
			$(CC) $(CFLAGS) -o $@ -c hnmsd/snmp.c
$(BIN)/SNMP-types.o:	gen/SNMP-types.c gen/SNMP-types.h
			cd gen; \
			$(CC) $(CFLAGS) -o $@ -c SNMP-types.c

#			---- OBJECTS FOR HNMSTOOL --------------------------*
#
$(BIN)/hnmstool.o:	hnmslib/stdhnms.h hnmstool/hnmstool.c
			$(CC) $(CFLAGS) -o $@ -c hnmstool/hnmstool.c

#			---- MACHINE-GENERATED SOURCES ---------------------*
#
gen/HNMP-types.h:	gen/HNMP-types.c
gen/HNMP-types.c:	gen/HNMP-types.py
			$(PEPY) -A -o $@ gen/HNMP-types.py; \
			mv HNMP-types.h HNMP.ph gen
gen/HNMP-types.py:	asn1/HNMP-asn.py
			$(POSY) -f -h0 -o $@ asn1/HNMP-asn.py
gen/SNMP-types.h:	gen/SNMP-types.c
gen/SNMP-types.c:	gen/SNMP-types.py
			$(PEPY) -A -o $@ gen/SNMP-types.py; \
			mv SNMP-types.h SNMP.ph gen
gen/SNMP-types.py:	asn1/SNMP-asn.py
			$(POSY) -f -h0 -o $@ asn1/SNMP-asn.py
gen/oids.h:		gen/mibtable asn1/makeoids
			sh asn1/makeoids
gen/oids.c:		gen/oids.h
gen/mibtable:		asn1/hnms.mib asn1/miblist
			rm -f $@; \
			$(SMIC) -N asn1/miblist > $@

#			---- HOUSEKEEPING ----------------------------------*
#
clean:			
			cd bin/$(CPU); rm -f *.o; cd ../../ui; rm -f *.o

clobber:		
			cd gen; rm -f *; \
			cd ../bin/$(CPU); rm -f *; cd ../../ui; rm -f *.o

backup:			
			tar cf `date +%y%m%d`.tar Makefile asn1 gen hnmslib \
			hnmsd hnmstool ui; gzip `date +%y%m%d`.tar
