internal void LoadTargetFile(BuildTool tool, string fileName)
        {
            Project proj;
            string fullpath = ExpandEnvVars(fileName, "");

            try
            {
                proj = LoadProject(fullpath);

                foreach (ProjectImportElement import in proj.Xml.Imports)
                {
                    if (string.IsNullOrEmpty(import.Condition))
                    {
                        LoadTargetFile(tool, ExpandVars(import.Project, Path.GetDirectoryName(fileName)));
                    }
                }

                Regex expISA = new Regex(@"'\$\(INSTRUCTION_SET\)'=='", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                foreach (ProjectPropertyGroupElement pg in proj.Xml.PropertyGroups)
                {
                    if (expISA.IsMatch(pg.Condition))
                    {
                        ISA isa = LoadISASettings(pg);
                        if (isa != null)
                        {
                            tool.SupportedISAs.Add(isa);
                        }
                        continue;
                    }

                    tool.BuildOptions = LoadToolChainOptions(pg);

                    foreach (ProjectPropertyElement bp in pg.Properties)
                    {
                        string cond = CombineConditionals(pg.Condition, bp.Condition);

                        switch (bp.Name)
                        {
                            case "BuildToolName":
                                tool.Name = bp.Value;
                                break;
                            case "Documentation":
                                tool.Documentation = bp.Value;
                                break;
                            case "BuildToolGuid":
                                tool.Guid = bp.Value;
                                break;
                            case ObjExtFlag:
                                tool.ObjExt = bp.Value;
                                break;
                            case LibExtFlag:
                                tool.LibExt = bp.Value;
                                break;
                            case ExeExtFlag:
                                tool.BinExt = bp.Value;
                                break;

                            case CCompilerTag:
                                tool.CCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case CppCompilerTag:
                                tool.CppCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case AsmCompilerTag:
                                tool.AsmCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case ArchiverTag:
                                tool.Archiver.Exec = RemoveWrapper(bp.Value);
                                break;
                            case LinkerTag:
                                tool.Linker.Exec = RemoveWrapper(bp.Value);
                                break;
                            case FromElfTag:
                                tool.FromELF.Exec = RemoveWrapper(bp.Value);
                                break;
                            case ToolWrapperTag:
                            case AdsWrapperTag:
                            case AdiWrapperTag:
                            case ArcWrapperTag:
                                tool.BuildToolWrapper = RemoveWrapper(bp.Value);
                                break;
                            case PKUI_CpuNamesTag:
                                {
                                    List<string> pts = (List<string>)this.DeserializeXml(bp.Value, typeof(List<string>));
                                    tool.SupportedCpuNames.AddRange(pts);
                                }
                                break;
                            case "ProcessorTypes":
                            case CpuNamesTag:
                                {
                                    foreach (string sType in bp.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                                    {
                                        tool.SupportedCpuNames.Add(sType);
                                    }
                                }
                                break;
                            case PKUI_ISAsTag:
                                {
                                    List<ISA> isas = (List<ISA>)this.DeserializeXml(bp.Value, typeof(List<ISA>));
                                    tool.SupportedISAs.AddRange(isas);
                                }
                                break;
                            case ISAsTag:
                                {
                                    //legacy
                                    if (bp.Value.Contains(";"))
                                    {
                                        foreach (string sISA in bp.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                                        {
                                            ISA isa = new ISA();
                                            isa.Name = sISA;
                                            isa.Guid = System.Guid.NewGuid().ToString("B");

                                            tool.SupportedISAs.Add(isa);
                                        }
                                    }
                                }
                                break;

                            default:
                                {
                                    MFProperty prop = new MFProperty();
                                    prop.Name = bp.Name;
                                    prop.Value = bp.Value;
                                    prop.Condition = cond;

                                    tool.Properties.Add(prop);
                                }
                                break;
                        }
                    }
                }

                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        string cond = CombineConditionals(big.Condition, bi.Condition);

                        MFProperty prop = new MFProperty();
                        prop.Name = bi.ItemType;
                        prop.Value = bi.Include;
                        prop.Condition = cond;

                        tool.Items.Add(prop);
                    }
                }

                foreach (ProjectTargetElement targ in proj.Xml.Targets)
                {
                    switch (targ.Name)
                    {
                        case AdiAsmTargetTag:
                        case ArmAsmTargetTag:
                        case ArcAsmTargetTag:
                        case AsmCompilerTargetTag:
                            tool.AsmCompiler.Conditional = targ.Condition;
                            tool.AsmCompiler.Description = AsmCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.AsmCompiler, tool.BuildOptions.AsmFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiCCompilerTargetTag:
                        case ArmCCompilerTargetTag:
                        case ArcCCompilerTargetTag:
                        case CCompilerTargetTag:
                            tool.CCompiler.Conditional = targ.Condition;
                            tool.CCompiler.Description = CCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.CCompiler, tool.BuildOptions.CFlags, tool.BuildOptions.C_CppFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiCppCompilerTargetTag:
                        case ArmCppCompilerTargetTag:
                        case ArcCppCompilerTargetTag:
                        case CppCompilerTargetTag:
                            tool.CppCompiler.Conditional = targ.Condition;
                            tool.CppCompiler.Description = CppCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.CppCompiler, tool.BuildOptions.CppFlags, tool.BuildOptions.C_CppFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiLibTargetTag:
                        case ArmLibTargetTag:
                        case ArcLibTargetTag:
                        case LibTargetTag:
                            tool.Archiver.Conditional = targ.Condition;
                            tool.Archiver.Description = ArchiverTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.Archiver, tool.BuildOptions.ArchiverFlags);
                            break;
                        case AdiExeTargetTag:
                        case ArmExeTargetTag:
                        case ArcExeTargetTag:
                        case ExeTargetTag:
                            tool.Linker.Conditional = targ.Condition;
                            tool.Linker.Description = LinkerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.Linker, tool.BuildOptions.LinkerFlags);
                            break;
                        default:
                            MiscBuildTool misc = new MiscBuildTool();
                            misc.BuildTool.Conditional = targ.Condition;
                            misc.BuildTool.Exec = targ.Name;
                            misc.BuildTool.Description = targ.Name;
                            misc.Name = targ.Name;
                            LoadTargetTasks(targ, misc.EnvironmentVariables, misc.BuildTool, misc.BuildToolOptions);
                            tool.MiscTools.Add(misc);
                            break;
                    }
                }

                BuildToolDefine[] tools = new BuildToolDefine[]
            {
                tool.Archiver,
                tool.AsmCompiler,
                tool.CCompiler,
                tool.CppCompiler,
                tool.Linker,
                tool.FromELF,
            };

                //first time to determine path
                foreach (BuildToolDefine td in tools)
                {
                    ExtractToolPath(tool, td.Exec);
                }
                //second time to remove path from exec command
                foreach (BuildToolDefine td in tools)
                {
                    td.Exec = ExtractToolPath(tool, td.Exec);
                }

                tool.ProjectPath = ConvertPathToEnv(fileName);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: loading target file: " + fullpath + "\r\n", e.Message);
            }
        }
        private void LoadTargetTasks(ProjectTargetElement target, List<EnvVar> vars, BuildToolDefine tool, ToolOptions toolOptions, params List<ToolFlag>[] commonFlags)
        {
            foreach (ProjectTaskElement task in target.Tasks)
            {
                BuildScript script = new BuildScript();

                string exeCmdEnv = ToEnvVar(tool.Description.ToLower()).Trim();
                string exeCmd = tool.Description.ToLower();

                int idx = -1;
                script.Conditional = task.Condition;
                script.Script = task.GetParameter(TaskScriptAttributeName);
                if (!string.IsNullOrEmpty(script.Script))
                {
                    if ((idx = script.Script.ToLower().IndexOf(exeCmdEnv)) >= 0)
                    {
                        // remove exe command and 
                        script.Script = script.Script.Remove(idx, exeCmdEnv.Length);

                        script.Script = RemoveFlagsAndWrapper(script.Script, toolOptions, commonFlags);

                        toolOptions.BuildToolParameters.Parameters.Add(script);
                    }
                    else if ((idx = script.Script.ToLower().IndexOf(exeCmd)) >= 0)
                    {
                        // remove exe command and 
                        script.Script = script.Script.Remove(idx, exeCmd.Length);

                        script.Script = RemoveFlagsAndWrapper(script.Script, toolOptions, commonFlags);

                        toolOptions.BuildToolParameters.Parameters.Add(script);
                    }
                    else if (toolOptions.BuildToolParameters.Parameters.Count > 0)
                    {
                        toolOptions.BuildToolParameters.PostBuild.Add(script);
                    }
                    else
                    {
                        toolOptions.BuildToolParameters.PreBuild.Add(script);
                    }
                }
                else if(string.Compare(task.Name, SetEnvScriptTag) == 0)
                {
                    EnvVar var = new EnvVar();
                    var.Name = task.GetParameter("Name");
                    var.Conditional = task.Condition;
                    var.Value = task.GetParameter("Value");
                    vars.Add(var);
                }
            }
        }