# 
# Copyright (C) 1999, 2000, 2001  Network Associates, Incorporated (NAI)
# All rights reserved.
#
# This file is part of the NAI Generic Software Wrappers Toolkit
# (GSWTK).  See ftp://ftp.tislabs.com/pub/wrappers/ for the latest
# distribution.
#
# The GSWTK is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# The GSWTK is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

TOPDIR		= .

.PHONY: all clean distclean install release tar
.PHONY: default.mak config config.mak reconfig touchconfig cleanconfig
.PHONY: mkpkgcontents

include ${TOPDIR}/mak/${OS}${OSTYPE}.mak

all: default.mak config
	@${MAKE} -f Makefile.stage2 $@

install:
	@${MAKE} -f Makefile.stage2 $@

release:
	@${MAKE} -f Makefile.stage2 $@

clean: default.mak touchconfig
	@${MAKE} -f Makefile.stage2 $@

default.mak: mak/default.mak wr.mak/default.mak

mak/default.mak wr.mak/default.mak: mak/$(OS)$(OSTYPE).mak wr.mak/$(OS)$(OSTYPE).mak
	@${RM} mak/default.mak wr.mak/default.mak
	@${CP} mak/$(OS)$(OSTYPE).mak mak/default.mak
	@${CP} wr.mak/$(OS)$(OSTYPE).mak wr.mak/default.mak
	@echo default.mak file created.

config: config.mak

config.mak: configuration mak/config.mak

configuration mak/config.mak: configure configure${OSSCRIPTEXT}
	@touch mak/config.mak
	@${OSSCRIPTRUN} configure${OSSCRIPTEXT} ${CONFIGUREFLAGS}

reconfig:
	@${RM} configuration mak/config.mak
	@touch mak/config.mak
	@${OSSCRIPTRUN} configure${OSSCRIPTEXT} ${CONFIGUREFLAGS}

distclean: clean cleanconfig

cleanconfig:
	${RM} configuration mak/config.mak mak/default.mak \
		include/configuration.h

touchconfig:
	@if [ ! -f mak/config.mak -o ! -s mak/config.mak ]; then \
		echo 'include $${TOPDIR}/mak/default.mak' > mak/config.mak; \
	fi

mkpkgcontents:
	@if [ -d ${TOPDIR}/._package_contents_ ]; then \
	   ${RM} -r ${TOPDIR}/._package_contents_; \
	fi
	@${TOPDIR}/mak/mkdirhier ${TOPDIR}/._package_contents_
	@${MAKE} INSTALLROOT=`pwd`/._package_contents_ -f Makefile.stage2 install

tar: mkpkgcontents
	@PWD=`pwd`; \
	cd ${TOPDIR}/._package_contents_; \
	echo "tar -cpf - . | gzip -c - > ${TOPDIR}/../gswtk-1.9-${OS}${OSTYPE}.tgz"; \
	tar -cpf - . | gzip -c - > ${TOPDIR}/../gswtk-1.9-${OS}${OSTYPE}.tgz;
	@${RM} -r ${TOPDIR}/._package_contents_

