do reboot more flexibly
[unix-history] / usr / src / old / make / main.c
CommitLineData
96cf4ac6 1static char *sccsid = "@(#)main.c 4.8 (Berkeley) 86/01/09";
8f5e70e1
BJ
2# include "defs"
3/*
4command make to update programs.
5Flags: 'd' print out debugging comments
6 'p' print out a version of the input graph
7 's' silent mode--don't print out commands
8 'f' the next argument is the name of the description file;
9 "makefile" is the default
10 'i' ignore error codes from the shell
11 'S' stop after any command fails (normally do parallel work)
12 'n' don't issue, just print, commands
13 't' touch (update time of) files but don't issue command
14 'q' don't do anything, but check if object is up to date;
15 returns exit code 0 if up to date, -1 if not
16*/
17
18struct nameblock *mainname = NULL;
19struct nameblock *firstname = NULL;
20struct lineblock *sufflist = NULL;
21struct varblock *firstvar = NULL;
22struct pattern *firstpat = NULL;
b342e078 23struct dirhdr *firstod = NULL;
8f5e70e1
BJ
24
25#include <signal.h>
26int sigivalue = 0;
27int sigqvalue = 0;
28int waitpid = 0;
29
30int dbgflag = NO;
31int prtrflag = NO;
32int silflag = NO;
33int noexflag = NO;
34int keepgoing = NO;
35int noruleflag = NO;
36int touchflag = NO;
37int questflag = NO;
38int ndocoms = NO;
39int ignerr = NO; /* default is to stop on error */
40int okdel = YES;
41int inarglist;
42#ifdef pwb
43char *prompt = ">"; /* other systems -- pick what you want */
44#else
45char *prompt = ""; /* other systems -- pick what you want */
46#endif
47int nopdir = 0;
48char junkname[20];
49char funny[128];
6738d7a9 50char options[26 + 1] = { '-' };
8f5e70e1
BJ
51
52main(argc,argv)
53int argc;
54char *argv[];
55{
56register struct nameblock *p;
57int i, j;
58int descset, nfargs;
59TIMETYPE tjunk;
60char c, *s;
61static char onechar[2] = "X";
62#ifdef unix
63int intrupt();
c93a5b01 64#endif
6738d7a9 65char *op = options + 1;
8f5e70e1
BJ
66
67
8f5e70e1
BJ
68#ifdef METERFILE
69meter(METERFILE);
70#endif
71
72descset = 0;
73
74funny['\0'] = (META | TERMINAL);
75for(s = "=|^();&<>*?[]:$`'\"\\\n" ; *s ; ++s)
76 funny[*s] |= META;
77for(s = "\n\t :;&>|" ; *s ; ++s)
78 funny[*s] |= TERMINAL;
79
80
81inarglist = 1;
82for(i=1; i<argc; ++i)
83 if(argv[i]!=0 && argv[i][0]!='-' && eqsign(argv[i]))
84 argv[i] = 0;
85
86setvar("$","$");
87inarglist = 0;
88
6738d7a9
SL
89for (i=1; i<argc; ++i)
90 if (argv[i]!=0 && argv[i][0]=='-') {
91 for (j=1 ; (c=argv[i][j])!='\0' ; ++j) {
92 *op++ = c;
93 switch (c) {
94
95 case 'd':
96 dbgflag = YES;
97 break;
98
99 case 'p':
100 prtrflag = YES;
101 break;
102
103 case 's':
104 silflag = YES;
105 break;
106
107 case 'i':
108 ignerr = YES;
109 break;
110
111 case 'S':
112 keepgoing = NO;
113 break;
114
115 case 'k':
116 keepgoing = YES;
117 break;
118
119 case 'n':
120 noexflag = YES;
121 break;
122
123 case 'r':
124 noruleflag = YES;
125 break;
126
127 case 't':
128 touchflag = YES;
129 break;
130
131 case 'q':
132 questflag = YES;
133 break;
134
135 case 'f':
136 op--; /* don't pass this one */
137 if(i >= argc-1)
138 fatal("No description argument after -f flag");
139 if( rddescf(argv[i+1]) )
8f5e70e1 140 fatal1("Cannot open %s", argv[i+1]);
6738d7a9
SL
141 argv[i+1] = 0;
142 ++descset;
143 break;
144
145 default:
146 onechar[0] = c; /* to make lint happy */
147 fatal1("Unknown flag argument %s", onechar);
148 }
8f5e70e1 149 }
6738d7a9 150 argv[i] = 0;
8f5e70e1
BJ
151 }
152
6738d7a9 153*op++ = '\0';
83d9028e
SL
154if (strcmp(options, "-") == 0)
155 *options = '\0';
6738d7a9
SL
156setvar("MFLAGS", options); /* MFLAGS=options to make */
157
8f5e70e1
BJ
158if( !descset )
159#ifdef unix
160 if( rddescf("makefile") ) rddescf("Makefile");
161#endif
162#ifdef gcos
163 rddescf("makefile");
164#endif
165
166if(prtrflag) printdesc(NO);
167
168if( srchname(".IGNORE") ) ++ignerr;
169if( srchname(".SILENT") ) silflag = 1;
170if(p=srchname(".SUFFIXES")) sufflist = p->linep;
171if( !sufflist ) fprintf(stderr,"No suffix list.\n");
172
173#ifdef unix
174sigivalue = (int) signal(SIGINT, SIG_IGN) & 01;
175sigqvalue = (int) signal(SIGQUIT, SIG_IGN) & 01;
176enbint(intrupt);
177#endif
178
179nfargs = 0;
180
181for(i=1; i<argc; ++i)
182 if((s=argv[i]) != 0)
183 {
184 if((p=srchname(s)) == 0)
185 {
186 p = makename(s);
187 }
188 ++nfargs;
189 doname(p, 0, &tjunk);
190 if(dbgflag) printdesc(YES);
191 }
192
193/*
194If no file arguments have been encountered, make the first
195name encountered that doesn't start with a dot
196*/
197
198if(nfargs == 0)
199 if(mainname == 0)
200 fatal("No arguments or description file");
201 else {
202 doname(mainname, 0, &tjunk);
203 if(dbgflag) printdesc(YES);
204 }
205
206exit(0);
207}
208
a781a4b6 209#include <sys/stat.h>
8f5e70e1
BJ
210
211#ifdef unix
212intrupt()
213{
214struct varblock *varptr();
215char *p;
216TIMETYPE exists();
a781a4b6 217struct stat sbuf;
8f5e70e1
BJ
218
219if(okdel && !noexflag && !touchflag &&
a781a4b6
SL
220 (p = varptr("@")->varval) &&
221 (stat(p, &sbuf) >= 0 && (sbuf.st_mode&S_IFMT) == S_IFREG) &&
222 !isprecious(p) )
8f5e70e1
BJ
223 {
224 fprintf(stderr, "\n*** %s removed.", p);
225 unlink(p);
226 }
227
228if(junkname[0])
229 unlink(junkname);
230fprintf(stderr, "\n");
231exit(2);
232}
233
234
235
236
237isprecious(p)
238char *p;
239{
240register struct lineblock *lp;
241register struct depblock *dp;
242register struct nameblock *np;
243
244if(np = srchname(".PRECIOUS"))
245 for(lp = np->linep ; lp ; lp = lp->nxtlineblock)
246 for(dp = lp->depp ; dp ; dp = dp->nxtdepblock)
247 if(! unequal(p, dp->depname->namep))
248 return(YES);
249
250return(NO);
251}
252
253
254enbint(k)
255int (*k)();
256{
257if(sigivalue == 0)
258 signal(SIGINT,k);
259if(sigqvalue == 0)
260 signal(SIGQUIT,k);
261}
262#endif
263\f
264extern char *builtin[];
265
266char **linesptr = builtin;
267
268FILE * fin;
269int firstrd = 0;
270
271
272rddescf(descfile)
273char *descfile;
274{
275FILE * k;
276
277/* read and parse description */
278
279if( !firstrd++ )
280 {
281 if( !noruleflag )
282 rdd1( (FILE *) NULL);
283
284#ifdef pwb
285 {
dbf5cc74 286 char *nlog, s[BUFSIZ];
8f5e70e1
BJ
287 nlog = logdir();
288 if ( (k=fopen( concat(nlog,"/makecomm",s), "r")) != NULL)
289 rdd1(k);
290 else if ( (k=fopen( concat(nlog,"/Makecomm",s), "r")) != NULL)
291 rdd1(k);
292
293 if ( (k=fopen("makecomm", "r")) != NULL)
294 rdd1(k);
295 else if ( (k=fopen("Makecomm", "r")) != NULL)
296 rdd1(k);
297 }
298#endif
299
300 }
301if(! unequal(descfile, "-"))
302 return( rdd1(stdin) );
303
304if( (k = fopen(descfile,"r")) != NULL)
305 return( rdd1(k) );
306
307return(1);
308}
309
310
311
312
313rdd1(k)
314FILE * k;
315{
316extern int yylineno;
317extern char *zznextc;
318
319fin = k;
320yylineno = 0;
321zznextc = 0;
322
323if( yyparse() )
324 fatal("Description file error");
325
96cf4ac6 326if(fin != NULL && fin != stdin)
8f5e70e1
BJ
327 fclose(fin);
328
329return(0);
330}
331\f
332printdesc(prntflag)
333int prntflag;
334{
335struct nameblock *p;
336struct depblock *dp;
337struct varblock *vp;
b342e078 338struct dirhdr *od;
8f5e70e1
BJ
339struct shblock *sp;
340struct lineblock *lp;
341
342#ifdef unix
343if(prntflag)
344 {
345 printf("Open directories:\n");
346 for (od = firstod; od; od = od->nxtopendir)
b342e078 347 printf("\t%d: %s\n", od->dirfc->dd_fd, od->dirn);
8f5e70e1
BJ
348 }
349#endif
350
351if(firstvar != 0) printf("Macros:\n");
352for(vp = firstvar; vp ; vp = vp->nxtvarblock)
353 printf("\t%s = %s\n" , vp->varname , vp->varval);
354
355for(p = firstname; p; p = p->nxtnameblock)
356 {
357 printf("\n\n%s",p->namep);
358 if(p->linep != 0) printf(":");
359 if(prntflag) printf(" done=%d",p->done);
360 if(p==mainname) printf(" (MAIN NAME)");
361 for(lp = p->linep ; lp ; lp = lp->nxtlineblock)
362 {
363 if( dp = lp->depp )
364 {
365 printf("\n depends on:");
366 for(; dp ; dp = dp->nxtdepblock)
367 if(dp->depname != 0)
368 printf(" %s ", dp->depname->namep);
369 }
370
371 if(sp = lp->shp)
372 {
373 printf("\n commands:\n");
374 for( ; sp!=0 ; sp = sp->nxtshblock)
375 printf("\t%s\n", sp->shbp);
376 }
377 }
378 }
379printf("\n");
380fflush(stdout);
381}