TargetDir = $(ASMLDEVDIR)\bin\$(Config)
ReleaseDir = $(ASMLDEVDIR)\bin\Debug
ASMLC = $(MAKEDIR)\asmlc.bootx.exe
CSC = csc
GREP = grep
WATCH =
ILMERGE = $(ASMLDEVDIR)\bin\Debug\ILMerge.exe
Config = Debug
RuntimeReferences = /reference:AsmLRuntime.dll /reference:AsmL15CompatibilityLibrary.dll
VERSION=0
BUILD=0

MAKECALL=$(MAKE) /nologo /$(MAKEFLAGS) ASMLC="$(ASMLC)" CSC="$(CSC)" Config="$(Config)" TargetDir="$(TargetDir)" RuntimeReferences="$(RuntimeReferences)" 

# main targets
ALLTARGETS= makeDtd makeCCI makeCustomTypeEditors makeRuntime makeUtilities makeFramework makeCompiler makeRemoting makeEnv makeDriver makeWord 

all: 
	@-mkdir $(TargetDir)
	@$(MAKECALL) Target=  $(ALLTARGETS)

minimal:
	@-mkdir $(TargetDir)
	@$(MAKECALL) Target= makeCCI makeCustomTypeEditors makeUtilities makeRuntime makeFramework makeCompiler makeRemoting makeEnv makeDriver 

docs: 
	@-regsvr32 /s $(ASMLDEVDIR)\bin\AsmLAddInHelper.dll
	@$(MAKECALL) Target=all makeDoc
	@$(MAKECALL) Target=doc $(ALLTARGETS)

install: 
	@$(MAKECALL) Target=install $(ALLTARGETS)

minimalinstall: 
	@$(MAKECALL) Target=install makeRuntime makeWeb makeFramework makeCompiler makeEnv makeDriver makeWord 

clean: 
	@$(MAKECALL) Target=clean $(ALLTARGETS)

rebuild: 
	@$(MAKECALL) Target=rebuild $(ALLTARGETS)

bootcompiler: all 
	@echo --------------- Boot Compiler -------------------------------
	@$(MAKECALL) ASMLCBOOT=$(MAKEDIR)\asmlc.boot.exe $(MAKEDIR)\asmlc.boot.exe

testboot:  
	@echo --------------- Boot Compiler -------------------------------
	@$(MAKECALL) ASMLCBOOT=$(MAKEDIR)\asmlc.bootx.exe $(MAKEDIR)\asmlc.bootx.exe

selftest: minimal
	@echo --------------- Selftest 1st Step ---------------------------
	@$(MAKECALL) ASMLCBOOT=$(MAKEDIR)\asmlc.new.exe $(MAKEDIR)\asmlc.new.exe
	@$(WATCH) $(MAKE) /nologo /$(MAKEFLAGS) ASMLC=$(MAKEDIR)\asmlc.new.exe CSC=$(CSC) Config=Self1 TargetDir=$(ASMLDEVDIR)\bin\Self1 all 
	@echo --------------- Selftest 2nd Step ---------------------------
	@$(MAKE) /nologo /$(MAKEFLAGS) Config=Self1 TargetDir=$(ASMLDEVDIR)\bin\Self1 ASMLCBOOT=$(MAKEDIR)\asmlc.self1.exe $(MAKEDIR)\asmlc.self1.exe
    set ASMLNOTYPEASSERTS=yes
    set ASMLNOEXCEPTIONWRAPPING=yes
	@$(WATCH) $(MAKE) /nologo /$(MAKEFLAGS) ASMLC=$(MAKEDIR)\asmlc.self1.exe CSC=$(CSC) Config=Self2 TargetDir=$(ASMLDEVDIR)\bin\Self2 all

asmlc.self2.exe: selftest
	@$(MAKE) /nologo /$(MAKEFLAGS) Config=Self2 TargetDir=$(ASMLDEVDIR)\bin\Self2 ASMLCBOOT=$(MAKEDIR)\asmlc.self2.exe $(MAKEDIR)\asmlc.self2.exe

bench: asmlc.self2.exe
	@$(WATCH) $(MAKE) /nologo /$(MAKEFLAGS) ASMLC=$(MAKEDIR)\asmlc.self2.exe CSC=$(CSC) Config=Self3 TargetDir=$(ASMLDEVDIR)\bin\Self3 all


qselftest1: minimal
	@echo --------------- Non-Merging Selftest 1st Step ---------------
	@$(WATCH) $(MAKE) ASMLC=$(ASMLDEVDIR)\bin\Debug\asmlc Config=QSelf1 TargetDir=$(ASMLDEVDIR)\bin\QSelf1 minimal

