#
# Makefile for customs agent and its clients.
#
# $Id: Makefile,v 1.7 89/11/14 17:54:21 adam Exp $ SPRITE (Berkeley)
#
# If your machine is on more than 10 networks, on all of which you want to
# run the customs service, you should redefine MAXNETS in the CFLAGS variable.
# The multi-network code has never actually been tested, however.
#
# Copyright (c) 1988, 1989 by the Regents of the University of California
# Copyright (c) 1988, 1989 by Adam de Boor
# Copyright (c) 1989 by Berkeley Softworks
#
# Permission to use, copy, modify, and distribute this
# software and its documentation for any non-commercial purpose
# and without fee is hereby granted, provided that the above copyright
# notice appears in all copies.  The University of California,
# Berkeley Softworks and Adam de Boor make no representations about
# the suitability of this software for any purpose.  It is provided
# "as is" without express or implied warranty.
#

#
# Owner of the various binaries
#
OWNER		= adam

#
# BINDIR is where the various user-accessible clients go.
# ETCDIR is where the system-control clients and the daemon itself go.
#
BINDIR		= /usr/public
ETCDIR		= /usr/public
#
# Mode system-control clients and customs should be. In a hostile environment,
# this should be 700 and OWNER should be root
#
ETCMODE		= 755

#
# Include PMake common description
#
DEPFILE		?= dependencies.mk
#include	"../common.mk"

#
# Additional path definitions
#
.PATH.h		: $(INCLUDE)
.PATH.a		: $(LSTDIR) $(SPRITEDIR) 
.PATH.c		: test

#
# Customs itself logs important information in a file whose name is gotten
# by tacking ".<hostname>" to the end of LOG_BASE. I use a directory that
# is available to all machines so as to keep the information in a single place.
#
LOG_BASE	= /n/lithium/src/pmake/customs/log/log

#
# If INSECURE is defined, Customs will allow root to export things. This should
# only be done in a very friendly environment, as there is little other
# security built in.
#
INSECURE	= -DINSECURE

CFLAGS		+= -g $(INSECURE) -DLOG_BASE=\"$(LOG_BASE)\" -I.

#CC		= gcc -O -fstrength-reduce -finline-functions
#
# If there's no /dev/kbd from which Customs can derive the user's idle time
# (this is intended for workstations only), don't do idle time checking.
#
#if !exists(/dev/kbd)
CFLAGS		+= -DNO_IDLE
#endif sun

#
# If making a profiled version, give the proper flags and configure pieces of
# code properly. Note this isn't done on a sun because the last time I profiled
# pmake on a sun, it died in the profiling code...
#
#if make(prof) && !defined(sun)
CFLAGS		+= -pg -DPROF
#endif

#
# Objects that make up the Customs daemon itself. OSOBJ is the object file
# that contains the OS functions to determine the state of the machine.
#	os-sunos4 should be used for suns running SunOS4.0 or higher
#	os-bsd can be used for all unixes that are based on the Berkeley
#	    Software Distribution.
# I have no System V machine around, so I can't write the interface for it.
#
OSOBJ		= os-sunos4.o -lkvm
#OSOBJ		= os-bsd.o
CUSTOMSOBJS 	= customs.o mca.o avail.o import.o election.o rpc.o xdr.o \
		log.o swap.o $(OSOBJ)
#
# Files required by all clients to talk to the Customs agent
#
RPCOBJS		= customslib.o rpc.o

#
# All clients made by this makefile
#
USERCLIENTS	= export reginfo pmake
SYSCLIENTS	= importquota cctrl logd
CLIENTS		= $(USERCLIENTS) $(SYSCLIENTS)

#
# Add the rpc objects to the list of objects, as the customs rmt module needs
# them.
#
OBJS		+= $(RPCOBJS)

#
all		: customs $(CLIENTS) 

#
# Simple installation rule -- not all systems allow one to install many files
# at once, so do it in a 'for' loop
#
install		:: .NOEXPORT all
	for i in $(SYSCLIENTS) customs; do
	    install -m $(ETCMODE) -o root -g wheel $i $(ETCDIR)
	done
	for i in $(USERCLIENTS); do
	    install -m 755 -o $(OWNER) $i $(BINDIR)
	done


#
# Rule to link all clients. Very simple
#
LINK		: .USE .EXPORTSAME
	$(CC) $(CFLAGS) $(LDFLAGS) $(.ALLSRC) -o $(.TARGET)

customs		: $(CUSTOMSOBJS) $(LISTLIB) 			LINK
#host		: host.o $(RPCOBJS)				LINK
export		: export.c $(RPCOBJS) .NOEXPORT			LINK
importquota	: importquota.o $(RPCOBJS)			LINK
reginfo		: reginfo.o $(RPCOBJS)				LINK
logd		: logd.o $(RPCOBJS) xdr.o			LINK
prof		: pmake
pmake		: $(OBJS) $(LISTLIB) $(SPRITELIB) 		LINK
cctrl		: cctrl.o $(RPCOBJS)				LINK

#
# These were used for testing and benchmarking only.
#
#nulltest	: test/nulltest.c $(RPCOBJS)			LINK
#rpctest	: test/rpctest.c rpc.o				LINK
#rpcsrv		: test/rpcsrv.c rpc.o				LINK
#pmake.ideal	: $(OBJS:s/job/idealJob/) -llst -lwild LINKCOMPAT

clean		:: .NOEXPORT
	rm -f customs $(CLIENTS) *.o
#
# Declare additional sources for which dependencies should be generated
#
depend		: $(CUSTOMSOBJS:S/.o$/.c/g) host.c export.c importquota.c \
		reginfo.c logd.c cctrl.c customslib.c

#include "$(DEPFILE)"

