#
#  Makefile for the parallel Make program running under UNIX
#
#  $Header: /usr/src/local/icsi/pmake/RCS/makefile,v 1.22 2001/05/17 02:38:54 stolcke Exp $ SPRITE (Berkeley)
#
SHELL		= /bin/sh

#
# Path variables:
#	DESTDIR			Installation root
#	BINDIR			where pmake should be installed.
#	LIBDIR			place to store pmake's canned makefiles
#				(e.g. system.mk -- DEFSYSPATH in config.h)
#	SYSTEM_MK    	    	Actual name for the system makefile. I
#				use system.mk.
#	LIBSRC	    	    	directory in which pmake's libraries are stored
#	MKDIR	    	    	where distributed canned makefiles are stored
#				before being installed in DESTLIB
#	SPRITEDIR		where the Sprite->UNIX compatibility
#				library is located.
#	LSTDIR			location of linked-list library
#
DESTDIR		=
BINDIR		= /usr/local/bin
LIBDIR		= /usr/local/lib/pmake
SYSTEM_MK	= system.mk

LIBSRC		= lib
MKDIR		= $(LIBSRC)/mk
SPRITEDIR	= $(LIBSRC)/sprite
LSTDIR		= $(LIBSRC)/lst

#
# SOURCE DEFINITIONS -- All Sources for this program:
#
HDRS		= make.h job.h nonints.h config.h
OBJS		= arch.o compat.o cond.o dir.o make.o job.o main.o parse.o \
                  suff.o targ.o rmt.o str.o var.o
SRCS		= src/arch.c src/compat.c src/cond.c src/dir.c src/make.c \
                  src/job.c src/main.c src/parse.c src/suff.c src/targ.c \
                  $(RMT) src/str.c src/var.c
LLIBS		= $(LSTDIR)/llib-llst.ln $(SPRITEDIR)/llib-lsprite.ln
LIBS		= $(LSTDIR)/liblst.a $(SPRITEDIR)/libsprite.a

#
# Alter egos you want to support. smake and vmake both do System V
# impersonations, while just make pretends to be Make
#
#ALIASES		= make smake vmake
ALIASES		= vmake

#
# Configuration info.
#	CONFDIR	    Where the system-dependent files config.h and rmt.c are
#	CONFIG	    The actual path to config.h
#	RMT 	    Ditto for rmt.c
#
CONFDIR		= unix
CONFIG		= $(CONFDIR)/config.h
RMT		= $(CONFDIR)/rmt.c

#
# FLAG DEFINITIONS -- Flag variables for the various compilers, syntax
# checkers and whatnots
#
COFLAGS 	=
LDFLAGS		= $(CCFLAGS) $(SYSFLAGS)
LNFLAGS		= -b

#
# MACHFLAGS	machine-specific flags (e.g. -m68010 for sun-2 compatibility
#		on sun-3's)
# SYSFLAGS	system-specific flags (e.g. -DSYSV for System V)
# INCLUDES	location of our include files
#
MACHFLAGS	= -O -g
# SunOS 5.x
#CC		= gcc
#SYSFLAGS	= -DSYSV -DSVR4
# HP-UX
#SYSFLAGS	= -DSYSV
# SGI
#SYSFLAGS	= -xansi -D__STDC__ -DSYSV
# OSF/Alpha
#CC		= cc -std1
#SYSFLAGS	= -DSYSV
# Linux 
SYSFLAGS	= -DSYSV -DSVR4
# BSD
#SYSFLAGS	= 
#SYSLIBS		=

INCLUDES	= -I$(CONFDIR) -Isrc -I$(LSTDIR) -I$(LIBSRC)/include

CONFIGFLAGS	= -DDEFSYSPATH=\"$(LIBDIR)\" \
		  -DDEFSYSMK=\"$(SYSTEM_MK)\"

#
# CCFLAGS are for defining additional flags on the command line...
#

CFLAGS		= $(INCLUDES) $(MACHFLAGS) $(SYSFLAGS) $(CCFLAGS)


pmake		: $(OBJS) $(LIBS)
	$(CC) -o $@ $(LDFLAGS) $(OBJS) $(LIBS) $(SYSLIBS)

$(LSTDIR)/liblst.a:
	(cd $(LSTDIR); make $(MFLAGS) "INCLUDES=-I../include" \
		"CC=$(CC)" "MACHFLAGS=$(MACHFLAGS) $(SYSFLAGS)")

$(SPRITEDIR)/libsprite.a:
	(cd $(SPRITEDIR); make $(MFLAGS) \
		"CC=$(CC)" "MACHFLAGS=$(MACHFLAGS) $(SYSFLAGS)")

libraries	:
	(cd $(LSTDIR); make $(MFLAGS) "INCLUDES=-I../include" \
		"CC=$(CC)" "MACHFLAGS=$(MACHFLAGS) $(SYSFLAGS)")
	(cd $(SPRITEDIR); make $(MFLAGS) "INCLUDES=-I../include" \
	        "CC=$(CC)" "MACHFLAGS=$(MACHFLAGS) $(SYSFLAGS)")

nonints		: 
	rm -f src/nonints.h
	$(LIBSRC)/findni $(.ALLSRC) > /tmp/mni$$; \
	    sed -e 's/(.*)/()/' /tmp/mni$$ > src/nonints.h
	chmod 444 src/nonints.h

install		: pmake
	test -d $(DESTDIR)$(BINDIR) || mkdir $(DESTDIR)$(BINDIR)
	cp pmake $(DESTDIR)$(BINDIR)
	for i in $(ALIASES); do \
		rm -f $(DESTDIR)$(BINDIR)/$$i; \
		ln -s pmake $(DESTDIR)$(BINDIR)/$$i; \
	done
	test -d $(DESTDIR)$(LIBDIR) || mkdir $(DESTDIR)$(LIBDIR)
	cd $(MKDIR); for f in $(SYSTEM_MK) *.mk ; do \
		rm -f $(DESTDIR)$(LIBDIR)/$$f ; \
		cp $$f $(DESTDIR)$(LIBDIR)/$$f ; \
	done

depend		:
	makedepend -p $(INCLUDES) -f makefile $(SRCS)

clean		:
	rm -f pmake $(OBJS)
	(cd $(LIBSRC); make clean)

#
# This is truly gross, but most makes can't handle multiple directories, nor
# do they look at the list of sources to determine the transformation rule
# to use...
#
arch.o		: src/arch.c
	$(CC) $(CFLAGS) -c src/arch.c
compat.o	: src/compat.c
	$(CC) $(CFLAGS) -c src/compat.c
cond.o		: src/cond.c
	$(CC) $(CFLAGS) -c src/cond.c
dir.o		: src/dir.c
	$(CC) $(CFLAGS) -c src/dir.c
make.o		: src/make.c
	$(CC) $(CFLAGS) -c src/make.c
job.o		: src/job.c
	$(CC) $(CFLAGS) -c src/job.c
main.o		: src/main.c
	$(CC) $(CFLAGS) $(CONFIGFLAGS) -c src/main.c
parse.o		: src/parse.c
	$(CC) $(CFLAGS) -c src/parse.c
suff.o		: src/suff.c
	$(CC) $(CFLAGS) -c src/suff.c
targ.o		: src/targ.c
	$(CC) $(CFLAGS) -c src/targ.c
rmt.o		: $(RMT)
	$(CC) $(CFLAGS) -c $(RMT)
str.o		: src/str.c
	$(CC) $(CFLAGS) -c src/str.c
var.o		: src/var.c
	$(CC) $(CFLAGS) -c src/var.c
#
# This is for system V only
#
utimes.o	: src/utimes.c
	$(CC) $(CFLAGS) -c src/utimes.c

package		: 
	-mkdir $(PKGDIR)
	-mkdir $(PKGDIR)/unix
	-mkdir $(PKGDIR)/src
	-mkdir $(PKGDIR)/tests
	cp Makefile copyright common.mk patchlevel README makefile $(PKGDIR)
	cp src/*.[ch] $(PKGDIR)/src
	cp unix/rmt.c unix/config.h $(PKGDIR)/unix
	cp tests/*.test tests/TESTALL tests/README tests/ucb.l \
            tests/openStreams.c $(PKGDIR)/tests
	(cd customs; make PKGDIR=$(PKGDIR)/customs package)
	(cd lib; make PKGDIR=$(PKGDIR)/lib package)
	(cd doc; make PKGDIR=$(PKGDIR)/doc package)
	(cd prefix; make PKGDIR=$(PKGDIR)/prefix package)

# DO NOT DELETE THIS LINE -- make depend depends on it.

arch.o: src/make.h
arch.o: lib/include/sprite.h lib/lst/lst.h unix/config.h src/nonints.h
arch.o: lib/include/hash.h lib/include/list.h
compat.o: src/make.h lib/include/sprite.h lib/lst/lst.h
compat.o: unix/config.h src/nonints.h
cond.o: src/make.h lib/include/sprite.h lib/lst/lst.h unix/config.h
cond.o: src/nonints.h lib/include/buf.h
dir.o: src/make.h lib/include/sprite.h
dir.o: lib/lst/lst.h unix/config.h src/nonints.h
dir.o: lib/include/hash.h lib/include/list.h
make.o: src/make.h lib/include/sprite.h
make.o: lib/lst/lst.h unix/config.h src/nonints.h
job.o: src/make.h
job.o: lib/include/sprite.h lib/lst/lst.h unix/config.h src/nonints.h
main.o: src/make.h lib/include/sprite.h lib/lst/lst.h unix/config.h
main.o: src/nonints.h lib/include/option.h
parse.o: src/make.h
parse.o: lib/include/sprite.h lib/lst/lst.h
parse.o: unix/config.h src/nonints.h lib/include/buf.h
suff.o: src/make.h lib/include/sprite.h lib/lst/lst.h unix/config.h
suff.o: src/nonints.h lib/include/bit.h
targ.o: src/make.h
targ.o: lib/include/sprite.h lib/lst/lst.h unix/config.h src/nonints.h lib/include/hash.h
targ.o: lib/include/list.h
rmt.o: src/make.h lib/include/sprite.h
rmt.o: lib/lst/lst.h unix/config.h src/nonints.h
str.o: src/make.h lib/include/sprite.h
str.o: lib/lst/lst.h unix/config.h src/nonints.h
var.o: src/make.h lib/include/sprite.h lib/lst/lst.h unix/config.h src/nonints.h
var.o: lib/include/buf.h
