#
# Makefile for LSF version of pmake 
#
# $Id: Makefile,v 1.3 1995/08/19 17:58:30 stolcke Exp $ ICSI (Berkeley)
#
# 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
# Copyright (c) 1995 by Andreas Stolcke
#
# 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, Adam de Boor, and Andreas Stolcke 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		= $$USER

#
# Strip installed binaries
#
STRIP		= -s

#
# Install flags for user clients that can do no harm.
#
BINMODE		= -m 755 -o $(OWNER) $(STRIP)
#
# Install flags for exporting clients.  If USE_RESERVED_PORTS was enabled in
# config.h, these need to be suid root.
#
XBINMODE	= -m 4755 -o root $(STRIP)

#
# Shell commands run after binary installation is complete.  May be used
# to fix up anything that needs special handling.
#
POSTINSTALL	= true

#
# Include PMake common description
#
DEPFILE		?= dependencies.mk
#include	"$(.CURDIR)/../common.mk"

#
# Local changes to installation, etc.
#
#if exists($(.CURDIR)/../config.mk)
#include	"$(.CURDIR)/../config.mk"
#endif

LSF_INCDIR	= /people/LSF/include
LSF_LIBDIR	= /apps/lsf/lib
LSF_LIBS	= -llsf

#
# System dependencies
#
#if defined(sun) && defined(SVR4)
LSF_LIBS	+= -lsocket -lnsl
#endif

#
#
# Additional path definitions
#
.PATH.h		: $(INCLUDE) $(.CURDIR)/.. $(LSF_INCDIR)
.PATH.a		: $(SPRITEDIR)/$(MAKEOBJDIR) $(LSF_LIBDIR)
.PATH.c		: test

.SHELL:

CC		?= cc
LDCC		?= $(CC)
MACHFLAGS	?=
OPTIMIZE	?= -g -O

CFLAGS		+= $(OPTIMIZE) $(MACHFLAGS) -I.

#ifdef PURIFY
LDCC		:= purify $(LDCC) $(STATICFLAG)
CFLAGS		+= -DPURIFY
#endif

#ifdef SYSV
CFLAGS		+= -DSYSV
#endif
#ifdef SVR4
CFLAGS		+= -DSVR4
#endif

EXTRASRCS	= normPath.c
EXTRAOBJS	= normPath.o

#
# 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

#
# All clients made by this makefile
#
XUSERCLIENTS	= pmake

all		: pmake

#
# Simple installation rule -- not all systems allow one to install many files
# at once, so do it in a 'for' loop
#
install		:: install-bin

install-bin	:: .NOEXPORT
	test -d $(DESTDIR)$(BINDIR) || mkdir $(DESTDIR)$(BINDIR)
	if test ! -f $(DESTDIR)$(BINDIR)/pmake.nolsf; then
	   -mv $(DESTDIR)$(BINDIR)/pmake $(DESTDIR)$(BINDIR)/pmake.nolsf
	else
	   -mv $(DESTDIR)$(BINDIR)/pmake $(DESTDIR)$(BINDIR)/pmake~
	fi
	for i in $(XUSERCLIENTS); do
	    $(INSTALL) $(XBINMODE) $i $(DESTDIR)$(BINDIR)/`basename $i`
	done
	$(POSTINSTALL)

#
# Bump version number whenever any part of the system is updated.
# version.h is included in customs.c.  We cannot let version.h depend
# on customs.o because that would create a cyclic dependency.
# Don't export to get the hostname in the version string right.
#
version.h	: $(LISTLIB) $(SPRITELIB) \
		  .NOEXPORT
		sh $(.CURDIR)/../etc/newvers.sh

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

# link customs as pure executable so doesn't depend on server binary
pmake		: $(OBJS) $(EXTRAOBJS) $(LIBS) $(LSF_LIBS)	LINK

#ifdef exists($(DEPFILE))
#include "$(DEPFILE)"
#endif

clean		:: .NOEXPORT
	$(RM) *.o

#
# Declare additional sources for which dependencies should be generated
#
depend		: $(EXTRASRCS) .NOEXPORT

tags		: $(EXTRASRCS)

#
# Some targets for testing
#
#TESTCMD	= hostname
TESTCMD		= /bin/sleep 10
TESTTARGETS = 0 1 2 3 4 5 6 7 8 9
test:	$(TESTTARGETS)
	:

$(TESTTARGETS):
	$(TESTCMD)

testrm: test.c
	touch testrm
	$(TESTCMD)
