private void PrecompileHeaders(ProjectFileCollection projectFiles, CProjectConfiguration configuration, string args) { foreach (ProjectFile file in projectFiles) { if (file.Subtype == Subtype.Code && CProject.IsHeaderFile(file.Name)) { string precomp = Path.Combine(configuration.SourceDirectory, ".prec"); precomp = Path.Combine(precomp, configuration.Name); precomp = Path.Combine(precomp, Path.GetFileName(file.Name) + ".ghc"); if (!File.Exists(precomp)) { DoPrecompileHeader(file, precomp, args); continue; } if (configuration.UseCcache || File.GetLastWriteTime(file.Name) > File.GetLastWriteTime(precomp)) { DoPrecompileHeader(file, precomp, args); } } } }
/// <summary> /// Finds the corresponding source or header file /// </summary> /// <param name="sourceFile"> /// The name of the file to be matched /// <see cref="System.String"/> /// </param> /// <returns> /// The corresponding file, or null if not found /// <see cref="System.String"/> /// </returns> public string MatchingFile(string sourceFile) { string filenameStub = Path.GetFileNameWithoutExtension(sourceFile); bool wantHeader = !CProject.IsHeaderFile(sourceFile); foreach (ProjectFile file in this.Files) { if (filenameStub == Path.GetFileNameWithoutExtension(file.Name) && (wantHeader == IsHeaderFile(file.Name))) { return(file.Name); } } return(null); }
private bool PrecompileHeaders(ProjectFileCollection projectFiles, CProjectConfiguration configuration, string args, ProgressMonitor monitor, CompilerResults cr) { monitor.BeginTask(GettextCatalog.GetString("Precompiling headers"), 1); bool success = true; foreach (ProjectFile file in projectFiles) { if (file.Subtype == Subtype.Code && CProject.IsHeaderFile(file.Name)) { string precomp = Path.Combine(configuration.IntermediateOutputDirectory, "prec"); precomp = Path.Combine(precomp, configuration.Id); precomp = Path.Combine(precomp, Path.GetFileName(file.Name) + ".ghc"); if (file.BuildAction == BuildAction.Compile) { if (!File.Exists(precomp) || configuration.UseCcache || File.GetLastWriteTime(file.Name) > File.GetLastWriteTime(precomp)) { if (DoPrecompileHeader(file, precomp, args, monitor, cr) == false) { success = false; break; } } } else { //remove old files or they'll interfere with the build if (File.Exists(precomp)) { File.Delete(precomp); } } } } if (success) { monitor.Step(1); } monitor.EndTask(); return(success); }
public override BuildResult Compile( Project project, ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, ProgressMonitor monitor) { if (!appsChecked) { appsChecked = true; compilerFound = CheckApp(compilerCommand); linkerFound = CheckApp(linkerCommand); } if (!compilerFound) { BuildResult cres = new BuildResult(); cres.AddError("Compiler not found: " + compilerCommand); return(cres); } if (!linkerFound) { BuildResult cres = new BuildResult(); cres.AddError("Linker not found: " + linkerCommand); return(cres); } CompilerResults cr = new CompilerResults(new TempFileCollection()); bool success = true; string compilerArgs = GetCompilerFlags(project, configuration) + " " + GeneratePkgCompilerArgs(packages); string outputName = Path.Combine(configuration.OutputDirectory, configuration.CompiledOutputName); // Precompile header files and place them in prec/<config_name>/ if (configuration.PrecompileHeaders) { string precDir = Path.Combine(configuration.IntermediateOutputDirectory, "prec"); string precConfigDir = Path.Combine(precDir, configuration.Id); if (!Directory.Exists(precDir)) { Directory.CreateDirectory(precDir); } if (!Directory.Exists(precConfigDir)) { Directory.CreateDirectory(precConfigDir); } if (!PrecompileHeaders(projectFiles, configuration, compilerArgs, monitor, cr)) { success = false; } } else { //old headers could interfere with the build CleanPrecompiledHeaders(configuration); } //compile source to object files monitor.BeginTask(GettextCatalog.GetString("Compiling source to object files"), 1); foreach (ProjectFile f in projectFiles) { if (!success) { break; } if (f.Subtype == Subtype.Directory || f.BuildAction != BuildAction.Compile || CProject.IsHeaderFile(f.FilePath)) { continue; } if (configuration.UseCcache || NeedsCompiling(f, configuration)) { success = DoCompilation(f, configuration, compilerArgs, monitor, cr, configuration.UseCcache); } } if (success) { monitor.Step(1); } monitor.EndTask(); if (success) { switch (configuration.CompileTarget) { case CBinding.CompileTarget.Bin: MakeBin(project, projectFiles, configuration, packages, cr, monitor, outputName); break; case CBinding.CompileTarget.StaticLibrary: MakeStaticLibrary(project, projectFiles, configuration, packages, cr, monitor, outputName); break; case CBinding.CompileTarget.SharedLibrary: MakeSharedLibrary(project, projectFiles, configuration, packages, cr, monitor, outputName); break; } } return(new BuildResult(cr, "")); }