home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
new
/
dev
/
c
/
dice
/
cc
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-01
|
30KB
|
1,557 lines
/*
* MAIN.C
*
* (c)Copyright 1990, Matthew Dillon, All Rights Reserved
*
* dcc <options> <files>
*/
#include "defs.h"
#ifndef AZLAT_COMPAT
#define DoLink_Dice DoLink
#define DoCompile_Dice DoCompile
#define DoAssemble_Dice DoAssemble
#define DoPrelink_Dice DoPrelink
#endif
#ifdef _DCC
IDENT("DCC",".37");
DCOPYRIGHT;
#endif
Prototype void myexit(void);
Prototype int main(int, char **);
Prototype void AddFile(char *);
Prototype void help(int);
Prototype char *TmpFileName(char *);
Prototype char *MungeFile(char *, char *, char *);
Prototype void AddName(LIST *, char *, char *);
Prototype void AddOpt(LIST *, char *, char *);
Prototype char *Tailer(char *);
Prototype char *XFilePart(char *);
Prototype char *OptListToStr(LIST *);
Prototype char *OptListToStr2(LIST *, char *);
Prototype void run_cmd(char *);
Prototype int OutOfDate(char *, char *);
Prototype void HandleCFile(char *, int);
Prototype void HandleAFile(char *, int);
Prototype void PushTmpFile(char *);
Prototype void PopTmpFile(char *);
Prototype long LoadSegLock(long);
Prototype int DoCompile(char *, char *);
Prototype int DoCompile_Dice(char *, char *);
Prototype int DoCompile_Aztec(char *, char *);
Prototype int DoCompile_Lattice(char *, char *);
Prototype int DoAssemble(char *, char *);
Prototype int DoAssemble_Dice(char *, char *);
Prototype int DoAssemble_Aztec(char *, char *);
Prototype int DoAssemble_Lattice(char *, char *);
Prototype char *DoPrelink(void);
Prototype char *DoPrelink_Dice(void);
Prototype char *DoPrelink_Aztec(void);
Prototype char *DoPrelink_Lattice(void);
Prototype int DoLink(char *);
Prototype int DoLink_Dice(char *);
Prototype int DoLink_Aztec(char *);
Prototype int DoLink_Lattice(char *);
void OrderApp(char *);
void AddLibApp(char *, char);
void DelLibApp(char *, char);
/*
* Note that we use exec_dcc if DCC, which only works with 'dcc' programs
* thus, the executables are renamed to prevent problems.
*/
Prototype __aligned char Buf[512];
__aligned char Buf[512];
char TmpFile[64];
char ErrOptStr[128];
char *ErrFile;
char *OutFile;
char *OutDir = "T:";
char *TmpDir = "T:";
char *AmigaLib = "dlib:amiga";
char *CLib = "dlib:c";
char ALibOS[4];
char ALibApp[32] = { "s" };
char CLibApp[32] = { "s" };
LIST TmpList;
short NewOpt;
short FastOpt;
short FragOpt;
short ChipOpt;
short MC68020Opt;
short MC68881Opt;
short FFPOpt;
short DDebug;
short RegCallOpt;
short NoHeirOpt;
short NoEnvOpt;
short SlashSlashOpt;
short ProfOpt;
short DLinkPostFixOpt;
char DLINK[32];
char DAS[32];
char DC1[32];
char DCPP[32];
typedef struct NameNode {
struct Node n_Node;
char *n_In;
char *n_Out;
short n_IsTmp;
} NameNode;
LIST CList;
LIST AList;
LIST OList;
LIST LList;
LIST CppOptList;
LIST LinkOptList;
short NoLink;
short NoAsm;
short SmallCode = 1;
short SmallData = 1;
short ConstCode; /* -ms */
short AbsData; /* -mw, -ma */
short ResOpt;
short AltSectOpt;
short SymOpt;
short RomOpt;
short ProtoOnlyOpt;
short NoIntermediateAssembly;
short PIOpt;
short GenStackOpt;
short GenLinkOpt;
short Verbose;
short NoDefaultLibs;
short CompilerOpt = DICE_C;
long AbsDataStart; /* -mw <addr> */
char DebugOpts[64];
extern struct Library *SysBase;
void
myexit()
{
NODE *node;
while (node = RemHead(&TmpList)) {
remove(node->ln_Name);
free(node);
}
}
int
main(xac, xav)
int xac;
char *xav[];
{
int fc = 0;
int ac;
char **av;
#ifdef LATTICE
{
long n = (long)Buf;
if (n & 3) {
puts("software error, Buf not aligned");
exit(1);
}
}
#endif
#ifdef NOTDEF
expand_args(xac, xav, &ac, &av);
#else
ac = xac;
av = xav;
#endif
NewList(&CList);
NewList(&AList);
NewList(&OList);
NewList(&LList);
NewList(&TmpList);
NewList(&CppOptList);
NewList(&LinkOptList);
atexit(myexit);
if (ac == 1)
help(0);
{
char *ptr = av[0]; /* cmd name */
char prefix[32];
short i;
for (i = strlen(ptr); i >= 0 && ptr[i] != ':' && ptr[i] != '/'; --i);
++i;
ptr = ptr + i; /* base name */
for (i = 0; ptr[i] && ptr[i] != '_'; ++i);
if (ptr[i] == '_') {
strncpy(prefix, ptr, i + 1);
prefix[i+1] = 0;
} else {
prefix[0] = 0;
}
sprintf(DLINK, "%s%s", prefix, "dlink");
sprintf(DAS , "%s%s", prefix, "das");
sprintf(DC1 , "%s%s", prefix, "dc1");
sprintf(DCPP , "%s%s", prefix, "dcpp");
}
/*
* check for -no-env option before processing DCCOPTS
*/
{
long i;
for (i = 1; i < ac; ++i) {
if (strcmp(av[i], "-no-env") == 0) {
NoEnvOpt = 1;
break;
}
}
}
if (NoEnvOpt == 0) {
char **argv = av;
ac = ExtArgsEnv(ac, &argv, "DCCOPTS");
av = argv;
}
{
long i;
char *dummy;
for (i = 1; i < ac; ++i) {
char *ptr = av[i];
if (*ptr == '-') {
ptr += 2;
switch(ptr[-1]) {
case '0': /* -020 */
MC68020Opt = 1;
break;
case '1': /* 1.4, 1.3 */
case '2': /* 2.0, 2.1.. */
if (ptr[0] != '.')
help(1);
AddOpt(&CppOptList, ptr - 2, "");
ALibOS[0] = ptr[-1];
ALibOS[1] = ptr[1];
break;
case '8':
MC68881Opt = 1;
break;
case 'f':
if (*ptr == 0)
FastOpt = 1;
else if (*ptr == 'r')
FragOpt = 1;
else if (*ptr == 'f')
FFPOpt = 1;
break;
case 'r':
if (strcmp(ptr, "om") == 0) {
RomOpt = 1;
} else {
if (PIOpt && ResOpt == 0)
puts("DCC: Warning, -r -pi = -pr");
ResOpt = 1;
}
break;
case 'c':
if (*ptr == 0)
NoLink = 1;
else if (stricmp(ptr, "hip") == 0)
ChipOpt = 1;
else
help(1);
break;
case 'a':
if (strcmp(ptr, "ztec") == 0) {
CompilerOpt = AZTEC_C;
break;
}
NoAsm = 1;
NoLink= 1;
break;
case 'g':
switch (*ptr) {
case 's':
GenStackOpt = 1;
break;
case 'l':
GenLinkOpt = 1;
break;
default:
help(1);
}
break;
case 'l':
if (strcmp(ptr, "attice") == 0) {
CompilerOpt = LATTICE_C;
break;
}
if (ptr[0] == '0' && ptr[1] == 0) {
NoDefaultLibs = 1;
break;
}
if (*ptr == 0)
ptr = av[++i];
AddName(&LList, ".lib", ptr);
DLinkPostFixOpt = 1;
break;
case 'L': /* -Idir */
if (ptr[0] == '0' && ptr[1] == 0) {
AddOpt(&LinkOptList, "-L0", "");
break;
}
if (*ptr == 0)
ptr = av[++i];
AddOpt(&LinkOptList, "-L", ptr);
break;
case 'I': /* -Idir */
if (ptr[0] == '0' && ptr[1] == 0) {
AddOpt(&CppOptList, "-I0", "");
break;
}
if (*ptr == 0)
ptr = av[++i];
AddOpt(&CppOptList, "-I", ptr);
break;
case 'd': /* -dice -d<n> -d<debug_opts> */
if (strcmp(ptr, "ice") == 0) {
CompilerOpt = DICE_C;
break;
}
if (atoi(ptr)) {
DDebug = atoi(ptr);
break;
}
sprintf(DebugOpts, " -d%s", ptr);
break;
case 'D': /* -Ddefine[=str] */
if (*ptr == 0)
ptr = av[++i];
AddOpt(&CppOptList, "-D", ptr);
break;
case 'H': /* -H<path>=<include_name> */
if (*ptr == 0)
ptr = av[++i];
AddOpt(&CppOptList, "-H", ptr);
break;
case 'U': /* -U -undefine certain symbols */
AddOpt(&CppOptList, "-U", ptr);
break;
case 'o':
if (*ptr)
OutFile = ptr;
else
OutFile = av[++i];
{
short idx = strlen(OutFile) - 2;
if (idx >= 0) {
if (stricmp(OutFile + idx, ".h") == 0 || stricmp(OutFile + idx, ".c") == 0) {
puts("ERROR! -o output file may not end in .c or .h!");
exit(20);
}
}
}
break;
case 'O':
if (*ptr)
OutDir = ptr;
else
OutDir = av[++i];
break;
case 'E': /* error output append */
if (*ptr == 0)
ptr = av[++i];
if (freopen(ptr, "a", stderr)) {
ErrFile = ptr;
sprintf(ErrOptStr," -E %s", ptr);
} else {
printf("unable to append to %s\n", ptr);
}
break;
case 'p':
if (str