anchor.diff:      "Compile" ==>
       "Default"
   
  -let knownPackages = 
  +let ownPackages = 
       Set.ofList [
           "Aardvark.Rendering"
       ]
   
  +let subModulePackages =
  +    Map.ofList [
  +        "src/Aardvark.Base", [
  +            "Aardvark.Base"
  +            "Aardvark.Base.FSharp"
  +            "Aardvark.Base.Essentials"
  +            "Aardvark.Base.Incremental"
  +        ]
  +    ]
  +
   
   Target "CreatePackage" (fun () ->
       let branch = Fake.Git.Information.getBranchName "."
  
positive.code:     if branch = "master" then
          let tag = Fake.Git.Information.getLastTag()
  
          for id in knownPackages do
              NuGetPack (fun p -> 
                  { p with OutputPath = "bin"; 
                           Version = tag; 
                           ReleaseNotes = releaseNotes; 
                           WorkingDir = "bin"
                           Dependencies = p.Dependencies |> List.map (fun (id,version) -> if Set.contains id knownPackages then (id, tag) else (id,version)) 
                  }) (sprintf "bin/%s.nuspec" id)
      
      else 
  
negative.code:         traceError (sprintf "cannot deploy branch: %A" branch)
  )
  
  // installs local packages specified by subModulePackages 
  // NOTE: current packages will always be replaced
  Target "InstallLocal" (fun () ->
  
      let buildCmdName =
          match Environment.OSVersion.Platform with
              | PlatformID.Unix 
              | PlatformID.MacOSX -> "build.sh"
              | _ -> "build.cmd"
  
      for (localModulePath, packages) in Map.toSeq subModulePackages do
          let modulePath = Path.GetFullPath localModulePath
          if Directory.Exists modulePath then
  
              let rec findPackagePath l =
                  match l with
                      | [] -> None
                      | p::ps -> 
                          let p = Path.Combine(modulePath, p)
                          if Directory.Exists p then Some p
                          else findPackagePath ps
  
              let buildCmd = Path.Combine(modulePath, buildCmdName)
  
              let packageOutputPath = findPackagePath ["bin"; "build"]
  
              match packageOutputPath with
                  | Some packageOutputPath ->
                      if File.Exists buildCmd then
                          let ret = 
                              ExecProcess (fun info -> 
                                  info.UseShellExecute <- true
                                  info.CreateNoWindow <- false
                                  info.FileName <- buildCmd
                                  info.Arguments <- "CreatePackage"
                                  info.WorkingDirectory <- modulePath
                              ) TimeSpan.MaxValue
  
  
                          if ret = 0 then
                              let packagePath = Path.Combine(modulePath, "packages")
  
                              for p in packages do
                                  try
                                      let outputFolders = Directory.GetDirectories("packages", p + ".*")
                                      for outputFolder in outputFolders do
                                          Directory.Delete(outputFolder, true)
  
                                      Std.noOut (fun () ->
                                          RestorePackageId (fun p -> { p with Sources = [packageOutputPath; packagePath]; OutputPath = "packages"; }) p
                                      )
                                      trace (sprintf "successfully reinstalled %A" p)
  
                                  with :? UnauthorizedAccessException as e ->
                                      traceImportant (sprintf "could not reinstall %A" p  )
  
  
                          else
                              traceError (sprintf "build failed for submodule: %A" localModulePath)
                      else
                          traceError (sprintf "could not locate build.cmd in submodule %A" localModulePath)
                  | _ ->
                      traceError (sprintf "could not locate output folder in submodule %A" localModulePath)
          else
              trace (sprintf "could not locate submodule %A" localModulePath)
  
      ()
  )
  
  
  "Compile" ==> "CreatePackage"
  "CreatePackage" ==> "Deploy"
  
  