forked from LeenkxTeam/Kmake
CFLAGS
This commit is contained in:
@ -1,279 +1,279 @@
|
|||||||
import { Exporter } from 'kmake/Exporters/Exporter';
|
import { Exporter } from 'kmake/Exporters/Exporter';
|
||||||
import { Project } from 'kmake/Project';
|
import { Project } from 'kmake/Project';
|
||||||
import * as fs from 'kmake/fsextra';
|
import * as fs from 'kmake/fsextra';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export class MakeExporter extends Exporter {
|
export class MakeExporter extends Exporter {
|
||||||
cCompiler: string;
|
cCompiler: string;
|
||||||
cppCompiler: string;
|
cppCompiler: string;
|
||||||
cFlags: string;
|
cFlags: string;
|
||||||
cppFlags: string;
|
cppFlags: string;
|
||||||
linkerFlags: string;
|
linkerFlags: string;
|
||||||
outputExtension: string;
|
outputExtension: string;
|
||||||
|
|
||||||
constructor(options: any, cCompiler: string, cppCompiler: string, cFlags: string, cppFlags: string, linkerFlags: string, outputExtension: string, libsLine: (p: Project) => string = null) {
|
constructor(options: any, cCompiler: string, cppCompiler: string, cFlags: string, cppFlags: string, linkerFlags: string, outputExtension: string, libsLine: (p: Project) => string = null) {
|
||||||
super(options);
|
super(options);
|
||||||
this.cCompiler = cCompiler;
|
this.cCompiler = cCompiler;
|
||||||
this.cppCompiler = cppCompiler;
|
this.cppCompiler = cppCompiler;
|
||||||
this.cFlags = cFlags;
|
this.cFlags = cFlags;
|
||||||
this.cppFlags = cppFlags;
|
this.cppFlags = cppFlags;
|
||||||
this.linkerFlags = linkerFlags;
|
this.linkerFlags = linkerFlags;
|
||||||
this.outputExtension = outputExtension;
|
this.outputExtension = outputExtension;
|
||||||
if (libsLine != null) {
|
if (libsLine != null) {
|
||||||
this.libsLine = libsLine;
|
this.libsLine = libsLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libsLine(project: Project): string {
|
libsLine(project: Project): string {
|
||||||
let libs = '';
|
let libs = '';
|
||||||
for (let lib of project.getLibs()) {
|
for (let lib of project.getLibs()) {
|
||||||
libs += ' -l' + lib;
|
libs += ' -l' + lib;
|
||||||
}
|
}
|
||||||
return libs;
|
return libs;
|
||||||
}
|
}
|
||||||
|
|
||||||
async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
|
async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
|
||||||
// TODO: Figure out why we cant get the relative path and if we even need to manually include the m files
|
// TODO: Figure out why we cant get the relative path and if we even need to manually include the m files
|
||||||
let koreBasePath = '';
|
let koreBasePath = '';
|
||||||
for (let fileobject of project.getFiles()) {
|
for (let fileobject of project.getFiles()) {
|
||||||
if (fileobject.file.includes('Kore/Backends')) {
|
if (fileobject.file.includes('Kore/Backends')) {
|
||||||
let parts = fileobject.file.split('/');
|
let parts = fileobject.file.split('/');
|
||||||
let koreIndex = parts.indexOf('Kore');
|
let koreIndex = parts.indexOf('Kore');
|
||||||
if (koreIndex !== -1) {
|
if (koreIndex !== -1) {
|
||||||
koreBasePath = parts.slice(0, koreIndex + 1).join('/');
|
koreBasePath = parts.slice(0, koreIndex + 1).join('/');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mFiles = [
|
let mFiles = [
|
||||||
koreBasePath + '/Backends/System/Apple/Sources/kinc/backend/appleunit.m',
|
koreBasePath + '/Backends/System/Apple/Sources/kinc/backend/appleunit.m',
|
||||||
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/macosunit.m',
|
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/macosunit.m',
|
||||||
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/system.m.h',
|
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/system.m.h',
|
||||||
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.m.h',
|
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/BasicOpenGLView.m.h',
|
||||||
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/display.m.h',
|
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/display.m.h',
|
||||||
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/mouse.m.h'
|
koreBasePath + '/Backends/System/macOS/Sources/kinc/backend/mouse.m.h'
|
||||||
];
|
];
|
||||||
for (let mFile of mFiles) {
|
for (let mFile of mFiles) {
|
||||||
let found = false;
|
let found = false;
|
||||||
for (let fileobject of project.getFiles()) {
|
for (let fileobject of project.getFiles()) {
|
||||||
if (fileobject.file === mFile) {
|
if (fileobject.file === mFile) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
project.files.push({file: mFile, options: null, projectDir: from, projectName: project.name});
|
project.files.push({file: mFile, options: null, projectDir: from, projectName: project.name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let mFile of mFiles) {
|
for (let mFile of mFiles) {
|
||||||
let found = false;
|
let found = false;
|
||||||
for (let fileobject of project.getFiles()) {
|
for (let fileobject of project.getFiles()) {
|
||||||
if (fileobject.file === mFile) {
|
if (fileobject.file === mFile) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
project.files.push({file: mFile, options: null, projectDir: from, projectName: project.name});
|
project.files.push({file: mFile, options: null, projectDir: from, projectName: project.name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let objects: any = {};
|
let objects: any = {};
|
||||||
let ofiles: any = {};
|
let ofiles: any = {};
|
||||||
let outputPath = path.resolve(to, options.buildPath);
|
let outputPath = path.resolve(to, options.buildPath);
|
||||||
fs.ensureDirSync(outputPath);
|
fs.ensureDirSync(outputPath);
|
||||||
|
|
||||||
for (let fileobject of project.getFiles()) {
|
for (let fileobject of project.getFiles()) {
|
||||||
let file = fileobject.file;
|
let file = fileobject.file;
|
||||||
if (file.endsWith('.cpp') || file.endsWith('.c') || file.endsWith('.cc') || file.endsWith('.s') || file.endsWith('.S') || file.endsWith('.m') || file.endsWith('.mm') || file.endsWith('.m.h')) {
|
if (file.endsWith('.cpp') || file.endsWith('.c') || file.endsWith('.cc') || file.endsWith('.s') || file.endsWith('.S') || file.endsWith('.m') || file.endsWith('.mm') || file.endsWith('.m.h')) {
|
||||||
if (fileobject.options && fileobject.options.nocompile) {
|
if (fileobject.options && fileobject.options.nocompile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = file.toLowerCase();
|
let name = file.toLowerCase();
|
||||||
if (name.indexOf('/') >= 0) name = name.substr(name.lastIndexOf('/') + 1);
|
if (name.indexOf('/') >= 0) name = name.substr(name.lastIndexOf('/') + 1);
|
||||||
name = name.substr(0, name.lastIndexOf('.'));
|
name = name.substr(0, name.lastIndexOf('.'));
|
||||||
if (!objects[name]) {
|
if (!objects[name]) {
|
||||||
objects[name] = true;
|
objects[name] = true;
|
||||||
ofiles[file] = name;
|
ofiles[file] = name;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
while (objects[name]) {
|
while (objects[name]) {
|
||||||
name = name + '_';
|
name = name + '_';
|
||||||
}
|
}
|
||||||
objects[name] = true;
|
objects[name] = true;
|
||||||
ofiles[file] = name;
|
ofiles[file] = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let gchfilelist = '';
|
let gchfilelist = '';
|
||||||
let precompiledHeaders: string[] = [];
|
let precompiledHeaders: string[] = [];
|
||||||
for (let file of project.getFiles()) {
|
for (let file of project.getFiles()) {
|
||||||
if (file.options && file.options.pch && precompiledHeaders.indexOf(file.options.pch) < 0) {
|
if (file.options && file.options.pch && precompiledHeaders.indexOf(file.options.pch) < 0) {
|
||||||
precompiledHeaders.push(file.options.pch);
|
precompiledHeaders.push(file.options.pch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let file of project.getFiles()) {
|
for (let file of project.getFiles()) {
|
||||||
let precompiledHeader: string = null;
|
let precompiledHeader: string = null;
|
||||||
for (let header of precompiledHeaders) {
|
for (let header of precompiledHeaders) {
|
||||||
if (file.file.endsWith(header)) {
|
if (file.file.endsWith(header)) {
|
||||||
precompiledHeader = header;
|
precompiledHeader = header;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (precompiledHeader !== null) {
|
if (precompiledHeader !== null) {
|
||||||
// let realfile = path.relative(outputPath, path.resolve(from, file.file));
|
// let realfile = path.relative(outputPath, path.resolve(from, file.file));
|
||||||
gchfilelist += path.basename(file.file) + '.gch ';
|
gchfilelist += path.basename(file.file) + '.gch ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ofilelist = '';
|
let ofilelist = '';
|
||||||
for (let o in objects) {
|
for (let o in objects) {
|
||||||
ofilelist += o + '.o ';
|
ofilelist += o + '.o ';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.writeFile(path.resolve(outputPath, 'makefile'));
|
this.writeFile(path.resolve(outputPath, 'makefile'));
|
||||||
|
|
||||||
let incline = '-I./ '; // local directory to pick up the precompiled headers
|
let incline = '-I./ '; // local directory to pick up the precompiled headers
|
||||||
for (let inc of project.getIncludeDirs()) {
|
for (let inc of project.getIncludeDirs()) {
|
||||||
inc = path.relative(outputPath, path.resolve(from, inc));
|
inc = path.relative(outputPath, path.resolve(from, inc));
|
||||||
incline += '-I' + inc + ' ';
|
incline += '-I' + inc + ' ';
|
||||||
}
|
}
|
||||||
this.p('INC=' + incline);
|
this.p('INC=' + incline);
|
||||||
|
|
||||||
let linkerline = this.linkerFlags;
|
let linkerline = this.linkerFlags;
|
||||||
linkerline += this.libsLine(project);
|
linkerline += this.libsLine(project);
|
||||||
linkerline += ' ';
|
linkerline += ' ';
|
||||||
for (let flag of project.linkerFlags) {
|
for (let flag of project.linkerFlags) {
|
||||||
linkerline += flag + ' ';
|
linkerline += flag + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.p('LIB=' + linkerline);
|
this.p('LIB=' + linkerline);
|
||||||
|
|
||||||
let defline = '';
|
let defline = '';
|
||||||
for (const def of project.getDefines()) {
|
for (const def of project.getDefines()) {
|
||||||
if (def.config && def.config.toLowerCase() === 'debug' && !options.debug) {
|
if (def.config && def.config.toLowerCase() === 'debug' && !options.debug) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def.config && def.config.toLowerCase() === 'release' && options.debug) {
|
if (def.config && def.config.toLowerCase() === 'release' && options.debug) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
defline += '-D' + def.value.replace(/\"/g, '\\"') + ' ';
|
defline += '-D' + def.value.replace(/\"/g, '\\"') + ' ';
|
||||||
}
|
}
|
||||||
if (!options.debug) {
|
if (!options.debug) {
|
||||||
defline += '-DNDEBUG ';
|
defline += '-DNDEBUG ';
|
||||||
}
|
}
|
||||||
this.p('DEF=' + defline);
|
this.p('DEF=' + defline);
|
||||||
this.p();
|
this.p();
|
||||||
|
|
||||||
let cline = this.cFlags;
|
let cline = this.cFlags;
|
||||||
if (project.cStd !== '') {
|
if (project.cStd !== '') {
|
||||||
cline = '-std=' + project.cStd + ' ';
|
cline = '-std=' + project.cStd + ' ';
|
||||||
}
|
}
|
||||||
if (options.dynlib) {
|
if (options.dynlib) {
|
||||||
cline += '-fPIC ';
|
cline += '-fPIC ';
|
||||||
}
|
}
|
||||||
for (let flag of project.cFlags) {
|
for (let flag of project.cFlags) {
|
||||||
cline += flag + ' ';
|
cline += flag + ' ';
|
||||||
}
|
}
|
||||||
this.p('CFLAGS=' + cline);
|
this.p('CFLAGS=' + cline);
|
||||||
|
|
||||||
let cppline = this.cppFlags;
|
let cppline = this.cppFlags;
|
||||||
if (project.cppStd !== '') {
|
if (project.cppStd !== '') {
|
||||||
cppline = '-std=' + project.cppStd + ' ';
|
cppline = '-std=' + project.cppStd + ' ';
|
||||||
}
|
}
|
||||||
if (options.dynlib) {
|
if (options.dynlib) {
|
||||||
cppline += '-fPIC ';
|
cppline += '-fPIC ';
|
||||||
}
|
}
|
||||||
for (let flag of project.cppFlags) {
|
for (let flag of project.cppFlags) {
|
||||||
cppline += flag + ' ';
|
cppline += flag + ' ';
|
||||||
}
|
}
|
||||||
this.p('CPPFLAGS=' + cppline);
|
this.p('CPPFLAGS=' + cppline);
|
||||||
|
|
||||||
let optimization = '';
|
let optimization = '';
|
||||||
if (!options.debug) {
|
if (!options.debug) {
|
||||||
optimization = '-O2';
|
optimization = '-O2';
|
||||||
}
|
}
|
||||||
else optimization = '-g';
|
else optimization = '-g';
|
||||||
|
|
||||||
let executableName = project.getSafeName();
|
let executableName = project.getSafeName();
|
||||||
if (project.getExecutableName()) {
|
if (project.getExecutableName()) {
|
||||||
executableName = project.getExecutableName();
|
executableName = project.getExecutableName();
|
||||||
}
|
}
|
||||||
|
|
||||||
let outputname = this.outputExtension === '.html' ? 'index.html' : executableName + this.outputExtension;
|
let outputname = this.outputExtension === '.html' ? 'index.html' : executableName + this.outputExtension;
|
||||||
this.p(outputname + ': ' + gchfilelist + ofilelist);
|
this.p(outputname + ': ' + gchfilelist + ofilelist);
|
||||||
|
|
||||||
let output = '-o "' + outputname + '"';
|
let output = '-o "' + outputname + '"';
|
||||||
if (options.dynlib) {
|
if (options.dynlib) {
|
||||||
output = '-shared -o "' + executableName + '.so"';
|
output = '-shared -o "' + executableName + '.so"';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.lib) {
|
if (options.lib) {
|
||||||
this.p('\t' + 'ar rcs ' + output + ' ' + ofilelist);
|
this.p('\t' + 'ar rcs ' + output + ' ' + ofilelist);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.p('\t' + this.cppCompiler + ' ' + output + ' ' + optimization + ' ' + ofilelist + ' $(LIB)');
|
this.p('\t' + this.cppCompiler + ' ' + output + ' ' + optimization + ' ' + ofilelist + ' $(LIB)');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let file of project.getFiles()) {
|
for (let file of project.getFiles()) {
|
||||||
let precompiledHeader: string = null;
|
let precompiledHeader: string = null;
|
||||||
for (let header of precompiledHeaders) {
|
for (let header of precompiledHeaders) {
|
||||||
if (file.file.endsWith(header)) {
|
if (file.file.endsWith(header)) {
|
||||||
precompiledHeader = header;
|
precompiledHeader = header;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (precompiledHeader !== null) {
|
if (precompiledHeader !== null) {
|
||||||
let realfile = path.relative(outputPath, path.resolve(from, file.file));
|
let realfile = path.relative(outputPath, path.resolve(from, file.file));
|
||||||
this.p('-include ' + path.basename(file.file) + '.d');
|
this.p('-include ' + path.basename(file.file) + '.d');
|
||||||
this.p(path.basename(realfile) + '.gch: ' + realfile);
|
this.p(path.basename(realfile) + '.gch: ' + realfile);
|
||||||
this.p('\t' + this.cppCompiler + ' ' + optimization + ' $(INC) $(DEF) -MD -c ' + realfile + ' -o ' + path.basename(file.file) + '.gch');
|
this.p('\t' + this.cppCompiler + ' ' + optimization + ' $(INC) $(DEF) -MD -c ' + realfile + ' -o ' + path.basename(file.file) + '.gch');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let fileobject of project.getFiles()) {
|
for (let fileobject of project.getFiles()) {
|
||||||
let file = fileobject.file;
|
let file = fileobject.file;
|
||||||
if (file.endsWith('.c') || file.endsWith('.cpp') || file.endsWith('.cc') || file.endsWith('.s') || file.endsWith('.S') || file.endsWith('.m') || file.endsWith('.mm') || file.endsWith('.m.h')) {
|
if (file.endsWith('.c') || file.endsWith('.cpp') || file.endsWith('.cc') || file.endsWith('.s') || file.endsWith('.S') || file.endsWith('.m') || file.endsWith('.mm') || file.endsWith('.m.h')) {
|
||||||
if (fileobject.options && fileobject.options.nocompile) {
|
if (fileobject.options && fileobject.options.nocompile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.p();
|
this.p();
|
||||||
let name = ofiles[file];
|
let name = ofiles[file];
|
||||||
let realfile = path.relative(outputPath, path.resolve(from, file));
|
let realfile = path.relative(outputPath, path.resolve(from, file));
|
||||||
|
|
||||||
this.p('-include ' + name + '.d');
|
this.p('-include ' + name + '.d');
|
||||||
|
|
||||||
this.p(name + '.o: ' + realfile);
|
this.p(name + '.o: ' + realfile);
|
||||||
|
|
||||||
let compiler = this.cppCompiler;
|
let compiler = this.cppCompiler;
|
||||||
let flags = '$(CPPFLAGS)';
|
let flags = '$(CFLAGS)';
|
||||||
if (file.endsWith('.c')) {
|
if (file.endsWith('.c')) {
|
||||||
compiler = this.cCompiler;
|
compiler = this.cCompiler;
|
||||||
flags = '$(CFLAGS)';
|
flags = '$(CFLAGS)';
|
||||||
}
|
}
|
||||||
else if (file.endsWith('.s') || file.endsWith('.S')) {
|
else if (file.endsWith('.s') || file.endsWith('.S')) {
|
||||||
compiler = this.cCompiler;
|
compiler = this.cCompiler;
|
||||||
flags = '';
|
flags = '';
|
||||||
}
|
}
|
||||||
else if (file.endsWith('.m') || file.endsWith('.m.h')) {
|
else if (file.endsWith('.m') || file.endsWith('.m.h')) {
|
||||||
compiler = this.cCompiler;
|
compiler = this.cCompiler;
|
||||||
flags = '$(CPPFLAGS)';
|
flags = '$(CFLAGS)';
|
||||||
}
|
}
|
||||||
else if (file.endsWith('.mm')) {
|
else if (file.endsWith('.mm')) {
|
||||||
compiler = this.cppCompiler;
|
compiler = this.cppCompiler;
|
||||||
flags = '$(CPPFLAGS)';
|
flags = '$(CFLAGS)';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.p('\t' + compiler + ' ' + optimization + ' $(INC) $(DEF) -MD ' + flags + ' -c ' + realfile + ' -o ' + name + '.o');
|
this.p('\t' + compiler + ' ' + optimization + ' $(INC) $(DEF) -MD ' + flags + ' -c ' + realfile + ' -o ' + name + '.o');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.closeFile();
|
this.closeFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user