qselftest: qselftest1
	@echo --------------- Non-Merging Selftest 2st Step ---------------
	@$(WATCH) $(MAKE) ASMLC=$(ASMLDEVDIR)\bin\QSelf1\asmlc.exe Config=QSelf2 TargetDir=$(ASMLDEVDIR)\bin\QSelf2 minimal

cleanselftest:
	-del $(MAKEDIR)\asmlc.new.exe 
	-del /Q $(ASMLDEVDIR)\bin\Self1\* 
	-del $(MAKEDIR)\asmlc.self1.exe 
	-del /Q $(ASMLDEVDIR)\bin\Self2\*

cleanqselftest:
	-del /Q $(ASMLDEVDIR)\bin\QSelf1\* 
	-del /Q $(ASMLDEVDIR)\bin\QSelf2\*

# subtargets
makeDtd:
    copy Doc\asml.dtd $(ASMLDEVDIR)\bin\Debug\asml.dtd
    copy Doc\specs.dtd $(ASMLDEVDIR)\bin\Debug\specs.dtd

makeCCI: 
	@echo --------------- CCI -----------------------------------
	@cd $(MAKEDIR)\Tools\CCI 
    @$(MAKECALL) $(Target)

makeDoc: 
	@echo --------------- Doc -----------------------------------
	@cd $(MAKEDIR)\Doc 
    @$(MAKECALL) $(Target)

makeUtilities: 
	@echo --------------- Utilities -----------------------------------
	@cd $(MAKEDIR)\Utilities 
    @$(MAKECALL) $(Target)

makeRuntime: 
	@echo --------------- Runtime -------------------------------------
	@cd $(MAKEDIR)\Runtime 
    @$(MAKECALL) $(Target)

makeCustomTypeEditors:
	@echo --------------- Tools\CustomTypeEditors ---------------------
	@cd $(MAKEDIR)\Tools\CustomTypeEditors
    @$(MAKECALL) $(Target)

makeFramework: 
	@echo --------------- Tools\Framework -----------------------------
	@cd $(MAKEDIR)\Tools\Framework 
    @$(MAKECALL) $(Target)

makeCompiler: 
	@echo --------------- Tools\Compiler ------------------------------
	@cd $(MAKEDIR)\Tools\Compiler 
    @$(MAKECALL) $(Target)

makeRemoting: 
    @echo --------------- Tools\Remoting -----------------------------------
    @cd $(MAKEDIR)\Tools\Remoting 
    @$(MAKECALL) $(Target)

makeEnv: 
	@echo --------------- Tools\Env -----------------------------------
	@cd $(MAKEDIR)\Tools\Env 
    @$(MAKECALL) $(Target)

makeDriver: 
	@echo --------------- Tools\Driver --------------------------------
	@cd $(MAKEDIR)\Tools\BatchCompilerDriver 
    @$(MAKECALL) $(Target)

makeWord: 
	@echo --------------- Tools\Word ----------------------------------
	@cd $(MAKEDIR)\Tools\Word
    @$(MAKECALL) $(Target)

ASMLCBOOT=$(MAKEDIR)\asmlc.bootx.exe

BootAssemblyDeps = $(TargetDir)\AsmLRuntime.dll $(TargetDir)\AsmL15CompatibilityLibrary.dll $(TargetDir)\AsmL.Tools.Framework.dll $(TargetDir)\AsmL.Tools.Compiler.dll $(TargetDir)\AsmL.Tools.Env.dll $(TargetDir)\asmlc.exe

SYSTEMCOMPILERREFS=System.Compiler.dll System.Compiler.Runtime.dll

BootAssemblies = AsmLRuntime.dll AsmL15CompatibilityLibrary.dll AsmL.Tools.Performance.dll AsmL.Tools.Framework.dll SSVParseLib.dll AsmL.Tools.Compiler.ASParser.dll AsmL.Tools.Compiler.dll $(SYSTEMCOMPILERREFS) AsmL.Tools.Env.dll AsmL.Tools.CustomTypeEditors.dll
$(ASMLCBOOT): $(BootAssemblyDeps)
	attrib -r $(ASMLCBOOT)
	$(ILMERGE) /log:ilmerge.log /closed  /target:exe /out:$(ASMLCBOOT) /lib:$(TargetDir) /lib:$(TargetDir) $(TargetDir)\asmlc.exe $(BootAssemblies)
