"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LinuxExporter = void 0; const Exporter_1 = require("kmake/Exporters/Exporter"); const Options_1 = require("kmake/Options"); const Platform_1 = require("kmake/Platform"); const Compiler_1 = require("kmake/Compiler"); const fs = require("kmake/fsextra"); const path = require("path"); const NinjaExporter_1 = require("kmake/Exporters/NinjaExporter"); const MakeExporter_1 = require("kmake/Exporters/MakeExporter"); const CLionExporter_1 = require("kmake/Exporters/CLionExporter"); const CompileCommandsExporter_1 = require("kmake/Exporters/CompileCommandsExporter"); class LinuxExporter extends Exporter_1.Exporter { constructor(options) { super(options); let linkerFlags = '-static-libgcc -static-libstdc++ -pthread'; if (Options_1.Options.compiler === Compiler_1.Compiler.MuslGcc || this.getOS().includes('Alpine')) { linkerFlags += ' -static'; } let outputExtension = ''; if (options.lib) { outputExtension = '.a'; } else if (options.dynlib) { outputExtension = '.so'; } this.ninja = new NinjaExporter_1.NinjaExporter(options, this.getCCompiler(), this.getCPPCompiler(), '', '', linkerFlags, outputExtension); this.make = new MakeExporter_1.MakeExporter(options, this.getCCompiler(), this.getCPPCompiler(), '', '', linkerFlags, outputExtension); this.clion = new CLionExporter_1.CLionExporter(options); this.compileCommands = new CompileCommandsExporter_1.CompilerCommandsExporter(options); } async exportSolution(project, from, to, platform, vrApi, options) { this.ninja.exportSolution(project, from, to, platform, vrApi, options); this.make.exportSolution(project, from, to, platform, vrApi, options); this.exportCodeBlocks(project, from, to, platform, vrApi, options); this.clion.exportSolution(project, from, to, platform, vrApi, options); this.compileCommands.exportSolution(project, from, to, platform, vrApi, options); } getCCompiler() { switch (Options_1.Options.compiler) { case Compiler_1.Compiler.Default: case Compiler_1.Compiler.GCC: return 'gcc'; case Compiler_1.Compiler.Clang: return 'clang'; case Compiler_1.Compiler.MuslGcc: return 'musl-gcc'; case Compiler_1.Compiler.Custom: return Options_1.Options.ccPath; default: throw 'Unsupported compiler ' + Options_1.Options.compiler; } } getCPPCompiler() { switch (Options_1.Options.compiler) { case Compiler_1.Compiler.Default: case Compiler_1.Compiler.GCC: return 'g++'; case Compiler_1.Compiler.Clang: return 'clang++'; case Compiler_1.Compiler.MuslGcc: return 'g++'; case Compiler_1.Compiler.Custom: return Options_1.Options.cxxPath; default: throw 'Unsupported compiler ' + Options_1.Options.compiler; } } getOS() { try { const data = fs.readFileSync('/etc/os-release', 'utf8'); const lines = data.split('\n'); let name = null; for (const line of lines) { if (line.trim().startsWith('NAME')) { name = line.split('=')[1]; name = name.substring(1, name.length - 1); break; } } if (name) { return name; } else { return 'Unknown'; } } catch (error) { return 'Unknown'; } } exportCodeBlocks(project, from, to, platform, vrApi, options) { this.writeFile(path.resolve(to, project.getSafeName() + '.cbp')); this.p(''); this.p(''); this.p('', 1); this.p('', 1); this.p('', 1); this.p(''); this.closeFile(); } } exports.LinuxExporter = LinuxExporter; //# sourceMappingURL=LinuxExporter.js.map