Extended to handle user libraries
This commit is contained in:
parent
a0d2a1ea74
commit
575d4f5223
5 changed files with 80 additions and 21 deletions
|
|
@ -12,6 +12,7 @@ struct file_list {
|
||||||
char *a_dir; /* directory in which it resides */
|
char *a_dir; /* directory in which it resides */
|
||||||
struct idf *a_idf; /* its idf-structure */
|
struct idf *a_idf; /* its idf-structure */
|
||||||
struct file_list *a_next; /* next in list */
|
struct file_list *a_next; /* next in list */
|
||||||
|
char a_notfound; /* could not open ... */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define f_walk(list, ctrl) \
|
#define f_walk(list, ctrl) \
|
||||||
|
|
@ -20,3 +21,4 @@ struct file_list {
|
||||||
#define f_filename(a) ((a)->a_filename)
|
#define f_filename(a) ((a)->a_filename)
|
||||||
#define f_idf(a) ((a)->a_idf)
|
#define f_idf(a) ((a)->a_idf)
|
||||||
#define f_dir(a) ((a)->a_dir)
|
#define f_dir(a) ((a)->a_dir)
|
||||||
|
#define f_notfound(a) ((a)->a_notfound)
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,17 @@
|
||||||
/* $Header$ */
|
/* $Header$ */
|
||||||
|
|
||||||
#include <em_path.h>
|
#include <em_path.h>
|
||||||
|
#include <alloc.h>
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
static char lib_dir[128] = EM_DIR;
|
static char lib_dir[128] = EM_DIR;
|
||||||
|
|
||||||
|
static struct liblist {
|
||||||
|
int libno;
|
||||||
|
struct liblist *libnext;
|
||||||
|
} *lblist;
|
||||||
|
|
||||||
|
int
|
||||||
is_library_dir(d)
|
is_library_dir(d)
|
||||||
char *d;
|
char *d;
|
||||||
{
|
{
|
||||||
|
|
@ -20,7 +28,13 @@ is_library_dir(d)
|
||||||
"system" definition modules. Return 1 if it is, 0 otherwise.
|
"system" definition modules. Return 1 if it is, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return strcmp(lib_dir, d) == 0;
|
register struct liblist *p = lblist;
|
||||||
|
|
||||||
|
while (p) {
|
||||||
|
if (! strcmp(DEFPATH[p->libno], d)) return 1;
|
||||||
|
p = p->libnext;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_lib()
|
init_lib()
|
||||||
|
|
@ -28,5 +42,15 @@ init_lib()
|
||||||
extern char *strcat();
|
extern char *strcat();
|
||||||
|
|
||||||
strcat(lib_dir, "/lib/m2");
|
strcat(lib_dir, "/lib/m2");
|
||||||
AddInclDir(lib_dir);
|
AddLibDir(lib_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_libdir(n)
|
||||||
|
{
|
||||||
|
register struct liblist *p =
|
||||||
|
(struct liblist *) Malloc(sizeof(struct liblist));
|
||||||
|
|
||||||
|
p->libnext = lblist;
|
||||||
|
p->libno = n;
|
||||||
|
lblist = p;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
.SH NAME
|
.SH NAME
|
||||||
m2mm \- Modula-2 makefile generator
|
m2mm \- Modula-2 makefile generator
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
\fBm2mm\fP [ \fB-I\fPdir \fB-M\fPflags \fB-C\fPcompiler \fB-S\fPsuffix ] file ...
|
\fBm2mm\fP [ \fB-I\fPdir \fB-L\fPdir \fB-l\fPlibrary \fB-M\fPflags \fB-C\fPcompiler \fB-S\fPsuffix ] file ...
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.I M2mm
|
.I M2mm
|
||||||
is a makefile generator and fast syntax checker for Modula-2 programs.
|
is a makefile generator and fast syntax checker for Modula-2 programs.
|
||||||
|
|
@ -17,7 +17,7 @@ Using
|
||||||
.IR make (1)
|
.IR make (1)
|
||||||
without an argument will make all these programs.
|
without an argument will make all these programs.
|
||||||
.PP
|
.PP
|
||||||
In the makefile, the variables \fBMOD\fP, \fBM2FLAGS\fP, \fBIFLAGS\fP, and
|
In the makefile, the variables \fBMOD\fP, \fBM2FLAGS\fP, \fBIFLAGS\fP, \fBLIBS\fP, and
|
||||||
\fBSUFFIX\fP will be defined.
|
\fBSUFFIX\fP will be defined.
|
||||||
The generated rules have the following form:
|
The generated rules have the following form:
|
||||||
.DS
|
.DS
|
||||||
|
|
@ -30,11 +30,21 @@ recognizes the following options:
|
||||||
Add \fIdir\fP to the list of directories where definition modules are
|
Add \fIdir\fP to the list of directories where definition modules are
|
||||||
looked for. Also add the flag to \fBIFLAGS\fP.
|
looked for. Also add the flag to \fBIFLAGS\fP.
|
||||||
The default value for \fBIFLAGS\fP is empty.
|
The default value for \fBIFLAGS\fP is empty.
|
||||||
|
.IP \fB-L\fP\fIdir\fP
|
||||||
|
Add \fIdir\fP to the list of directories where definition modules are
|
||||||
|
looked for. Also add the corresponding \fB-I\fP flag to \fBIFLAGS\fP.
|
||||||
|
The difference with the \fB-I\fP flag is, that the \fB-L\fP directories are considered
|
||||||
|
interfaces to libraries, and thus no rules are generated using or creating
|
||||||
|
object files for modules found in these directories. Instead, the user is
|
||||||
|
expected to add a library to the \fBLIBS\fP macro, using the \fB-l\fP flag.
|
||||||
.IP \fB-M\fP\fIflags\fP
|
.IP \fB-M\fP\fIflags\fP
|
||||||
Set \fBM2FLAGS\fP to \fIflags\fP.
|
Set \fBM2FLAGS\fP to \fIflags\fP.
|
||||||
.IP \fB-C\fP\fIcompiler\fP
|
.IP \fB-C\fP\fIcompiler\fP
|
||||||
Set \fBMOD\fP to \fIcompiler\fP.
|
Set \fBMOD\fP to \fIcompiler\fP.
|
||||||
The default value for \fBMOD\fP is "ack" (for the time being).
|
The default value for \fBMOD\fP is "ack" (for the time being).
|
||||||
|
.IP \fB-l\fP\fIlibrary\fP
|
||||||
|
Add \fIlibrary\fP to the \fBLIBS\fP macro. This macro is initially empty,
|
||||||
|
and is passed to the loader.
|
||||||
.IP \fB-S\fPsuffix
|
.IP \fB-S\fPsuffix
|
||||||
Set \fBSUFFIX\fP to \fIsuffix\fP.
|
Set \fBSUFFIX\fP to \fIsuffix\fP.
|
||||||
The default suffix is "o".
|
The default suffix is "o".
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ static struct file_list *arglist;
|
||||||
char *mflags = "";
|
char *mflags = "";
|
||||||
char *compiler = "ack";
|
char *compiler = "ack";
|
||||||
char *suff = "o";
|
char *suff = "o";
|
||||||
|
char *llibs = 0;
|
||||||
|
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
register char **argv;
|
register char **argv;
|
||||||
|
|
@ -104,7 +105,7 @@ main(argc, argv)
|
||||||
for (i = 1; i < nDEF; i++) {
|
for (i = 1; i < nDEF; i++) {
|
||||||
print(" -I%s", DEFPATH[i]);
|
print(" -I%s", DEFPATH[i]);
|
||||||
}
|
}
|
||||||
print("\nM2FLAGS = %s\nMOD = %s\nSUFFIX = %s\n", mflags, compiler, suff);
|
print("\nM2FLAGS = %s\nMOD = %s\nSUFFIX = %s\nLIBS = %s\n", mflags, compiler, suff, llibs ? llibs : "");
|
||||||
init_lib();
|
init_lib();
|
||||||
ProcessArgs();
|
ProcessArgs();
|
||||||
find_dependencies();
|
find_dependencies();
|
||||||
|
|
@ -157,18 +158,10 @@ openfile(a)
|
||||||
register struct file_list *a;
|
register struct file_list *a;
|
||||||
{
|
{
|
||||||
char *fn;
|
char *fn;
|
||||||
register struct file_list *p, *prev = 0;
|
|
||||||
|
|
||||||
if (! InsertFile(f_filename(a), DEFPATH, &fn)) {
|
if (!f_notfound(a) && ! InsertFile(f_filename(a), DEFPATH, &fn)) {
|
||||||
|
a->a_notfound = 1;
|
||||||
Gerror("Could not find %s", f_filename(a));
|
Gerror("Could not find %s", f_filename(a));
|
||||||
f_walk(arglist, p) {
|
|
||||||
if (p == a) {
|
|
||||||
if (! prev) arglist = p->a_next;
|
|
||||||
else prev->a_next = a->a_next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
prev = p;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
FileName = fn;
|
FileName = fn;
|
||||||
|
|
@ -240,7 +233,7 @@ find_dependencies()
|
||||||
if (dotspot && strcmp(dotspot, ".mod") == 0) {
|
if (dotspot && strcmp(dotspot, ".mod") == 0) {
|
||||||
register struct idf *id = f_idf(arg);
|
register struct idf *id = f_idf(arg);
|
||||||
|
|
||||||
if (id) {
|
if (! f_notfound(arg) && id) {
|
||||||
if (id->id_type == PROGRAM) {
|
if (id->id_type == PROGRAM) {
|
||||||
*dotspot = 0;
|
*dotspot = 0;
|
||||||
print("%s ", fn);
|
print("%s ", fn);
|
||||||
|
|
@ -331,7 +324,7 @@ print_dep()
|
||||||
if (dotspot && strcmp(dotspot, ".mod") == 0) {
|
if (dotspot && strcmp(dotspot, ".mod") == 0) {
|
||||||
register struct idf *id = f_idf(arg);
|
register struct idf *id = f_idf(arg);
|
||||||
|
|
||||||
if (id) {
|
if (! f_notfound(arg) && id) {
|
||||||
char *obj = object(arg);
|
char *obj = object(arg);
|
||||||
register struct file_list *a;
|
register struct file_list *a;
|
||||||
|
|
||||||
|
|
@ -388,7 +381,7 @@ module_in_arglist(n)
|
||||||
f_walk(arglist, a) {
|
f_walk(arglist, a) {
|
||||||
char *dotp = strrindex(f_filename(a), '.');
|
char *dotp = strrindex(f_filename(a), '.');
|
||||||
|
|
||||||
if (dotp && strcmp(dotp, ".mod") == 0) {
|
if (dotp && strcmp(dotp, ".mod") == 0 && ! f_notfound(a)) {
|
||||||
*dotp = 0;
|
*dotp = 0;
|
||||||
if (strcmp(f_filename(a), n) == 0) {
|
if (strcmp(f_filename(a), n) == 0) {
|
||||||
*dotp = '.';
|
*dotp = '.';
|
||||||
|
|
@ -417,14 +410,14 @@ pr_prog_dep(id, a)
|
||||||
if (module_in_arglist(f_filename(p)) || ! f_dir(p)) {
|
if (module_in_arglist(f_filename(p)) || ! f_dir(p)) {
|
||||||
/* nothing */
|
/* nothing */
|
||||||
}
|
}
|
||||||
else if (! is_library_dir(f_dir(p))) {
|
else if (! is_library_dir(f_dir(p))) {
|
||||||
print(" \\\n\t%s/%s", f_dir(p), object(p));
|
print(" \\\n\t%s/%s", f_dir(p), object(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("\n\n");
|
print("\n\n");
|
||||||
print("o_files:\t$(OBS_%s)\n\n", id->id_text);
|
print("o_files:\t$(OBS_%s)\n\n", id->id_text);
|
||||||
print("%s:\t$(OBS_%s) $(OBS2_%s)\n", basename(f_filename(a)), id->id_text, id->id_text);
|
print("%s:\t$(OBS_%s) $(OBS2_%s)\n", basename(f_filename(a)), id->id_text, id->id_text);
|
||||||
print("\t$(MOD) -.mod -o %s $(M2FLAGS) $(OBS_%s) $(OBS2_%s)\n", basename(f_filename(a)), id->id_text, id->id_text);
|
print("\t$(MOD) -.mod -o %s $(M2FLAGS) $(OBS_%s) $(OBS2_%s) $(LIBS)\n", basename(f_filename(a)), id->id_text, id->id_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
programs()
|
programs()
|
||||||
|
|
@ -437,7 +430,7 @@ programs()
|
||||||
if (dotspot && strcmp(dotspot, ".mod") == 0) {
|
if (dotspot && strcmp(dotspot, ".mod") == 0) {
|
||||||
register struct idf *id = f_idf(a);
|
register struct idf *id = f_idf(a);
|
||||||
|
|
||||||
if (id && id->id_type == PROGRAM) {
|
if (! f_notfound(a) && id && id->id_type == PROGRAM) {
|
||||||
prog_dep(id, a);
|
prog_dep(id, a);
|
||||||
/* *dotspot = 0; */
|
/* *dotspot = 0; */
|
||||||
pr_prog_dep(id, a);
|
pr_prog_dep(id, a);
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,14 @@ DoOption(text)
|
||||||
extern char *mflags;
|
extern char *mflags;
|
||||||
extern char *suff;
|
extern char *suff;
|
||||||
extern char *compiler;
|
extern char *compiler;
|
||||||
|
extern char *llibs;
|
||||||
|
|
||||||
switch(*text++) {
|
switch(*text++) {
|
||||||
|
|
||||||
|
case 'L' :
|
||||||
|
AddLibDir(text);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'I' :
|
case 'I' :
|
||||||
AddInclDir(text);
|
AddInclDir(text);
|
||||||
break;
|
break;
|
||||||
|
|
@ -41,6 +46,22 @@ DoOption(text)
|
||||||
suff = text;
|
suff = text;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
{ static unsigned int liblen = 0;
|
||||||
|
unsigned int len = strlen(text) + 4;
|
||||||
|
|
||||||
|
if (liblen) {
|
||||||
|
llibs = Realloc(llibs, liblen += len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
llibs = Malloc(liblen = len);
|
||||||
|
*llibs = '\0';
|
||||||
|
}
|
||||||
|
strcat(llibs,"\\\n\t");
|
||||||
|
strcat(llibs, text);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Gerror("Unrecognized option: -%s", text-1);
|
Gerror("Unrecognized option: -%s", text-1);
|
||||||
break;
|
break;
|
||||||
|
|
@ -72,3 +93,12 @@ AddInclDir(text)
|
||||||
new = tmp;
|
new = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddLibDir(text)
|
||||||
|
char *text;
|
||||||
|
{
|
||||||
|
if (*text) {
|
||||||
|
set_libdir(ndirs);
|
||||||
|
AddInclDir(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue