# -*- Makefile -*-
# $Id: Makefile,v 1.12 1997/06/02 04:39:14 miyazaki Exp $
#
# Makefile for creating relations
#
# Copyright (C) 1996-1997 by Haruo Yokota, 
#	Japan Advanced Inst. of Sci. and Tech.,
#	1-1 Asahidai, Tatsunokuchi, Ishikawa 923-12, Japan.


SHELL		= /bin/sh
RM		= /bin/rm -f
ENCODER		= ../coding/encoder

#RELATIONS 	= attributes dept emp stpcd1 stpcd10 stpcd3 faculty students location rule audit
#RELATIONS 	= attributes dept emp faculty students location rule audit
RELATIONS 	= attributes dept emp faculty location rule audit
NSDISKDIRS	= //d020 //d021 //d030 //d031 //d040 //d041 //d050 //d051 \
		  //d060 //d061 //d070 //d071 //d080 //d081 //d090 //d091

NSDISKROOT	= parade2

.PHONY:	all sun install.sun ncube install.ncube makedirs copyrels

all: sun

sun:
	relroot=$(PARADEROOT)/common; \
	if [ ! -f relations ]; then \
	  sed -e s@RELROOT@$${relroot}/rel@ relations.skel > relations; \
	fi; \
	if [ ! -d ../newrel ]; then \
	  mkdir ../newrel ; \
	fi; \
	if [ ! -f ../newrel/relations ]; then \
	  sed -e s@RELROOT@$${relroot}/newrel@ \
		relations.skel | $(ENCODER) ../newrel/relations; \
	fi; \
	for file in $(RELATIONS); do \
	  if [ ! -f ../newrel/$$file ]; then \
	    echo "encoding $$file"; \
	    $(ENCODER) $$file ../newrel/$$file; \
	  fi; \
	done

install.sun: sun

ncube:
	- for nsdiskdir in $(NSDISKDIRS); do \
	  echo "mkdir $${nsdiskdir}/$(NSDISKROOT)"; \
	  xnc mkdir $${nsdiskdir}/$(NSDISKROOT); \
	done; \
	sed -e s@RELROOT@$(NSDISKROOT)@ nrelations.skel > nrelations; \
	$(ENCODER) nrelations ../newrel/nrelations; \
	distdir=`grep relations nrelations \
		| sed -e s@\\[@@ -e s@\\]\\.@@ -e s@\"@@g \
		| awk -F, '{print $$2}' | grep $${relation}$$`; \
	echo "copying ../newrel/nrelations to $$distdir"; \
	xnc cp ../newrel/nrelations  $$distdir; \
	for relation in $(RELATIONS); do \
	  distdir=`grep $$relation nrelations \
		| sed -e s@\\[@@ -e s@\\]\\.@@ -e s@\"@@g \
		| awk -F, '{print $$2}' | grep $${relation}$$`; \
	  echo "copying ../newrel/$$relation to $$distdir"; \
	  xnc cp ../newrel/$$relation $$distdir; \
	done

install.ncube: ncube

####
.PHONY:	all-clean clean.sun clean.ncube clean

all-clean: clean.sun clean.ncube
	$(RM) core

clean.sun:
	$(RM) relations nrelations log
	(cd ../newrel && $(RM) -r $(RELATIONS) *);

clean.ncube:
	-for dir in $(NSDISKDIRS); do \
	  echo "cleaning $${dir}/$(NSDISKROOT)"; \
	  xnc rm -r -f $${dir}/$(NSDISKROOT); \
	done

clean:
