1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | #include "extern.h" |
63 | |
64 | |
65 | #if defined(_MSC_VER) || defined(__MINGW32__) |
66 | # define HAVE_GETMODULEFILENAMEFUNC 1 |
67 | |
68 | |
69 | # include <sys/timeb.h> |
70 | #endif |
71 | |
72 | |
73 | #if __CYGWIN__ |
74 | # include <sys/cygwin.h> |
75 | #endif |
76 | |
77 | #include "sysintf.h" |
78 | #if HAVE_ERRNO_H1 |
79 | # include <errno(*__errno_location ()).h> |
80 | #else |
81 | extern int errno(*__errno_location ()); |
82 | #endif |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | static time_t |
94 | really_dostat(name, buf) |
95 | char *name; |
96 | struct stat *buf; |
97 | { |
98 | return( ( DMSTATstat(name,buf)==-1 |
99 | || (STOBOOL(Augmake)(Augmake && ((*Augmake | 0x20) == 'y')) && (buf->st_mode & S_IFDIR0040000))) |
100 | ? (time_t)0L |
101 | : (time_t) buf->st_mtimest_mtim.tv_sec |
102 | ); |
103 | } |
104 | |
105 | |
106 | PUBLIC time_t |
107 | Do_stat(name, lib, member, force) |
108 | char *name; |
109 | char *lib; |
110 | char **member; |
111 | int force; |
112 | { |
113 | struct stat buf; |
114 | time_t seek_arch(); |
115 | |
116 | if( member != NIL(char *)((char **)((void*)0)) ) |
117 | Fatal("Library symbol names not supported"); |
118 | |
119 | buf.st_mtimest_mtim.tv_sec = (time_t)0L; |
120 | if( lib != NIL(char)((char*)((void*)0)) ) |
121 | return( seek_arch(Basename(name), lib) ); |
122 | else if( strlen(Basename(name)) > NameMax ) { |
123 | Warning( "Filename [%s] longer than value of NAMEMAX [%d].\n\ |
124 | Assume unix time 0.\n", Basename(name), NameMax ); |
125 | return((time_t)0L); |
126 | } |
127 | else if( STOBOOL(UseDirCache)(UseDirCache && ((*UseDirCache | 0x20) == 'y')) ) |
128 | return(CacheStat(name,force)); |
129 | else |
130 | return(really_dostat(name,&buf)); |
131 | } |
132 | |
133 | |
134 | |
135 | |
136 | PUBLIC int |
137 | Do_touch(name, lib, member) |
138 | char *name; |
139 | char *lib; |
140 | char **member; |
141 | { |
142 | if( member != NIL(char *)((char **)((void*)0)) ) |
143 | Fatal("Library symbol names not supported"); |
144 | |
145 | if (lib != NIL(char)((char*)((void*)0))) |
146 | return( touch_arch(Basename(name), lib) ); |
147 | else if( strlen(Basename(name)) > NameMax ) { |
148 | Warning( "Filename [%s] longer than value of NAMEMAX [%d].\n\ |
149 | File timestamp not updated to present time.\n", Basename(name), NameMax ); |
150 | return(-1); |
151 | } |
152 | else |
153 | #ifdef HAVE_UTIME_NULL1 |
154 | return( utime(name, NULL((void*)0)) ); |
155 | #else |
156 | # error "Utime NULL not supported" |
157 | #endif |
158 | } |
159 | |
160 | |
161 | |
162 | PUBLIC void |
163 | Void_lib_cache( lib_name, member_name ) |
164 | |
165 | |
166 | char *lib_name; |
167 | char *member_name; |
168 | { |
169 | VOID_LCACHE( lib_name, member_name )(void) void_lcache(lib_name,member_name); |
170 | } |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | PUBLIC time_t |
178 | Do_time() |
179 | { |
180 | return (time( NIL(time_t)((time_t*)((void*)0)) )); |
181 | } |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | PUBLIC void |
189 | Do_profile_output( text, mtype, target ) |
190 | char *text; |
191 | uint16 mtype; |
192 | CELLPTR target; |
193 | { |
194 | |
195 | time_t time_sec; |
196 | uint32 time_msec; |
197 | char *tstrg; |
198 | char *tname; |
199 | |
200 | #ifdef HAVE_GETTIMEOFDAY1 |
201 | struct timeval timebuffer; |
202 | gettimeofday(&timebuffer, NULL((void*)0)); |
203 | time_sec = timebuffer.tv_sec; |
204 | time_msec = timebuffer.tv_usec/1000; |
205 | #else |
206 | #if defined(_MSC_VER) || defined(__MINGW32__) |
207 | struct _timeb timebuffer; |
208 | _ftime( &timebuffer ); |
209 | time_sec = timebuffer.time; |
210 | time_msec = timebuffer.millitm; |
211 | # else |
212 | time_sec = time( NIL(time_t)((time_t*)((void*)0)) ); |
213 | time_msec = 0; |
214 | # endif |
215 | #endif |
216 | |
217 | tname = target->CE_NAMEce_name->ht_name; |
218 | if( mtype & M_TARGET0x01 ) { |
219 | tstrg = "target"; |
220 | |
221 | if( tname[0] == '.' && (strcmp(".TARGETS", tname) == 0 || \ |
222 | strcmp(".ROOT", tname) == 0) ) { |
223 | return; |
224 | } |
225 | } else { |
226 | tstrg = "recipe"; |
227 | } |
228 | |
229 | |
230 | if( (target->ce_attr & A_SHELLESC0x40000000) && !(Measure & M_SHELLESC0x08) ) { |
231 | return; |
232 | } |
233 | |
234 | |
235 | if( !(target->ce_attr & A_SHELLESC0x40000000) && (Measure & M_ABSPATH0x04) ) { |
236 | printf("%s %s %lu.%.3u %s%s%s\n",text, tstrg, time_sec, time_msec, Pwd, DirSepStr, tname); |
237 | } else { |
238 | printf("%s %s %lu.%.3u %s\n",text, tstrg, time_sec, time_msec, tname); |
239 | } |
240 | } |
241 | |
242 | |
243 | |
244 | PUBLIC int |
245 | Do_cmnd(cmd, group, do_it, target, cmnd_attr, last) |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | char **cmd; |
261 | int group; |
262 | |
263 | int do_it; |
264 | CELLPTR target; |
265 | t_attr cmnd_attr; |
266 | int last; |
267 | { |
268 | int i; |
269 | |
270 | DB_ENTER( "Do_cmnd" ); |
271 | |
272 | if( !do_it ) { |
273 | if( last && !Doing_bang ) { |
274 | |
275 | |
276 | Update_time_stamp( target ); |
277 | } |
278 | DB_RETURN( 0 )return (0); |
279 | } |
280 | |
281 | |
282 | |
283 | if ( target->ce_attr & A_ERROR0x10000000 ) { |
284 | if ( last ) { |
285 | Update_time_stamp( target ); |
286 | } |
287 | DB_RETURN( 0 )return (0); |
288 | } |
289 | |
290 | if( Max_proc == 1 ) Wait_for_completion = TRUE1; |
291 | |
292 | |
293 | if( Wait_for_completion ) cmnd_attr |= A_WFC0x00200; |
294 | |
295 | |
296 | if( iswhite(**cmd)((**cmd == ' ') || (**cmd == '\t')) ) { |
297 | char *p; |
298 | if( (p = DmStrSpn(*cmd," \t") ) != *cmd ) |
299 | strcpy(*cmd,p); |
300 | } |
301 | |
302 | |
303 | if( (cmnd_attr & A_SHELL0x00800) || group || (*DmStrPbrk(*cmd, Shell_metas)!='\0') ) |
304 | cmnd_attr |= A_SHELL0x00800; |
305 | |
306 | |
307 | |
308 | |
309 | i = runargv(target, group, last, cmnd_attr, cmd); |
310 | |
311 | DB_RETURN( i )return (i); |
312 | } |
313 | |
314 | |
315 | #define MINARGV64 64 |
316 | |
317 | PUBLIC char ** |
318 | Pack_argv( group, shell, cmd ) |
319 | |
320 | |
321 | |
322 | |
323 | int group; |
324 | int shell; |
325 | char **cmd; |
326 | { |
327 | static char **av = NIL(char *)((char **)((void*)0)); |
328 | static int avs = 0; |
329 | int i = 0; |
330 | char *s; |
331 | |
332 | if( av == NIL(char *)((char **)((void*)0)) ) { |
333 | TALLOC(av, MINARGV, char*)if ((av = (char**) calloc((unsigned int)(64), (size_t)sizeof( char*))) == (char**)0) {No_ram();}; |
334 | avs = MINARGV64; |
335 | } |
336 | av[0] = NIL(char)((char*)((void*)0)); |
337 | |
338 | if (**cmd) { |
339 | if( shell||group ) { |
340 | char* sh = group ? GShell : Shell; |
341 | |
342 | if( sh != NIL(char)((char*)((void*)0)) ) { |
343 | av[i++] = sh; |
344 | if( (av[i] = (group?GShell_flags:Shell_flags)) != NIL(char)((char*)((void*)0)) ) i++; |
345 | |
346 | if( shell && Shell_quote && *Shell_quote ) { |
347 | |
348 | s = DmStrJoin(Shell_quote, *cmd, -1, FALSE0); |
349 | FREE(*cmd)free((char*)(*cmd)); |
350 | *cmd = DmStrJoin(s, Shell_quote, -1, TRUE1); |
351 | } |
352 | av[i++] = *cmd; |
353 | |
354 | #if defined(USE_CREATEPROCESS) |
355 | |
356 | av[0] = DmStrAdd(av[0], av[1], FALSE0); |
357 | av[1] = NIL(char)((char*)((void*)0)); |
358 | |
359 | if( i == 3 ) { |
360 | s = av[0]; |
361 | av[0] = DmStrAdd(s, av[2], FALSE0); |
362 | FREE(s)free((char*)(s)); |
363 | av[2] = NIL(char)((char*)((void*)0)); |
364 | } |
365 | |
366 | FREE(*cmd)free((char*)(*cmd)); |
367 | *cmd = av[0]; |
368 | #endif |
369 | av[i] = NIL(char)((char*)((void*)0)); |
370 | } |
371 | else |
372 | Fatal("%sSHELL macro not defined", group?"GROUP":""); |
373 | } |
374 | else { |
375 | char *tcmd = *cmd; |
376 | |
377 | #if defined(USE_CREATEPROCESS) |
378 | |
379 | |
380 | while( iswhite(*tcmd)((*tcmd == ' ') || (*tcmd == '\t')) ) ++tcmd; |
381 | if( *tcmd ) av[i++] = tcmd; |
382 | #else |
383 | |
384 | |
385 | do { |
386 | |
387 | |
388 | while( iswhite(*tcmd)((*tcmd == ' ') || (*tcmd == '\t')) ) ++tcmd; |
389 | if( *tcmd ) av[i++] = tcmd; |
390 | |
391 | while( *tcmd != '\0' && !iswhite(*tcmd)((*tcmd == ' ') || (*tcmd == '\t')) ) ++tcmd; |
392 | if( *tcmd ) *tcmd++ = '\0'; |
393 | |
394 | |
395 | if( i == avs ) { |
396 | avs += MINARGV64; |
397 | av = (char **) realloc( av, avs*sizeof(char *) ); |
398 | } |
399 | } while( *tcmd ); |
400 | #endif |
401 | |
402 | av[i] = NIL(char)((char*)((void*)0)); |
403 | } |
404 | } |
405 | |
406 | return(av); |
407 | } |
408 | |
409 | |
410 | |
411 | |
412 | |
413 | |
414 | |
415 | PUBLIC char * |
416 | Read_env_string(ename) |
417 | char *ename; |
418 | { |
419 | return( getenv(ename) ); |
420 | } |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | PUBLIC int |
428 | Write_env_string(ename, value) |
429 | char *ename; |
430 | char *value; |
431 | { |
432 | #if defined(HAVE_SETENV1) |
433 | |
434 | return( setenv(ename, value, 1) ); |
435 | |
436 | #else /* !HAVE_SETENV */ |
437 | |
438 | char* p; |
439 | char* envstr = DmStrAdd(ename, value, FALSE0); |
440 | |
441 | p = envstr+strlen(ename); |
442 | *p++ = '='; |
443 | if( !*value ) *p = '\0'; |
444 | |
445 | return( putenv(envstr) ); |
446 | |
447 | #endif /* !HAVE_SETENV */ |
448 | } |
449 | |
450 | |
451 | PUBLIC void |
452 | ReadEnvironment() |
453 | { |
454 | extern char **Rule_tab; |
455 | #if !defined(_MSC_VER) |
456 | #if defined(__BORLANDC__) && __BORLANDC__ >= 0x500 |
457 | extern char ** _RTLENTRY _EXPDATA environ; |
458 | #else |
459 | extern char **environ; |
460 | #endif |
461 | #endif |
462 | char **rsave; |
463 | |
464 | #if !defined(__ZTC__) && !defined(_MPW) |
465 | # define make_env() |
466 | # define free_env() |
467 | #else |
468 | void make_env(); |
469 | void free_env(); |
470 | #endif |
471 | |
472 | make_env(); |
473 | |
474 | rsave = Rule_tab; |
475 | Rule_tab = environ; |
476 | Readenv = TRUE1; |
477 | |
478 | Parse( NIL(FILE)((FILE*)((void*)0)) ); |
479 | |
480 | Readenv = FALSE0; |
481 | Rule_tab = rsave; |
482 | |
483 | free_env(); |
484 | } |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | PUBLIC void |
492 | Catch_signals(fn) |
493 | void (*fn)(int); |
494 | { |
495 | |
496 | if( (void (*)(int)) signal(SIGINT2, SIG_IGN((__sighandler_t) 1)) != (void (*)(int))SIG_IGN((__sighandler_t) 1) ) |
497 | signal( SIGINT2, fn ); |
498 | if( (void (*)(int)) signal(SIGQUIT3, SIG_IGN((__sighandler_t) 1)) != (void (*)(int))SIG_IGN((__sighandler_t) 1) ) |
499 | signal( SIGQUIT3, fn ); |
500 | } |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | |
507 | PUBLIC void |
508 | Clear_signals() |
509 | { |
510 | if( (void (*)())signal(SIGINT2, SIG_IGN((__sighandler_t) 1)) != (void (*)())SIG_IGN((__sighandler_t) 1) ) |
511 | signal( SIGINT2, SIG_DFL((__sighandler_t) 0) ); |
512 | if( (void (*)())signal(SIGQUIT3, SIG_IGN((__sighandler_t) 1)) != (void (*)())SIG_IGN((__sighandler_t) 1) ) |
513 | signal( SIGQUIT3, SIG_DFL((__sighandler_t) 0) ); |
514 | } |
515 | |
516 | |
517 | |
518 | |
519 | |
520 | |
521 | PUBLIC void |
522 | Prolog(argc, argv) |
523 | int argc; |
524 | char* argv[]; |
525 | { |
526 | Pname = (argc == 0) ? DEF_MAKE_PNAME"dmake" : argv[0]; |
527 | |
528 | |
529 | #ifdef HAVE_GETMODULEFILENAMEFUNC |
530 | if( (AbsPname = MALLOC( PATH_MAX, char)(char*) malloc((unsigned int)(4096)*(size_t)sizeof(char))) == NIL(char)((char*)((void*)0)) ) No_ram(); |
531 | GetModuleFileName(NULL((void*)0), AbsPname, PATH_MAX4096*sizeof(char)); |
532 | #else |
533 | AbsPname = ""; |
534 | #endif |
535 | |
536 | #if __CYGWIN__ |
537 | |
538 | if ( (CygDrvPre = MALLOC( PATH_MAX, char)(char*) malloc((unsigned int)(4096)*(size_t)sizeof(char))) == NIL(char)((char*)((void*)0)) ) |
539 | No_ram(); |
540 | else { |
541 | int err = cygwin_conv_to_posix_path("c:", CygDrvPre); |
542 | if (err) |
543 | Fatal( "error converting \"%s\" - %s\n", |
544 | CygDrvPre, strerror (errno(*__errno_location ()))); |
545 | if( (CygDrvPreLen = strlen(CygDrvPre)) == 2 ) { |
546 | |
547 | *CygDrvPre = '\0'; |
548 | CygDrvPreLen = 0; |
549 | } else { |
550 | |
551 | CygDrvPre[CygDrvPreLen-2] = '\0'; |
552 | |
553 | |
554 | CygDrvPre++; |
555 | CygDrvPreLen -= 3; |
556 | } |
557 | } |
558 | #endif |
559 | |
560 | |
561 | |
562 | DirSepStr = "/"; |
563 | |
564 | Root = Def_cell( ".ROOT" ); |
565 | Targets = Def_cell( ".TARGETS" ); |
566 | Add_prerequisite(Root, Targets, FALSE0, FALSE0); |
567 | |
568 | Targets->ce_flag = Root->ce_flag = F_RULES0x0010|F_TARGET0x0008|F_STAT0x0040; |
569 | Targets->ce_attr = Root->ce_attr = A_NOSTATE0x08000|A_PHONY0x04000; |
570 | |
571 | Root->ce_flag |= F_MAGIC0x2000; |
572 | Root->ce_attr |= A_SEQ0x00200; |
573 | |
574 | tzset(); |
575 | } |
576 | |
577 | |
578 | |
579 | |
580 | |
581 | |
582 | PUBLIC void |
583 | Epilog(ret_code) |
584 | int ret_code; |
585 | { |
586 | Write_state(); |
587 | Unlink_temp_files(Root); |
588 | Hook_std_writes(NIL(char)); |
589 | exit( ret_code ); |
590 | } |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | |
598 | PUBLIC char * |
599 | Get_current_dir() |
600 | { |
601 | static char buf[PATH_MAX4096+2]; |
602 | |
603 | if( !getcwd(buf, sizeof(buf)) ) |
604 | Fatal("Internal Error: Error when calling getcwd()!"); |
605 | |
606 | #ifdef __EMX__ |
607 | char *slash; |
608 | slash = buf; |
609 | while( (slash=strchr(slash,'/')) ) |
610 | *slash = '\\'; |
611 | #endif |
612 | |
613 | return buf; |
614 | } |
615 | |
616 | |
617 | |
618 | |
619 | |
620 | |
621 | PUBLIC int |
622 | Set_dir(path) |
623 | char* path; |
624 | { |
625 | return( chdir(path) ); |
626 | } |
627 | |
628 | |
629 | |
630 | |
631 | |
632 | |
633 | PUBLIC char |
634 | Get_switch_char() |
635 | { |
636 | return( getswitchar()'-' ); |
637 | } |
638 | |
639 | |
640 | int Create_temp(tmpdir, path) |
641 | |
642 | |
643 | |
644 | |
645 | |
646 | |
647 | char *tmpdir; |
648 | char **path; |
649 | { |
650 | int fd; |
651 | |
652 | #if defined(HAVE_MKSTEMP1) |
653 | mode_t mask; |
654 | |
655 | *path = DmStrJoin( tmpdir, DirSepStr, -1, FALSE0); |
656 | *path = DmStrJoin( *path, "mkXXXXXX", -1, TRUE1 ); |
657 | |
658 | mask = umask(0066); |
659 | fd = mkstemp( *path ); |
660 | umask(mask); |
661 | |
662 | #elif defined(HAVE_TEMPNAM1) |
663 | char pidbuff[32]; |
664 | #if _MSC_VER >= 1300 |
665 | |
666 | long npid; |
667 | long nticks; |
668 | |
669 | npid = _getpid(); |
670 | nticks = GetTickCount() & 0xfff; |
671 | sprintf(pidbuff,"mk%d_%d_",npid,nticks); |
672 | #else |
673 | sprintf(pidbuff,"mk"); |
674 | #endif |
675 | *path = tempnam(tmpdir, pidbuff); |
676 | fd = open(*path, O_CREAT0100 | O_EXCL0200 | O_TRUNC01000 | O_RDWR02, 0600); |
677 | #else |
678 | |
679 | #error mkstemp() or tempnam() is needed |
680 | |
681 | #endif |
682 | |
683 | return fd; |
684 | } |
685 | |
686 | |
687 | PUBLIC FILE* |
688 | Get_temp(path, mode) |
689 | |
690 | |
691 | |
692 | |
693 | |
694 | |
695 | |
696 | |
697 | char **path; |
698 | char *mode; |
699 | { |
700 | int fd; |
701 | FILE *fp; |
702 | char *tmpdir; |
703 | int tries = 20; |
704 | |
705 | tmpdir = Read_env_string( "TMPDIR" ); |
706 | if( tmpdir == NIL(char)((char*)((void*)0)) ) |
707 | tmpdir = "/tmp"; |
708 | |
709 | while( --tries ) |
710 | { |
711 | |
712 | if( (fd = Create_temp(tmpdir, path)) != -1) |
713 | break; |
714 | |
715 | free(*path); |
716 | } |
717 | |
718 | if( fd != -1) |
719 | { |
720 | Def_macro( "TMPFILE", DO_WINPATH(*path)*path, M_MULTI0x0004|M_EXPANDED0x0008 ); |
721 | |
722 | fp = fdopen(fd, mode); |
723 | } |
724 | else |
725 | fp = NIL(FILE)((FILE*)((void*)0)); |
726 | |
727 | return fp; |
728 | } |
729 | |
730 | |
731 | PUBLIC FILE * |
732 | Start_temp( suffix, cp, fname ) |
733 | |
734 | |
735 | |
736 | |
737 | |
738 | |
739 | |
740 | |
741 | |
742 | |
743 | |
744 | |
745 | char *suffix; |
746 | CELLPTR cp; |
747 | char **fname; |
748 | { |
749 | FILE *fp, *fp2; |
750 | char *tmpname; |
751 | char *name; |
752 | char *fname_suff; |
753 | |
754 | name = (cp != NIL(CELL)((CELL*)((void*)0)))?cp->CE_NAMEce_name->ht_name:"makefile text"; |
755 | |
756 | |
757 | if( (fp = Get_temp(&tmpname, "w")) == NIL(FILE)((FILE*)((void*)0)) ) |
758 | Open_temp_error( tmpname, name ); |
759 | |
760 | |
761 | Link_temp( cp, fp, tmpname ); |
762 | *fname = tmpname; |
763 | |
764 | |
765 | |
766 | if ( suffix && *suffix ) { |
767 | |
768 | #ifdef HAVE_MKSTEMP1 |
769 | |
770 | |
771 | mode_t mask; |
772 | |
773 | mask = umask(0066); |
774 | #endif |
775 | |
776 | fname_suff = DmStrJoin( tmpname, suffix, -1, FALSE0 ); |
777 | |
778 | |
779 | Def_macro( "TMPFILE", DO_WINPATH(fname_suff)fname_suff, M_MULTI0x0004|M_EXPANDED0x0008 ); |
780 | |
781 | if( (fp2 = fopen(fname_suff, "w" )) == NIL(FILE)((FILE*)((void*)0)) ) |
782 | Open_temp_error( fname_suff, name ); |
783 | #ifdef HAVE_MKSTEMP1 |
784 | umask(mask); |
785 | #endif |
786 | |
787 | |
788 | Link_temp( cp, fp2, fname_suff ); |
789 | fp = fp2; |
790 | *fname = fname_suff; |
791 | } |
792 | |
793 | return( fp ); |
794 | } |
795 | |
796 | |
797 | |
798 | |
799 | |
800 | PUBLIC void |
801 | Open_temp_error( tmpname, name ) |
802 | char *tmpname; |
803 | char *name; |
804 | { |
805 | Fatal("Cannot open temp file `%s' while processing `%s'", tmpname, name ); |
806 | } |
807 | |
808 | |
809 | |
810 | |
811 | |
812 | PUBLIC void |
813 | Link_temp( cp, fp, fname ) |
814 | CELLPTR cp; |
815 | FILE *fp; |
816 | char *fname; |
817 | { |
818 | FILELISTPTR new; |
819 | |
820 | if( cp == NIL(CELL)((CELL*)((void*)0)) ) cp = Root; |
| 1 | Assuming 'cp' is not equal to null | |
|
| |
821 | |
822 | TALLOC( new, 1, FILELIST )if ((new = (FILELIST*) calloc((unsigned int)(1), (size_t)sizeof (FILELIST))) == (FILELIST*)0) {No_ram();}; |
| 3 | | Within the expansion of the macro 'TALLOC':
| |
b | Assuming pointer value is null |
|
823 | |
824 | new->fl_next = cp->ce_files; |
| 4 | | Access to field 'fl_next' results in a dereference of a null pointer (loaded from variable 'new') |
|
825 | new->fl_name = fname; |
826 | new->fl_file = fp; |
827 | |
828 | cp->ce_files = new; |
829 | } |
830 | |
831 | |
832 | |
833 | |
834 | |
835 | PUBLIC void |
836 | Close_temp(cp, file) |
837 | CELLPTR cp; |
838 | FILE *file; |
839 | { |
840 | FILELISTPTR fl; |
841 | if( cp == NIL(CELL)((CELL*)((void*)0)) ) cp = Root; |
842 | |
843 | for( fl=cp->ce_files; fl && fl->fl_file != file; fl=fl->fl_next ); |
844 | if( fl ) { |
845 | fl->fl_file = NIL(FILE)((FILE*)((void*)0)); |
846 | fclose(file); |
847 | } |
848 | } |
849 | |
850 | |
851 | |
852 | |
853 | |
854 | PUBLIC void |
855 | Unlink_temp_files( cp ) |
856 | |
857 | |
858 | |
859 | CELLPTR cp; |
860 | { |
861 | FILELISTPTR cur, next; |
862 | |
863 | if( cp == NIL(CELL)((CELL*)((void*)0)) || cp->ce_files == NIL(FILELIST)((FILELIST*)((void*)0)) ) return; |
864 | |
865 | for( cur=cp->ce_files; cur != NIL(FILELIST)((FILELIST*)((void*)0)); cur=next ) { |
866 | next = cur->fl_next; |
867 | |
868 | if( cur->fl_file ) fclose( cur->fl_file ); |
869 | |
870 | if( Verbose & V_LEAVE_TMP0x01 ) |
871 | fprintf( stderrstderr, "%s: Left temp file [%s]\n", Pname, cur->fl_name ); |
872 | else |
873 | (void) Remove_file( cur->fl_name ); |
874 | |
875 | FREE(cur->fl_name)free((char*)(cur->fl_name)); |
876 | FREE(cur)free((char*)(cur)); |
877 | } |
878 | |
879 | cp->ce_files = NIL(FILELIST)((FILELIST*)((void*)0)); |
880 | } |
881 | |
882 | |
883 | PUBLIC void |
884 | Handle_result(status, ignore, abort_flg, target) |
885 | |
886 | |
887 | |
888 | int status; |
889 | int ignore; |
890 | int abort_flg; |
891 | CELLPTR target; |
892 | { |
893 | status = ((status&0xff)==0 ? status>>8 |
894 | : (status & 0xff)==SIGTERM15 ? -1 |
895 | : (status & 0x7f)+128); |
896 | |
897 | |
898 | if( status ) { |
899 | if( !abort_flg ) { |
900 | char buf[512]; |
901 | |
902 | sprintf(buf, "%s: Error code %d, while making '%s'", |
903 | Pname, status, target->ce_fname ); |
904 | |
905 | if( ignore || Continue ) { |
906 | if (!(Glob_attr & A_SILENT0x00002)) { |
907 | strcat(buf, " (Ignored" ); |
908 | |
909 | if ( Continue ) { |
910 | |
911 | strcat(buf,",Continuing"); |
912 | target->ce_attr |= A_ERROR0x10000000; |
913 | } |
914 | strcat(buf,")"); |
915 | if (Verbose) |
916 | fprintf(stderrstderr, "%s\n", buf); |
917 | } |
918 | |
919 | if( target->ce_attr & A_ERRREMOVE0x40000 |
920 | && Remove_file( target->ce_fname ) == 0 |
921 | && !(Glob_attr & A_SILENT0x00002)) |
922 | fprintf(stderrstderr,"%s: '%s' removed.\n", Pname, target->ce_fname); |
923 | } |
924 | else { |
925 | fprintf(stderrstderr, "%s\n",buf); |
926 | |
927 | if(!(target->ce_attr & A_PRECIOUS0x00001)||(target->ce_attr & A_ERRREMOVE0x40000)) |
928 | if( Remove_file( target->ce_fname ) == 0 ) |
929 | fprintf(stderrstderr,"%s: '%s' removed.\n", Pname, |
930 | target->ce_fname); |
931 | |
932 | Quit(0); |
933 | } |
934 | } |
935 | else if(!(target->ce_attr & A_PRECIOUS0x00001)||(target->ce_attr & A_ERRREMOVE0x40000)) |
936 | Remove_file( target->ce_fname ); |
937 | } |
938 | } |
939 | |
940 | |
941 | PUBLIC void |
942 | Update_time_stamp( cp ) |
943 | |
944 | |
945 | |
946 | |
947 | CELLPTR cp; |
948 | { |
949 | HASHPTR hp; |
950 | LINKPTR dp; |
951 | CELLPTR tcp; |
952 | time_t mintime; |
953 | int phony = ((cp->ce_attr&A_PHONY0x04000) != 0); |
954 | |
955 | for(dp=CeMeToo(cp)&((cp)->ce_all); dp; dp=dp->cl_next) { |
956 | tcp=dp->cl_prq; |
957 | |
958 | |
959 | |
960 | |
961 | mintime = tcp->ce_time; |
962 | |
963 | if( tcp->ce_attr & A_LIBRARY0x00004 ) |
964 | Void_lib_cache( tcp->ce_fname, NIL(char)((char*)((void*)0)) ); |
965 | else if( !Touch && (tcp->ce_attr & A_LIBRARYM0x80000) ) |
966 | Void_lib_cache( tcp->ce_lib, tcp->ce_fname ); |
967 | |
968 | |
969 | |
970 | if( phony ) { |
971 | tcp->ce_time = Do_time(); |
972 | } |
973 | else if (Trace) { |
974 | tcp->ce_time = Do_time(); |
975 | } |
976 | else { |
977 | Stat_target(tcp, -1, TRUE1); |
978 | |
979 | if( tcp->ce_time == (time_t) 0L ) { |
980 | |
981 | |
982 | |
983 | |
984 | |
985 | |
986 | |
987 | if( cp->ce_recipe == NIL(STRING)((STRING*)((void*)0)) && mintime > 1 ) { |
988 | tcp->ce_time = mintime; |
989 | } |
990 | else { |
991 | tcp->ce_time = Do_time(); |
992 | } |
993 | } |
994 | else { |
995 | |
996 | |
997 | |
998 | |
999 | if( cp->ce_recipe == NIL(STRING)((STRING*)((void*)0)) ) { |
1000 | time_t newtime = ( mintime > 1 ? mintime : Do_time() ); |
1001 | |
1002 | if( !(tcp->ce_attr & A_SILENT0x00002) ) |
1003 | Warning( "Found file corresponding to virtual target [%s].", |
1004 | tcp->CE_NAMEce_name->ht_name ); |
1005 | |
1006 | if( newtime > tcp->ce_time ) |
1007 | tcp->ce_time = mintime; |
1008 | } |
1009 | } |
1010 | } |
1011 | |
1012 | if( Trace ) { |
1013 | tcp->ce_flag |= F_STAT0x0040; |
1014 | } |
1015 | |
1016 | if( Verbose & V_MAKE0x10 ) |
1017 | printf( "%s: <<<< Set [%s] time stamp to %lu\n", |
1018 | Pname, tcp->CE_NAMEce_name->ht_name, tcp->ce_time ); |
1019 | |
1020 | if( Measure & M_TARGET0x01 ) |
1021 | Do_profile_output( "e", M_TARGET0x01, tcp ); |
1022 | |
1023 | |
1024 | |
1025 | DB_PRINT( "make", ("time stamp: %ld, required mintime: %ld", |
1026 | cp->ce_time, mintime) ); |
1027 | if( tcp->ce_time < mintime && !(tcp->ce_attr & A_SILENT0x00002) ) { |
1028 | Warning( "Target [%s] was made but the time stamp has not been updated.", |
1029 | tcp->CE_NAMEce_name->ht_name ); |
1030 | } |
1031 | |
1032 | |
1033 | Unlink_temp_files( tcp ); |
1034 | tcp->ce_flag |= F_MADE0x8000; |
1035 | tcp->ce_attr |= A_UPDATED0x800000; |
1036 | } |
1037 | |
1038 | |
1039 | |
1040 | |
1041 | |
1042 | |
1043 | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | if( strcmp(cp->CE_NAMEce_name->ht_name,".REMOVE") != 0 && |
1050 | (hp = Get_name(".REMOVE", Defs, FALSE0)) != NIL(HASH)((HASH*)((void*)0)) ) { |
1051 | register LINKPTR dp; |
1052 | int flag = FALSE0; |
1053 | int rem; |
1054 | t_attr attr; |
1055 | |
1056 | tcp = hp->CP_OWNRvar.val.ht.ht_owner; |
1057 | |
1058 | |
1059 | tcp->ce_flag |= F_TARGET0x0008; |
1060 | Clear_prerequisites( tcp ); |
1061 | |
1062 | for(dp=cp->ce_prq; dp != NIL(LINK)((LINK*)((void*)0)); dp=dp->cl_next) { |
1063 | register CELLPTR prq = dp->cl_prq; |
1064 | |
1065 | attr = Glob_attr | prq->ce_attr; |
1066 | |
1067 | |
1068 | |
1069 | |
1070 | rem = (prq->ce_flag & F_REMOVE0x1000) && |
1071 | (prq->ce_flag & F_MADE0x8000 ) && |
1072 | !(prq->ce_count ) && |
1073 | !(prq->ce_attr & A_PHONY0x04000) && |
1074 | !(attr & A_PRECIOUS0x00001); |
1075 | |
1076 | |
1077 | if(rem) { |
1078 | LINKPTR tdp; |
1079 | |
1080 | |
1081 | |
1082 | for(tdp=CeMeToo(prq)&((prq)->ce_all); tdp; tdp=tdp->cl_next) { |
1083 | CELLPTR tmpcell=tdp->cl_prq; |
1084 | |
1085 | (Add_prerequisite(tcp,tmpcell,FALSE0,FALSE0))->cl_flag|=F_TARGET0x0008; |
1086 | tmpcell->ce_flag &= ~F_REMOVE0x1000; |
1087 | } |
1088 | flag = TRUE1; |
1089 | } |
1090 | } |
1091 | |
1092 | if( flag ) { |
1093 | int sv_force = Force; |
1094 | |
1095 | Force = FALSE0; |
1096 | Remove_prq( tcp ); |
1097 | Force = sv_force; |
1098 | |
1099 | for(dp=tcp->ce_prq; dp != NIL(LINK)((LINK*)((void*)0)); dp=dp->cl_next) { |
1100 | register CELLPTR prq = dp->cl_prq; |
1101 | |
1102 | prq->ce_flag &= ~(F_MADE0x8000|F_VISITED0x0080|F_STAT0x0040); |
1103 | prq->ce_flag |= F_REMOVE0x1000; |
1104 | prq->ce_time = (time_t)0L; |
1105 | } |
1106 | } |
1107 | } |
1108 | } |
1109 | |
1110 | |
1111 | PUBLIC int |
1112 | Remove_file( name ) |
1113 | char *name; |
1114 | { |
1115 | struct stat buf; |
1116 | |
1117 | if( stat(name, &buf) != 0 ) |
1118 | return 1; |
1119 | if( (buf.st_mode & S_IFMT0170000) == S_IFDIR0040000 ) |
1120 | return 1; |
1121 | return(unlink(name)); |
1122 | } |
1123 | |
1124 | |
1125 | #if defined(__CYGWIN__) |
1126 | char * |
1127 | cygdospath(char *src, int winpath) |
1128 | |
1129 | |
1130 | |
1131 | |
1132 | { |
1133 | static char *buf = NIL(char)((char*)((void*)0)); |
1134 | |
1135 | if ( !buf && ( (buf = MALLOC( PATH_MAX, char)(char*) malloc((unsigned int)(4096)*(size_t)sizeof(char))) == NIL(char)((char*)((void*)0)) ) ) |
1136 | No_ram(); |
1137 | |
1138 | DB_PRINT( "cygdospath", ("converting [%s] with winpath [%d]", src, winpath ) ); |
1139 | |
1140 | |
1141 | |
1142 | if( !src || !winpath ) |
1143 | return src; |
1144 | |
1145 | if( *src && src[0] == '/' ) { |
1146 | char *tmp; |
1147 | int err = cygwin_conv_to_win32_path(src, buf); |
1148 | if (err) |
1149 | Fatal( "error converting \"%s\" - %s\n", |
1150 | src, strerror (errno(*__errno_location ()))); |
1151 | |
1152 | tmp = buf; |
1153 | while ((tmp = strchr (tmp, '\\')) != NULL((void*)0)) { |
1154 | *tmp = '/'; |
1155 | tmp++; |
1156 | } |
1157 | |
1158 | return buf; |
1159 | } |
1160 | else |
1161 | return src; |
1162 | } |
1163 | #endif |