forked from pyrite-dev/pmake
stuff
This commit is contained in:
parent
fac750a2b3
commit
7278e994da
14 changed files with 128 additions and 40 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -5,5 +5,5 @@
|
||||||
/Makefile
|
/Makefile
|
||||||
/*.make
|
/*.make
|
||||||
/src/compiler/*.c
|
/src/compiler/*.c
|
||||||
/src/action/*.c
|
/src/system/*.c
|
||||||
/src/js/*.c
|
/src/js/*.c
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ all: pmake$(EXE)
|
||||||
include mk/js.mk
|
include mk/js.mk
|
||||||
|
|
||||||
mk/js.mk:
|
mk/js.mk:
|
||||||
find src/js src/action src/compiler -name "*.js" | while read js; do \
|
find src/compiler src/system src/js -name "*.js" | while read js; do \
|
||||||
name="`echo $$js | cut -d/ -f2`_`echo $$js | $(NAME)`" ; \
|
name="`echo $$js | cut -d/ -f2`_`echo $$js | $(NAME)`" ; \
|
||||||
c="`echo $$js | sed 's/\.js$$/.c/'`" ; \
|
c="`echo $$js | sed 's/\.js$$/.c/'`" ; \
|
||||||
o="`echo $$js | sed 's/\.js$$/.o/'`" ; \
|
o="`echo $$js | sed 's/\.js$$/.o/'`" ; \
|
||||||
|
|
@ -81,7 +81,7 @@ src/config.h:
|
||||||
echo "#ifndef __CONFIG_H__" > $@
|
echo "#ifndef __CONFIG_H__" > $@
|
||||||
echo "#define __CONFIG_H__" >> $@
|
echo "#define __CONFIG_H__" >> $@
|
||||||
echo "" >> $@
|
echo "" >> $@
|
||||||
for i in compiler action; do \
|
for i in compiler system; do \
|
||||||
echo "#define `echo $$i | tr '[:lower:]' '[:upper:]'`S \\" >> $@ ; \
|
echo "#define `echo $$i | tr '[:lower:]' '[:upper:]'`S \\" >> $@ ; \
|
||||||
find src/$$i -name "*.js" | while read js; do \
|
find src/$$i -name "*.js" | while read js; do \
|
||||||
echo " X(`echo $$js | $(NAME)`, $$i) \\" ; \
|
echo " X(`echo $$js | $(NAME)`, $$i) \\" ; \
|
||||||
|
|
@ -90,7 +90,7 @@ src/config.h:
|
||||||
done
|
done
|
||||||
echo "#define JS \\" >> $@
|
echo "#define JS \\" >> $@
|
||||||
echo " COMPILERS \\" >> $@
|
echo " COMPILERS \\" >> $@
|
||||||
echo " ACTIONS" >> $@
|
echo " SYSTEMS" >> $@
|
||||||
echo "" >> $@
|
echo "" >> $@
|
||||||
echo "#endif" >> $@
|
echo "#endif" >> $@
|
||||||
|
|
||||||
|
|
@ -103,4 +103,4 @@ pmake$(EXE): $(OBJS)
|
||||||
clean:
|
clean:
|
||||||
rm -f pmake pmake.exe
|
rm -f pmake pmake.exe
|
||||||
find . -name "*.o" >/dev/null && rm -f $(shell find . -name "*.o")
|
find . -name "*.o" >/dev/null && rm -f $(shell find . -name "*.o")
|
||||||
rm -f src/compiler/*.c src/action/*.c src/js/*.c
|
rm -f src/compiler/*.c src/system/*.c src/js/*.c
|
||||||
|
|
|
||||||
28
mk/js.mk
generated
28
mk/js.mk
generated
|
|
@ -1,11 +1,3 @@
|
||||||
OBJS += src/js/core.o
|
|
||||||
src/js/core.c: src/js/core.js
|
|
||||||
xxd -njs_core -i src/js/core.js > src/js/core.c
|
|
||||||
|
|
||||||
OBJS += src/js/cmdline.o
|
|
||||||
src/js/cmdline.c: src/js/cmdline.js
|
|
||||||
xxd -njs_cmdline -i src/js/cmdline.js > src/js/cmdline.c
|
|
||||||
|
|
||||||
OBJS += src/compiler/watcom.o
|
OBJS += src/compiler/watcom.o
|
||||||
src/compiler/watcom.c: src/compiler/watcom.js
|
src/compiler/watcom.c: src/compiler/watcom.js
|
||||||
xxd -ncompiler_watcom -i src/compiler/watcom.js > src/compiler/watcom.c
|
xxd -ncompiler_watcom -i src/compiler/watcom.js > src/compiler/watcom.c
|
||||||
|
|
@ -14,3 +6,23 @@ OBJS += src/compiler/gcc.o
|
||||||
src/compiler/gcc.c: src/compiler/gcc.js
|
src/compiler/gcc.c: src/compiler/gcc.js
|
||||||
xxd -ncompiler_gcc -i src/compiler/gcc.js > src/compiler/gcc.c
|
xxd -ncompiler_gcc -i src/compiler/gcc.js > src/compiler/gcc.c
|
||||||
|
|
||||||
|
OBJS += src/system/unix.o
|
||||||
|
src/system/unix.c: src/system/unix.js
|
||||||
|
xxd -nsystem_unix -i src/system/unix.js > src/system/unix.c
|
||||||
|
|
||||||
|
OBJS += src/system/windows.o
|
||||||
|
src/system/windows.c: src/system/windows.js
|
||||||
|
xxd -nsystem_windows -i src/system/windows.js > src/system/windows.c
|
||||||
|
|
||||||
|
OBJS += src/js/core.o
|
||||||
|
src/js/core.c: src/js/core.js
|
||||||
|
xxd -njs_core -i src/js/core.js > src/js/core.c
|
||||||
|
|
||||||
|
OBJS += src/js/cmdline.o
|
||||||
|
src/js/cmdline.c: src/js/cmdline.js
|
||||||
|
xxd -njs_cmdline -i src/js/cmdline.js > src/js/cmdline.c
|
||||||
|
|
||||||
|
OBJS += src/js/postinit.o
|
||||||
|
src/js/postinit.c: src/js/postinit.js
|
||||||
|
xxd -njs_postinit -i src/js/postinit.js > src/js/postinit.c
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,20 @@ Watcom.description = "Open Watcom";
|
||||||
Watcom.output = function(target) {
|
Watcom.output = function(target) {
|
||||||
if(target instanceof pmake.LibraryProject) {
|
if(target instanceof pmake.LibraryProject) {
|
||||||
return target.output + ".lib";
|
return target.output + ".lib";
|
||||||
|
} else if(target instanceof pmake.ExecutableProject) {
|
||||||
|
return target.output + ".exe";
|
||||||
}
|
}
|
||||||
|
|
||||||
return pmake.Compiler.prototype.output.call(this, target);
|
return pmake.Compiler.prototype.output.call(this, target);
|
||||||
}
|
};
|
||||||
|
|
||||||
Watcom.compile = function(target, obj, src) {
|
Watcom.compile = function(target, obj, src) {
|
||||||
function add_i(x) {
|
function add_i(x) {
|
||||||
return "-i=" + x;
|
return "-i=" + x;
|
||||||
}
|
}
|
||||||
|
|
||||||
const includes = pmake.includes(target).map(add_i).join(" ");
|
const includes = pmake.includes(target).map(add_i).join(" ");
|
||||||
const flags = "-bt=nt -q " + includes + " -fo=" + obj + " " + src;
|
const flags = "-bt=nt -fr= -q " + includes + " -fo=" + obj + " " + src;
|
||||||
|
|
||||||
if(src.endsWith(".c")) {
|
if(src.endsWith(".c")) {
|
||||||
return "wcc386 " + flags;
|
return "wcc386 " + flags;
|
||||||
|
|
@ -36,15 +38,23 @@ Watcom.link = function(target, files) {
|
||||||
return "file \"" + x + "\"";
|
return "file \"" + x + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_lib(x) {
|
||||||
|
return x + ".lib";
|
||||||
|
}
|
||||||
|
|
||||||
function add_library(x) {
|
function add_library(x) {
|
||||||
return "library \"" + x + "\"";
|
return "library \"" + x + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "wlink option quiet system nt name " + this.output(target) + " " + files.map(add_file).join(" ") + " " + pmake.libs(target).map(add_library).join(" ");
|
return "wlink option quiet system nt name " + this.output(target) + " " + files.map(add_file).join(" ") + " " + pmake.libs(target, add_lib).map(add_library).join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Watcom.init = function() {
|
||||||
|
pmake.setSystem("Windows");
|
||||||
|
};
|
||||||
|
|
||||||
pmake.register(Watcom);
|
pmake.register(Watcom);
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
6
src/config.h
generated
6
src/config.h
generated
|
|
@ -5,10 +5,12 @@
|
||||||
X(watcom, compiler) \
|
X(watcom, compiler) \
|
||||||
X(gcc, compiler)
|
X(gcc, compiler)
|
||||||
|
|
||||||
#define ACTIONS
|
#define SYSTEMS \
|
||||||
|
X(unix, system) \
|
||||||
|
X(windows, system)
|
||||||
|
|
||||||
#define JS \
|
#define JS \
|
||||||
COMPILERS \
|
COMPILERS \
|
||||||
ACTIONS
|
SYSTEMS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
24
src/js.c
24
src/js.c
|
|
@ -3,14 +3,13 @@
|
||||||
duk_context* js_ctx;
|
duk_context* js_ctx;
|
||||||
|
|
||||||
LOAD(js_core);
|
LOAD(js_core);
|
||||||
|
LOAD(js_postinit);
|
||||||
LOAD(js_cmdline);
|
LOAD(js_cmdline);
|
||||||
LOAD(js_end);
|
|
||||||
|
|
||||||
static void js_argv_init(int argc, char** argv) {
|
static void js_argv_init(int argc, char** argv) {
|
||||||
int arr;
|
int arr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
duk_push_global_object(js_ctx);
|
|
||||||
arr = duk_push_array(js_ctx);
|
arr = duk_push_array(js_ctx);
|
||||||
|
|
||||||
for(i = 0; i < argc; i++) {
|
for(i = 0; i < argc; i++) {
|
||||||
|
|
@ -19,16 +18,26 @@ static void js_argv_init(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
duk_put_prop_string(js_ctx, 0, "ARGV");
|
duk_put_prop_string(js_ctx, 0, "ARGV");
|
||||||
|
}
|
||||||
|
|
||||||
duk_pop(js_ctx);
|
static void js_win32_init(void) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
duk_push_number(js_ctx, 1);
|
||||||
|
#else
|
||||||
|
duk_push_number(js_ctx, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
duk_put_prop_string(js_ctx, 0, "WIN32");
|
||||||
}
|
}
|
||||||
|
|
||||||
int js_init(int argc, char** argv) {
|
int js_init(int argc, char** argv) {
|
||||||
int st;
|
int st;
|
||||||
|
|
||||||
js_ctx = duk_create_heap_default();
|
js_ctx = duk_create_heap_default();
|
||||||
|
duk_push_global_object(js_ctx);
|
||||||
|
|
||||||
js_argv_init(argc, argv);
|
js_argv_init(argc, argv);
|
||||||
|
js_win32_init();
|
||||||
js_console_init();
|
js_console_init();
|
||||||
js_process_init();
|
js_process_init();
|
||||||
js_fs_init();
|
js_fs_init();
|
||||||
|
|
@ -44,14 +53,13 @@ int js_init(int argc, char** argv) {
|
||||||
return 1; \
|
return 1; \
|
||||||
}
|
}
|
||||||
JS;
|
JS;
|
||||||
#undef X
|
|
||||||
|
X(postinit, js);
|
||||||
|
|
||||||
if((st = js_run("pmake.js")) != 0) return st;
|
if((st = js_run("pmake.js")) != 0) return st;
|
||||||
|
|
||||||
if(duk_peval_lstring(js_ctx, js_cmdline, js_cmdline_len) != 0) {
|
X(cmdline, js);
|
||||||
printf("JS error: js/cmdline.js: %s\n", duk_safe_to_string(js_ctx, -1));
|
#undef X
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
const PADDING = 24;
|
const PADDING = 24;
|
||||||
|
|
||||||
pmake.compiler = pmake.compilers["GCC"];
|
|
||||||
|
|
||||||
for(var i = 1; i < ARGV.length; i++) {
|
for(var i = 1; i < ARGV.length; i++) {
|
||||||
if(ARGV[i] == "--help") {
|
if(ARGV[i] == "--help") {
|
||||||
var keys;
|
var keys;
|
||||||
|
|
@ -79,6 +77,8 @@ for(var i = 1; i < ARGV.length; i++) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
function make(output) {
|
function make(output) {
|
||||||
const targets = pmake.resolveProjects(pmake.projects);
|
const targets = pmake.resolveProjects(pmake.projects);
|
||||||
|
|
@ -134,8 +134,10 @@ function make(output) {
|
||||||
mk.write("\n");
|
mk.write("\n");
|
||||||
|
|
||||||
mk.write(pmake.compiler.output(self) + ": " + objs.join(" ") + "\n");
|
mk.write(pmake.compiler.output(self) + ": " + objs.join(" ") + "\n");
|
||||||
mk.write(" @echo LINK " + pmake.compiler.output(self) + "\n");
|
if(!(self instanceof pmake.InterfaceProject)) {
|
||||||
mk.write(" $(SILENT)" + pmake.compiler.link(self, objs) + "\n");
|
mk.write(" @echo LINK " + pmake.compiler.output(self) + "\n");
|
||||||
|
mk.write(" $(SILENT)" + pmake.compiler.link(self, objs) + "\n");
|
||||||
|
}
|
||||||
mk.write("\n");
|
mk.write("\n");
|
||||||
|
|
||||||
for(var i = 0; i < objs.length; i++) {
|
for(var i = 0; i < objs.length; i++) {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ if(!Array.prototype.flat) {
|
||||||
const pmake = {
|
const pmake = {
|
||||||
VERSION : "0.0",
|
VERSION : "0.0",
|
||||||
compilers : {},
|
compilers : {},
|
||||||
|
systems : {},
|
||||||
options : {},
|
options : {},
|
||||||
options_category : {},
|
options_category : {},
|
||||||
projects : []
|
projects : []
|
||||||
|
|
@ -53,6 +54,8 @@ pmake.inherited = function(base, parent) {
|
||||||
pmake.register = function(target) {
|
pmake.register = function(target) {
|
||||||
if(target instanceof pmake.Compiler) {
|
if(target instanceof pmake.Compiler) {
|
||||||
pmake.compilers[target.target] = target;
|
pmake.compilers[target.target] = target;
|
||||||
|
} else if(target instanceof pmake.System) {
|
||||||
|
pmake.systems[target.target] = target;
|
||||||
} else if(target instanceof pmake.Option) {
|
} else if(target instanceof pmake.Option) {
|
||||||
if(!pmake.options_category[target.category]) pmake.options_category[target.category] = {};
|
if(!pmake.options_category[target.category]) pmake.options_category[target.category] = {};
|
||||||
|
|
||||||
|
|
@ -118,11 +121,26 @@ pmake.libs = function(target, if_str) {
|
||||||
return targets.map(libs).flat();
|
return targets.map(libs).flat();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pmake.setSystem = function(target){
|
||||||
|
pmake.system = pmake.systems[target];
|
||||||
|
|
||||||
|
if(pmake.system.init) pmake.system.init();
|
||||||
|
};
|
||||||
|
|
||||||
|
pmake.setCompiler = function(target){
|
||||||
|
pmake.compiler = pmake.compilers[target];
|
||||||
|
|
||||||
|
if(pmake.compiler.init) pmake.compiler.init();
|
||||||
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
const Compiler = function() {
|
const Compiler = function() {
|
||||||
this.prefix = "";
|
this.prefix = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Compiler.prototype.init = function() {
|
||||||
|
};
|
||||||
|
|
||||||
Compiler.prototype.output = function(target) {
|
Compiler.prototype.output = function(target) {
|
||||||
if((typeof target) == "string") {
|
if((typeof target) == "string") {
|
||||||
if(target.endsWith(".c")) return target.replace(/\.c$/, ".o");
|
if(target.endsWith(".c")) return target.replace(/\.c$/, ".o");
|
||||||
|
|
@ -180,6 +198,11 @@ POSIXCompiler.prototype.link = function(target, files) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const System = function() {};
|
||||||
|
|
||||||
|
System.prototype.init = function() {
|
||||||
|
};
|
||||||
|
|
||||||
const Option = function() {};
|
const Option = function() {};
|
||||||
|
|
||||||
const Project = function(target) {
|
const Project = function(target) {
|
||||||
|
|
@ -216,6 +239,7 @@ File.prototype.close = function() {
|
||||||
|
|
||||||
pmake.Compiler = Compiler;
|
pmake.Compiler = Compiler;
|
||||||
pmake.POSIXCompiler = POSIXCompiler;
|
pmake.POSIXCompiler = POSIXCompiler;
|
||||||
|
pmake.System = System;
|
||||||
pmake.Option = Option;
|
pmake.Option = Option;
|
||||||
pmake.Project = Project;
|
pmake.Project = Project;
|
||||||
pmake.LibraryProject = LibraryProject;
|
pmake.LibraryProject = LibraryProject;
|
||||||
|
|
@ -238,8 +262,24 @@ Compiler.options = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Compiler.action = function(value) {
|
Compiler.action = function(value) {
|
||||||
pmake.compiler = pmake.compilers[value];
|
pmake.setCompiler(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const System = new pmake.Option();
|
||||||
|
|
||||||
|
System.category = "General";
|
||||||
|
System.target = "system";
|
||||||
|
System.description = "Generate files for a different system; one of:";
|
||||||
|
System.option = "VALUE";
|
||||||
|
|
||||||
|
System.options = function() {
|
||||||
|
return Object.keys(pmake.systems);
|
||||||
|
};
|
||||||
|
|
||||||
|
System.action = function(value) {
|
||||||
|
pmake.setSystem(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
pmake.register(Compiler);
|
pmake.register(Compiler);
|
||||||
|
pmake.register(System);
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
7
src/js/postinit.js
Normal file
7
src/js/postinit.js
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
pmake.setCompiler("GCC");
|
||||||
|
|
||||||
|
if(WIN32) {
|
||||||
|
pmake.setSystem("Windows");
|
||||||
|
}else{
|
||||||
|
pmake.setSystem("Unix");
|
||||||
|
}
|
||||||
|
|
@ -9,13 +9,10 @@ static duk_ret_t js_console_log(duk_context* self) {
|
||||||
void js_console_init(void) {
|
void js_console_init(void) {
|
||||||
int obj;
|
int obj;
|
||||||
|
|
||||||
duk_push_global_object(js_ctx);
|
|
||||||
obj = duk_push_object(js_ctx);
|
obj = duk_push_object(js_ctx);
|
||||||
|
|
||||||
duk_push_c_function(js_ctx, js_console_log, 1);
|
duk_push_c_function(js_ctx, js_console_log, 1);
|
||||||
duk_put_prop_string(js_ctx, obj, "log");
|
duk_put_prop_string(js_ctx, obj, "log");
|
||||||
|
|
||||||
duk_put_prop_string(js_ctx, 0, "console");
|
duk_put_prop_string(js_ctx, 0, "console");
|
||||||
|
|
||||||
duk_pop(js_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,6 @@ static duk_ret_t js_fs_close(duk_context* self) {
|
||||||
void js_fs_init(void) {
|
void js_fs_init(void) {
|
||||||
int obj;
|
int obj;
|
||||||
|
|
||||||
duk_push_global_object(js_ctx);
|
|
||||||
obj = duk_push_object(js_ctx);
|
obj = duk_push_object(js_ctx);
|
||||||
|
|
||||||
duk_push_c_function(js_ctx, js_fs_glob, DUK_VARARGS);
|
duk_push_c_function(js_ctx, js_fs_glob, DUK_VARARGS);
|
||||||
|
|
@ -114,6 +113,4 @@ void js_fs_init(void) {
|
||||||
duk_put_prop_string(js_ctx, obj, "close");
|
duk_put_prop_string(js_ctx, obj, "close");
|
||||||
|
|
||||||
duk_put_prop_string(js_ctx, 0, "fs");
|
duk_put_prop_string(js_ctx, 0, "fs");
|
||||||
|
|
||||||
duk_pop(js_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ static duk_ret_t js_process_system(duk_context* self) {
|
||||||
void js_process_init(void) {
|
void js_process_init(void) {
|
||||||
int obj;
|
int obj;
|
||||||
|
|
||||||
duk_push_global_object(js_ctx);
|
|
||||||
obj = duk_push_object(js_ctx);
|
obj = duk_push_object(js_ctx);
|
||||||
|
|
||||||
duk_push_c_function(js_ctx, js_process_exit, DUK_VARARGS);
|
duk_push_c_function(js_ctx, js_process_exit, DUK_VARARGS);
|
||||||
|
|
@ -40,6 +39,4 @@ void js_process_init(void) {
|
||||||
duk_put_prop_string(js_ctx, obj, "system");
|
duk_put_prop_string(js_ctx, obj, "system");
|
||||||
|
|
||||||
duk_put_prop_string(js_ctx, 0, "process");
|
duk_put_prop_string(js_ctx, 0, "process");
|
||||||
|
|
||||||
duk_pop(js_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
src/system/unix.js
Normal file
8
src/system/unix.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
(function() {
|
||||||
|
const Unix = new pmake.System();
|
||||||
|
|
||||||
|
Unix.target = "Unix";
|
||||||
|
Unix.description = "Unix/Unix-like";
|
||||||
|
|
||||||
|
pmake.register(Unix);
|
||||||
|
})();
|
||||||
8
src/system/windows.js
Normal file
8
src/system/windows.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
(function() {
|
||||||
|
const Windows = new pmake.System();
|
||||||
|
|
||||||
|
Windows.target = "Windows";
|
||||||
|
Windows.description = "Windows";
|
||||||
|
|
||||||
|
pmake.register(Windows);
|
||||||
|
})();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue