#
# Makefile to make the mini compiler and environment
#
VERSION = 2.3

TOP = $(HOME)/mini

# where go the include files
IDIR = $(TOP)/include

# where goes the prelude
ETCDIR = $(TOP)/etc

# where go the libraries
LDIR = $(TOP)/lib

# where goes the binary
BDIR = $(TOP)/bin

# which compiler
CC = gcc

# default CFLAGS
DCFL = '-O -Wall'
# DCFL = -g

default: install

help:
	@echo "Possible make targets:"
	@echo "all	 Create local libraries and programs."
	@echo "install	 Build and install libraries and programs."
	@echo "clean	 Free disk space."
	@echo "veryclean Free even more disk space."
	@echo "help	 Dump this information."
	@echo "dist	 Build mini distribution."
	@echo "default	 install."

install: dirs
	cd mrts; $(MAKE) install LDIR=$(LDIR) IDIR=$(IDIR) DCFL=$(DCFL) CC=$(CC); cd ..
	cd gen; $(MAKE) install BDIR=$(BDIR) ETCDIR=$(ETCDIR) DCFL=$(DCFL) CC=$(CC); cd ..
	cd prelude; $(MAKE) install ETCDIR=$(ETCDIR); cd ..
	cd driver; $(MAKE) install LDIR=$(LDIR) BDIR=$(BDIR) DCFL=$(DCFL) CC=$(CC); cd ..
	cd scripts; $(MAKE) install BDIR=$(BDIR); cd ..

all:
	cd mrts; $(MAKE) all LDIR=$(LDIR) IDIR=$(IDIR) DCFL=$(DCFL) CC=$(CC); cd ..
	cd gen; $(MAKE) all BDIR=$(BDIR) DCFL=$(DCFL) CC=$(CC); cd ..
	cd prelude; $(MAKE) all ETCDIR=$(ETCDIR); cd ..
	cd driver; $(MAKE) all LDIR=$(LDIR)  BDIR=$(BDIR) DCFL=$(DCFL) CC=$(CC); cd ..
	cd scripts; $(MAKE) all BDIR=$(BDIR); cd ..

clean:
	cd mrts; $(MAKE) clean; cd ..
	cd gen; $(MAKE) clean; cd ..
	cd driver; $(MAKE) clean; cd ..
	cd ex1; $(MAKE) clean; cd ..

dirs:
	if [ ! -d $(BDIR) ]; then mkdir $(BDIR); fi
	if [ ! -d $(ETCDIR) ]; then mkdir $(ETCDIR); fi
	if [ ! -d $(IDIR) ]; then mkdir $(IDIR); fi
	if [ ! -d $(LDIR) ]; then mkdir $(LDIR); fi

veryclean: clean
	rm -rf $(BDIR)
	rm -rf $(ETCDIR)
	rm -rf $(IDIR)
	rm -rf $(LDIR)
	cd doc; rm -rf *.log *.dvi *.ps; cd ..

dist:	veryclean
	cd ..; \
	tar cvfz mini-2.3.tgz mini/Makefile mini/doc mini/driver mini/ex1 \
	 	          mini/gen mini/mrts mini/prelude mini/scripts;
	cd mini
