#
# Copyright (c) 1992-1994 Michael A. Cooper.
# This software may be freely distributed provided it is not sold for 
# profit and the author is credited appropriately.
#
# $Id: Makefile,v 1.40 1994/11/23 19:04:32 mcooper Exp $
#
# Sysinfo Makefile
#
# To compile, just run "make".  This should automatically figure out
# your OS type.
#

#
# Location of your Kernel specific directory.
# This is usually only for SunOS 4.x.  If you don't have
# one, set this to nothing.
#
#KVMDIR		= /usr/kvm
KVMDIR		=

#
# The bin directory that user's will run the program from.
# For systems with a $(KVMDIR) (above), a symlink will be put 
# in $(BIN) pointing to $(KVMDIR)/sysinfo.  On systems without 
# a $(KVMDIR), the program will be copied to $(BIN).
#
# A good place is something like /usr/local/bin.
#
BIN 		= /usr/local/bin

#
# Directory to install man page in.
#
MAN 		= /usr/local/man/man1

#
# Directory containing sysinfo.cf configuration files
#
#CONFDIR	= /usr/local/lib/sysinfo
CONFDIR		= /usr/lsd/conf/sysinfo

#
# Installation options
#
# Sysinfo needs to be able to read your unix image (/vmunix usually),
# /dev/kmem, and device files in /dev for things like disk drives and tapes.
# Under SunOS, /dev/kmem is owned by group "kmem", but the disk files
# (e.g. /dev/rsd0a) are owned by group "operator".  Therefor, you usually
# can't make setgid to a group, but need it setuid root.
#
# You should set INSTALLMODE and INSTALLOWN appropriately to allow sysinfo 
# to read everything it needs to.  Try running "sysinfo -debug" to find out 
# the special files it reads.
#
INSTALLMODE	= -m 4555
INSTALLOWN 	= -o root -g bin
INSTALLOPTS 	= $(INSTALLMODE) $(INSTALLOWN)

#
# Name of the program that installs files.
# This program should support the BSD-style install(1) options.
# If such a program is not available (like for HP-UX) use "./bsdinst.sh"
#
#INSTALLPROG	= ./bsdinst.sh
INSTALLPROG	= install

###########################################################################
#
# 	END OF NORMAL SITE CONFIGURATION
#
###########################################################################

#
# The make program to use
#
MAKE		= make

#
# The name of the kvm library to use.
# For SunOS this should be "-lkvm".  If you don't have one, add
# "kvmlib.o" to MISSINGFILES below and leave LIBKVM blank.
#
LIBKVM		= #-lkvm

#
# SunOS 4.0, 4.0.1, and 4.0.3 requires using the System V cc and libc
# in order to get uname().  Enable the two lines below if your OS is one
# of these.
#
# Do NOT set CC to /usr/ucb/cc for SunOS 5.x.  This enables BSD 
# compatibility mode in SunC which breaks sysinfo.
#
#CC		= gcc
LIBS 		= $(OSLIBS)

#
# Defines
#
DEFINES		= $(OSDEFINES) -DCONFIG_DIR=\"$(CONFDIR)\"

#
# Optimization or debugging flag
#
OPT		= -g

#
# Include directories
#
INCLUDES	= -I.

CFLAGS 		= ${OPT} ${INCLUDES} ${DEFINES}

NetIf-Files	= netif.o info-netif.o
Env-Files	= getenv.o putenv.o setenv.o

#
# OS Specific Files
#
AIX-OS-Files	= os-aix.o
Mach-OS-Files	= os-mach.o
NeXT-OS-Files	= os-next.o ${Mach-OS-Files} ${NetIf-Files} ${Env-Files}
SunOS-OS-Files	= os-sunos.o kbd-sun.o obp.o ${NetIf-Files}
SunOS4-OS-Files	= os-sunos4.o ${SunOS-OS-Files}
SunOS5-OS-Files	= os-sunos5.o dlpi.o ${SunOS-OS-Files}
Ultrix-OS-Files	= os-ultrix.o ${NetIf-Files}
HPUX-OS-Files	= os-hpux.o
SPPUX-OS-Files	= os-sppux.o

