Unify replacement.
This commit is contained in:
@ -306,7 +306,8 @@ $(WINDOWS)/uEf64.exe: \
|
||||
$(ESP32)/ESP32forth:
|
||||
mkdir -p $@
|
||||
|
||||
ESP32_PARTS = esp32/template.ino \
|
||||
ESP32_PARTS = common/replace.js \
|
||||
esp32/template.ino \
|
||||
common/opcodes.h \
|
||||
common/calling.h \
|
||||
common/floats.h \
|
||||
@ -314,9 +315,17 @@ ESP32_PARTS = esp32/template.ino \
|
||||
common/interp.h \
|
||||
$(GEN)/esp32_boot.h
|
||||
|
||||
$(ESP32)/ESP32forth/ESP32forth.ino: \
|
||||
esp32/fuse_ino.js $(ESP32_PARTS) | $(ESP32)/ESP32forth
|
||||
$< $(VERSION) $(REVISION) $(ESP32_PARTS) >$@
|
||||
$(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth
|
||||
cat esp32/template.ino | common/replace.js \
|
||||
VERSION=$(VERSION) \
|
||||
REVISION=$(REVISION) \
|
||||
opcodes=@common/opcodes.h \
|
||||
calling=@common/calling.h \
|
||||
floats=@common/floats.h \
|
||||
core=@common/core.h \
|
||||
interp=@common/interp.h \
|
||||
boot=@$(GEN)/esp32_boot.h \
|
||||
>$@
|
||||
|
||||
# ---- PACKAGE ----
|
||||
|
||||
|
||||
@ -43,25 +43,23 @@ for (var i = 2; i < process.argv.length; ++i) {
|
||||
var m = item.match(/^([^=]+)=@(.+)$/);
|
||||
if (m) {
|
||||
var content = DropCopyright(fs.readFileSync(m[2]).toString());
|
||||
replacements.push([m[1], content]);
|
||||
replacements.push(['{{' + m[1] + '}}', content]);
|
||||
continue;
|
||||
}
|
||||
var m = item.match(/^([^=]+)=(.+)$/);
|
||||
if (m) {
|
||||
replacements.push([m[1], m[2]]);
|
||||
replacements.push(['{{' + m[1] + '}}', m[2]]);
|
||||
continue;
|
||||
}
|
||||
throw 'Bad replacement ' + item;
|
||||
}
|
||||
|
||||
var version = process.argv[3];
|
||||
var revision = process.argv[4];
|
||||
|
||||
for (;;) {
|
||||
var old_source = source;
|
||||
for (var i = 0; i < replacements.length; ++i) {
|
||||
source = source.replace('{{' + replacements[i][0] + '}}',
|
||||
replacements[i][1]);
|
||||
source = source.replace(
|
||||
replacements[i][0],
|
||||
function() { return replacements[i][1]});
|
||||
}
|
||||
if (old_source == source) {
|
||||
break;
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
#! /usr/bin/env nodejs
|
||||
// Copyright 2021 Bradley D. Nelson
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
function DropCopyright(source) {
|
||||
var lines = source.split('\n');
|
||||
var cleaned = [];
|
||||
for (var i = 0; i < lines.length; ++i) {
|
||||
if (lines[i].search('Copyright') >= 0) {
|
||||
while (lines[i] != '') {
|
||||
++i;
|
||||
}
|
||||
} else {
|
||||
cleaned.push(lines[i]);
|
||||
}
|
||||
}
|
||||
return cleaned.join('\n');
|
||||
}
|
||||
|
||||
var version = process.argv[2];
|
||||
var revision = process.argv[3];
|
||||
var code = fs.readFileSync(process.argv[4]).toString();
|
||||
var opcodes = DropCopyright(fs.readFileSync(process.argv[5]).toString());
|
||||
var calling = DropCopyright(fs.readFileSync(process.argv[6]).toString());
|
||||
var floats = DropCopyright(fs.readFileSync(process.argv[7]).toString());
|
||||
var core = DropCopyright(fs.readFileSync(process.argv[8]).toString());
|
||||
var interp = DropCopyright(fs.readFileSync(process.argv[9]).toString());
|
||||
var boot = DropCopyright(fs.readFileSync(process.argv[10]).toString());
|
||||
|
||||
code = code.replace('{{VERSION}}', function() { return version; });
|
||||
code = code.replace('{{REVISION}}', function() { return revision; });
|
||||
code = code.replace('{{opcodes}}', function() { return opcodes; });
|
||||
code = code.replace('{{floats}}', function() { return floats; });
|
||||
code = code.replace('{{calling}}', function() { return calling; });
|
||||
code = code.replace('{{boot}}', function() { return boot; });
|
||||
code = code.replace('{{core}}', function() { return core; });
|
||||
code = code.replace('{{interp}}', function() { return interp; });
|
||||
|
||||
process.stdout.write(code);
|
||||
Reference in New Issue
Block a user