Config = Debug
TargetDir = $(ASMLDEVDIR)\bin\$(Config)
ASharp = no

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

ASMLCDEFS =
ASMLCOPTS = /nohint:"adapting to accessibility" /nohint:"inserted a possibly failing" /lib:$(TargetDir) /nonullcheck /notypeasserts /noexceptionwrapping /csdebug  /v:4
#/DPimporter /DP:1
#/PA /PAtypes
GACUTIL=gacutil
OPTIM=/optimize+
CSC = csc
CSCOPTS= /nowarn:0679 /nowarn:0164 /nowarn:0114 /nowarn:0108 /nowarn:0183 /nowarn:0168 /nowarn:0219 /nowarn:0169 /nowarn:0162 $(OPTIM) /debug+ /debug:full /d:Debug /d:Breakpoints

Targets=$(TargetDir)\AsmLRuntime.dll $(TargetDir)\AsmL15CompatibilityLibrary.dll 
CSTargets=$(TargetDir)\AsmLRuntime.cs $(TargetDir)\AsmL15CompatibilityLibrary.cs 
Docs=AsmLStandardLibraryReference.doc

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

all: $(Targets) $(CSTargets)
	@$(MAKECALL) Target= makeBacktracking


clean:
	-del $(Targets) 
	-del $(CSTargets)
	del $(Docs)
	@$(MAKECALL) Target=clean makeBacktracking

rebuild: clean all

install: $(TargetDir)\AsmLRuntime.dll $(TargetDir)\AsmL15CompatibilityLibrary.dll 
	$(GACUTIL) /if $(TargetDir)\AsmLRuntime.dll
	$(GACUTIL) /if $(TargetDir)\AsmL15CompatibilityLibrary.dll
	@$(MAKECALL) Target=install makeBacktracking


######################### BASIC RUNTIME

$(TargetDir)\AsmLRuntime.dll:  $(TargetDir)\AsmLRuntime.cs
	$(CSC) $(CSCOPTS) /debug+ /debug:full /target:library /out:$(TargetDir)\AsmlRuntime.dll $(TargetDir)\AsmLRuntime.cs 

!if "$(ASharp)"!="yes"
RUNTIMESOURCES=AsmLRuntimeManifest.asml Exceptions.asml AsmLVariablesImpl.asml AsmLVariablesImplSingleThreaded.asml AsmLVariablesImplMultiThreaded.asml AsmLStandardLibrary.asml AsmLCollectionsImpl.asml AsmLSignAttrs.asml SpyLibrary.asml InterfaceContractsLibrary.asml ProfilerLibrary.asml ReflectionLibrary.asml CapturableExecutionContext.asml FastExecutionContext.asml UnsteppedExecutionContext.asml SteppingExecutionContext.asml ExecutionContext.asml 
!else
RUNTIMESOURCES=AsmLRuntimeManifest.as Exceptions.as AsmLVariablesImpl.as AsmLVariablesImplSingleThreaded.as AsmLVariablesImplMultiThreaded.as AsmLStandardLibrary.as AsmLCollectionsImpl.as AsmLSignAttrs.as SpyLibrary.as InterfaceContractsLibrary.as ProfilerLibrary.as ReflectionLibrary.as 
!endif

PPVALUETYPES=/ppvaluetype:X /ppvaluetype:A /ppvaluetype:B /ppvaluetype:A1 /ppvaluetype:A1' /ppvaluetype:A2' /ppvaluetype:B1 /ppvaluetype:B2 /ppvaluetype:A2 /ppvaluetype:A3 /ppvaluetype:A4 /ppvaluetype:A5 /ppvaluetype:A6 /ppvaluetype:A7 /ppvaluetype:A8 /ppvaluetype:A9 /ppvaluetype:A10 /ppvaluetype:A11 /ppvaluetype:A12 /ppvaluetype:_A1 /ppvaluetype:_A2 /ppvaluetype:__A /ppvaluetype:__V /ppvaluetype:System.Runtime.Serialization.StreamingContext /ppvaluetype:AddedRemoved /ppvaluetype:ContractionMode /ppvaluetype:CacheValueKind /ppvaluetype:RequiredThreadingMode /ppvaluetype:AccessKind /ppvaluetype:InternalConstructorType /ppvaluetype:System.Reflection.BindingFlags /ppvaluetype:BindingFlags /ppvaluetype:SpyConstructorType /ppvaluetype:WeaverMethodKind /ppvaluetype:WeaverMethodAspect /ppvaluetype:DefaultPathElementAction /ppvaluetype:DefaultAccessKind /ppvaluetype:ProfilerMethodKind /ppvaluetype:ProfilerBranchKind /ppvaluetype:AsmL.Range /ppvaluetype:Range /ppvaluetype:maxBuilder /ppvaluetype:minBuilder /ppvaluetype:MapBuilder /ppvaluetype:SetBuilder /ppvaluetype:SeqBuilder /ppvaluetype:ArrayBuilder /ppvaluetype:AnyBuilder /ppvaluetype:TheBuilder

$(TargetDir)\AsmLRuntime.cs: $(RUNTIMESOURCES)
	$(ASMLC) $(ASMLCDEFS) $(ASMLCOPTS) /DPdebugstyle -nocsc -ocs=$(TargetDir)\AsmLRuntime.cs -nortsload -nodefgen -p /reference:System $(RUNTIMESOURCES) 

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

.SUFFIXES: .asml .as

######################### AsmL 1.5 Compat Library
$(TargetDir)\AsmL15CompatibilityLibrary.dll: $(TargetDir)\AsmL15CompatibilityLibrary.cs
	$(CSC) $(CSCOPTS) /target:library /reference:AsmLRuntime.dll /reference:System.dll /lib:$(TargetDir) /out:$(TargetDir)\AsmL15CompatibilityLibrary.dll $(TargetDir)\AsmL15CompatibilityLibrary.cs 

$(TargetDir)\AsmL15CompatibilityLibrary.cs: AsmL15Compatibility.asml AsmL15CompatibilityManifest.asml
#  set enableconstrainedtypes=
	$(ASMLC) $(ASMLCOPTS) -reference:System.dll -nocsc -v=4 -ocs=$(TargetDir)\AsmL15CompatibilityLibrary.cs AsmL15CompatibilityManifest.asml AsmL15Compatibility.asml 

doc: $(Docs)

AsmLStandardLibraryReference.doc: AsmLStandardLibrarySelectedSignatures.asml
	$(ASML2DOC) AsmLStandardLibrarySelectedSignatures.asml AsmLStandardLibraryReference.doc

# echo Generating AsmL15CompatibilityLibrary.exp...
# type AsmL15Compatibility.imports AsmL15CompatibilityLibraryRaw.exp >AsmL15CompatibilityLibrary.exp

# subtargets
makeBacktracking:
	@echo --------------- Runtime\Backtracking ------------------------
	@cd $(MAKEDIR)\Backtracking
    @$(MAKECALL) ASharp=$(ASharp) $(Target)



# SINGULARITY

SG=c:\a2\sg

singularity:
	@-mkdir $(ASMLDEVDIR)\bin\Singularity
	@$(MAKE) /nologo $(MAKEFLAGS) Config=Singularity ASMLCDEFS=/define:SINGULARITY Target=makeSingularity makeSingularity


makeSingularity: $(TargetDir)\AsmLRuntime.cs
	copy $(TargetDir)\AsmLRuntime.cs $(SG)\base\specsrts\specsrts.cs