#
# Select the OS specific files to compile
#
OSFILES		=

#
# Missing files
#
# List of files of things your system may not have.
#
MISSINGFILES	=

BASE 		= sysinfo
PROG 		= ${BASE}
OBJS 		= sysinfo.o devices.o memory.o run.o run-data.o kvm.o \
			options.o virtmem.o getosver.o getosname.o getcpu.o \
			gethost.o getmodel.o psi.o getmisc.o \
			kernel.o general.o class.o var.o misc.o \
			cf.o define.o devdefine.o strutil.o namelist.o \
			getarch.o getkernver.o getman.o macinfo.o sysconf.o \
			${MISSINGFILES} ${OSFILES}

#
# Default
#
default:
	@ostype="`./ostype`"; \
	case "$${ostype}" in \
	aix3*)		os=aix3;; \
	nextstep2*)	os=nextstep2;; \
	nextstep3*)	os=nextstep3;; \
	sunos4*)	os=sunos4;; \
	sunos5*)	os=sunos5;; \
	ultrix4*)	os=ultrix4;; \
	hp-ux*)		os=hp-ux;; \
	spp-ux*)	os=spp-ux;; \
	*) \
		echo "You OS type ($$ostype) is not supported."; \
		exit 1; \
	esac; \
	$(MAKE) $${os}

all: ${PROG}

${PROG}: ${OBJS} versinfo.o
	rm -f $@
	${CC} ${CFLAGS} -o $@ ${OBJS} versinfo.o ${LIBS} ${LIBKVM}

versinfo.c: $(OBJS) mkversion
	@./mkversion $@

install:
	@make $(MFLAGS) install.cf
	@if [ ! -z "$(KVMDIR)" ]; then \
		echo "$(INSTALLPROG) -c ${INSTALLOPTS} ${PROG} $(KVMDIR)/${BASE}"; \
		$(INSTALLPROG) -c ${INSTALLOPTS} ${PROG} $(KVMDIR)/${BASE}; \
		echo "cd ${BIN} && rm -f ${BASE} && ln -s $(KVMDIR)/${BASE} ${BASE}"; \
		(cd ${BIN} && rm -f ${BASE} && ln -s $(KVMDIR)/${BASE} ${BASE}); \
	else \
		echo $(INSTALLPROG) -c ${INSTALLOPTS} ${PROG} ${BIN}/${BASE}; \
		$(INSTALLPROG) -c ${INSTALLOPTS} ${PROG} ${BIN}/${BASE}; \
	fi

#
# See the file "metasysinfo" for more information on "installmeta".
#
installmeta:
	$(INSTALLPROG) -c -m 555 $(INSTALLOWN) metasysinfo $(BIN)/$(BASE)
	@$(INSTALLPROG) -c $(INSTALLOPTS) $(PROG) \
			$(BIN)/$(BASE)-`uname -m`-`uname -r`; \
		echo $(INSTALLPROG) -c $(INSTALLOPTS) $(PROG) \
			$(BIN)/$(BASE)-`uname -m`-`uname -r`

install.man: sysinfo.man sysinfo.cf.man
	$(INSTALLPROG) -c -m 444 -o bin -g bin sysinfo.man ${MAN}/sysinfo.${S1}
	$(INSTALLPROG) -c -m 444 -o bin -g bin sysinfo.man \
		${MAN}/sysinfo.cf.${S5}

$(CONFDIR):
	mkdir $(CONFDIR)
	chmod 755 $(CONFDIR)

install.cf: $(CONFDIR)
	@for file in config/*.cf ; do \
		cf=`echo $$file | sed -e 's;.*/;;'`; \
		echo $(INSTALLPROG) -c -m 444 $(INSTALLOWN) $$file $(CONFDIR)/$$cf; \
		$(INSTALLPROG) -c -m 444 $(INSTALLOWN) $$file $(CONFDIR)/$$cf; \
	done

