# Makefile
#
# COPYRIGHT (c) 2009 The Fellowship of SML/NJ (http://www.smlnj.org)
# All rights reserved.
#

SHELL =			/bin/sh
SML =			sml
ML_BUILD =		ml-build
ML_MAKEDEPEND =		ml-makedepend

# NOTE: the @SMLsuffix option is new with SML/NJ 110.72
#HEAP_SUFFIX = $(shell sml @SMLsuffix)
HEAP_SUFFIX = $(shell echo 'TextIO.output (TextIO.stdErr, SMLofNJ.SysInfo.getHeapSuffix ());' | sml 2>&1 1> /dev/null)

PROGRAM =	ml-ulex
HEAP_IMAGE =	$(PROGRAM).$(HEAP_SUFFIX)

FE = 		FrontEnds
BE = 		BackEnds

ML_LEX =	$(FE)/ml-lex
ML_LEX_SRC = 	$(wildcard $(ML_LEX)/*.sml) $(ML_LEX)/ml-lex.lex $(ML_LEX)/ml-lex.yacc

ML_ULEX =	$(FE)/ml-ulex
ML_ULEX_SRC = 	$(wildcard $(ML_ULEX)/*.sml) $(ML_ULEX)/ml-ulex.lex $(ML_ULEX)/ml-ulex.grm

DUMP_SRC =	$(wildcard $(BE)/Dump/*.sml)
DOT_SRC =	$(wildcard $(BE)/Dot/*.sml)
SML_SRC = 	$(wildcard $(BE)/SML/*.sml)
MATCH_SRC = 	$(wildcard $(BE)/Match/*.sml)

FE_SRC = 	$(wildcard $(FE)/*.sml) $(ML_LEX_SRC) $(ML_ULEX_SRC)
BE_SRC = 	$(wildcard $(BE)/*.sml) $(DOT_SRC) $(SML_SRC) $(MATCH_SRC)

CORE_SRC =	$(wildcard *.sml)

SOURCES =	$(CORE_SRC) $(FE_SRC) $(BE_SRC) sources.cm

build:		$(HEAP_IMAGE)

$(HEAP_IMAGE):	$(SOURCES)
	$(ML_BUILD) sources.cm Main.main $(PROGRAM)

.depend:	$(CM_FILES)
	touch .depend
	$(ML_MAKEDEPEND) -n -f .depend sources.cm $(HEAP_IMAGE)

sinclude .depend

# NOTE: do NOT clean out ml-lex.lex.sml, it is not autogenerated!
clean:
	rm -rf .depend .cm $(HEAP_IMAGE)
