1987-03-10 11:49:39 +00:00
|
|
|
/* $Header$ */
|
1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1987-01-06 15:16:53 +00:00
|
|
|
/* MAIN PROGRAM */
|
|
|
|
|
1987-05-11 14:30:12 +00:00
|
|
|
#include <alloc.h>
|
1987-08-19 10:36:37 +00:00
|
|
|
#include <em_arith.h>
|
1990-01-23 15:25:21 +00:00
|
|
|
#include <assert.h>
|
1990-02-12 11:47:50 +00:00
|
|
|
#include <system.h>
|
1987-01-06 15:16:53 +00:00
|
|
|
#include "file_info.h"
|
|
|
|
#include "idfsize.h"
|
1990-01-23 15:25:21 +00:00
|
|
|
#include "idf.h"
|
|
|
|
#include "macro.h"
|
1987-01-06 15:16:53 +00:00
|
|
|
|
|
|
|
extern char *symbol2str();
|
1987-01-16 16:14:22 +00:00
|
|
|
extern char *getwdir();
|
1987-01-06 15:16:53 +00:00
|
|
|
extern int err_occurred;
|
1990-02-12 11:47:50 +00:00
|
|
|
extern int do_dependencies;
|
|
|
|
extern char *dep_file;
|
1987-01-06 15:16:53 +00:00
|
|
|
int idfsize = IDFSIZE;
|
1990-01-23 15:25:21 +00:00
|
|
|
extern char options[];
|
1990-02-12 11:47:50 +00:00
|
|
|
static File *dep_fd = STDOUT;
|
1987-01-06 15:16:53 +00:00
|
|
|
|
1987-08-19 10:36:37 +00:00
|
|
|
arith ifval;
|
1987-01-06 15:16:53 +00:00
|
|
|
|
|
|
|
char *prog_name;
|
|
|
|
|
1987-05-11 14:30:12 +00:00
|
|
|
extern char **inctable;
|
|
|
|
extern int inc_max, inc_total;
|
|
|
|
|
1987-01-06 15:16:53 +00:00
|
|
|
main(argc, argv)
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
/* parse and interpret the command line options */
|
|
|
|
prog_name = argv[0];
|
|
|
|
|
|
|
|
init_idf();
|
1987-05-11 14:30:12 +00:00
|
|
|
|
|
|
|
inctable = (char **) Malloc(10 * sizeof(char *));
|
|
|
|
inc_max = 10;
|
1990-01-26 11:53:08 +00:00
|
|
|
inc_total = 3;
|
1989-02-16 11:18:44 +00:00
|
|
|
inctable[0] = "";
|
1987-05-11 14:30:12 +00:00
|
|
|
inctable[1] = "/usr/include";
|
1987-01-06 15:16:53 +00:00
|
|
|
init_pp(); /* initialise the preprocessor macros */
|
|
|
|
|
|
|
|
/* Note: source file "-" indicates that the source is supplied
|
|
|
|
as standard input. This is only allowed if INP_READ_IN_ONE is
|
|
|
|
not defined!
|
|
|
|
*/
|
|
|
|
while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') {
|
|
|
|
char *par = &argv[1][1];
|
|
|
|
|
|
|
|
if (*par == '-')
|
|
|
|
par++;
|
|
|
|
do_option(par);
|
|
|
|
argc--, argv++;
|
|
|
|
}
|
|
|
|
compile(argc - 1, &argv[1]);
|
1987-03-09 12:59:18 +00:00
|
|
|
exit(err_occurred);
|
1987-01-06 15:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
compile(argc, argv)
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
register char *source = 0;
|
|
|
|
char *dummy;
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 1:
|
|
|
|
source = argv[0];
|
|
|
|
FileName = source;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
FileName = "";
|
1987-03-02 16:43:19 +00:00
|
|
|
WorkingDir = 0;
|
1987-01-06 15:16:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
1987-04-23 12:53:54 +00:00
|
|
|
FileName = argv[0];
|
1987-01-06 15:16:53 +00:00
|
|
|
fatal("use: %s [options] [source]", prog_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!InsertFile(source, (char **) 0, &dummy)) /* read the source file */
|
|
|
|
fatal("%s: no source file %s\n", prog_name,
|
|
|
|
source ? source : "stdin");
|
1987-03-02 16:43:19 +00:00
|
|
|
if (source) WorkingDir = getwdir(dummy);
|
1987-01-06 15:16:53 +00:00
|
|
|
preprocess(source);
|
1990-02-12 11:47:50 +00:00
|
|
|
if (do_dependencies) list_dependencies(source);
|
1987-01-06 15:16:53 +00:00
|
|
|
}
|
1990-01-23 15:25:21 +00:00
|
|
|
|
|
|
|
struct idf *file_head;
|
1990-01-26 11:53:08 +00:00
|
|
|
extern char *strrindex();
|
1990-01-23 15:25:21 +00:00
|
|
|
|
1990-01-26 11:53:08 +00:00
|
|
|
list_dependencies(source)
|
|
|
|
char *source;
|
1990-01-23 15:25:21 +00:00
|
|
|
{
|
|
|
|
register struct idf *p = file_head;
|
|
|
|
|
1990-01-26 11:53:08 +00:00
|
|
|
if (source) {
|
|
|
|
register char *s = strrindex(source, '.');
|
|
|
|
|
|
|
|
if (s && *(s+1)) {
|
|
|
|
s++;
|
|
|
|
*s++ = 'o';
|
|
|
|
*s = '\0';
|
1990-02-12 09:32:04 +00:00
|
|
|
/* the source may be in another directory than the
|
|
|
|
* object generated, so don't include the pathname
|
|
|
|
* leading to it.
|
|
|
|
*/
|
|
|
|
if (s = strrindex(source, '/')) {
|
|
|
|
source = s + 1;
|
|
|
|
}
|
1990-01-26 11:53:08 +00:00
|
|
|
}
|
|
|
|
else source = 0;
|
|
|
|
}
|
1990-02-12 11:47:50 +00:00
|
|
|
if (dep_file && !sys_open(dep_file, OP_WRITE, &dep_fd)) {
|
|
|
|
fatal("could not open %s", dep_file);
|
|
|
|
}
|
1990-01-23 15:25:21 +00:00
|
|
|
while (p) {
|
|
|
|
assert(p->id_resmac == K_FILE);
|
1990-01-26 11:53:08 +00:00
|
|
|
dependency(p->id_text, source);
|
1990-01-23 15:25:21 +00:00
|
|
|
p = p->id_file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1990-01-26 11:53:08 +00:00
|
|
|
add_dependency(s)
|
1990-01-23 15:25:21 +00:00
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
register struct idf *p = str2idf(s, 0);
|
|
|
|
|
|
|
|
if (! p->id_resmac) {
|
|
|
|
p->id_resmac = K_FILE;
|
|
|
|
p->id_file = file_head;
|
|
|
|
file_head = p;
|
|
|
|
}
|
|
|
|
}
|
1990-01-26 11:53:08 +00:00
|
|
|
|
|
|
|
dependency(s, source)
|
1990-02-12 11:47:50 +00:00
|
|
|
char *s, *source;
|
1990-01-26 11:53:08 +00:00
|
|
|
{
|
1990-06-06 16:01:03 +00:00
|
|
|
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
|
1990-01-26 11:53:08 +00:00
|
|
|
return;
|
|
|
|
}
|
1990-02-12 11:47:50 +00:00
|
|
|
if (options['m'] && source) {
|
|
|
|
fprint(dep_fd, "%s: %s\n", source, s);
|
|
|
|
}
|
|
|
|
else fprint(dep_fd, "%s\n", s);
|
1990-01-26 11:53:08 +00:00
|
|
|
}
|