GenerateSource( this C.CObjectFileCollection collection) { // generate source file var generatedSourceFile = Bam.Core.Module.Create <GeneratedSourceModule>(collection); // compile the generated source file var objFile = collection.AddFile(generatedSourceFile); // return both generated source, and the compiled object file return(new System.Tuple <Bam.Core.Module, Bam.Core.Module>(generatedSourceFile, objFile)); }
Init() { base.Init(); if (this.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows)) { this.Macros[C.ModuleMacroNames.PluginFileExtension] = Bam.Core.TokenizedString.CreateVerbatim(".pyd"); var pyConfigHeader = Bam.Core.Graph.Instance.FindReferencedModule <PyConfigHeader>(); if ((pyConfigHeader.Configuration as IConfigurePython).PyDEBUG) { this.Macros[Bam.Core.ModuleMacroNames.OutputName] = Bam.Core.TokenizedString.CreateVerbatim(this.ModuleName + "_d"); } else { this.Macros[Bam.Core.ModuleMacroNames.OutputName] = Bam.Core.TokenizedString.CreateVerbatim(this.ModuleName); } } else { this.Macros[Bam.Core.ModuleMacroNames.OutputName] = Bam.Core.TokenizedString.CreateVerbatim(this.ModuleName); this.Macros[C.ModuleMacroNames.PluginPrefix] = Bam.Core.TokenizedString.CreateVerbatim(string.Empty); this.Macros[C.ModuleMacroNames.PluginFileExtension] = Bam.Core.TokenizedString.CreateVerbatim(".so"); } this.SetSemanticVersion(Version.Major, Version.Minor, Version.Patch); this.moduleSourceModules = this.CreateCSourceCollection(); foreach (var basename in this.SourceFiles) { this.moduleSourceModules.AddFiles(System.String.Format("$(packagedir)/{0}.c", basename)); } this.moduleSourceModules.PrivatePatch(settings => { var preprocessor = settings as C.ICommonPreprocessorSettings; preprocessor.PreprocessorDefines.Add("Py_ENABLE_SHARED"); var cCompiler = settings as C.ICOnlyCompilerSettings; cCompiler.LanguageStandard = C.ELanguageStandard.C99; // // some C99 features are now used from 3.6 (https://www.python.org/dev/peps/pep-0007/#c-dialect) if (settings is C.ICommonCompilerSettingsWin winCompiler) { winCompiler.CharacterSet = C.ECharacterSet.NotSet; } if (settings is VisualCCommon.ICommonCompilerSettings vcCompiler) { vcCompiler.WarningLevel = VisualCCommon.EWarningLevel.Level4; } if (settings is GccCommon.ICommonCompilerSettings gccCompiler) { gccCompiler.AllWarnings = true; gccCompiler.ExtraWarnings = true; gccCompiler.Pedantic = true; if ((settings.Module.Tool as C.CompilerTool).Version.AtLeast(GccCommon.ToolchainVersion.GCC_8)) { var compiler = settings as C.ICommonCompilerSettings; compiler.DisableWarnings.AddUnique("cast-function-type"); } } if (settings is ClangCommon.ICommonCompilerSettings clangCompiler) { clangCompiler.AllWarnings = true; clangCompiler.ExtraWarnings = true; clangCompiler.Pedantic = true; } }); if (null != this.CompilationPatch) { this.moduleSourceModules.PrivatePatch(this.CompilationPatch); } if (null != this.AssemblerFiles) { var assemblerSource = this.CreateAssemblerSourceCollection(); foreach (var leafname in this.AssemblerFiles) { assemblerSource.AddFiles($"$(packagedir)/{leafname}"); } if (null != this.AssemblerPatch) { assemblerSource.PrivatePatch(this.AssemblerPatch); } } this.CompileAndLinkAgainst <PythonLibrary>(this.moduleSourceModules); if (this.LibsToLink != null) { this.PrivatePatch(settings => { var linker = settings as C.ICommonLinkerSettings; foreach (var lib in this.LibsToLink) { linker.Libraries.AddUnique(lib); } }); } if (null != this.LinkerPatch) { this.PrivatePatch(this.LinkerPatch); } }