#
#	Makefile for the Clean Standard Environment
#

#
#		make (= make stdenv):
#			compiles all modules
#
#		make install:
#			compiles all modules
#			copies files to install directory
#
#		make cleanup:
#			removes all files in this directory that can be recreated
#


CLEAN_MODULES = \
	StdArray StdCharList StdClass StdEnv \
	StdFunc StdList StdOverloaded StdTuple _SystemEnum

SYSTEM_MODULES = \
	StdBool StdChar StdEnum StdFile StdInt StdMisc StdReal \
	StdString _SystemArray

ABC_MODULES = \
	_system

OBJECT_MODULES = \
	_startup # _reals

# Solaris: crt

#
# the order here is important, because the files will be
# installed in the order given below.
#
STDENV_FILES = \
	$(CLEAN_MODULES:%=%.icl) \
	$(CLEAN_MODULES:%=%.dcl) \
	$(SYSTEM_MODULES:%=%.dcl) \
	$(CLEAN_MODULES:%=%.abc) \
	$(SYSTEM_MODULES:%=%.abc) \
	$(ABC_MODULES:%=%.abc) \
	$(CLEAN_MODULES:%=%.o) \
	$(SYSTEM_MODULES:%=%.o) \
	$(ABC_MODULES:%=%.o) \
	$(OBJECT_MODULES:%=%.o)

#
# Compile
#

stdenv: $(STDENV_FILES)

#
# Install
#

INSTALL_STDENV_DIR = /tmp/ronny/local/lib/clean/stdenv
INSTALL_STDENV_FILES = $(STDENV_FILES:%=$(INSTALL_STDENV_DIR)/%)

install: stdenv $(INSTALL_STDENV_DIR) $(INSTALL_STDENV_FILES)

$(INSTALL_STDENV_DIR) : 
	install -d $@

$(INSTALL_STDENV_DIR)/% : %
	install -m 644 $< $@

#
# Cleanup
#

cleanup:
	$(RM) $(CLEAN_MODULES:%=%.abc) \
	$(RM) $(CLEAN_MODULES:%=%.o) \
	$(RM) $(SYSTEM_MODULES:%=%.o) \
	$(RM) $(ABC_MODULES:%=%.o)


#
# Commands
#

CLM = clm
CLMFLAGS =

.SUFFIXES: .abc .dcl .icl .o

.icl.abc:
	$(CLM) $(CLMFLAGS) -ABC $*

.icl.o:
	$(CLM) $(CLMFLAGS) -O $*

.abc.o:
	$(CLM) $(CLMFLAGS) -O $*
