anchor.diff:              true
       end.
   
  -build_apps (Conf, IncludePaths, AppDir, Index) ->
  -    AppName = bname(AppDir),
  +build_apps (Conf, IncludePaths, AppName, AppDir, Index) ->
       ?log("Building ~s", [AppName]),
  -    Files   = ensure_docsrc(Conf, IncludePaths, AppDir),
  -    Map = fun (F) -> build_file_map(Conf, AppName, F) end,
  -    [["app", AppName, AppName, "[application]"] |
  -     pmapreduce(Map, fun lists:append/2, [], Files) ++ Index].
  -
  -build_file_map (Conf, AppName, File) ->
  -    Module = bname(File, ".xml"),
  +    Files = ensure_docsrc(Conf, IncludePaths, AppName, AppDir),
  +    Map = fun (File) -> build_file_map(Conf, AppName, bname(File,".xml"), File) end,
  +    [ ["app", AppName, AppName, "[application]"]
  +      | pmapreduce(Map, fun lists:append/2, [], Files)
  +      ++ Index
  +    ].
  +
  +build_file_map (Conf, AppName, Module, File) ->
       case is_ignored(AppName, Module) of
           true ->
               ?log("HTML generation for ~s skipped - ~p", [Module, File]),
               [];
           false ->
  -            ?log("Generating HTML - ~s ~p", [Module, File]),
               {Type, _Attr, Content} = read_xml(File),
  -
               case is_buildable(Type) of
                   false ->
                       ?log("HTML generation for ~s impossible - ~p", [Module, File]),
                       [];
                   true ->
  -                    TypeSpecsFile = jname([kf(dest,Conf), ?ERLDOCS_SPECS_TMP, "specs_"++Module++".xml"]),
  -                    case filelib:is_file(TypeSpecsFile) of
  -                        false ->                      TypeSpecs = [];
  -                        true ->
  -                            case read_xml(TypeSpecsFile) of
  -                                {error, _, _} ->      TypeSpecs = [];
  -                                {module, _, Specs} -> TypeSpecs = strip_whitespace(Specs)
  -                            end
  -                    end,
  -
  +                    ?log("Generating HTML - ~s ~p", [Module, File]),
                       Xml = strip_whitespace(Content),
  -
  -                    %% strip silly shy characters
                       Funs = get_funs(AppName, Module, lists:keyfind(funcs, 1, Xml)),
  -
  +                    TypeSpecs = read_xml_specs(Conf, Module),
                       ok = render(AppName, Module, Content, TypeSpecs, Conf),
  -
                       Sum = lists:flatten(module_summary(Type, Xml)),
                       [ ["mod", AppName, Module, Sum] | Funs]
               end
  
positive.code:     %% Output XML files to destination folder
      %% This prevents from polluting the source files
      TmpRoot = jname(kf(dest,Conf), ?ERLDOCS_SPECS_TMP),
      XMLDir  = jname(TmpRoot, bname(AppDir)),
      mkdir_p(XMLDir ++ "/"),
  
      lists:foreach(fun (File) -> gen_type_specs(TmpRoot, IncludePaths, File) end, ErlFiles),
  
      %% Return the complete list of XML files
      XMLFiles ++ tmp_cd(XMLDir, fun () ->
                                         gen_docsrc(AppDir, SrcFiles, IncludePaths, XMLDir)
                                 end).
  
  gen_type_specs (SpecsDest, IncludePaths, ErlFile) ->
      case erlang:system_info(otp_release) of
          [$R,$1,Digit|_] when Digit < $5 -> SpecsGenModule = specs_gen__below_R15;
          "R"++_ ->                          SpecsGenModule = specs_gen__R15_to_17;
          Vsn when Vsn < "18" ->             SpecsGenModule = specs_gen__R15_to_17;
          _ ->                               SpecsGenModule = specs_gen__18_and_above
      end,
      ?log("Generating Type Specs - ~p", [ErlFile]),
      Args = ["-o"++SpecsDest] ++ ["-I"++Inc || Inc <- IncludePaths] ++ [ErlFile],
      try SpecsGenModule:main(Args)
      catch _:_SpecsGenError ->
              ?log("Error generating type specs for ~p", [ErlFile])
      end.
  
  includes (AppDir) ->
  
negative.code: -spec dispatch (list()) -> boolean().
  dispatch (Conf) ->
      ?ERLDOCS_XMERL_ETS_TABLE = ets:new(?ERLDOCS_XMERL_ETS_TABLE, [named_table, set, public]),
      DidBuild = build([ {building_otp,is_building_otp(kf(apps,Conf))} | Conf]),
      ?log("Woot, finished"),
      DidBuild.
  
  is_building_otp ([]) -> false;
  is_building_otp ([AppDir|Rest]) ->
      case find_erlang_module(AppDir) of
          false -> is_building_otp(Rest);
          Path -> {true, Path}
      end.
  
  find_erlang_module (AppDir) ->
      ExitFast = fun (Fn, _Acc) -> throw({found, Fn}) end,
      try filelib:fold_files(AppDir, "^erlang\\.erl$", true, ExitFast, not_found) of
          not_found -> false
      catch
          {found,Fn} ->
              ?log("building_otp: true"),
              Fn
      end.
  
  
  