Skip to content

Commit 0ca778c

Browse files
committed
move gcc '--specs=xxx' options to 'global' region
1 parent eceb898 commit 0ca778c

1 file changed

Lines changed: 52 additions & 61 deletions

File tree

src/ToolchainManager.ts

Lines changed: 52 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -311,85 +311,73 @@ export class ToolchainManager {
311311
// if exist
312312
if (configFile.IsFile()) {
313313

314-
const optionObj: ICompileOptions = JSON.parse(configFile.Read());
315-
const oldVersion: number = optionObj.version || 0;
314+
const curOption: ICompileOptions = JSON.parse(configFile.Read());
315+
const oldVersion: number = curOption.version || 0;
316316

317317
// if obsoleted, update it
318318
if (toolchain.version > oldVersion) {
319+
319320
const defOptions: ICompileOptions = toolchain.getDefaultConfig();
320321

321322
// update version
322-
optionObj.version = defOptions.version;
323-
324-
const updateList = ['global', 'c/cpp-compiler', 'asm-compiler', 'linker'];
325-
const properFile = File.fromArray([ResManager.GetInstance().getLangDir().path, toolchain.verifyFileName]);
326-
const properties = JSON.parse(properFile.Read())['properties'];
323+
curOption.version = defOptions.version;
327324

328325
// compatible some linker old params
329-
if (optionObj.linker) {
330-
// sdcc
331-
if (toolchain.name === 'SDCC' && optionObj.linker['executable-format']) {
332-
defOptions.linker['output-format'] = optionObj.linker['executable-format'];
326+
if (curOption.linker) {
327+
// sdcc: rename 'executable-format'
328+
if (toolchain.name === 'SDCC' && curOption.linker['executable-format']) {
329+
curOption.linker['output-format'] = curOption.linker['executable-format'];
330+
curOption.linker['executable-format'] = undefined;
333331
}
334-
// all
335-
if (optionObj.linker['output-lib']) {
336-
defOptions.linker['output-format'] = 'lib';
332+
// all: rename 'output-lib'
333+
if (curOption.linker['output-lib']) {
334+
curOption.linker['output-format'] = 'lib';
335+
curOption.linker['output-lib'] = undefined;
337336
}
338337
}
339338

340339
// compatible some c/cpp-compiler old params
341-
if (optionObj['c/cpp-compiler']) {
342-
// armcc5
343-
if (toolchain.name === 'AC5' && optionObj['c/cpp-compiler']['misc-control']) {
344-
if (optionObj['c/cpp-compiler']['C_FLAGS']) {
345-
optionObj['c/cpp-compiler']['C_FLAGS'] =
346-
optionObj['c/cpp-compiler']['misc-control'] + ' ' + optionObj['c/cpp-compiler']['C_FLAGS'];
347-
} else {
348-
optionObj['c/cpp-compiler']['C_FLAGS'] = optionObj['c/cpp-compiler']['misc-control'];
349-
}
340+
if (curOption['c/cpp-compiler']) {
341+
// armcc5, rename 'c/cpp-compiler'.'misc-control' -> 'c/cpp-compiler'.'C_FLAGS'
342+
if (toolchain.name === 'AC5' && curOption['c/cpp-compiler']['misc-control']) {
343+
const existedFlags = curOption['c/cpp-compiler']['C_FLAGS'] || '';
344+
curOption['c/cpp-compiler']['C_FLAGS'] = curOption['c/cpp-compiler']['misc-control'] + ' ' + existedFlags;
345+
curOption['c/cpp-compiler']['misc-control'] = undefined;
350346
}
351347
}
352348

353-
// iar stm8 code-mode, data-mode
354-
if (optionObj["c/cpp-compiler"] && toolchain.name === 'IAR_STM8') {
355-
defOptions.global['code-mode'] = optionObj["c/cpp-compiler"]['code-mode'] || defOptions.global['code-mode'];
356-
defOptions.global['data-mode'] = optionObj["c/cpp-compiler"]['data-mode'] || defOptions.global['data-mode'];
357-
}
358-
359-
// clear invalid properties
360-
for (const name of updateList) {
361-
if (properties[name]) {
362-
const propertyFields = properties[name]['properties'];
363-
const currentObj = (<any>optionObj)[name];
364-
if (currentObj) {
365-
for (const field in currentObj) {
366-
if (propertyFields[field] === undefined) { // if not have this property, clear it
367-
currentObj[field] = undefined;
368-
}
369-
}
370-
}
371-
}
349+
// iar stm8 'code-mode', 'data-mode' has been moved to 'global' from 'c/cpp-compiler'
350+
if (curOption["c/cpp-compiler"] && toolchain.name === 'IAR_STM8') {
351+
curOption.global['code-mode'] = curOption["c/cpp-compiler"]['code-mode'] || defOptions.global['code-mode'];
352+
curOption.global['data-mode'] = curOption["c/cpp-compiler"]['data-mode'] || defOptions.global['data-mode'];
353+
curOption["c/cpp-compiler"]['code-mode'] = undefined;
354+
curOption["c/cpp-compiler"]['data-mode'] = undefined;
372355
}
373356

374-
// update null properties
375-
for (const name of updateList) {
376-
const currentObj = (<any>optionObj)[name];
377-
const defObj = (<any>defOptions)[name];
378-
if (defObj) { // if default object is valid
379-
if (currentObj) {
380-
for (const key in defObj) {
381-
if (currentObj[key] === undefined) {
382-
currentObj[key] = defObj[key];
383-
}
384-
}
357+
// for gcc, '--specs=xxx' should be global options
358+
// ref: https://github.com/github0null/eide/issues/259
359+
if (/GCC/.test(toolchain.name) && curOption.linker && typeof curOption.linker['LD_FLAGS'] == 'string') {
360+
const specsOpts = curOption.linker['LD_FLAGS'].match(/--specs=[^\s]+/g);
361+
if (specsOpts && specsOpts.length > 0) {
362+
let optstr = specsOpts.join(' ');
363+
// move to global region
364+
if (curOption.global == undefined) curOption.global = {};
365+
if (curOption.global['misc-control']) {
366+
curOption.global['misc-control'] = curOption.global['misc-control'] + ' ' + optstr;
385367
} else {
386-
(<any>optionObj)[name] = defObj;
368+
curOption.global['misc-control'] = optstr;
387369
}
370+
// clear them in linker
371+
let ldflags = curOption.linker['LD_FLAGS'];
372+
specsOpts.forEach(opt => {
373+
ldflags = ldflags.replace(opt, '');
374+
});
375+
curOption.linker['LD_FLAGS'] = ldflags;
388376
}
389377
}
390378

391379
// write to file
392-
configFile.Write(JSON.stringify(optionObj, undefined, 4));
380+
configFile.Write(JSON.stringify(curOption, undefined, 4));
393381
}
394382
} else {
395383
// write default config to file
@@ -1797,7 +1785,7 @@ class AC6 implements IToolchian {
17971785

17981786
class GCC implements IToolchian {
17991787

1800-
readonly version = 4;
1788+
readonly version = 5;
18011789

18021790
readonly settingName: string = 'EIDE.ARM.GCC.InstallDirectory';
18031791

@@ -1990,7 +1978,8 @@ class GCC implements IToolchian {
19901978
afterBuildTasks: [],
19911979
global: {
19921980
"$float-abi-type": 'softfp',
1993-
"output-debug-info": 'enable'
1981+
"output-debug-info": 'enable',
1982+
"misc-control": "--specs=nosys.specs --specs=nano.specs"
19941983
},
19951984
'c/cpp-compiler': {
19961985
"language-c": "c11",
@@ -2008,7 +1997,7 @@ class GCC implements IToolchian {
20081997
linker: {
20091998
"output-format": "elf",
20101999
"remove-unused-input-sections": true,
2011-
"LD_FLAGS": "--specs=nosys.specs --specs=nano.specs",
2000+
"LD_FLAGS": "",
20122001
"LIB_FLAGS": "-lm"
20132002
}
20142003
};
@@ -2304,6 +2293,7 @@ class IARSTM8 implements IToolchian {
23042293
}
23052294

23062295
class MTI_GCC implements IToolchian {
2296+
23072297
readonly version = 1;
23082298

23092299
readonly settingName: string = 'EIDE.MIPS.InstallDirectory';
@@ -2529,7 +2519,7 @@ class MTI_GCC implements IToolchian {
25292519

25302520
class RISCV_GCC implements IToolchian {
25312521

2532-
readonly version = 1;
2522+
readonly version = 2;
25332523

25342524
readonly settingName: string = 'EIDE.RISCV.InstallDirectory';
25352525

@@ -2763,7 +2753,8 @@ class RISCV_GCC implements IToolchian {
27632753
"output-debug-info": 'enable',
27642754
"arch": "rv32imac",
27652755
"abi": "ilp32",
2766-
"code-model": "medlow"
2756+
"code-model": "medlow",
2757+
"misc-control": "--specs=nosys.specs --specs=nano.specs"
27672758
},
27682759
'c/cpp-compiler': {
27692760
"language-c": "c11",
@@ -2781,7 +2772,7 @@ class RISCV_GCC implements IToolchian {
27812772
linker: {
27822773
"output-format": "elf",
27832774
"remove-unused-input-sections": true,
2784-
"LD_FLAGS": "-Wl,--cref -Wl,--no-relax --specs=nosys.specs --specs=nano.specs -nostartfiles",
2775+
"LD_FLAGS": "-Wl,--cref -Wl,--no-relax -nostartfiles",
27852776
"LIB_FLAGS": ""
27862777
}
27872778
};

0 commit comments

Comments
 (0)