home *** CD-ROM | disk | FTP | other *** search
- /*
- (c) 1990 S.Hawtin.
- Permission is granted to copy this file provided that:
- 1) It is not used for commercial gain
- 2) This notice is included in all copies
- 3) Altered copies are marked as such.
-
- No liability is accepted for the contents of the file.
-
- gomake.c within WBmake
-
- */
-
- /* Actually run the make over the dependancy tree */
-
- #include <stdio.h>
- #include <string.h>
- #include <libraries/dos.h>
- #include "make.h"
-
- extern long dstodate();
- extern ConsCell *defaults;
- extern int just_test;
- extern ConsCell *cons();
- extern FileInfo *find_file();
-
- add_cmnd(fptr,base,file,cmnd)
- FILE *fptr;
- char *base;
- FileInfo *file;
- char *cmnd;
- {/* Construct the command string and add it to the file */
- char full_cmnd[256];
- int i,oc,ic;
-
- oc = 0;
- for(i=0;cmnd[i]!='\0';i++)
- {/* Go through the string */
- if(cmnd[i]=='$')
- {/* Some form of variable */
- i++;
- switch(cmnd[i])
- {case '*':
- for(ic=0;base[ic]!='\0';ic++)
- full_cmnd[oc++] = base[ic];
- break;
- case '$':
- full_cmnd[oc++] = '$';
- break;
- default:
- printf("Cannot do $%c yet\n",cmnd[i]);
- }
- }
- else
- full_cmnd[oc++] = cmnd[i];
- }
- full_cmnd[oc] = '\0';
-
- /* So full_cmnd now has the complete command, all variables have
- been given values */
- if(fptr)
- {fprintf(fptr,"echo \"%s\"\n",full_cmnd);
- if(just_test==0)
- fprintf(fptr,"%s\n",full_cmnd);
- }
- /* system(curr->contents); */
- }
-
- get_base(str,file)
- char *str;
- FileInfo *file;
- {/* Get the base file name into the buffer, with the suffix removed */
- char *temp;
-
- strcpy(str,file->name);
- temp = strrchr(str,'.');
- if(temp)
- *temp = '\0';
- }
-
- really_make(file,fptr)
- FileInfo *file;
- FILE *fptr;
- {/* First try to run the create string */
- String *curr;
- ConsCell *this_cons;
- char base_name[32];
-
- get_base(base_name,file);
-
- curr = file->create;
- if(curr)
- {/* Run each line of the string as a command */
- while(curr)
- {
- add_cmnd(fptr,base_name,file,curr->contents);
- curr = curr->next;
- }
- }
- else
- {
- printf("Don't know how to make %s\n",file->name);
- }
- }
-
- add_create(file,on_dep)
- FileInfo *file;
- int on_dep;
- {/* Find the default create method for this file and add it to
- the file's create */
- extern APTR Lock();
- APTR lock;
- ConsCell *def_list;
-
- def_list = defaults;
- while(def_list)
- {/* Is this default method for our file type? */
- if(def_list->car->type == file->type)
- {/* Can we find the source file */
- char srcname[32];
- char extens[12];
-
- get_base(srcname,file);
- get_base(extens,def_list->car);
- strcat(srcname,extens);
-
- if(on_dep)
- {/* Look on dependancy list */
- ConsCell *dep_list;
- dep_list = file->depends;
- while(dep_list)
- {if(strcmp(srcname,dep_list->car->name)==0)
- {file->create = def_list->car->create;
- return;
- }
- dep_list = dep_list->cdr;
- }
- }
- else
- {/* So we now have to look for the file within the current
- directory */
- lock = Lock(srcname,ACCESS_READ);
- if(lock!=0)
- {/* Got the lock, the file exists */
- UnLock(lock);
- file->depends = cons(find_file(srcname,-1),file->depends);
- file->create = def_list->car->create;
- return;
- }
- }
- }
- def_list = def_list->cdr;
- }
- if(on_dep)
- add_create(file,0);
- }
-
- go_make(file,fptr)
- FileInfo *file;
- FILE *fptr;
- {/* Recursive search down the tree of dependancies */
- ConsCell *depend;
- struct DateStamp ds;
- long last_src = 0;
-
- if(file->flags & MAKING)
- {printf("Dependancy loop with %s\n",file->name);
- return;
- }
- file->flags |= MAKING;
- /* Do we need to work out how to make this file ? */
- if(file->create == NULL)
- {/* No create method, go look the file up */
- add_create(file,-1);
- }
- /* Make all the files this file depends on */
- depend = file->depends;
- while(depend)
- {go_make(depend->car,fptr);
- if(depend->car->date > last_src)
- last_src = depend->car->date;
- depend = depend->cdr;
- }
- /* OK now should we make this one ? */
- if(last_src > file->date)
- {/* Make the file */
- really_make(file,fptr);
- /* Now set up the date to reflect the fact we have just made it */
- DateStamp(&ds);
- file->date = dstodate(&ds);
- }
- if(strcmp(file->name,"always")==0)
- {/* Always update always */
- DateStamp(&ds);
- file->date = dstodate(&ds);
- }
- file->flags &= ~MAKING;
- }
-