pike.git
/
NT
/
tools
/
rntcc
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/NT/tools/rntcc:1:
#!/usr/local/bin/pike
+
// RNTCC, a front-end to WatCOM C/C++ with options similar to GCC
+
// Written by Fredrik Hubinette.
+
inherit "lib.pike";
-
+
// Verbose is default for now, this can be turned off one this
+
// frontend has been refined to where it does not require more
+
// debugging.
+
+
int verbose=1;
+
int compile(string *sources, string dest, string errorfile, string *cflags) { int ret;
-
+
mixed cmd;
if(!dest) { string tmp=reverse(sources[0]); sscanf(tmp,"%*s.%s",tmp); dest=reverse(tmp)+".o"; } dest=fixpath(dest); sources=Array.map(sources,fixpath); if(lower_case(sources[0][strlen(sources[0])-3..])==".s") {
-
ret=do_
cmd(
(
{ "wasm", "-fe"+errorfile, "-fo"+dest,})+ sources
)
;
+
cmd
=({ "wasm", "-fe"+errorfile, "-fo"+dest,})+ sources;
}else{
-
ret=do_
cmd(
(
{ "wcc386" }) + cflags + ({"-fr"+errorfile, "-fo"+dest}) + sources
)
;
+
cmd
=({ "wcc386" }) + cflags + ({"-fr"+errorfile, "-fo"+dest}) + sources;
}
-
return
ret
;
+
+
if(verbose)
+
return
do_cmd(cmd)
;
+
else
+
return silent_do_cmd(cmd);
} string check_errorfile(string errorfile) { object f=Stdio.File(); if(f->open(errorfile,"r")) { string data; write(data=f->read()); f->close();
pike.git/NT/tools/rntcc:53:
string operation="link"; string *cflags=({}); string *ldopts=({"OPTION","STACK=8m"}); string *libraries=({}); string *objects=({}); string *sources=({}); int debug,optimize; string output; int share=0;
-
mixed *opts=Getopt.find_all_options(argv, (
{
+
mixed *opts=Getopt.find_all_options(argv,
aggregate
(
({"oper_pre",Getopt.NO_ARG, ({"-E"}) }), ({"oper_comp",Getopt.NO_ARG, ({"-c"}) }),
-
+
({"verbose",Getopt.NO_ARG, ({"-v"}) }),
({"debug",Getopt.MAY_HAVE_ARG, ({"-g"}) }), ({"optimize",Getopt.MAY_HAVE_ARG, ({"-O"}) }), ({"include",Getopt.HAS_ARG, ({"-I"}) }), ({"link",Getopt.HAS_ARG, ({"-l"}) }), ({"share",Getopt.MAY_HAVE_ARG, ({"-s"}) }), ({"ignore",Getopt.MAY_HAVE_ARG, ({"-t"}) }), ({"ignore",Getopt.HAS_ARG, ({"-R","-L"}) }), ({"warn",Getopt.MAY_HAVE_ARG, ({"-W"}) }), ({"define",Getopt.HAS_ARG, ({"-D"}) }), ({"undefine",Getopt.HAS_ARG, ({"-U"})}), ({"output",Getopt.HAS_ARG, ({"-o"}) }), ({"export",Getopt.HAS_ARG, ({"--export"}) })
-
}
));
+
));
foreach(opts, mixed *option) { switch(option[0]) {
-
+
case "verbose":
+
verbose=1;
+
break;
+
case "export": ldopts+=({"export",option[1]+"_"}); break; case "share": share=1; ldopts=({"SYSTEM","nt_dll","initinstance","terminstance"})+ldopts; cflags+=({"-bd"}); break;
pike.git/NT/tools/rntcc:103:
if(!option[1]) option[1]=1; switch(optimize=(int)option[1]) { case 0: optimize=0; break; case 1: cflags+=({"-ox"}); break; case 2..: cflags+=({"-otexan"}); break; } break; case "include":
+
// Avoid searching 'local' include dirs.
+
// This is not a very pretty solution.
if(sscanf(option[1],"/usr/include/%*s") || sscanf(option[1],"/usr/local/%*s")) break; cflags+=({"-i"+fixpath(option[1])}); break; case "link":
-
+
// -lm and -lc are automatically handled by wlink
if(option[1]=="m" || option[1]=="c") break;
-
libraries+=(
{"LIBRARY",option
[1]});
+
// We optimiza a little, no need to bring in the same
+
// library many times in a row.
+
if(!sizeof(libraries) || libraries[-1]!=option[1])
+
libraries+=(
{option
[1]});
break; case "warn":
-
if(option[1]
&&
sscanf(option[1],"l,%*s")) break;
+
if(option[1]
)
+
{
+
// This allows us to pass options to the linker
+
if(
sscanf(option[1],"l,%
s",string tmp))
+
{
+
// This was done for my convenience, it can be taken
+
// out once smartlink has been fixed to not use absoute
+
// paths for the 'uname' binary.
+
if(sscanf(tmp,"-rpath%
*s")) break;
+
+
ldopts+=({tmp});
+
break;
+
}
+
}
+
+
// More options should be recognized, options which are not
+
// recognized should generate warning/error messages.
switch(option[1]) { case "all": cflags+=({"-wx"}); break; default: cflags+=({"-w2"}); break; } break; case "define": cflags+=({"-d"+option[1]}); break; case "undefine": cflags+=({"-u"+option[1]}); break; case "output": output=option[1]; break; } }
-
+
// Scan through the remaining arguments
argv=Getopt.get_args(argv); foreach(argv[1..], string tmp) { string ext; if(tmp[0]=='-') { werror("Unrecognized option "+tmp+".\n"); exit(1); } sscanf(reverse(tmp),"%s.",ext);
-
+
+
// Recognize which files need to be compiled
switch(ext) {
-
+
case "bil":
case "o":
-
+
case "jbo":
case "a":
-
+
case "lld":
objects+=({tmp}); break; default: sources+=({tmp}); } } if(output) rm(output); string errorfile="TMP"+getpid()+".err"; rm(errorfile);
-
+
// Flags required to make the compiler behave well
cflags+=({"-bm","-zq","-hc","-sg"}); switch(operation) { default: werror("Unknown operation "+operation+".\n"); exit(1); case "compile": compile(sources,output,errorfile,cflags);
pike.git/NT/tools/rntcc:197:
check_errorfile(errorfile); } string ldfile="TMP"+getpid()+".lk"; if(!output) output="a.out"; rm(ldfile); target=output; if(!share) target+=".exe";
-
Stdio.write_file
(
ldfile,
-
"NAME
"+target+"
"
+ldopts
*" "+" "+
-
"
FIL
"+Array.map(objects,fixpath)*","+" "+
-
libraries*
" "
+
" ");
+
string linkopts=
(
"NAME "+target+" " +
+
ldopts
*" "+" "+
+
"
FILE
"+Array.map(objects,fixpath)*","+" "+
+
sprintf(
"
%{LIBRARY
%s %}
"
,libraries));
+
Stdio.write_file(ldfile,linkopts);
+
if(verbose)
+
werror(
"
DOING
wlink
"
+linkopts+"\n"
);
#if 0 Process.system("cat "+ldfile); write("\n"); #endif
-
do_cmd( ({"wlink","@"+ldfile }), lambda(string data)
+
silent_
do_cmd( ({"wlink","@"+ldfile }), lambda(string data)
{ if(search(data," W1008:")!=-1) exit(1); }); if(getenv("CLEANUP")!="no") rm(ldfile); } check_errorfile(errorfile);