install.compat:
	$(INSTALLPROG) -c -m 555 -o bin -g bin cpumodel.sh /usr/lsd/etc/cpumodel
	rm -f $MAN/${BASE}.8 $MAN/cpumodel.1
	(cd /usr/usc/bin; rm -f sysinfo; ln -s ${BIN}/sysinfo)

clean:
	rm -f *.o ${PROG} *~ *% \#* core a.out \
		versinfo.c sysinfo.tar sysinfo.tar.Z

${OBJS}: os.h defs.h

#
# OS targets
#

#
# SunOS 4.x (Solaris 1.x)
#
sunos4 solaris1:
	@echo "Making ${BASE} for SunOS 4.x ... "; \
	$(MAKE)	KVMDIR="$(KVMDIR)" \
		LIBKVM=-lkvm \
		OSLIBS="" \
		OSDEFINES="-DSUNOS=4 -D`/bin/arch -k`" \
		OSFILES="${SunOS4-OS-Files}" \
		MISSINGFILES="strcasecmp.o strdup.o strerror.o" \
		all

#
# SunOS 5.x (Solaris 2.x)
#
sunos5 solaris2:
	@echo "Making ${BASE} for SunOS 5.x ... "; \
	echo "Make sure that \`cc' is not \`/usr/ucb/cc' or sysinfo may not work."; \
	$(MAKE)	KVMDIR="" \
		LIBKVM=-lkvm \
		OSLIBS="-lsocket -lnsl -lelf -ladm" \
		OSDEFINES=-DSUNOS=5 \
		OSFILES="${SunOS5-OS-Files}" \
		MISSINGFILES="setreuid.o" \
		all

#
# AIX 3.x for RS/6000
#
aix3:
	@echo "Making ${BASE} for AIX ... "; \
	$(MAKE)	KVMDIR="" \
		LIBKVM="" \
		OSLIBS="-lodm -lcfg" \
		OSDEFINES="" \
		OSFILES="${AIX-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all

#
# Ultrix 4.x
#
ultrix4:
	@echo "Making ${BASE} for Ultrix ... "; \
	$(MAKE)	KVMDIR="" \
		LIBKVM="" \
		OSLIBS="" \
		OSDEFINES="" \
		OSFILES="${Ultrix-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all

#
# NeXTStep 2.x
#
next2 nextstep2:
	@echo "Making ${BASE} for NeXTStep 2.x ... "; \
	$(MAKE)	KVMDIR="" \
		LIBKVM="" \
		OSLIBS="" \
		OSDEFINES="-DNEXTSTEP=2" \
		OSFILES="${NeXT-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all

#
# NeXTStep 3.x
#
next3 nextstep3:
	@echo "Making ${BASE} for NeXTStep 3.x ... "; \
	$(MAKE)	KVMDIR="" \
		LIBKVM="" \
		OSLIBS="" \
		OSDEFINES="-DNEXTSTEP=3" \
		OSFILES="${NeXT-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all

#
# HP-UX 9.x
#
hp-ux hpux9:
	@echo "Making ${BASE} for HP-UX 9.x ... "; \
	$(MAKE)	KVMDIR="" \
		LIBKVM="" \
		OSLIBS="" \
		OSDEFINES=-DHPUX=9 \
		OSFILES="${HPUX-OS-Files}" \
		MISSINGFILES="kvmlib.o" \
		OPT="" \
		all

#
# Convex SPP-UX
#
spp-ux sppux:
	@echo "Making ${BASE} for SPP-UX ... "; \
	echo "Ignore errors regarding /usr/include/sys/wait.h"; \
	$(MAKE)	KVMDIR="" \
		LIBKVM="" \
		OSLIBS="/lib/cnx_syscall.a" \
		OSDEFINES=-DSPPUX \
		OSFILES="${SPPUX-OS-Files}" \
		MISSINGFILES="kvmlib.o" \
		OPT="-cxdb" \
		CC=/usr/convex/bin/cc \
		all

