#
# Copyright (c) 1992-1993 Michael A. Cooper.
# This software may be freely distributed provided it is not sold for 
# profit and the author is credited appropriately.
#
# $Header: /src/common/usc/bin/sysinfo/RCS/Makefile,v 1.23 1993/09/20 21:29:54 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

#
# 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 the INSTALLOPTS appropriately to allow sysinfo to read
# everything it needs to.  Try running "sysinfo -debug" to find out the
# special files it reads.
#
INSTALLOPTS 	= -m 4555 -o root -g wheel
INSTALLPROG	= install

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

#
# 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.
#
#CC		= gcc
LIBS 		=

#
# Defines
#
DEFINES		=

#
# Optimization or debugging flag
#
OPT		= -g

#
# Include directories
#
INCLUDES	= -I.

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

NetIf-Files	= netif.o info-netif.o

#
# OS Specific Files
#
AIX-OS-Files	= os-aix.o info-aix.o
Concen-OS-Files	= os-concen.o info-concen.o
Mach-OS-Files	= os-mach.o info-mach.o
NeXT-OS-Files	= os-next.o info-next.o ${Mach-OS-Files} ${NetIf-Files}
SunOS-OS-Files	= os-sunos.o info-sunos.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 info-ultrix.o ${NetIf-Files}

#
# 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 		= ${BASE}.o devices.o memory.o run.o kvm.o options.o \
			virtmem.o getosver.o getosname.o getcpu.o \
			getarch.o getkernver.o getman.o macinfo.o namelist.o \
			${MISSINGFILES} ${OSFILES}

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

all: ${PROG}

${PROG}: ${OBJS}
	${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS} ${LIBKVM}

install: ${PROG}
	@if [ "$(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

install.man: ${BASE}.man
	$(INSTALLPROG) -c -m 444 -o bin -g bin ${BASE}.man ${MAN}/${BASE}.1

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 sysinfo.tar sysinfo.tar.Z

${OBJS}: os.h defs.h

#
# OS targets
#

#
# SunOS 4.x (Solaris 1.x)
#
sunos4 solaris1:
	@echo "Making SunOS 4.x ${BASE} ... "; \
	make 	KVMDIR="$(KVMDIR)" \
		LIBKVM=-lkvm \
		LIBS="" \
		DEFINES="-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 SunOS 5.x ${BASE} ... "; \
	make 	KVMDIR="" \
		LIBKVM=-lkvm \
		LIBS="-lsocket -lnsl -lelf -ladm" \
		DEFINES=-DSUNOS=5 \
		OSFILES="${SunOS5-OS-Files}" \
		MISSINGFILES="" \
		all

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

#
# Ultrix 4.x
#
ultrix4:
	@echo "Making Ultrix ${BASE} ... "; \
	make 	KVMDIR="" \
		LIBKVM="" \
		LIBS="" \
		DEFINES="" \
		OSFILES="${Ultrix-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all

#
# NeXTStep 2.x
#
next2 nextstep2:
	@echo "Making NeXTStep 2.x ${BASE} ... "; \
	make 	KVMDIR="" \
		LIBKVM="" \
		LIBS="" \
		DEFINES="-DNEXTSTEP=2" \
		OSFILES="${NeXT-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all

#
# NeXTStep 3.x
#
next3 nextstep3:
	@echo "Making NeXTStep 3.x ${BASE} ... "; \
	make 	KVMDIR="" \
		LIBKVM="" \
		LIBS="" \
		DEFINES="-DNEXTSTEP=3" \
		OSFILES="${NeXT-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all

#
# Alliant Concentrix
#
concen concentrix alliant:
	@echo "Making Concentrix ${BASE} ... "; \
	make 	KVMDIR="" \
		LIBKVM="" \
		LIBS="-lcommon" \
		DEFINES="" \
		OSFILES="${Concen-OS-Files}" \
		MISSINGFILES="strdup.o kvmlib.o" \
		all
