
#ASMLC = asmlc.exe
ASMLP = $(ASMLDEVDIR)\bin\Debug\asmlp.exe
#ASMLC = twexec /launch $(ASMLDEVDIR)\AsmL\asmlc.boot.exe
ASMLC = $(ASMLDEVDIR)\AsmL\asmlc.bootx.exe
ASML2DOC = $(ASMLDEVDIR)\bin\WordGenerator.exe

ASharp = no
CSC = csc
Config = Debug
TargetDir = $(ASMLDEVDIR)\bin\$(Config)
TargetName = $(TargetDir)\AsmL.Tools.Compiler.dll
MinimalCCI=no

!if "$(MinimalCCI)"=="yes"
SYSTEMCOMPILER=System.Compiler.Minimal.dll
!else
SYSTEMCOMPILER=System.Compiler.dll
!endif


References = /lib:$(TargetDir) /reference:AsmL.Tools.Framework.dll /reference:cscompmgd.dll /reference:system.dll /reference:AsmL.Tools.Compiler.ASParser.dll /reference:SSVParseLib.dll /reference:System.Xml.dll /reference:System.Design.dll /reference:$(SYSTEMCOMPILER) /reference:AsmL.Tools.CustomTypeEditors.dll
RuntimeReferences = /reference:AsmLRuntime.dll /reference:AsmL15CompatibilityLibrary.dll
CSReferences = $(References) $(RuntimeReferences)

!if "$(Config)"=="QSelf1"
#QSELF1_OPTIONS = /basicblock
!endif

VERB=4
Options = /v:$(VERB) /localvaropt /nohint:"AsmL not longer" /nohint:"inserted a possibly failing" /nohint:"uninitialized" /nohint:"adapting" /ignoreSomeAsmL15CompatibilityIssues /allprimitive /nowarn:"deprecated"
CSOptions=/nowarn:0108 /nowarn:0114 /nowarn:0162 /nowarn:0164 /nowarn:0183 /nowarn:0168 /nowarn:0219 /debug+ /optimize+  /debug:full

PPVALUETYPES=/ppvaluetype:TextPosition /ppvaluetype:GivenKind /ppvaluetype:MethodKind /ppvaluetype:Modifier /ppvaluetype:AttrTarget /ppvaluetype:StorageMode /ppvaluetype:FieldKind  /ppvaluetype:LocalUsage /ppvaluetype:CoreTypeTag /ppvaluetype:TypePatKind /ppvaluetype:ChoiceKind /ppvaluetype:QuantKind /ppvaluetype:WhileKind /ppvaluetype:ForKind /ppvaluetype:TryKind /ppvaluetype:BlockKind /ppvaluetype:AssertKind /ppvaluetype:CastKind /ppvaluetype:CastMode /ppvaluetype:BranchKind /ppvaluetype:System.Decimal /ppvaluetype:TriggerClass /ppvaluetype:ProjectTarget /ppvaluetype:UniMode /ppvaluetype:AsmLSignKind /ppvaluetype:CoreTypeKind /ppvaluetype:SyntaxLevel

.SUFFIXES: .asml .as
.asml.as:
      $(ASMLP) $(PPVALUETYPES) /compat15 /ppomitasml /pp:asharp /ppout:$*.as $**


all: build

build: buildASGrammar $(TargetName)

###### PARSER
!if "$(ASharp)"!="yes"
ParserSource=manifest.asml lexis.asml scanner.asml parser.asml xmlparser.asml asparser.asml checkingcodestripper.asml asgenerator.asml
!else
ParserSource=manifest.asml lexis.xas scanner.xas parser.xas xmlparser.xas asparser.xas checkingcodestripper.asml asgenerator.asml
!endif

CSParserSource=$(TargetDir)\parser.cs

$(CSParserSource): $(ParserSource)
	$(ASMLC) $(QSELF1_OPTIONS) $(Options) /compat15 /nocsc /ocs:$(CSParserSource) $(ParserSource) $(References) 

###### SUBMACHINES
SubmachinesSource = submachinereducer.asml
CSSubmachinesSource = $(TargetDir)\submachines.cs
SubmachinesTarget = $(TargetDir)\AsmL.Tools.Compiler.Submachines.dll

submachines: $(SubmachinesTarget)

$(CSSubmachinesSource): $(SubmachinesSource)
      $(ASMLC) /compat15 $(QSELF1_OPTIONS) $(Options) /nocsc /ocs:$(CSSubmachinesSource) $(SubmachinesSource) $(References)

$(SubmachinesTarget): $(CSSubmachinesSource)
	$(CSC) $(CSOptions) /target:library /out:$(SubmachinesTarget) $(CSSubmachinesSource) $(CSReferences)

###### BASICBLOCKS
BasicBlockSource = basicblock.asml flattener.asml
CSBasicBlockSource = $(TargetDir)\basicblock.cs
BasicBlockTarget = $(TargetDir)\AsmL.Tools.Compiler.BasicBlock.dll

basicblock: $(BasicBlockTarget)

$(CSBasicBlockSource): $(BasicBlockSource)
      $(ASMLC) $(QSELF1_OPTIONS) $(Options) /nocsc /ocs:$(CSBasicBlockSource) $(BasicBlockSource) $(References)

$(BasicBlockTarget): $(CSBasicBlockSource)
	$(CSC) $(CSOptions) /target:library /out:$(BasicBlockTarget) $(CSBasicBlockSource) $(CSReferences)


###### CHECKER

!if "$(ASharp)"!="yes"
CheckerSource=tagging.asml typechecker.asml
!else
CheckerSource=tagging.asml typechecker.xas
!endif

CSCheckerSource=$(TargetDir)\typechecker.cs

$(CSCheckerSource): $(CheckerSource)
	$(ASMLC) $(QSELF1_OPTIONS) $(Options) /compat15 /nocsc /ocs:$(CSCheckerSource) $(CheckerSource) $(References)

###### IMPORTER

!if "$(ASharp)"!="yes"
ImporterSource=importer.asml
!else
ImporterSource=importer.xas
!endif


CSImporterSource=$(TargetDir)\importer.cs

$(CSImporterSource): $(ImporterSource)
	$(ASMLC) $(QSELF1_OPTIONS) $(Options) /compat15 /nocsc /ocs:$(CSImporterSource) $(ImporterSource) $(References)

CoderSource=coder.asml codegen.asml csharpcoder.asml dotnetbackendservices.asml
CSCoderSource=$(TargetDir)\coder.cs

$(CSCoderSource): $(CoderSource)
	$(ASMLC) $(QSELF1_OPTIONS) $(Options) /compat15 /nocsc /ocs:$(CSCoderSource) $(CoderSource) $(References)


###### SIMPLIFIER

!if "$(ASharp)"!="yes"
SimplifierSource=lambdalifter.asml genericdelegatecreationreducer.asml assertionreducer.asml definiteassignment.asml asmvarreducer.asml typeconstraintsreducer.asml simplifier.asml 
!else
SimplifierSource=lambdalifter.xas genericdelegatecreationreducer.xas assertionreducer.xas asmvarreducer.xas definiteassignment.xas typeconstraintsreducer.as simplifier.xas
!endif

CSSimplifierSource=$(TargetDir)\simplifier.cs

$(CSSimplifierSource): $(SimplifierSource)
	$(ASMLC) $(QSELF1_OPTIONS) $(Options) /compat15 /nocsc /ocs:$(CSSimplifierSource) $(SimplifierSource) $(References)


###### PRINTERS

!if "$(ASharp)"!="yes"
PrintingSource=printing.asml asprinting.asml
!else
PrintingSource=printing.xas asprinting.xas
!endif

CSPrintingSource=$(TargetDir)\printing.cs

$(CSPrintingSource): $(PrintingSource)
	$(ASMLC) $(QSELF1_OPTIONS) $(Options) /compat15 /nocsc /ocs:$(CSPrintingSource) $(PrintingSource) $(References)


###### PROJECT SERVICE

!if "$(ASharp)"!="yes"
ProjectServiceSource=projectserviceprovider.asml 
!else
ProjectServiceSource=projectserviceprovider.xas 
!endif

CSProjectServiceSource=$(TargetDir)\projectserviceprovider.cs

$(CSProjectServiceSource): $(ProjectServiceSource)
	$(ASMLC) $(QSELF1_OPTIONS) $(Options) /compat15 /nocsc /ocs:$(CSProjectServiceSource) $(ProjectServiceSource) $(References)



# CS Compilation

CSSource=$(CSParserSource) $(CSCheckerSource) $(CSImporterSource) $(CSSimplifierSource) $(CSCoderSource) $(CSPrintingSource) $(CSASParserSource) $(CSBasicBlockSource) $(CSProjectServiceSource) $(CSSubmachinesSource)

$(TargetName): $(CSSource) compilerserviceproviders.cs
	$(CSC) $(CSOptions) /target:library /out:$(TargetName) $(CSSource) compilerserviceproviders.cs $(CSReferences)





makeASParser:
  @cd ASParser
  @$(MAKE) ASMLC=$(ASMLC) CSC=$(CSC) TargetDir=$(TargetDir) $(Target)

# FIXME: we should be able to convert all sources....
# Docs=typechecker.doc simplifier.doc ...

clean:	cleanASGrammar
      -del /f /q $(TargetName) 
      -del /f /q $(CSSource) 
      -del /f /q $(CSASParserSource)
#-del $(Docs)

rebuild: clean build

.SUFFIXES: .doc .asml
.asml.doc:
	$(ASML2DOC) $< $@

doc: $(Docs)
  @$(MAKE) Target=doc makeASParser

install:


# AS grammar

asharp:
  $(MAKE) Target=all0 makeASParser
  $(MAKE) all

ASParserSources= ASParser/AssemblyInfo.cs ASParser/asLexClass.cs ASParser/asLexTable.cs ASParser/asYaccClass.cs ASParser/asYaccClassEx.cs ASParser/asYaccTable.cs

buildASGrammar:
  $(MAKE) TargetDir=$(TargetDir) Target=all makeASParser


#  @if $(Config)==Debug devenv ASParser\ASParser.sln /build Debug
#  @if not $(Config)==Debug devenv ASParser\ASParser.sln /build Debug
#  @if not $(Config)==Debug copy $(ASMLDEVDIR)\bin\Debug\AsmL.Tools.Compiler.ASParser.* $(TargetDir)

cleanASGrammar:
  @$(MAKE) Target=clean makeASParser
  @if $(Config)==Debug devenv ASParser\ASParser.sln /clean $(Config)
  @-if not $(Config)==Debug del /Q $(TargetDir)\AsmL.Tools.Compiler.ASParser.*

perf:
  $(CSC) /out:perfc.exe perf.as
  $(ASMLC) /out:perfa.exe perf.as
  $(ASMLC) /d:PRIMITIVE /out:perfp.exe perf.as
  $(ASMLC) /basicblock /out:perfb.exe perf.as
  $(ASMLC) /d:ASML /out:perfaa.exe perf.as
  $(ASMLC) /d:ASML /d:PRIMITIVE /out:perfpa.exe perf.as
  $(ASMLC) /d:ASML /basicblock /out:perfba.exe perf.as

btest:
  asmlc  /ocs:asgenerator.cs /basicblock $(References) /target:library asgenerator.asml 
