stuff
This commit is contained in:
parent
fac750a2b3
commit
7278e994da
14 changed files with 128 additions and 40 deletions
|
|
@ -7,18 +7,20 @@ Watcom.description = "Open Watcom";
|
|||
Watcom.output = function(target) {
|
||||
if(target instanceof pmake.LibraryProject) {
|
||||
return target.output + ".lib";
|
||||
} else if(target instanceof pmake.ExecutableProject) {
|
||||
return target.output + ".exe";
|
||||
}
|
||||
|
||||
return pmake.Compiler.prototype.output.call(this, target);
|
||||
}
|
||||
};
|
||||
|
||||
Watcom.compile = function(target, obj, src) {
|
||||
Watcom.compile = function(target, obj, src) {
|
||||
function add_i(x) {
|
||||
return "-i=" + x;
|
||||
}
|
||||
|
||||
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")) {
|
||||
return "wcc386 " + flags;
|
||||
|
|
@ -36,15 +38,23 @@ Watcom.link = function(target, files) {
|
|||
return "file \"" + x + "\"";
|
||||
}
|
||||
|
||||
function add_lib(x) {
|
||||
return x + ".lib";
|
||||
}
|
||||
|
||||
function add_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 "";
|
||||
};
|
||||
|
||||
Watcom.init = function() {
|
||||
pmake.setSystem("Windows");
|
||||
};
|
||||
|
||||
pmake.register(Watcom);
|
||||
})();
|
||||
|
|
|
|||
6
src/config.h
generated
6
src/config.h
generated
|
|
@ -5,10 +5,12 @@
|
|||
X(watcom, compiler) \
|
||||
X(gcc, compiler)
|
||||
|
||||
#define ACTIONS
|
||||
#define SYSTEMS \
|
||||
X(unix, system) \
|
||||
X(windows, system)
|
||||
|
||||
#define JS \
|
||||
COMPILERS \
|
||||
ACTIONS
|
||||
SYSTEMS
|
||||
|
||||
#endif
|
||||
|
|
|
|||
24
src/js.c
24
src/js.c
|
|
@ -3,14 +3,13 @@
|
|||
duk_context* js_ctx;
|
||||
|
||||
LOAD(js_core);
|
||||
LOAD(js_postinit);
|
||||
LOAD(js_cmdline);
|
||||
LOAD(js_end);
|
||||
|
||||
static void js_argv_init(int argc, char** argv) {
|
||||
int arr;
|
||||
int i;
|
||||
|
||||
duk_push_global_object(js_ctx);
|
||||
arr = duk_push_array(js_ctx);
|
||||
|
||||
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_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 st;
|
||||
|
||||
js_ctx = duk_create_heap_default();
|
||||
duk_push_global_object(js_ctx);
|
||||
|
||||
js_argv_init(argc, argv);
|
||||
js_win32_init();
|
||||
js_console_init();
|
||||
js_process_init();
|
||||
js_fs_init();
|
||||
|
|
@ -44,14 +53,13 @@ int js_init(int argc, char** argv) {
|
|||
return 1; \
|
||||
}
|
||||
JS;
|
||||
#undef X
|
||||
|
||||
X(postinit, js);
|
||||
|
||||
if((st = js_run("pmake.js")) != 0) return st;
|
||||
|
||||
if(duk_peval_lstring(js_ctx, js_cmdline, js_cmdline_len) != 0) {
|
||||
printf("JS error: js/cmdline.js: %s\n", duk_safe_to_string(js_ctx, -1));
|
||||
return 1;
|
||||
}
|
||||
X(cmdline, js);
|
||||
#undef X
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
const PADDING = 24;
|
||||
|
||||
pmake.compiler = pmake.compilers["GCC"];
|
||||
|
||||
for(var i = 1; i < ARGV.length; i++) {
|
||||
if(ARGV[i] == "--help") {
|
||||
var keys;
|
||||
|
|
@ -79,6 +77,8 @@ for(var i = 1; i < ARGV.length; i++) {
|
|||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
(function() {
|
||||
function make(output) {
|
||||
const targets = pmake.resolveProjects(pmake.projects);
|
||||
|
|
@ -134,8 +134,10 @@ function make(output) {
|
|||
mk.write("\n");
|
||||
|
||||
mk.write(pmake.compiler.output(self) + ": " + objs.join(" ") + "\n");
|
||||
mk.write(" @echo LINK " + pmake.compiler.output(self) + "\n");
|
||||
mk.write(" $(SILENT)" + pmake.compiler.link(self, objs) + "\n");
|
||||
if(!(self instanceof pmake.InterfaceProject)) {
|
||||
mk.write(" @echo LINK " + pmake.compiler.output(self) + "\n");
|
||||
mk.write(" $(SILENT)" + pmake.compiler.link(self, objs) + "\n");
|
||||
}
|
||||
mk.write("\n");
|
||||
|
||||
for(var i = 0; i < objs.length; i++) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ if(!Array.prototype.flat) {
|
|||
const pmake = {
|
||||
VERSION : "0.0",
|
||||
compilers : {},
|
||||
systems : {},
|
||||
options : {},
|
||||
options_category : {},
|
||||
projects : []
|
||||
|
|
@ -53,6 +54,8 @@ pmake.inherited = function(base, parent) {
|
|||
pmake.register = function(target) {
|
||||
if(target instanceof pmake.Compiler) {
|
||||
pmake.compilers[target.target] = target;
|
||||
} else if(target instanceof pmake.System) {
|
||||
pmake.systems[target.target] = target;
|
||||
} else if(target instanceof pmake.Option) {
|
||||
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();
|
||||
};
|
||||
|
||||
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() {
|
||||
const Compiler = function() {
|
||||
this.prefix = "";
|
||||
};
|
||||
|
||||
Compiler.prototype.init = function() {
|
||||
};
|
||||
|
||||
Compiler.prototype.output = function(target) {
|
||||
if((typeof target) == "string") {
|
||||
if(target.endsWith(".c")) return target.replace(/\.c$/, ".o");
|
||||
|
|
@ -180,6 +198,11 @@ POSIXCompiler.prototype.link = function(target, files) {
|
|||
return "";
|
||||
}
|
||||
|
||||
const System = function() {};
|
||||
|
||||
System.prototype.init = function() {
|
||||
};
|
||||
|
||||
const Option = function() {};
|
||||
|
||||
const Project = function(target) {
|
||||
|
|
@ -216,6 +239,7 @@ File.prototype.close = function() {
|
|||
|
||||
pmake.Compiler = Compiler;
|
||||
pmake.POSIXCompiler = POSIXCompiler;
|
||||
pmake.System = System;
|
||||
pmake.Option = Option;
|
||||
pmake.Project = Project;
|
||||
pmake.LibraryProject = LibraryProject;
|
||||
|
|
@ -238,8 +262,24 @@ Compiler.options = function() {
|
|||
};
|
||||
|
||||
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(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) {
|
||||
int obj;
|
||||
|
||||
duk_push_global_object(js_ctx);
|
||||
obj = duk_push_object(js_ctx);
|
||||
|
||||
duk_push_c_function(js_ctx, js_console_log, 1);
|
||||
duk_put_prop_string(js_ctx, obj, "log");
|
||||
|
||||
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) {
|
||||
int obj;
|
||||
|
||||
duk_push_global_object(js_ctx);
|
||||
obj = duk_push_object(js_ctx);
|
||||
|
||||
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, 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) {
|
||||
int obj;
|
||||
|
||||
duk_push_global_object(js_ctx);
|
||||
obj = duk_push_object(js_ctx);
|
||||
|
||||
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, 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