#
# General Makefile for PMake. Handles distribution, packaging, etc.
#
# $Id: Makefile,v 1.22 1995/08/19 18:09:52 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
#
# 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 make no representations about
# the suitability of this software for any purpose.  It is provided
# "as is" without express or implied warranty.
#

LOCALS		= Distfile Makefile README common.mk makefile patchlevel.h
SUBDIRS		= doc lib unix lsf src etc
SUBDIRS		+= customs
NO_DIST_FILES	= pmake doc/pmake.1 doc/index/index customs/myconfig.h \
		  customs/pmake customs/reginfo customs/customs customs/export \
		  customs/cctrl customs/importquota customs/logd customs/host \
		  customs/version etc/snake etc/fixes FTPLOG
NO_DIST_PATTERN	= -type d -name \*.md \
		  -o -name \*.o -o -name \*.a -o -name \*.ln -o -name \*.bak \
		  -o -name RCS -o -name LOCK.make -o -name core -o -name .exrc \
		  -o -name dependencies.mk

VERSION		!= awk -f etc/version.awk patchlevel.h

DIRNAME		= /tmp/dirname
EXCLUDE		= /tmp/exclude
ARCHIVE		= /usr/local/ftp/ai/stolcke/software/pmake-$(VERSION).tar.Z

#if exists(config.mk)
#include	"config.mk"
#endif

#ifdef TARG_NAME
OBJDIR		= MAKEOBJDIR=$(TARG_NAME).md
#else
OBJDIR		=
#endif

ERROR		::
	: Please specify something to make...

new		:
	@echo "Cleaning first build"
	rm -f pmake *.o
	(cd lib; MAKEOBJDIR=. $(MAKE) clean)
	@echo "Making object dirs"
	$(MAKE) dirs
	@echo "Trying to make dependencies"
	-(cd customs; $(OBJDIR) $(MAKE) depend)
	@echo "Making all"
	$(MAKE) all

dist		: $(ARCHIVE)

beta		:	.NOEXPORT
	$(MAKE) VERSION=$(VERSION)beta dist

check-dist	:	.NOEXPORT
	uncompress < $(ARCHIVE) | tar tvf - 

$(ARCHIVE)	: .NOEXPORT
	basename `pwd` > $(DIRNAME)
	(cd ..; find `cat $(DIRNAME)` \
		\( $(NO_DIST_PATTERN) \) -print ) \
		> $(EXCLUDE)
	for f in $(NO_DIST_FILES); do \
		echo `cat $(DIRNAME)`/$$f >> $(EXCLUDE) ; \
	done
	echo `cat $(DIRNAME)`/src/Makefile >> $(EXCLUDE)
	echo `cat $(DIRNAME)`/$(ARCHIVE) >> $(EXCLUDE)
	(cd ..; tar cofX - $(EXCLUDE) `cat $(DIRNAME)`) | compress > $@

all dirs clean	:	.NOEXPORT
	(cd lib; $(OBJDIR) $(MAKE) $(.TARGET))
	(cd customs; $(OBJDIR) $(MAKE) $(.TARGET))

tags		:	.NOEXPORT
	(cd lib; $(MAKE) $(.TARGET))
	(cd customs; $(MAKE) $(.TARGET))

install		:	.NOEXPORT
	(cd customs; $(OBJDIR) $(MAKE) $(.TARGET))
	(cd doc; $(MAKE) $(.TARGET))

