waforth2c: Simplify build system

This commit is contained in:
Remko Tronçon 2019-03-09 13:20:41 +01:00
parent f42c172335
commit a03f8a5fbc
2 changed files with 21 additions and 34 deletions

View file

@ -1,12 +1,16 @@
CFLAGS=
CPPFLAGS=-I. -Iwaforth.gen -Iwasm2c
CPPFLAGS=-Wno-main-return-type -Wno-main -I. -Iwaforth.gen -Iwasm2c
LINKFLAGS=-g
.DEFAULT_GOAL := all
-include waforth.gen/Makefile.inc
OBJECTS=waforth_core.o main.o waforth.o wasm2c/wasm-rt-impl.o $(WAFORTH_MODULE_OBJECTS)
WAFORTH_MODULE_SOURCES=$(patsubst %.wasm,%.c,$(WAFORTH_MODULES))
WAFORTH_MODULE_HEADERS=$(patsubst %.wasm,%.h,$(WAFORTH_MODULES))
WAFORTH_MODULE_OBJECTS=$(patsubst %.wasm,%.o,$(WAFORTH_MODULES))
OBJECTS=waforth_core.o main.o waforth.o wasm2c/wasm-rt-impl.o $(WAFORTH_MODULE_OBJECTS) waforth.gen/waforth_modules.o
.PHONY: all
all: main
@ -31,3 +35,14 @@ waforth_core.c: ../../src/waforth.wasm
waforth_core.o: waforth_core.c
$(CC) $(CPPFLAGS) $(CFLAGS) -DWASM_RT_MODULE_PREFIX=waforth_core_ -c $< -o $@
waforth.gen/waforth_module_%.c waforth.gen/waforth_module_%.h: waforth.gen/waforth_module_%.wasm
wasm2c $< -o $(subst .wasm,.c,$<)
waforth.gen/waforth_module_%.wasm: waforth.gen/waforth_module_%.in.wasm
wasm-dis $< -o $(subst .wasm,.wat,$@)
wasm-as $(subst .wasm,.wat,$@) -o $@
waforth.gen/waforth_module_%.o: waforth.gen/waforth_module_%.c
$(CC) $(CPPFLAGS) $(CFLAGS) -DWASM_RT_MODULE_PREFIX=$(subst waforth.gen/,,$(subst .o,,$@))_ -c $< -o $@
waforth.gen/waforth_modules.h: $(WAFORTH_MODULE_HEADERS)

View file

@ -94,15 +94,7 @@ WebAssembly.instantiate(coreWasm, {
fs.mkdirSync("waforth.gen");
}
const make = [
"waforth.gen/waforth_module_%.c waforth.gen/waforth_module_%.h: waforth.gen/waforth_module_%.wasm",
"\twasm2c $< -o $(subst .wasm,.c,$<)",
"",
"waforth.gen/waforth_module_%.wasm: waforth.gen/waforth_module_%.in.wasm",
"\twasm-dis $< -o $(subst .wasm,.wat,$@)",
"\twasm-as $(subst .wasm,.wat,$@) -o $@",
""
];
const make = [];
const include = [
"#pragma once",
"",
@ -125,40 +117,20 @@ WebAssembly.instantiate(coreWasm, {
(savedHere - dictionaryStart) +
");"
];
const objects = ["waforth.gen/waforth_modules.o"];
const moduleHeaders = [];
const moduleSources = [];
const moduleFiles = [];
for (let i = 0; i < modules.length; ++i) {
fs.writeFileSync(
"waforth.gen/waforth_module_" + i + ".in.wasm",
modules[i]
);
make.push(
"waforth.gen/waforth_module_" +
i +
".o: waforth.gen/waforth_module_" +
i +
".c"
);
make.push(
"\t$(CC) $(CPPFLAGS) $(CFLAGS) -DWASM_RT_MODULE_PREFIX=waforth_module_" +
i +
"_ -c $< -o $@"
);
make.push("");
include.push("#define WASM_RT_MODULE_PREFIX waforth_module_" + i + "_");
include.push('#include "waforth.gen/waforth_module_' + i + '.h"');
include.push("#undef WASM_RT_MODULE_PREFIX");
init.push("waforth_module_" + i + "_init();");
objects.push("waforth.gen/waforth_module_" + i + ".o");
moduleHeaders.push("waforth.gen/waforth_module_" + i + ".h");
moduleSources.push("waforth.gen/waforth_module_" + i + ".c");
moduleFiles.push("waforth.gen/waforth_module_" + i + ".wasm");
}
include.push("#define WASM_RT_MODULE_PREFIX");
make.push("WAFORTH_MODULE_OBJECTS = " + objects.join(" ") + "\n");
make.push("WAFORTH_MODULE_HEADERS = " + moduleHeaders.join(" ") + "\n");
make.push("WAFORTH_MODULE_SOURCES = " + moduleSources.join(" ") + "\n");
make.push("waforth.gen/waforth_modules.h: $(WAFORTH_MODULE_HEADERS)");
make.push("WAFORTH_MODULES = " + moduleFiles.join(" ") + "\n");
init.push("}");
fs.writeFileSync("waforth.gen/Makefile.inc", make.join("\n") + "\n");
fs.writeFileSync("waforth.gen/waforth_modules.h", include.join("\n") + "\n");