merged the vax and mantra versions
This commit is contained in:
parent
45f608bac0
commit
f784236908
1 changed files with 158 additions and 143 deletions
|
@ -1,11 +1,13 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
/*
|
/*
|
||||||
Driver for the CEMCOM compiler: works like /bin/cc and accepts the
|
Driver for the CEMCOM compiler: works like /bin/cc and accepts
|
||||||
options accepted by /bin/cc and /usr/em/bin/ack.
|
most of the options accepted by /bin/cc and /usr/em/bin/ack.
|
||||||
Date written: dec 4, 1985
|
Date written: dec 4, 1985
|
||||||
|
Adapted for 68000 (Aug 19, 1986)
|
||||||
|
Merged the vax and mantra versions (Nov 10, 1986)
|
||||||
Author: Erik Baalbergen
|
Author: Erik Baalbergen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -22,29 +24,43 @@ struct arglist {
|
||||||
|
|
||||||
/* some system-dependent variables */
|
/* some system-dependent variables */
|
||||||
char *PP = "/lib/cpp";
|
char *PP = "/lib/cpp";
|
||||||
char *CEM = "/user1/erikb/bin/cemcom";
|
char *CEM = "/usr/em/lib/em_cemcom";
|
||||||
char *AS_FIX = "/user1/erikb/bin/mcomm";
|
|
||||||
char *ENCODE = "/usr/em/lib/em_encode";
|
char *ENCODE = "/usr/em/lib/em_encode";
|
||||||
char *DECODE = "/usr/em/lib/em_decode";
|
char *DECODE = "/usr/em/lib/em_decode";
|
||||||
char *OPT = "/usr/em/lib/em_opt";
|
char *OPT = "/usr/em/lib/em_opt";
|
||||||
char *CG = "/usr/em/lib/vax4/cg";
|
|
||||||
char *AS = "/bin/as";
|
|
||||||
char *LD = "/bin/ld";
|
|
||||||
char *SHELL = "/bin/sh";
|
char *SHELL = "/bin/sh";
|
||||||
|
|
||||||
|
#ifndef MANTRA
|
||||||
|
char *CG = "/usr/em/lib/vax4/cg";
|
||||||
|
char *AS = "/bin/as";
|
||||||
|
char *AS_FIX = "/user1/erikb/bin/mcomm";
|
||||||
|
char *LD = "/bin/ld";
|
||||||
char *LIBDIR = "/user1/cem/lib";
|
char *LIBDIR = "/user1/cem/lib";
|
||||||
|
|
||||||
char *V_FLAG = "-Vs2.2w4.4i4.4l4.4f4.4d8.4p4.4";
|
char *V_FLAG = "-Vs2.2w4.4i4.4l4.4f4.4d8.4p4.4";
|
||||||
|
#else MANTRA
|
||||||
|
char *CG = "/usr/em/lib/m68k2/cg";
|
||||||
|
char *AS = "/usr/em/lib/m68k2/as";
|
||||||
|
char *LD = "/usr/em/lib/em_led";
|
||||||
|
char *CV = "/usr/em/lib/m68k2/cv";
|
||||||
|
char *LIBDIR = "/usr/em/lib/m68k2";
|
||||||
|
char *V_FLAG = "-Vs2.2w2.2i2.2l4.2f4.2d8.2p4.2";
|
||||||
|
#endif MANTRA
|
||||||
|
|
||||||
struct arglist LD_HEAD = {
|
struct arglist LD_HEAD = {
|
||||||
2,
|
2,
|
||||||
{
|
{
|
||||||
|
#ifndef MANTRA
|
||||||
"/usr/em/lib/vax4/head_em",
|
"/usr/em/lib/vax4/head_em",
|
||||||
"/usr/em/lib/vax4/head_cc"
|
"/usr/em/lib/vax4/head_cc"
|
||||||
|
#else MANTRA
|
||||||
|
"/usr/em/lib/m68k2/head_em",
|
||||||
|
"/usr/em/lib/m68k2/head_cc"
|
||||||
|
#endif MANTRA
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct arglist LD_TAIL = {
|
struct arglist LD_TAIL = {
|
||||||
|
#ifndef MANTRA
|
||||||
4,
|
4,
|
||||||
{
|
{
|
||||||
"/user1/cem/lib/libc.a",
|
"/user1/cem/lib/libc.a",
|
||||||
|
@ -52,11 +68,26 @@ struct arglist LD_TAIL = {
|
||||||
"/usr/em/lib/vax4/tail_mon",
|
"/usr/em/lib/vax4/tail_mon",
|
||||||
"/usr/em/lib/vax4/tail_em"
|
"/usr/em/lib/vax4/tail_em"
|
||||||
}
|
}
|
||||||
|
#else MANTRA
|
||||||
|
7,
|
||||||
|
{
|
||||||
|
"/usr/em/lib/m68k2/tail_cc.1s",
|
||||||
|
"/usr/em/lib/m68k2/tail_cc.2g",
|
||||||
|
"/usr/em/lib/m68k2/tail_cem",
|
||||||
|
"/usr/em/lib/m68k2/tail_fp.a",
|
||||||
|
"/usr/em/lib/m68k2/tail_em.rt",
|
||||||
|
"/usr/em/lib/m68k2/tail_mon",
|
||||||
|
"/usr/em/lib/m68k2/end_em"
|
||||||
|
}
|
||||||
|
#endif MANTRA
|
||||||
};
|
};
|
||||||
|
|
||||||
char *o_FILE = "a.out";
|
char *o_FILE = "a.out";
|
||||||
|
#ifdef MANTRA
|
||||||
|
char *cv_FILE = "cv.out";
|
||||||
|
#endif MANTRA
|
||||||
|
|
||||||
#define remove(str) (((t_flag == 0) && unlink(str)), (str)[0] = '\0')
|
#define remove(str) (((FLAG(t) == 0) && unlink(str)), (str)[0] = '\0')
|
||||||
#define cleanup(str) (str && remove(str))
|
#define cleanup(str) (str && remove(str))
|
||||||
#define mkname(dst, s1, s2) mkstr(dst, (s1), (s2), 0)
|
#define mkname(dst, s1, s2) mkstr(dst, (s1), (s2), 0)
|
||||||
#define init(al) (al)->al_argc = 1
|
#define init(al) (al)->al_argc = 1
|
||||||
|
@ -64,42 +95,34 @@ char *o_FILE = "a.out";
|
||||||
mkstr(alloc((unsigned int)strlen(nm) + strlen(LIBDIR) + 7), \
|
mkstr(alloc((unsigned int)strlen(nm) + strlen(LIBDIR) + 7), \
|
||||||
LIBDIR, "/lib", nm, ".a", 0)
|
LIBDIR, "/lib", nm, ".a", 0)
|
||||||
|
|
||||||
char *ProgCall = 0;
|
struct arglist SRCFILES, LDFILES, GEN_LDFILES, PP_FLAGS, CEM_FLAGS,
|
||||||
|
OPT_FLAGS, DECODE_FLAGS, ENCODE_FLAGS, CG_FLAGS, AS_FLAGS,
|
||||||
|
O_FLAGS, DEBUG_FLAGS, CALL_VEC;
|
||||||
|
|
||||||
struct arglist SRCFILES;
|
#ifndef MANTRA
|
||||||
struct arglist LDFILES;
|
|
||||||
struct arglist GEN_LDFILES;
|
|
||||||
|
|
||||||
struct arglist PP_FLAGS;
|
|
||||||
struct arglist CEM_FLAGS;
|
|
||||||
|
|
||||||
int debug = 0;
|
|
||||||
int exec = 1;
|
|
||||||
|
|
||||||
int RET_CODE = 0;
|
|
||||||
|
|
||||||
struct arglist OPT_FLAGS;
|
|
||||||
struct arglist DECODE_FLAGS;
|
|
||||||
struct arglist ENCODE_FLAGS;
|
|
||||||
struct arglist CG_FLAGS;
|
|
||||||
struct arglist AS_FLAGS;
|
|
||||||
struct arglist LD_FLAGS;
|
struct arglist LD_FLAGS;
|
||||||
struct arglist O_FLAGS;
|
#else MANTRA
|
||||||
struct arglist DEBUG_FLAGS;
|
struct arglist LD_FLAGS = {
|
||||||
|
5,
|
||||||
|
{
|
||||||
|
"-b0:0x80000",
|
||||||
|
"-a0:2",
|
||||||
|
"-a1:2",
|
||||||
|
"-a2:2",
|
||||||
|
"-a3:2"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct arglist CV_FLAGS;
|
||||||
|
int Nc_flag = 0;
|
||||||
|
#endif MANTRA
|
||||||
|
|
||||||
struct arglist CALL_VEC;
|
/* option naming */
|
||||||
|
#define NAME(chr) chr
|
||||||
int e_flag = 0;
|
#define FLAG(chr) NAME(chr)_flag
|
||||||
int E_flag = 0;
|
int E_flag, P_flag, S_flag, c_flag, e_flag, k_flag,
|
||||||
int c_flag = 0;
|
m_flag, o_flag, t_flag, v_flag;
|
||||||
int k_flag = 0;
|
|
||||||
int m_flag = 0;
|
|
||||||
int o_flag = 0;
|
|
||||||
int S_flag = 0;
|
|
||||||
int t_flag = 0;
|
|
||||||
int v_flag = 0;
|
|
||||||
int P_flag = 0;
|
|
||||||
|
|
||||||
|
/* various passes */
|
||||||
struct prog {
|
struct prog {
|
||||||
char *p_name;
|
char *p_name;
|
||||||
char **p_task;
|
char **p_task;
|
||||||
|
@ -114,87 +137,83 @@ struct prog {
|
||||||
{ "cg", &CG, &CG_FLAGS },
|
{ "cg", &CG, &CG_FLAGS },
|
||||||
{ "as", &AS, &AS_FLAGS },
|
{ "as", &AS, &AS_FLAGS },
|
||||||
{ "ld", &LD, &LD_FLAGS },
|
{ "ld", &LD, &LD_FLAGS },
|
||||||
|
#ifdef MANTRA
|
||||||
|
{ "cv", &CV, &CV_FLAGS },
|
||||||
|
#endif MANTRA
|
||||||
{ 0, 0, 0 }
|
{ 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* various forward declarations */
|
||||||
int trap();
|
int trap();
|
||||||
char *mkstr();
|
char *mkstr();
|
||||||
char *alloc();
|
char *alloc();
|
||||||
long sizeof_file();
|
long sizeof_file();
|
||||||
|
|
||||||
|
/* various globals */
|
||||||
|
char *ProgCall = 0;
|
||||||
|
int debug = 0;
|
||||||
|
int exec = 1;
|
||||||
|
int RET_CODE = 0;
|
||||||
|
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
char *argv[];
|
char *argv[];
|
||||||
{
|
{
|
||||||
char *str;
|
char *str, **argvec, *file, *ldfile = 0;
|
||||||
char **argvec;
|
int count, ext;
|
||||||
int count;
|
char Nfile[USTR_SIZE], kfile[USTR_SIZE], sfile[USTR_SIZE],
|
||||||
int ext;
|
mfile[USTR_SIZE], ofile[USTR_SIZE], BASE[USTR_SIZE];
|
||||||
char Nfile[USTR_SIZE];
|
|
||||||
char kfile[USTR_SIZE];
|
|
||||||
char sfile[USTR_SIZE];
|
|
||||||
char mfile[USTR_SIZE];
|
|
||||||
char ofile[USTR_SIZE];
|
|
||||||
register struct arglist *call = &CALL_VEC;
|
register struct arglist *call = &CALL_VEC;
|
||||||
char BASE[USTR_SIZE];
|
|
||||||
char *file;
|
|
||||||
char *ldfile = 0;
|
|
||||||
|
|
||||||
set_traps(trap);
|
set_traps(trap);
|
||||||
|
|
||||||
ProgCall = *argv++;
|
ProgCall = *argv++;
|
||||||
|
|
||||||
while (--argc > 0) {
|
while (--argc > 0) {
|
||||||
if (*(str = *argv++) != '-') {
|
if (*(str = *argv++) != '-') {
|
||||||
append(&SRCFILES, str);
|
append(&SRCFILES, str);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (str[1]) {
|
switch (str[1]) {
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
switch (str[2]) {
|
switch (str[2]) {
|
||||||
case 'C':
|
case 'C':
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'P':
|
case 'P':
|
||||||
E_flag = 1;
|
FLAG(E) = 1;
|
||||||
append(&PP_FLAGS, str);
|
append(&PP_FLAGS, str);
|
||||||
PP = CEM;
|
PP = CEM;
|
||||||
P_flag = (str[2] == 'P');
|
FLAG(P) = (str[2] == 'P');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
append(&DEBUG_FLAGS, str);
|
append(&DEBUG_FLAGS, str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'B':
|
case 'B':
|
||||||
PP = CEM = &str[2];
|
PP = CEM = &str[2];
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'P':
|
case 'P':
|
||||||
E_flag = 1;
|
FLAG(E) = 1;
|
||||||
append(&PP_FLAGS, str);
|
append(&PP_FLAGS, str);
|
||||||
P_flag = (str[1] == 'P');
|
FLAG(P) = (str[1] == 'P');
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
if (str[2] == '.') {
|
if (str[2] == '.') {
|
||||||
switch (str[3]) {
|
switch (str[3]) {
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
S_flag = 1;
|
FLAG(S) = 1;
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
k_flag = 1;
|
FLAG(k) = 1;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
c_flag = 1;
|
FLAG(c) = 1;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
m_flag = 1;
|
FLAG(m) = 1;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
e_flag = 1;
|
FLAG(e) = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bad_option(str);
|
bad_option(str);
|
||||||
|
@ -202,7 +221,7 @@ main(argc, argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (str[2] == '\0')
|
if (str[2] == '\0')
|
||||||
c_flag = 1;
|
FLAG(c) = 1;
|
||||||
else
|
else
|
||||||
bad_option(str);
|
bad_option(str);
|
||||||
break;
|
break;
|
||||||
|
@ -212,7 +231,7 @@ main(argc, argv)
|
||||||
append(&PP_FLAGS, str);
|
append(&PP_FLAGS, str);
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
k_flag = 1;
|
FLAG(k) = 1;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
if (str[2] == '\0') /* no standard libraries */
|
if (str[2] == '\0') /* no standard libraries */
|
||||||
|
@ -224,10 +243,24 @@ main(argc, argv)
|
||||||
LIBDIR = &str[2];
|
LIBDIR = &str[2];
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
m_flag = 1;
|
FLAG(m) = 1;
|
||||||
break;
|
break;
|
||||||
|
#ifdef MANTRA
|
||||||
|
case 'N':
|
||||||
|
switch (str[2]) {
|
||||||
|
case 'c': /* no a.out conversion */
|
||||||
|
Nc_flag = 1;
|
||||||
|
break;
|
||||||
|
case 'l': /* no default options to led */
|
||||||
|
LD_FLAGS.al_argc = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bad_option(str);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif MANTRA
|
||||||
case 'o':
|
case 'o':
|
||||||
o_flag = 1;
|
FLAG(o) = 1;
|
||||||
if (argc-- < 0)
|
if (argc-- < 0)
|
||||||
bad_option(str);
|
bad_option(str);
|
||||||
else
|
else
|
||||||
|
@ -246,58 +279,42 @@ main(argc, argv)
|
||||||
Roption(str);
|
Roption(str);
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
S_flag = 1;
|
FLAG(S) = 1;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
t_flag = 1;
|
FLAG(t) = 1;
|
||||||
break;
|
break;
|
||||||
case 'v': /* set debug switches */
|
case 'v': /* set debug switches */
|
||||||
v_flag = 1;
|
FLAG(v) = 1;
|
||||||
switch (str[2]) {
|
switch (str[2]) {
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
debug = 1;
|
debug = 1;
|
||||||
break;
|
break;
|
||||||
case 'n': /* no execute */
|
case 'n': /* no execute */
|
||||||
exec = 0;
|
exec = 0;
|
||||||
break;
|
break;
|
||||||
|
case '\0':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bad_option(str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
V_FLAG = str;
|
V_FLAG = str;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
|
||||||
case 'F':
|
|
||||||
case 'd':
|
|
||||||
case 'n':
|
|
||||||
case 'N':
|
|
||||||
case 'r':
|
|
||||||
case 's':
|
|
||||||
case 'u':
|
|
||||||
case 'x':
|
|
||||||
case 'X':
|
|
||||||
case 'z':
|
|
||||||
append(&LD_FLAGS, str);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
append(&CEM_FLAGS, str);
|
append(&LD_FLAGS, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (debug) report("Note: debug output");
|
||||||
if (debug)
|
|
||||||
report("Note: debug output");
|
|
||||||
if (exec == 0)
|
if (exec == 0)
|
||||||
report("Note: no execution");
|
report("Note: no execution");
|
||||||
|
|
||||||
count = SRCFILES.al_argc;
|
count = SRCFILES.al_argc;
|
||||||
argvec = &(SRCFILES.al_argv[0]);
|
argvec = &(SRCFILES.al_argv[0]);
|
||||||
|
|
||||||
Nfile[0] = '\0';
|
Nfile[0] = '\0';
|
||||||
|
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
basename(file = *argvec++, BASE);
|
basename(file = *argvec++, BASE);
|
||||||
|
if (FLAG(E)) {
|
||||||
if (E_flag) {
|
|
||||||
char ifile[USTR_SIZE];
|
char ifile[USTR_SIZE];
|
||||||
|
|
||||||
init(call);
|
init(call);
|
||||||
|
@ -305,12 +322,10 @@ main(argc, argv)
|
||||||
concat(call, &DEBUG_FLAGS);
|
concat(call, &DEBUG_FLAGS);
|
||||||
concat(call, &PP_FLAGS);
|
concat(call, &PP_FLAGS);
|
||||||
append(call, file);
|
append(call, file);
|
||||||
runvec(call, P_flag ? mkname(ifile, BASE, ".i") : 0);
|
runvec(call, FLAG(P) ? mkname(ifile, BASE, ".i") : 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ext = extension(file);
|
ext = extension(file);
|
||||||
|
|
||||||
/* .c to .k and .N */
|
/* .c to .k and .N */
|
||||||
if (ext == 'c' || ext == 'i') {
|
if (ext == 'c' || ext == 'i') {
|
||||||
init(call);
|
init(call);
|
||||||
|
@ -322,7 +337,6 @@ main(argc, argv)
|
||||||
append(call, file);
|
append(call, file);
|
||||||
append(call, mkname(kfile, BASE, ".k"));
|
append(call, mkname(kfile, BASE, ".k"));
|
||||||
append(call, mkname(Nfile, BASE, ".N"));
|
append(call, mkname(Nfile, BASE, ".N"));
|
||||||
|
|
||||||
if (runvec(call, (char *)0)) {
|
if (runvec(call, (char *)0)) {
|
||||||
file = kfile;
|
file = kfile;
|
||||||
ext = 'k';
|
ext = 'k';
|
||||||
|
@ -335,7 +349,6 @@ main(argc, argv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* .e to .k */
|
/* .e to .k */
|
||||||
if (ext == 'e') {
|
if (ext == 'e') {
|
||||||
init(call);
|
init(call);
|
||||||
|
@ -348,14 +361,11 @@ main(argc, argv)
|
||||||
file = kfile;
|
file = kfile;
|
||||||
ext = 'k';
|
ext = 'k';
|
||||||
}
|
}
|
||||||
|
if (FLAG(k))
|
||||||
if (k_flag)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* decode .k or .m */
|
/* decode .k or .m */
|
||||||
if (e_flag && (ext == 'k' || ext == 'm')) {
|
if (FLAG(e) && (ext == 'k' || ext == 'm')) {
|
||||||
char efile[USTR_SIZE];
|
char efile[USTR_SIZE];
|
||||||
|
|
||||||
init(call);
|
init(call);
|
||||||
append(call, DECODE);
|
append(call, DECODE);
|
||||||
concat(call, &DECODE_FLAGS);
|
concat(call, &DECODE_FLAGS);
|
||||||
|
@ -365,7 +375,6 @@ main(argc, argv)
|
||||||
cleanup(kfile);
|
cleanup(kfile);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* .k to .m */
|
/* .k to .m */
|
||||||
if (ext == 'k') {
|
if (ext == 'k') {
|
||||||
init(call);
|
init(call);
|
||||||
|
@ -378,10 +387,8 @@ main(argc, argv)
|
||||||
ext = 'm';
|
ext = 'm';
|
||||||
cleanup(kfile);
|
cleanup(kfile);
|
||||||
}
|
}
|
||||||
|
if (FLAG(m))
|
||||||
if (m_flag)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* .m to .s */
|
/* .m to .s */
|
||||||
if (ext == 'm') {
|
if (ext == 'm') {
|
||||||
init(call);
|
init(call);
|
||||||
|
@ -392,29 +399,32 @@ main(argc, argv)
|
||||||
if (runvec(call, (char *)0) == 0)
|
if (runvec(call, (char *)0) == 0)
|
||||||
continue;
|
continue;
|
||||||
if (Nfile[0] != '\0') {
|
if (Nfile[0] != '\0') {
|
||||||
|
#ifndef MANTRA
|
||||||
init(call);
|
init(call);
|
||||||
append(call, AS_FIX);
|
append(call, AS_FIX);
|
||||||
append(call, Nfile);
|
append(call, Nfile);
|
||||||
append(call, sfile);
|
append(call, sfile);
|
||||||
runvec(call, (char *)0);
|
runvec(call, (char *)0);
|
||||||
|
#endif MANTRA
|
||||||
remove(Nfile);
|
remove(Nfile);
|
||||||
}
|
}
|
||||||
cleanup(mfile);
|
cleanup(mfile);
|
||||||
file = sfile;
|
file = sfile;
|
||||||
ext = 's';
|
ext = 's';
|
||||||
}
|
}
|
||||||
|
if (FLAG(S))
|
||||||
if (S_flag)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* .s to .o */
|
/* .s to .o */
|
||||||
if (ext == 's') {
|
if (ext == 's') {
|
||||||
ldfile = c_flag ?
|
ldfile = FLAG(c) ?
|
||||||
ofile :
|
ofile :
|
||||||
alloc((unsigned)strlen(BASE) + 3);
|
alloc((unsigned)strlen(BASE) + 3);
|
||||||
init(call);
|
init(call);
|
||||||
append(call, AS);
|
append(call, AS);
|
||||||
concat(call, &AS_FLAGS);
|
concat(call, &AS_FLAGS);
|
||||||
|
#ifdef MANTRA
|
||||||
|
append(call, "-");
|
||||||
|
#endif MANTRA
|
||||||
append(call, "-o");
|
append(call, "-o");
|
||||||
append(call, mkname(ldfile, BASE, ".o"));
|
append(call, mkname(ldfile, BASE, ".o"));
|
||||||
append(call, file);
|
append(call, file);
|
||||||
|
@ -424,24 +434,25 @@ main(argc, argv)
|
||||||
ext = 'o';
|
ext = 'o';
|
||||||
cleanup(sfile);
|
cleanup(sfile);
|
||||||
}
|
}
|
||||||
|
if (FLAG(c))
|
||||||
if (c_flag)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
append(&LDFILES, file);
|
append(&LDFILES, file);
|
||||||
if (ldfile) {
|
if (ldfile) {
|
||||||
append(&GEN_LDFILES, ldfile);
|
append(&GEN_LDFILES, ldfile);
|
||||||
ldfile = 0;
|
ldfile = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *.o to a.out */
|
/* *.o to a.out */
|
||||||
if (RET_CODE == 0 && LDFILES.al_argc > 0) {
|
if (RET_CODE == 0 && LDFILES.al_argc > 0) {
|
||||||
init(call);
|
init(call);
|
||||||
append(call, LD);
|
append(call, LD);
|
||||||
concat(call, &LD_FLAGS);
|
concat(call, &LD_FLAGS);
|
||||||
append(call, "-o");
|
append(call, "-o");
|
||||||
|
#ifndef MANTRA
|
||||||
append(call, o_FILE);
|
append(call, o_FILE);
|
||||||
|
#else MANTRA
|
||||||
|
append(call, Nc_flag ? o_FILE : cv_FILE);
|
||||||
|
#endif MANTRA
|
||||||
concat(call, &LD_HEAD);
|
concat(call, &LD_HEAD);
|
||||||
concat(call, &LDFILES);
|
concat(call, &LDFILES);
|
||||||
concat(call, &LD_TAIL);
|
concat(call, &LD_TAIL);
|
||||||
|
@ -450,29 +461,40 @@ main(argc, argv)
|
||||||
|
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
remove(GEN_LDFILES.al_argv[i]);
|
remove(GEN_LDFILES.al_argv[i]);
|
||||||
|
#ifdef MANTRA
|
||||||
|
/* convert to local a.out format */
|
||||||
|
if (Nc_flag == 0) {
|
||||||
|
init(call);
|
||||||
|
append(call, CV);
|
||||||
|
concat(call, &CV_FLAGS);
|
||||||
|
append(call, cv_FILE);
|
||||||
|
append(call, o_FILE);
|
||||||
|
if (runvec(call, (char *)0))
|
||||||
|
remove(cv_FILE);
|
||||||
|
}
|
||||||
|
#endif MANTRA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(RET_CODE);
|
exit(RET_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BUFSIZE (USTR_SIZE * MAXARGC)
|
||||||
|
char alloc_buf[BUFSIZE];
|
||||||
|
|
||||||
char *
|
char *
|
||||||
alloc(u)
|
alloc(u)
|
||||||
unsigned u;
|
unsigned u;
|
||||||
{
|
{
|
||||||
#define BUFSIZE (USTR_SIZE * MAXARGC)
|
static char *bufptr = &alloc_buf[0];
|
||||||
static char buf[BUFSIZE];
|
|
||||||
static char *bufptr = &buf[0];
|
|
||||||
register char *p = bufptr;
|
register char *p = bufptr;
|
||||||
|
|
||||||
if ((bufptr += u) >= &buf[BUFSIZE])
|
if ((bufptr += u) >= &alloc_buf[BUFSIZE])
|
||||||
panic("no space");
|
panic("no space");
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
append(al, arg)
|
append(al, arg)
|
||||||
struct arglist *al;
|
register struct arglist *al;
|
||||||
char *arg;
|
char *arg;
|
||||||
{
|
{
|
||||||
if (al->al_argc >= MAXARGC)
|
if (al->al_argc >= MAXARGC)
|
||||||
|
@ -483,7 +505,7 @@ append(al, arg)
|
||||||
concat(al1, al2)
|
concat(al1, al2)
|
||||||
struct arglist *al1, *al2;
|
struct arglist *al1, *al2;
|
||||||
{
|
{
|
||||||
register i = al2->al_argc;
|
register int i = al2->al_argc;
|
||||||
register char **p = &(al1->al_argv[al1->al_argc]);
|
register char **p = &(al1->al_argv[al1->al_argc]);
|
||||||
register char **q = &(al2->al_argv[0]);
|
register char **q = &(al2->al_argv[0]);
|
||||||
|
|
||||||
|
@ -520,9 +542,8 @@ Roption(str)
|
||||||
char *prog, *arg;
|
char *prog, *arg;
|
||||||
char bc;
|
char bc;
|
||||||
char *cindex();
|
char *cindex();
|
||||||
|
|
||||||
prog = &str[2];
|
|
||||||
|
|
||||||
|
prog = &str[2];
|
||||||
if (eq = cindex(prog, '='))
|
if (eq = cindex(prog, '='))
|
||||||
bc = '=';
|
bc = '=';
|
||||||
else
|
else
|
||||||
|
@ -532,17 +553,14 @@ Roption(str)
|
||||||
bad_option(str);
|
bad_option(str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*eq++ = '\0';
|
*eq++ = '\0';
|
||||||
if (arg = eq) {
|
if (arg = eq) {
|
||||||
char *opt = 0;
|
char *opt = 0;
|
||||||
struct prog *pp = &ProgParts[0];
|
struct prog *pp = &ProgParts[0];
|
||||||
|
|
||||||
if (bc == '-') {
|
if (bc == '-')
|
||||||
opt = mkstr(alloc((unsigned)strlen(arg) + 2),
|
opt = mkstr(alloc((unsigned)strlen(arg) + 2),
|
||||||
"-", arg, 0);
|
"-", arg, 0);
|
||||||
}
|
|
||||||
|
|
||||||
while (pp->p_name) {
|
while (pp->p_name) {
|
||||||
if (strcmp(prog, pp->p_name) == 0) {
|
if (strcmp(prog, pp->p_name) == 0) {
|
||||||
if (opt)
|
if (opt)
|
||||||
|
@ -570,7 +588,7 @@ basename(str, dst)
|
||||||
p1--;
|
p1--;
|
||||||
if (*--p1 == '.')
|
if (*--p1 == '.')
|
||||||
*p1 = '\0';
|
*p1 = '\0';
|
||||||
while (*dst++ = *p2++);
|
while (*dst++ = *p2++) {}
|
||||||
*p1 = '.';
|
*p1 = '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,7 +598,7 @@ extension(fn)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while (*fn++) ;
|
while (*fn++) {}
|
||||||
fn--;
|
fn--;
|
||||||
c = *--fn;
|
c = *--fn;
|
||||||
return (*--fn == '.') ? c : 0;
|
return (*--fn == '.') ? c : 0;
|
||||||
|
@ -625,30 +643,27 @@ runvec(vec, outp)
|
||||||
char *task = vec->al_argv[1];
|
char *task = vec->al_argv[1];
|
||||||
|
|
||||||
vec->al_argv[vec->al_argc] = 0;
|
vec->al_argv[vec->al_argc] = 0;
|
||||||
if (v_flag)
|
if (FLAG(v))
|
||||||
print_vec(vec);
|
print_vec(vec);
|
||||||
if (exec == 0)
|
if (exec == 0)
|
||||||
return 1;
|
return 1;
|
||||||
if (fork() == 0) { /* start up the process */
|
if (fork() == 0) { /* start up the process */
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
if (outp) { /* redirect standard output */
|
if (outp) { /* redirect standard output */
|
||||||
|
close(1);
|
||||||
if ((fd = creat(outp, 0666)) < 0)
|
if ((fd = creat(outp, 0666)) < 0)
|
||||||
panic("cannot create %s", outp);
|
panic("cannot create %s", outp);
|
||||||
if (dup2(fd, 1) == -1)
|
if (fd != 1)
|
||||||
panic("dup failure");
|
panic("illegal redirection");
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
if (debug) report("exec %s", task);
|
if (debug) report("exec %s", task);
|
||||||
execv(task, &(vec->al_argv[1]));
|
execv(task, &(vec->al_argv[1]));
|
||||||
|
|
||||||
/* not an a.out file, let's try it with the SHELL */
|
/* not an a.out file, let's try it with the SHELL */
|
||||||
if (debug) report("try it with %s", SHELL);
|
if (debug) report("try it with %s", SHELL);
|
||||||
if (errno == ENOEXEC) {
|
if (errno == ENOEXEC) {
|
||||||
vec->al_argv[0] = SHELL;
|
vec->al_argv[0] = SHELL;
|
||||||
execv(SHELL, &(vec->al_argv[0]));
|
execv(SHELL, &(vec->al_argv[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* failed, so ... */
|
/* failed, so ... */
|
||||||
panic("cannot execute %s", task);
|
panic("cannot execute %s", task);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Reference in a new issue