4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Copyright 2016 RackTop Systems.
26 * Copyright (c) 2016 by Delphix. All rights reserved.
32 * Figure out which targets are out of date and rebuild them
38 #include <alloca.h> /* alloca() */
41 #include <mksh/i18n.h> /* get_char_semantics_value() */
42 #include <mksh/macro.h> /* getvar(), expand_value() */
43 #include <mksh/misc.h> /* getmem() */
48 #include <sys/errno.h>
50 #include <sys/types.h>
51 #include <sys/utsname.h> /* uname() */
53 #include <unistd.h> /* close() */
58 # define LOCALHOST "localhost"
62 // Sleep for .1 seconds between stat()'s
63 const int STAT_RETRY_SLEEP_TIME
= 100000;
72 static char hostName
[MAXNAMELEN
] = "";
73 static char userName
[MAXNAMELEN
] = "";
76 static int second_pass
= 0;
79 * File table of contents
81 extern Doname
doname_check(register Name target
, register Boolean do_get
, register Boolean implicit
, register Boolean automatic
);
82 extern Doname
doname(register Name target
, register Boolean do_get
, register Boolean implicit
, register Boolean automatic
);
83 static Boolean
check_dependencies(Doname
*result
, Property line
, Boolean do_get
, Name target
, Name true_target
, Boolean doing_subtree
, Chain
*out_of_date_tail
, Property old_locals
, Boolean implicit
, Property
*command
, Name less
, Boolean rechecking_target
, Boolean recheck_conditionals
);
84 void dynamic_dependencies(Name target
);
85 static Doname
run_command(register Property line
, Boolean print_machine
);
86 extern Doname
execute_serial(Property line
);
87 extern Name
vpath_translation(register Name cmd
);
88 extern void check_state(Name temp_file_name
);
89 static void read_dependency_file(register Name filename
);
90 static void check_read_state_file(void);
91 static void do_assign(register Name line
, register Name target
);
92 static void build_command_strings(Name target
, register Property line
);
93 static Doname
touch_command(register Property line
, register Name target
, Doname result
);
94 extern void update_target(Property line
, Doname result
);
95 static Doname
sccs_get(register Name target
, register Property
*command
);
96 extern void read_directory_of_file(register Name file
);
97 static void add_pattern_conditionals(register Name target
);
98 extern void set_locals(register Name target
, register Property old_locals
);
99 extern void reset_locals(register Name target
, register Property old_locals
, register Property conditional
, register int index
);
100 extern Boolean
check_auto_dependencies(Name target
, int auto_count
, Name
*automatics
);
101 static void delete_query_chain(Chain ch
);
104 extern Name
normalize_name(register wchar_t *name_string
, register int length
);
111 * doname_check(target, do_get, implicit, automatic)
113 * Will call doname() and then inspect the return value
116 * Indication if the build failed or not
119 * target The target to build
120 * do_get Passed thru to doname()
121 * implicit Passed thru to doname()
122 * automatic Are we building a hidden dependency?
124 * Global variables used:
125 * build_failed_seen Set if -k is on and error occurs
126 * continue_after_error Indicates that -k is on
127 * report_dependencies No error msg if -P is on
130 doname_check(register Name target
, register Boolean do_get
, register Boolean implicit
, register Boolean automatic
)
133 (void) fflush(stdout
);
135 switch (doname(target
, do_get
, implicit
, automatic
)) {
141 return build_running
;
143 if (!continue_after_error
) {
144 fatal(gettext("Target `%s' not remade because of errors"),
147 build_failed_seen
= true;
150 case build_dont_know
:
152 * If we can't figure out how to build an automatic
153 * (hidden) dependency, we just ignore it.
154 * We later declare the target to be out of date just in
155 * case something changed.
156 * Also, don't complain if just reporting the dependencies
157 * and not building anything.
159 if (automatic
|| (report_dependencies_level
> 0)) {
161 return build_dont_know
;
169 if (continue_after_error
&& !svr4
) {
170 warning(gettext("Don't know how to make target `%s'"),
172 build_failed_seen
= true;
175 fatal(gettext("Don't know how to make target `%s'"), target
->string_mb
);
182 enter_explicit_rule_from_dynamic_rule(Name target
, Name source
)
184 Property line
, source_line
;
185 Dependency dependency
;
187 source_line
= get_prop(source
->prop
, line_prop
);
188 line
= maybe_append_prop(target
, line_prop
);
189 line
->body
.line
.sccs_command
= false;
190 line
->body
.line
.target
= target
;
191 if (line
->body
.line
.command_template
== NULL
) {
192 line
->body
.line
.command_template
= source_line
->body
.line
.command_template
;
193 for (dependency
= source_line
->body
.line
.dependencies
;
195 dependency
= dependency
->next
) {
196 enter_dependency(line
, dependency
->name
, false);
198 line
->body
.line
.less
= target
;
200 line
->body
.line
.percent
= NULL
;
206 find_dyntarget(Name target
)
211 wchar_t buffer
[STRING_BUFFER_LENGTH
];
212 wchar_t *pp
, * bufend
;
213 wchar_t tbuffer
[MAXPATHLEN
];
216 for (p
= dyntarget_list
; p
!= NULL
; p
= p
->next
) {
217 INIT_STRING_FROM_STACK(string
, buffer
);
218 expand_value(p
->name
, &string
, false);
220 pp
= string
.buffer
.start
;
221 bufend
= pp
+ STRING_BUFFER_LENGTH
;
222 while((*pp
!= nul_char
) && (pp
< bufend
)) {
224 tbuffer
[i
] = nul_char
;
226 if (wcb
.equal(tbuffer
)) {
227 enter_explicit_rule_from_dynamic_rule(target
, p
->name
);
238 if(*pp
== nul_char
) {
239 tbuffer
[i
] = nul_char
;
241 if (wcb
.equal(tbuffer
)) {
242 enter_explicit_rule_from_dynamic_rule(target
, p
->name
);
256 * doname(target, do_get, implicit)
258 * Chases all files the target depends on and builds any that
259 * are out of date. If the target is out of date it is then rebuilt.
262 * Indiates if build failed or nt
265 * target Target to build
266 * do_get Run sccs get is nessecary
267 * implicit doname is trying to find an implicit rule
269 * Global variables used:
270 * assign_done True if command line assgnment has happened
271 * commands_done Preserved for the case that we need local value
272 * debug_level Should we trace make's actions?
273 * default_rule The rule for ".DEFAULT", used as last resort
274 * empty_name The Name "", used when looking for single sfx
275 * keep_state Indicates that .KEEP_STATE is on
276 * parallel True if building in parallel
277 * recursion_level Used for tracing
278 * report_dependencies make -P is on
281 doname(register Name target
, register Boolean do_get
, register Boolean implicit
, register Boolean automatic
)
283 Doname result
= build_dont_know
;
284 Chain out_of_date_list
= NULL
;
286 Property old_locals
= NULL
;
287 register Property line
;
288 Property command
= NULL
;
289 register Dependency dependency
;
291 Name true_target
= target
;
292 Name
*automatics
= NULL
;
293 register int auto_count
;
294 Boolean rechecking_target
= false;
295 Boolean saved_commands_done
;
296 Boolean restart
= false;
297 Boolean save_parallel
= parallel
;
298 Boolean doing_subtree
= false;
300 Boolean recheck_conditionals
= false;
302 if (target
->state
== build_running
) {
303 return build_running
;
305 line
= get_prop(target
->prop
, line_prop
);
308 * If this target is a member of target group and one of the
309 * other members of the group is running, mark this target
312 for (target_group
= line
->body
.line
.target_group
;
313 target_group
!= NULL
;
314 target_group
= target_group
->next
) {
315 if (is_running(target_group
->name
)) {
316 target
->state
= build_running
;
322 return build_running
;
327 * If the target is a constructed one for a "::" target,
328 * we need to consider that.
330 if (target
->has_target_prop
) {
331 true_target
= get_prop(target
->prop
,
332 target_prop
)->body
.target
.target
;
333 if (true_target
->colon_splits
> 0) {
334 /* Make sure we have a valid time for :: targets */
337 time
= get_prop(true_target
->prop
, time_prop
);
339 true_target
->stat
.time
= time
->body
.time
.time
;
343 (void) exists(true_target
);
345 * If the target has been processed, we don't need to do it again,
346 * unless it depends on conditional macros or a delayed assignment,
347 * or it has been done when KEEP_STATE is on.
349 if (target
->state
== build_ok
) {
350 if((!keep_state
|| (!target
->depends_on_conditional
&& !assign_done
))) {
353 recheck_conditionals
= true;
356 if (target
->state
== build_subtree
) {
357 /* A dynamic macro subtree is being built */
358 target
->state
= build_dont_know
;
359 doing_subtree
= true;
360 if (!target
->checking_subtree
) {
362 * This target has been started before and therefore
363 * not all dependencies have to be built.
367 } else if (target
->state
== build_pending
) {
368 target
->state
= build_dont_know
;
371 } else if (parallel &&
373 (target->conditional_cnt > 0)) {
374 if (!parallel_ok(target, false)) {
375 add_subtree(target, recursion_level, do_get, implicit);
376 target->state = build_running;
377 return build_running;
382 * If KEEP_STATE is on, we have to rebuild the target if the
383 * building of it caused new automatic dependencies to be reported.
384 * This is where we restart the build.
387 line
->body
.line
.percent
= NULL
;
390 /* Init all local variables */
391 result
= build_dont_know
;
392 out_of_date_list
= NULL
;
396 if (!restart
&& line
!= NULL
) {
398 * If this target has never been built before, mark all
399 * of the dependencies as never built.
401 for (dependency
= line
->body
.line
.dependencies
;
403 dependency
= dependency
->next
) {
404 dependency
->built
= false;
407 /* Save the set of automatic depes defined for this target */
410 (line
->body
.line
.dependencies
!= NULL
)) {
414 * First run thru the dependency list to see how many
417 for (dependency
= line
->body
.line
.dependencies
;
419 dependency
= dependency
->next
) {
420 if (dependency
->automatic
&& !dependency
->stale
) {
424 /* Create vector to hold the current autos */
426 (Name
*) alloca((int) (auto_count
* sizeof (Name
)));
428 for (p
= automatics
, dependency
= line
->body
.line
.dependencies
;
430 dependency
= dependency
->next
) {
431 if (dependency
->automatic
&& !dependency
->stale
) {
432 *p
++ = dependency
->name
;
436 if (debug_level
> 1) {
437 (void) printf("%*sdoname(%s)\n",
443 /* Avoid infinite loops */
444 if (target
->state
== build_in_progress
) {
445 warning(gettext("Infinite loop: Target `%s' depends on itself"),
449 target
->state
= build_in_progress
;
451 /* Activate conditional macros for the target */
452 if (!target
->added_pattern_conditionals
) {
453 add_pattern_conditionals(target
);
454 target
->added_pattern_conditionals
= true;
456 if (target
->conditional_cnt
> 0) {
457 old_locals
= (Property
) alloca(target
->conditional_cnt
*
458 sizeof (Property_rec
));
459 set_locals(target
, old_locals
);
463 * after making the call to dynamic_dependecies unconditional we can handle
464 * target names that are same as file name. In this case $$@ in the
465 * dependencies did not mean anything. WIth this change it expands it
468 if (!target
->has_depe_list_expanded
)
470 dynamic_dependencies(target
);
474 * FIRST SECTION -- GO THROUGH DEPENDENCIES AND COLLECT EXPLICIT
477 if ((line
= get_prop(target
->prop
, line_prop
)) != NULL
) {
478 if (check_dependencies(&result
,
490 recheck_conditionals
)) {
491 return build_running
;
493 if (line
->body
.line
.query
!= NULL
) {
494 delete_query_chain(line
->body
.line
.query
);
496 line
->body
.line
.query
= out_of_date_list
;
501 * If the target is a :: type, do not try to find the rule for the target,
502 * all actions will be taken by separate branches.
503 * Else, we try to find an implicit rule using various methods,
504 * we quit as soon as one is found.
506 * [tolik, 12 Sep 2002] Do not try to find implicit rule for the target
507 * being rechecked - the target is being rechecked means that it already
508 * has explicit dependencies derived from an implicit rule found
511 if (target
->colon_splits
== 0 && !rechecking_target
) {
512 /* Look for percent matched rule */
513 if ((result
== build_dont_know
) &&
515 switch (find_percent_rule(
518 recheck_conditionals
)) {
520 result
= build_failed
;
523 target
->state
= build_running
;
529 if (target
->conditional_cnt
> 0) {
532 get_prop(target
->prop
,
536 return build_running
;
542 /* Look for double suffix rule */
543 if (result
== build_dont_know
) {
546 if (target
->is_member
&&
547 ((member
= get_prop(target
->prop
, member_prop
)) !=
549 switch (find_ar_suffix_rule(target
,
553 recheck_conditionals
)) {
555 result
= build_failed
;
558 target
->state
= build_running
;
564 if (target
->conditional_cnt
> 0) {
567 get_prop(target
->prop
,
571 return build_running
;
573 /* ALWAYS bind $% for old style */
577 maybe_append_prop(target
,
580 line
->body
.line
.percent
=
581 member
->body
.member
.member
;
585 switch (find_double_suffix_rule(target
,
587 recheck_conditionals
)) {
589 result
= build_failed
;
592 target
->state
= build_running
;
598 if (target
->conditional_cnt
> 0) {
606 return build_running
;
610 /* Look for single suffix rule */
613 * I commented !implicit to fix bug 1247448: Suffix Rules failed when combine with Pattern Matching Rules.
614 * This caused problem with SVR4 tilde rules (infinite recursion). So I made some changes in "implicit.cc"
617 * Regression! See BugId 1255360
618 * If more than one percent rules are defined for the same target then
619 * the behaviour of 'make' with my previous fix may be different from one
621 * The global variable second_pass (maybe it should be an argument to doname())
622 * is intended to avoid this regression. It is set in doname_check().
623 * First, 'make' will work as it worked before. Only when it is
624 * going to say "don't know how to make target" it sets second_pass to true and
625 * run 'doname' again but now trying to use Single Suffix Rules.
627 if ((result
== build_dont_know
) && !automatic
&& (!implicit
|| second_pass
) &&
629 ((line
->body
.line
.target
!= NULL
) &&
630 !line
->body
.line
.target
->has_regular_dependency
))) {
631 switch (find_suffix_rule(target
,
635 recheck_conditionals
)) {
637 result
= build_failed
;
640 target
->state
= build_running
;
646 if (target
->conditional_cnt
> 0) {
649 get_prop(target
->prop
,
653 return build_running
;
656 /* Try to sccs get */
657 if ((command
== NULL
) &&
658 (result
== build_dont_know
) &&
660 result
= sccs_get(target
, &command
);
663 /* Use .DEFAULT rule if it is defined. */
664 if ((command
== NULL
) &&
665 (result
== build_dont_know
) &&
666 (true_target
->colons
== no_colon
) &&
669 /* Make sure we have a line prop */
670 line
= maybe_append_prop(target
, line_prop
);
673 if (true_target
->is_member
) {
674 out_of_date
= (Boolean
) OUT_OF_DATE_SEC(true_target
->stat
.time
,
675 line
->body
.line
.dependency_time
);
677 out_of_date
= (Boolean
) OUT_OF_DATE(true_target
->stat
.time
,
678 line
->body
.line
.dependency_time
);
680 if (build_unconditional
|| out_of_date
) {
681 line
->body
.line
.is_out_of_date
= true;
682 if (debug_level
> 0) {
683 (void) printf(gettext("%*sBuilding %s using .DEFAULT because it is out of date\n"),
686 true_target
->string_mb
);
689 line
->body
.line
.sccs_command
= false;
690 line
->body
.line
.command_template
= default_rule
;
691 line
->body
.line
.target
= true_target
;
692 line
->body
.line
.star
= NULL
;
693 line
->body
.line
.less
= true_target
;
694 line
->body
.line
.percent
= NULL
;
698 /* We say "target up to date" if no cmd were executed for the target */
699 if (!target
->is_double_colon_parent
) {
700 commands_done
= false;
704 ignore_errors
= ignore_errors_all
;
709 silent
= (Boolean
) target
->silent_mode
;
713 ignore_errors
= (Boolean
) target
->ignore_error_mode
;
717 int doname_dyntarget
= 0;
719 /* Run commands if any. */
720 if ((command
!= NULL
) &&
721 (command
->body
.line
.command_template
!= NULL
)) {
722 if (result
!= build_failed
) {
723 result
= run_command(command
,
724 (Boolean
) ((parallel
|| save_parallel
) && !silent
));
736 target
->state
= build_running
;
737 if ((line
= get_prop(target
->prop
,
738 line_prop
)) != NULL
) {
739 if (line
->body
.line
.query
!= NULL
) {
740 delete_query_chain(line
->body
.line
.query
);
742 line
->body
.line
.query
= NULL
;
744 if (target
->conditional_cnt
> 0) {
747 get_prop(target
->prop
,
751 return build_running
;
757 target
->state
= build_running
;
758 line
= get_prop(target
->prop
, line_prop
);
760 if (line
->body
.line
.query
!= NULL
) {
761 delete_query_chain(line
->body
.line
.query
);
763 line
->body
.line
.query
= NULL
;
765 if (target
->conditional_cnt
> 0) {
768 get_prop(target
->prop
,
772 return build_running
;
774 /* If all went OK set a nice timestamp */
775 if (true_target
->stat
.time
== file_doesnt_exist
) {
776 true_target
->stat
.time
= file_max_time
;
782 * If no command was found for the target, and it doesn't
783 * exist, and it is mentioned as a target in the makefile,
784 * we say it is extremely new and that it is OK.
786 if (target
->colons
!= no_colon
) {
787 if (true_target
->stat
.time
== file_doesnt_exist
){
788 true_target
->stat
.time
= file_max_time
;
793 * Trying dynamic targets.
795 if(!doname_dyntarget
) {
796 doname_dyntarget
= 1;
797 Name dtarg
= find_dyntarget(target
);
799 if (!target
->has_depe_list_expanded
) {
800 dynamic_dependencies(target
);
802 if ((line
= get_prop(target
->prop
, line_prop
)) != NULL
) {
803 if (check_dependencies(&result
,
815 recheck_conditionals
))
817 return build_running
;
819 if (line
->body
.line
.query
!= NULL
) {
820 delete_query_chain(line
->body
.line
.query
);
822 line
->body
.line
.query
= out_of_date_list
;
828 * If the file exists, it is OK that we couldnt figure
829 * out how to build it.
831 (void) exists(target
);
832 if ((target
->stat
.time
!= file_doesnt_exist
) &&
833 (result
== build_dont_know
)) {
839 * Some of the following is duplicated in the function finish_doname.
840 * If anything is changed here, check to see if it needs to be
843 if ((line
= get_prop(target
->prop
, line_prop
)) != NULL
) {
844 if (line
->body
.line
.query
!= NULL
) {
845 delete_query_chain(line
->body
.line
.query
);
847 line
->body
.line
.query
= NULL
;
849 target
->state
= result
;
850 parallel
= save_parallel
;
851 if (target
->conditional_cnt
> 0) {
854 get_prop(target
->prop
, conditional_prop
),
858 if (target
->is_member
) {
861 /* Propagate the timestamp from the member file to the member*/
862 if ((target
->stat
.time
!= file_max_time
) &&
863 ((member
= get_prop(target
->prop
, member_prop
)) != NULL
) &&
864 (exists(member
->body
.member
.member
) > file_doesnt_exist
)) {
866 member
->body
.member
.member
->stat
.time
;
870 * Check if we found any new auto dependencies when we
873 if ((result
== build_ok
) && check_auto_dependencies(target
,
876 if (debug_level
> 0) {
877 (void) printf(gettext("%*sTarget `%s' acquired new dependencies from build, rechecking all dependencies\n"),
880 true_target
->string_mb
);
882 rechecking_target
= true;
883 saved_commands_done
= commands_done
;
887 if (rechecking_target
&& !commands_done
) {
888 commands_done
= saved_commands_done
;
897 * check_dependencies(result, line, do_get,
898 * target, true_target, doing_subtree, out_of_date_tail,
899 * old_locals, implicit, command, less, rechecking_target)
902 * True returned if some dependencies left running
905 * result Pointer to cell we update if build failed
906 * line We get the dependencies from here
907 * do_get Allow use of sccs get in recursive doname()
908 * target The target to chase dependencies for
909 * true_target The real one for :: and lib(member)
910 * doing_subtree True if building a conditional macro subtree
911 * out_of_date_tail Used to set the $? list
912 * old_locals Used for resetting the local macros
913 * implicit Called when scanning for implicit rules?
914 * command Place to stuff command
915 * less Set to $< value
917 * Global variables used:
918 * command_changed Set if we suspect .make.state needs rewrite
919 * debug_level Should we trace actions?
920 * force The Name " FORCE", compared against
921 * recursion_level Used for tracing
922 * rewrite_statefile Set if .make.state needs rewriting
923 * wait_name The Name ".WAIT", compared against
926 check_dependencies(Doname
*result
, Property line
, Boolean do_get
, Name target
, Name true_target
, Boolean doing_subtree
, Chain
*out_of_date_tail
, Property old_locals
, Boolean implicit
, Property
*command
, Name less
, Boolean rechecking_target
, Boolean recheck_conditionals
)
928 Boolean dependencies_running
;
929 register Dependency dependency
;
931 Boolean dependency_changed
= false;
933 line
->body
.line
.dependency_time
= file_doesnt_exist
;
934 if (line
->body
.line
.query
!= NULL
) {
935 delete_query_chain(line
->body
.line
.query
);
937 line
->body
.line
.query
= NULL
;
938 line
->body
.line
.is_out_of_date
= false;
939 dependencies_running
= false;
941 * Run thru all the dependencies and call doname() recursively
944 for (dependency
= line
->body
.line
.dependencies
;
946 dependency
= dependency
->next
) {
947 Boolean this_dependency_changed
= false;
949 if (!dependency
->automatic
&&
950 (rechecking_target
|| target
->rechecking_target
)) {
952 * We only bother with the autos when rechecking
957 if (dependency
->name
== wait_name
) {
959 * The special target .WAIT means finish all of
960 * the prior dependencies before continuing.
962 if (dependencies_running
) {
965 } else if ((!parallel_ok(dependency
->name
, false)) &&
966 (dependencies_running
)) {
968 * If we can't execute the current dependency in
969 * parallel, hold off the dependency processing
970 * to preserve the order of the dependencies.
974 timestruc_t depe_time
= file_doesnt_exist
;
977 if (true_target
->is_member
) {
978 depe_time
= exists(dependency
->name
);
980 if (dependency
->built
||
981 (dependency
->name
->state
== build_failed
)) {
982 dep_result
= (Doname
) dependency
->name
->state
;
984 dep_result
= doname_check(dependency
->name
,
987 (Boolean
) dependency
->automatic
);
989 if (true_target
->is_member
|| dependency
->name
->is_member
) {
990 /* should compare only secs, cause lib members does not have nsec time resolution */
991 if (depe_time
.tv_sec
!= dependency
->name
->stat
.time
.tv_sec
) {
992 this_dependency_changed
=
997 if (depe_time
!= dependency
->name
->stat
.time
) {
998 this_dependency_changed
=
1003 dependency
->built
= true;
1004 switch (dep_result
) {
1006 dependencies_running
= true;
1009 *result
= build_failed
;
1011 case build_dont_know
:
1013 * If make can't figure out how to make a dependency, maybe the dependency
1014 * is out of date. In this case, we just declare the target out of date
1015 * and go on. If we really need the dependency, the make'ing of the target
1016 * will fail. This will only happen for automatic (hidden) dependencies.
1018 if(!recheck_conditionals
) {
1019 line
->body
.line
.is_out_of_date
= true;
1022 * Make sure the dependency is not saved
1023 * in the state file.
1025 dependency
->stale
= true;
1029 if (debug_level
> 0) {
1030 (void) printf(gettext("Target %s rebuilt because dependency %s does not exist\n"),
1031 true_target
->string_mb
,
1032 dependency
->name
->string_mb
);
1036 if (dependency
->name
->depends_on_conditional
) {
1037 target
->depends_on_conditional
= true;
1039 if (dependency
->name
== force
) {
1041 dependency
->name
->stat
.time
;
1044 * Propagate new timestamp from "member" to
1047 (void) exists(dependency
->name
);
1049 /* Collect the timestamp of the youngest dependency */
1050 line
->body
.line
.dependency_time
=
1051 MAX(dependency
->name
->stat
.time
,
1052 line
->body
.line
.dependency_time
);
1054 /* Correction: do not consider nanosecs for members */
1055 if(true_target
->is_member
|| dependency
->name
->is_member
) {
1056 line
->body
.line
.dependency_time
.tv_nsec
= 0;
1059 if (debug_level
> 1) {
1060 (void) printf(gettext("%*sDate(%s)=%s \n"),
1063 dependency
->name
->string_mb
,
1064 time_to_string(dependency
->name
->
1066 if (dependency
->name
->stat
.time
> line
->body
.line
.dependency_time
) {
1067 (void) printf(gettext("%*sDate-dependencies(%s) set to %s\n"),
1070 true_target
->string_mb
,
1071 time_to_string(line
->body
.line
.
1076 /* Build the $? list */
1077 if (true_target
->is_member
) {
1078 if (this_dependency_changed
== true) {
1079 true_target
->stat
.time
= dependency
->name
->stat
.time
;
1080 true_target
->stat
.time
.tv_sec
--;
1083 * The next statement is commented
1084 * out as a fix for bug #1051032.
1085 * if dependency hasn't changed
1086 * then there's no need to invalidate
1087 * true_target. This statemnt causes
1088 * make to take much longer to process
1089 * an already-built archive. Soren
1090 * said it was a quick fix for some
1091 * problem he doesn't remember.
1092 true_target->stat.time = file_no_time;
1094 (void) exists(true_target
);
1097 (void) exists(true_target
);
1099 Boolean out_of_date
;
1100 if (true_target
->is_member
|| dependency
->name
->is_member
) {
1101 out_of_date
= (Boolean
) OUT_OF_DATE_SEC(true_target
->stat
.time
,
1102 dependency
->name
->stat
.time
);
1104 out_of_date
= (Boolean
) OUT_OF_DATE(true_target
->stat
.time
,
1105 dependency
->name
->stat
.time
);
1107 if ((build_unconditional
|| out_of_date
) &&
1108 (dependency
->name
!= force
) &&
1109 (dependency
->stale
== false)) {
1110 *out_of_date_tail
= ALLOC(Chain
);
1111 if (dependency
->name
->is_member
&&
1112 (get_prop(dependency
->name
->prop
,
1113 member_prop
) != NULL
)) {
1114 (*out_of_date_tail
)->name
=
1115 get_prop(dependency
->name
->prop
,
1119 (*out_of_date_tail
)->name
=
1122 (*out_of_date_tail
)->next
= NULL
;
1123 out_of_date_tail
= &(*out_of_date_tail
)->next
;
1124 if (debug_level
> 0) {
1125 if (dependency
->name
->stat
.time
== file_max_time
) {
1126 (void) printf(gettext("%*sBuilding %s because %s does not exist\n"),
1129 true_target
->string_mb
,
1130 dependency
->name
->string_mb
);
1132 (void) printf(gettext("%*sBuilding %s because it is out of date relative to %s\n"),
1135 true_target
->string_mb
,
1136 dependency
->name
->string_mb
);
1140 if (dependency
->name
== force
) {
1143 force
->state
= build_dont_know
;
1147 if (dependencies_running
) {
1148 if (doing_subtree
) {
1149 if (target
->conditional_cnt
> 0) {
1150 reset_locals(target
,
1152 get_prop(target
->prop
,
1158 target
->state
= build_running
;
1164 if (target
->conditional_cnt
> 0) {
1165 reset_locals(target
,
1167 get_prop(target
->prop
,
1175 * Collect the timestamp of the youngest double colon target
1178 if (target
->is_double_colon_parent
) {
1179 for (dependency
= line
->body
.line
.dependencies
;
1181 dependency
= dependency
->next
) {
1184 if ((tmp_line
= get_prop(dependency
->name
->prop
, line_prop
)) != NULL
) {
1185 if(tmp_line
->body
.line
.dependency_time
!= file_max_time
) {
1187 MAX(tmp_line
->body
.line
.dependency_time
,
1193 if ((true_target
->is_member
) && (dependency_changed
== true)) {
1194 true_target
->stat
.time
= file_no_time
;
1197 * After scanning all the dependencies, we check the rule
1200 if (line
->body
.line
.command_template
!= NULL
) {
1201 if (line
->body
.line
.command_template_redefined
) {
1202 warning(gettext("Too many rules defined for target %s"),
1206 /* Check if the target is out of date */
1207 Boolean out_of_date
;
1208 if (true_target
->is_member
) {
1209 out_of_date
= (Boolean
) OUT_OF_DATE_SEC(true_target
->stat
.time
,
1210 line
->body
.line
.dependency_time
);
1212 out_of_date
= (Boolean
) OUT_OF_DATE(true_target
->stat
.time
,
1213 line
->body
.line
.dependency_time
);
1215 if (build_unconditional
|| out_of_date
){
1216 if(!recheck_conditionals
) {
1217 line
->body
.line
.is_out_of_date
= true;
1220 line
->body
.line
.sccs_command
= false;
1221 line
->body
.line
.target
= true_target
;
1224 // set $< for explicit rule
1225 if(line
->body
.line
.dependencies
!= NULL
) {
1226 less
= line
->body
.line
.dependencies
->name
;
1229 // set $* for explicit rule
1231 Name tt
= true_target
;
1233 register wchar_t *target_end
;
1234 register Dependency suffix
;
1235 register int suffix_length
;
1236 Wstring targ_string
;
1239 if (true_target
->is_member
&&
1240 ((member
= get_prop(target
->prop
, member_prop
)) !=
1242 tt
= member
->body
.member
.member
;
1244 targ_string
.init(tt
);
1245 target_end
= targ_string
.get_string() + tt
->hash
.length
;
1246 for (suffix
= suffixes
; suffix
!= NULL
; suffix
= suffix
->next
) {
1247 suffix_length
= suffix
->name
->hash
.length
;
1248 suf_string
.init(suffix
->name
);
1249 if (tt
->hash
.length
< suffix_length
) {
1251 } else if (!IS_WEQUALN(suf_string
.get_string(),
1252 (target_end
- suffix_length
),
1256 target_body
= GETNAME(
1257 targ_string
.get_string(),
1258 (int)(tt
->hash
.length
- suffix_length
)
1260 line
->body
.line
.star
= target_body
;
1263 // set result = build_ok so that implicit rules are not used.
1264 if(*result
== build_dont_know
) {
1269 line
->body
.line
.less
= less
;
1277 * dynamic_dependencies(target)
1279 * Checks if any dependency contains a macro ref
1280 * If so, it replaces the dependency with the expanded version.
1281 * Here, "$@" gets translated to target->string. That is
1282 * the current name on the left of the colon in the
1288 * Also, "$(@F)" translates to the same thing without a preceeding
1289 * directory path (if one exists).
1290 * Note, to enter "$@" on a dependency line in a makefile
1291 * "$$@" must be typed. This is because make expands
1292 * macros in dependency lists upon reading them.
1293 * dynamic_dependencies() also expands file wildcards.
1294 * If there are any Shell meta characters in the name,
1295 * search the directory, and replace the dependency
1296 * with the set of files the pattern matches
1299 * target Target to sanitize dependencies for
1301 * Global variables used:
1302 * c_at The Name "@", used to set macro value
1303 * debug_level Should we trace actions?
1304 * dot The Name ".", used to read directory
1305 * recursion_level Used for tracing
1308 dynamic_dependencies(Name target
)
1310 wchar_t pattern
[MAXPATHLEN
];
1311 register wchar_t *p
;
1313 register Dependency dependency
;
1314 register Dependency
*remove
;
1316 wchar_t buffer
[MAXPATHLEN
];
1317 register Boolean set_at
= false;
1318 register wchar_t *start
;
1319 Dependency new_depe
;
1320 register Boolean reuse_cell
;
1321 Dependency first_member
;
1326 Name true_target
= target
;
1329 if ((line
= get_prop(target
->prop
, line_prop
)) == NULL
) {
1332 /* If the target is constructed from a "::" target we consider that */
1333 if (target
->has_target_prop
) {
1334 true_target
= get_prop(target
->prop
,
1335 target_prop
)->body
.target
.target
;
1337 /* Scan all dependencies and process the ones that contain "$" chars */
1338 for (dependency
= line
->body
.line
.dependencies
;
1340 dependency
= dependency
->next
) {
1341 if (!dependency
->name
->dollar
) {
1344 target
->has_depe_list_expanded
= true;
1346 /* The make macro $@ is bound to the target name once per */
1347 /* invocation of dynamic_dependencies() */
1349 (void) SETVAR(c_at
, true_target
, false);
1352 /* Expand this dependency string */
1353 INIT_STRING_FROM_STACK(string
, buffer
);
1354 expand_value(dependency
->name
, &string
, false);
1355 /* Scan the expanded string. It could contain whitespace */
1356 /* which mean it expands to several dependencies */
1357 start
= string
.buffer
.start
;
1358 while (iswspace(*start
)) {
1361 /* Remove the cell (later) if the macro was empty */
1362 if (start
[0] == (int) nul_char
) {
1363 dependency
->name
= NULL
;
1366 /* azv 10/26/95 to fix bug BID_1170218 */
1367 if ((start
[0] == (int) period_char
) &&
1368 (start
[1] == (int) slash_char
)) {
1373 first_member
= NULL
;
1374 /* We use the original dependency cell for the first */
1375 /* dependency from the expansion */
1377 /* We also have to deal with dependencies that expand to */
1378 /* lib.a(members) notation */
1379 for (p
= start
; *p
!= (int) nul_char
; p
++) {
1380 if ((*p
== (int) parenleft_char
)) {
1381 lib
= GETNAME(start
, p
- start
);
1382 lib
->is_member
= true;
1383 first_member
= dependency
;
1385 while (iswspace(*start
)) {
1392 /* First skip whitespace */
1393 for (p
= start
; *p
!= (int) nul_char
; p
++) {
1394 if ((*p
== (int) nul_char
) ||
1396 (*p
== (int) parenright_char
)) {
1400 /* Enter dependency from expansion */
1402 /* Create new dependency cell if */
1403 /* this is not the first dependency */
1404 /* picked from the expansion */
1406 new_depe
= ALLOC(Dependency
);
1407 new_depe
->next
= dependency
->next
;
1408 new_depe
->automatic
= false;
1409 new_depe
->stale
= false;
1410 new_depe
->built
= false;
1411 dependency
->next
= new_depe
;
1412 dependency
= new_depe
;
1415 /* Internalize the dependency name */
1416 // tolik. Fix for bug 4110429: inconsistent expansion for macros that
1417 // include "//" and "/./"
1418 //dependency->name = GETNAME(start, p - start);
1419 dependency
->name
= normalize_name(start
, p
- start
);
1420 if ((debug_level
> 0) &&
1421 (first_member
== NULL
)) {
1422 (void) printf(gettext("%*sDynamic dependency `%s' for target `%s'\n"),
1425 dependency
->name
->string_mb
,
1426 true_target
->string_mb
);
1428 for (start
= p
; iswspace(*start
); start
++);
1431 } while ((*p
!= (int) nul_char
) &&
1432 (*p
!= (int) parenright_char
));
1433 /* If the expansion was of lib.a(members) format we now */
1434 /* enter the proper member cells */
1435 if (first_member
!= NULL
) {
1436 /* Scan the new dependencies and transform them from */
1437 /* "foo" to "lib.a(foo)" */
1438 for (; 1; first_member
= first_member
->next
) {
1439 /* Build "lib.a(foo)" name */
1440 INIT_STRING_FROM_STACK(string
, buffer
);
1443 (int) lib
->hash
.length
);
1444 append_char((int) parenleft_char
, &string
);
1445 APPEND_NAME(first_member
->name
,
1448 append_char((int) parenright_char
, &string
);
1449 member
= first_member
->name
;
1450 /* Replace "foo" with "lib.a(foo)" */
1451 first_member
->name
=
1452 GETNAME(string
.buffer
.start
, FIND_LENGTH
);
1453 if (string
.free_after_use
) {
1454 retmem(string
.buffer
.start
);
1456 if (debug_level
> 0) {
1457 (void) printf(gettext("%*sDynamic dependency `%s' for target `%s'\n"),
1460 first_member
->name
->
1462 true_target
->string_mb
);
1464 first_member
->name
->is_member
= lib
->is_member
;
1465 /* Add member property to member */
1466 prop
= maybe_append_prop(first_member
->name
,
1468 prop
->body
.member
.library
= lib
;
1469 prop
->body
.member
.entry
= NULL
;
1470 prop
->body
.member
.member
= member
;
1471 if (first_member
== dependency
) {
1478 /* Then scan all the dependencies again. This time we want to expand */
1479 /* shell file wildcards */
1480 for (remove
= &line
->body
.line
.dependencies
, dependency
= *remove
;
1482 dependency
= *remove
) {
1483 if (dependency
->name
== NULL
) {
1484 dependency
= *remove
= (*remove
)->next
;
1487 /* If dependency name string contains shell wildcards */
1488 /* replace the name with the expansion */
1489 if (dependency
->name
->wildcard
) {
1490 wcb
.init(dependency
->name
);
1491 if ((start
= (wchar_t *) wcschr(wcb
.get_string(),
1492 (int) parenleft_char
)) != NULL
) {
1493 /* lib(*) type pattern */
1495 (void) wcsncpy(buffer
,
1497 start
- wcb
.get_string());
1498 buffer
[start
-wcb
.get_string()] =
1500 (void) wcsncpy(pattern
,
1502 (int) (dependency
->name
->hash
.length
-(start
-wcb
.get_string())-2));
1503 pattern
[dependency
->name
->hash
.length
-
1504 (start
-wcb
.get_string()) - 2] =
1508 (void) wcsncpy(pattern
,
1510 (int) dependency
->name
->hash
.length
);
1511 pattern
[dependency
->name
->hash
.length
] =
1514 start
= (wchar_t *) wcsrchr(pattern
, (int) slash_char
);
1515 if (start
== NULL
) {
1519 directory
= GETNAME(pattern
, start
-pattern
);
1522 /* The expansion is handled by the read_dir() routine*/
1523 if (read_dir(directory
, p
, line
, library
)) {
1524 *remove
= (*remove
)->next
;
1526 remove
= &dependency
->next
;
1529 remove
= &dependency
->next
;
1533 /* Then unbind $@ */
1534 (void) SETVAR(c_at
, (Name
) NULL
, false);
1542 * Takes one Cmd_line and runs the commands from it.
1545 * Indicates if the command failed or not
1548 * line The command line to run
1550 * Global variables used:
1551 * commands_done Set if we do run command
1552 * current_line Set to the line we run a command from
1553 * current_target Set to the target we run a command for
1554 * file_number Used to form temp file name
1555 * keep_state Indicates that .KEEP_STATE is on
1556 * make_state The Name ".make.state", used to check timestamp
1557 * parallel True if currently building in parallel
1558 * parallel_process_cnt Count of parallel processes running
1559 * quest Indicates that make -q is on
1560 * rewrite_statefile Set if we do run a command
1561 * sunpro_dependencies The Name "SUNPRO_DEPENDENCIES", set value
1562 * temp_file_directory Used to form temp fie name
1563 * temp_file_name Set to the name of the temp file
1564 * touch Indicates that make -t is on
1567 run_command(register Property line
, Boolean
)
1569 register Doname result
= build_ok
;
1570 register Boolean remember_only
= false;
1571 register Name target
= line
->body
.line
.target
;
1573 char tmp_file_path
[MAXPATHLEN
];
1575 if (!line
->body
.line
.is_out_of_date
&& target
->rechecking_target
) {
1576 target
->rechecking_target
= false;
1581 * Build the command if we know the target is out of date,
1582 * or if we want to check cmd consistency.
1584 if (line
->body
.line
.is_out_of_date
|| keep_state
) {
1585 /* Hack for handling conditional macros in DMake. */
1586 if (!line
->body
.line
.dont_rebuild_command_used
) {
1587 build_command_strings(target
, line
);
1591 if (!line
->body
.line
.is_out_of_date
) {
1594 /* If quest, then exit(1) because the target is out of date */
1597 result
= execute_parallel(line
, true);
1602 /* We actually had to do something this time */
1603 rewrite_statefile
= commands_done
= true;
1605 * If this is an sccs command, we have to do some extra checking
1606 * and possibly complain. If the file can't be gotten because it's
1607 * checked out, we complain and behave as if the command was
1608 * executed eventhough we ignored the command.
1611 line
->body
.line
.sccs_command
&&
1612 (target
->stat
.time
!= file_doesnt_exist
) &&
1613 ((target
->stat
.mode
& 0222) != 0)) {
1614 fatal(gettext("%s is writable so it cannot be sccs gotten"),
1616 target
->has_complained
= remember_only
= true;
1619 * If KEEP_STATE is on, we make sure we have the timestamp for
1620 * .make.state. If .make.state changes during the command run,
1621 * we reread .make.state after the command. We also setup the
1622 * environment variable that asks utilities to report dependencies.
1627 (void) exists(make_state
);
1628 if((strlen(temp_file_directory
) == 1) &&
1629 (temp_file_directory
[0] == '/')) {
1630 tmp_file_path
[0] = '\0';
1632 strcpy(tmp_file_path
, temp_file_directory
);
1635 "%s/.make.dependency.%08x.%d.%d",
1640 MBSTOWCS(wcs_buffer
, mbs_buffer
);
1642 temp_file_name
= getname_fn(wcs_buffer
, FIND_LENGTH
, false, &fnd
);
1643 temp_file_name
->stat
.is_file
= true;
1644 int len
= 2*MAXPATHLEN
+ strlen(target
->string_mb
) + 2;
1645 wchar_t *to
= string
= ALLOC_WC(len
);
1646 for (wchar_t *from
= wcs_buffer
; *from
!= (int) nul_char
; ) {
1647 if (*from
== (int) space_char
) {
1648 *to
++ = (int) backslash_char
;
1652 *to
++ = (int) space_char
;
1653 MBSTOWCS(to
, target
->string_mb
);
1654 Name sprodep_name
= getname_fn(string
, FIND_LENGTH
, false, &fnd
);
1655 (void) SETVAR(sunpro_dependencies
,
1660 temp_file_name
= NULL
;
1664 * In case we are interrupted, we need to know what was going on.
1666 current_target
= target
;
1668 * We also need to be able to save an empty command instead of the
1669 * interrupted one in .make.state.
1671 current_line
= line
;
1672 if (remember_only
) {
1673 /* Empty block!!! */
1675 result
= touch_command(line
, target
, result
);
1677 result
= execute_parallel(line
, true);
1681 * If this is not a touch run, we need to execute the
1682 * proper command(s) for the target.
1685 if (!parallel_ok(target
, true)) {
1687 * We are building in parallel, but
1688 * this target must be built in serial.
1691 * If nothing else is building,
1692 * do this one, else wait.
1694 if (parallel_process_cnt
== 0) {
1695 result
= execute_parallel(line
, true, target
->localhost
);
1697 current_target
= NULL
;
1698 current_line
= NULL
;
1700 line->body.line.command_used = NULL;
1702 line
->body
.line
.dont_rebuild_command_used
= true;
1703 return build_serial
;
1706 result
= execute_parallel(line
, false);
1709 return build_running
;
1711 if (parallel_process_cnt
== 0) {
1712 result
= execute_parallel(line
, true, target
->localhost
);
1714 current_target
= NULL
;
1715 current_line
= NULL
;
1716 target
->parallel
= false;
1717 line
->body
.line
.command_used
=
1719 return build_serial
;
1724 result
= execute_parallel(line
, true, target
->localhost
);
1727 temp_file_name
= NULL
;
1728 if (report_dependencies_level
== 0){
1729 update_target(line
, result
);
1731 current_target
= NULL
;
1732 current_line
= NULL
;
1737 * execute_serial(line)
1739 * Runs thru the command line for the target and
1740 * executes the rules one by one.
1743 * The result of the command build
1746 * line The command to execute
1748 * Static variables used:
1750 * Global variables used:
1751 * continue_after_error -k flag
1752 * do_not_exec_rule -n flag
1753 * report_dependencies -P flag
1754 * silent Don't echo commands before executing
1755 * temp_file_name Temp file for auto dependencies
1756 * vpath_defined If true, translate path for command
1759 execute_serial(Property line
)
1762 Boolean printed_serial
;
1763 Doname result
= build_ok
;
1764 Cmd_line rule
, cmd_tail
, command
= NULL
;
1765 char mbstring
[MAXPATHLEN
];
1767 Name target
= line
->body
.line
.target
;
1769 target
->has_recursive_dependency
= false;
1770 // We have to create a copy of the rules chain for processing because
1771 // the original one can be destroyed during .make.state file rereading.
1772 for (rule
= line
->body
.line
.command_used
;
1774 rule
= rule
->next
) {
1775 if (command
== NULL
) {
1776 command
= cmd_tail
= ALLOC(Cmd_line
);
1778 cmd_tail
->next
= ALLOC(Cmd_line
);
1779 cmd_tail
= cmd_tail
->next
;
1784 cmd_tail
->next
= NULL
;
1786 for (rule
= command
; rule
!= NULL
; rule
= rule
->next
) {
1787 if (posix
&& (touch
|| quest
) && !rule
->always_exec
) {
1790 if (vpath_defined
) {
1791 rule
->command_line
=
1792 vpath_translation(rule
->command_line
);
1794 /* Echo command line, maybe. */
1795 if ((rule
->command_line
->hash
.length
> 0) &&
1797 (!rule
->silent
|| do_not_exec_rule
) &&
1798 (report_dependencies_level
== 0)) {
1799 (void) printf("%s\n", rule
->command_line
->string_mb
);
1801 if (rule
->command_line
->hash
.length
> 0) {
1802 /* Do assignment if command line prefixed with "=" */
1805 do_assign(rule
->command_line
, target
);
1806 } else if (report_dependencies_level
== 0) {
1807 /* Execute command line. */
1809 result
= dosys(rule
->command_line
,
1810 (Boolean
) rule
->ignore_error
,
1811 (Boolean
) rule
->make_refd
,
1812 /* ds 98.04.23 bug #4085164. make should always show error messages */
1814 /* BOOLEAN(rule->silent &&
1815 rule->ignore_error), */
1816 (Boolean
) rule
->always_exec
,
1818 check_state(temp_file_name
);
1823 if (result
== build_failed
) {
1824 if (silent
|| rule
->silent
) {
1825 (void) printf(gettext("The following command caused the error:\n%s\n"),
1826 rule
->command_line
->string_mb
);
1828 if (!rule
->ignore_error
&& !ignore_errors
) {
1829 if (!continue_after_error
) {
1830 fatal(gettext("Command failed for target `%s'"),
1834 * Make sure a failing command is not
1835 * saved in .make.state.
1837 line
->body
.line
.command_used
= NULL
;
1844 for (rule
= command
; rule
!= NULL
; rule
= cmd_tail
) {
1845 cmd_tail
= rule
->next
;
1849 if (temp_file_name
!= NULL
) {
1850 free_name(temp_file_name
);
1852 temp_file_name
= NULL
;
1854 Property spro
= get_prop(sunpro_dependencies
->prop
, macro_prop
);
1856 Name val
= spro
->body
.macro
.value
;
1859 spro
->body
.macro
.value
= NULL
;
1862 spro
= get_prop(sunpro_dependencies
->prop
, env_mem_prop
);
1864 char *val
= spro
->body
.env_mem
.value
;
1867 * Do not return memory allocated for SUNPRO_DEPENDENCIES
1868 * It will be returned in setvar_daemon() in macro.cc
1871 spro
->body
.env_mem
.value
= NULL
;
1881 * vpath_translation(cmd)
1883 * Translates one command line by
1884 * checking each word. If the word has an alias it is translated.
1887 * The translated command
1890 * cmd Command to translate
1892 * Global variables used:
1895 vpath_translation(register Name cmd
)
1897 wchar_t buffer
[STRING_BUFFER_LENGTH
];
1902 if (!vpath_defined
|| (cmd
== NULL
) || (cmd
->hash
.length
== 0)) {
1905 INIT_STRING_FROM_STACK(new_cmd
, buffer
);
1908 p
= wcb
.get_string();
1910 while (*p
!= (int) nul_char
) {
1911 while (iswspace(*p
) && (*p
!= (int) nul_char
)) {
1912 append_char(*p
++, &new_cmd
);
1915 while (!iswspace(*p
) && (*p
!= (int) nul_char
)) {
1918 cmd
= GETNAME(start
, p
- start
);
1919 if (cmd
->has_vpath_alias_prop
) {
1920 cmd
= get_prop(cmd
->prop
, vpath_alias_prop
)->
1921 body
.vpath_alias
.alias
;
1924 (int) cmd
->hash
.length
);
1926 append_string(start
, &new_cmd
, p
- start
);
1929 cmd
= GETNAME(new_cmd
.buffer
.start
, FIND_LENGTH
);
1930 if (new_cmd
.free_after_use
) {
1931 retmem(new_cmd
.buffer
.start
);
1937 * check_state(temp_file_name)
1939 * Reads and checks the state changed by the previously executed command.
1942 * temp_file_name The auto dependency temp file
1944 * Global variables used:
1947 check_state(Name temp_file_name
)
1954 * Then read the temp file that now might
1955 * contain dependency reports from utilities
1957 read_dependency_file(temp_file_name
);
1960 * And reread .make.state if it
1961 * changed (the command ran recursive makes)
1963 check_read_state_file();
1964 if (temp_file_name
!= NULL
) {
1965 (void) unlink(temp_file_name
->string_mb
);
1970 * read_dependency_file(filename)
1972 * Read the temp file used for reporting dependencies to make
1975 * filename The name of the file with the state info
1977 * Global variables used:
1978 * makefile_type The type of makefile being read
1979 * read_trace_level Debug flag
1980 * temp_file_number The always increasing number for unique files
1981 * trace_reader Debug flag
1984 read_dependency_file(register Name filename
)
1986 register Makefile_type save_makefile_type
;
1988 if (filename
== NULL
) {
1991 filename
->stat
.time
= file_no_time
;
1992 if (exists(filename
) > file_doesnt_exist
) {
1993 save_makefile_type
= makefile_type
;
1994 makefile_type
= reading_cpp_file
;
1995 if (read_trace_level
> 1) {
1996 trace_reader
= true;
1999 (void) read_simple_file(filename
,
2006 trace_reader
= false;
2007 makefile_type
= save_makefile_type
;
2012 * check_read_state_file()
2014 * Check if .make.state has changed
2015 * If it has we reread it
2019 * Global variables used:
2020 * make_state Make state file name
2021 * makefile_type Type of makefile being read
2022 * read_trace_level Debug flag
2023 * trace_reader Debug flag
2026 check_read_state_file(void)
2028 timestruc_t previous
= make_state
->stat
.time
;
2029 register Makefile_type save_makefile_type
;
2030 register Property makefile
;
2032 make_state
->stat
.time
= file_no_time
;
2033 if ((exists(make_state
) == file_doesnt_exist
) ||
2034 (make_state
->stat
.time
== previous
)) {
2037 save_makefile_type
= makefile_type
;
2038 makefile_type
= rereading_statefile
;
2039 /* Make sure we clear the old cached contents of .make.state */
2040 makefile
= maybe_append_prop(make_state
, makefile_prop
);
2041 if (makefile
->body
.makefile
.contents
!= NULL
) {
2042 retmem(makefile
->body
.makefile
.contents
);
2043 makefile
->body
.makefile
.contents
= NULL
;
2045 if (read_trace_level
> 1) {
2046 trace_reader
= true;
2049 (void) read_simple_file(make_state
,
2056 trace_reader
= false;
2057 makefile_type
= save_makefile_type
;
2061 * do_assign(line, target)
2063 * Handles runtime assignments for command lines prefixed with "=".
2066 * line The command that contains an assignment
2067 * target The Name of the target, used for error reports
2069 * Global variables used:
2070 * assign_done Set to indicate doname needs to reprocess
2073 do_assign(register Name line
, register Name target
)
2076 register wchar_t *string
= wcb
.get_string();
2077 register wchar_t *equal
;
2079 register Boolean append
= false;
2082 * If any runtime assignments are done, doname() must reprocess all
2083 * targets in the future since the macro values used to build the
2084 * command lines for the targets might have changed.
2087 /* Skip white space. */
2088 while (iswspace(*string
)) {
2092 /* Find "+=" or "=". */
2093 while (!iswspace(*equal
) &&
2094 (*equal
!= (int) plus_char
) &&
2095 (*equal
!= (int) equal_char
)) {
2098 /* Internalize macro name. */
2099 name
= GETNAME(string
, equal
- string
);
2100 /* Skip over "+=" "=". */
2101 while (!((*equal
== (int) nul_char
) ||
2102 (*equal
== (int) equal_char
) ||
2103 (*equal
== (int) plus_char
))) {
2108 fatal(gettext("= expected in rule `%s' for target `%s'"),
2117 /* Skip over whitespace in front of value. */
2118 while (iswspace(*equal
)) {
2121 /* Enter new macro value. */
2123 GETNAME(equal
, wcb
.get_string() + line
->hash
.length
- equal
),
2128 * build_command_strings(target, line)
2130 * Builds the command string to used when
2131 * building a target. If the string is different from the previous one
2132 * is_out_of_date is set.
2135 * target Target to build commands for
2136 * line Where to stuff result
2138 * Global variables used:
2139 * c_at The Name "@", used to set macro value
2140 * command_changed Set if command is different from old
2141 * debug_level Should we trace activities?
2142 * do_not_exec_rule Always echo when running -n
2143 * empty_name The Name "", used for empty rule
2144 * funny Semantics of characters
2145 * ignore_errors Used to init field for line
2146 * is_conditional Set to false befor evaling macro, checked
2147 * after expanding macros
2148 * keep_state Indicates that .KEEP_STATE is on
2149 * make_word_mentioned Set by macro eval, inits field for cmd
2150 * query The Name "?", used to set macro value
2151 * query_mentioned Set by macro eval, inits field for cmd
2152 * recursion_level Used for tracing
2153 * silent Used to init field for line
2156 build_command_strings(Name target
, register Property line
)
2158 String_rec command_line
;
2159 register Cmd_line command_template
= line
->body
.line
.command_template
;
2160 register Cmd_line
*insert
= &line
->body
.line
.command_used
;
2161 register Cmd_line used
= *insert
;
2162 wchar_t buffer
[STRING_BUFFER_LENGTH
];
2164 Name new_command_line
;
2165 register Boolean new_command_longer
= false;
2166 register Boolean ignore_all_command_dependency
= true;
2168 static Name less_name
;
2169 static Name percent_name
;
2173 if (less_name
== NULL
) {
2174 MBSTOWCS(wcs_buffer
, "<");
2175 less_name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2176 MBSTOWCS(wcs_buffer
, "%");
2177 percent_name
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2178 MBSTOWCS(wcs_buffer
, "*");
2179 star
= GETNAME(wcs_buffer
, FIND_LENGTH
);
2182 /* We have to check if a target depends on conditional macros */
2183 /* Targets that do must be reprocessed by doname() each time around */
2184 /* since the macro values used when building the target might have */
2186 conditional_macro_used
= false;
2187 /* If we are building a lib.a(member) target $@ should be bound */
2189 if (target
->is_member
&&
2190 ((member
= get_prop(target
->prop
, member_prop
)) != NULL
)) {
2191 target
= member
->body
.member
.library
;
2193 /* If we are building a "::" help target $@ should be bound to */
2194 /* the real target name */
2195 /* A lib.a(member) target is never :: */
2196 if (target
->has_target_prop
) {
2197 target
= get_prop(target
->prop
, target_prop
)->
2200 /* Bind the magic macros that make supplies */
2202 if(tmp_name
!= NULL
) {
2203 if (tmp_name
->has_vpath_alias_prop
) {
2204 tmp_name
= get_prop(tmp_name
->prop
, vpath_alias_prop
)->
2205 body
.vpath_alias
.alias
;
2208 (void) SETVAR(c_at
, tmp_name
, false);
2210 tmp_name
= line
->body
.line
.star
;
2211 if(tmp_name
!= NULL
) {
2212 if (tmp_name
->has_vpath_alias_prop
) {
2213 tmp_name
= get_prop(tmp_name
->prop
, vpath_alias_prop
)->
2214 body
.vpath_alias
.alias
;
2217 (void) SETVAR(star
, tmp_name
, false);
2219 tmp_name
= line
->body
.line
.less
;
2220 if(tmp_name
!= NULL
) {
2221 if (tmp_name
->has_vpath_alias_prop
) {
2222 tmp_name
= get_prop(tmp_name
->prop
, vpath_alias_prop
)->
2223 body
.vpath_alias
.alias
;
2226 (void) SETVAR(less_name
, tmp_name
, false);
2228 tmp_name
= line
->body
.line
.percent
;
2229 if(tmp_name
!= NULL
) {
2230 if (tmp_name
->has_vpath_alias_prop
) {
2231 tmp_name
= get_prop(tmp_name
->prop
, vpath_alias_prop
)->
2232 body
.vpath_alias
.alias
;
2235 (void) SETVAR(percent_name
, tmp_name
, false);
2237 /* $? is seldom used and it is expensive to build */
2238 /* so we store the list form and build the string on demand */
2239 Chain query_list
= NULL
;
2240 Chain
*query_list_tail
= &query_list
;
2242 for (Chain ch
= line
->body
.line
.query
; ch
!= NULL
; ch
= ch
->next
) {
2243 *query_list_tail
= ALLOC(Chain
);
2244 (*query_list_tail
)->name
= ch
->name
;
2245 if ((*query_list_tail
)->name
->has_vpath_alias_prop
) {
2246 (*query_list_tail
)->name
=
2247 get_prop((*query_list_tail
)->name
->prop
,
2248 vpath_alias_prop
)->body
.vpath_alias
.alias
;
2250 (*query_list_tail
)->next
= NULL
;
2251 query_list_tail
= &(*query_list_tail
)->next
;
2253 (void) setvar_daemon(query
,
2261 Chain hat_list
= NULL
;
2262 Chain
*hat_list_tail
= &hat_list
;
2264 for (Dependency dependency
= line
->body
.line
.dependencies
;
2266 dependency
= dependency
->next
) {
2267 /* skip automatic dependencies */
2268 if (!dependency
->automatic
) {
2269 if ((dependency
->name
!= force
) &&
2270 (dependency
->stale
== false)) {
2271 *hat_list_tail
= ALLOC(Chain
);
2273 if (dependency
->name
->is_member
&&
2274 (get_prop(dependency
->name
->prop
, member_prop
) != NULL
)) {
2275 (*hat_list_tail
)->name
=
2276 get_prop(dependency
->name
->prop
,
2277 member_prop
)->body
.member
.member
;
2279 (*hat_list_tail
)->name
= dependency
->name
;
2282 if((*hat_list_tail
)->name
!= NULL
) {
2283 if ((*hat_list_tail
)->name
->has_vpath_alias_prop
) {
2284 (*hat_list_tail
)->name
=
2285 get_prop((*hat_list_tail
)->name
->prop
,
2286 vpath_alias_prop
)->body
.vpath_alias
.alias
;
2290 (*hat_list_tail
)->next
= NULL
;
2291 hat_list_tail
= &(*hat_list_tail
)->next
;
2295 (void) setvar_daemon(hat
,
2302 /* We have two command sequences we need to handle */
2303 /* The old one that we probably read from .make.state */
2304 /* and the new one we are building that will replace the old one */
2305 /* Even when KEEP_STATE is not on we build a new command sequence and store */
2306 /* it in the line prop. This command sequence is then executed by */
2307 /* run_command(). If KEEP_STATE is on it is also later written to */
2308 /* .make.state. The routine replaces the old command line by line with the */
2309 /* new one trying to reuse Cmd_lines */
2311 /* If there is no old command_used we have to start creating */
2312 /* Cmd_lines to keep the new cmd in */
2314 new_command_longer
= true;
2315 *insert
= used
= ALLOC(Cmd_line
);
2317 used
->command_line
= NULL
;
2318 insert
= &used
->next
;
2320 /* Run thru the template for the new command and build the expanded */
2321 /* new command lines */
2323 command_template
!= NULL
;
2324 command_template
= command_template
->next
, insert
= &used
->next
, used
= *insert
) {
2325 /* If there is no old command_used Cmd_line we need to */
2326 /* create one and say that cmd consistency failed */
2328 new_command_longer
= true;
2329 *insert
= used
= ALLOC(Cmd_line
);
2331 used
->command_line
= empty_name
;
2333 /* Prepare the Cmd_line for the processing */
2334 /* The command line prefixes "@-=?" are stripped and that */
2335 /* information is saved in the Cmd_line */
2336 used
->assign
= false;
2337 used
->ignore_error
= ignore_errors
;
2338 used
->silent
= silent
;
2339 used
->always_exec
= false;
2340 /* Expand the macros in the command line */
2341 INIT_STRING_FROM_STACK(command_line
, buffer
);
2342 make_word_mentioned
=
2345 expand_value(command_template
->command_line
, &command_line
, true);
2346 /* If the macro $(MAKE) is mentioned in the command */
2347 /* "make -n" runs actually execute the command */
2348 used
->make_refd
= make_word_mentioned
;
2349 used
->ignore_command_dependency
= query_mentioned
;
2350 /* Strip the prefixes */
2351 start
= command_line
.buffer
.start
;
2354 (get_char_semantics_value(*start
) & (int) command_prefix_sem
);
2358 used
->ignore_command_dependency
= true;
2361 used
->ignore_command_dependency
= false;
2364 used
->assign
= true;
2367 used
->ignore_error
= true;
2370 if (!do_not_exec_rule
) {
2371 used
->silent
= true;
2376 used
->always_exec
= true;
2381 /* If all command lines of the template are prefixed with "?"*/
2382 /* the VIRTUAL_ROOT is not used for cmd consistency checks */
2383 if (!used
->ignore_command_dependency
) {
2384 ignore_all_command_dependency
= false;
2386 /* Internalize the expanded and stripped command line */
2387 new_command_line
= GETNAME(start
, FIND_LENGTH
);
2388 if ((used
->command_line
== NULL
) &&
2389 (line
->body
.line
.sccs_command
)) {
2390 used
->command_line
= new_command_line
;
2391 new_command_longer
= false;
2393 /* Compare it with the old one for command consistency */
2394 if (used
->command_line
!= new_command_line
) {
2395 Name vpath_translated
= vpath_translation(new_command_line
);
2397 !used
->ignore_command_dependency
&& (vpath_translated
!= used
->command_line
)) {
2398 if (debug_level
> 0) {
2399 if (used
->command_line
!= NULL
2400 && *used
->command_line
->string_mb
!=
2402 (void) printf(gettext("%*sBuilding %s because new command \n\t%s\n%*sdifferent from old\n\t%s\n"),
2406 vpath_translated
->string_mb
,
2413 (void) printf(gettext("%*sBuilding %s because new command \n\t%s\n%*sdifferent from empty old command\n"),
2417 vpath_translated
->string_mb
,
2422 command_changed
= true;
2423 line
->body
.line
.is_out_of_date
= true;
2425 used
->command_line
= new_command_line
;
2427 if (command_line
.free_after_use
) {
2428 retmem(command_line
.buffer
.start
);
2431 /* Check if the old command is longer than the new for */
2432 /* command consistency */
2436 !ignore_all_command_dependency
) {
2437 if (debug_level
> 0) {
2438 (void) printf(gettext("%*sBuilding %s because new command shorter than old\n"),
2443 command_changed
= true;
2444 line
->body
.line
.is_out_of_date
= true;
2447 /* Check if the new command is longer than the old command for */
2448 /* command consistency */
2449 if (new_command_longer
&&
2450 !ignore_all_command_dependency
&&
2452 if (debug_level
> 0) {
2453 (void) printf(gettext("%*sBuilding %s because new command longer than old\n"),
2458 command_changed
= true;
2459 line
->body
.line
.is_out_of_date
= true;
2461 /* Unbind the magic macros */
2462 (void) SETVAR(c_at
, (Name
) NULL
, false);
2463 (void) SETVAR(star
, (Name
) NULL
, false);
2464 (void) SETVAR(less_name
, (Name
) NULL
, false);
2465 (void) SETVAR(percent_name
, (Name
) NULL
, false);
2466 (void) SETVAR(query
, (Name
) NULL
, false);
2467 if (query_list
!= NULL
) {
2468 delete_query_chain(query_list
);
2470 (void) SETVAR(hat
, (Name
) NULL
, false);
2471 if (hat_list
!= NULL
) {
2472 delete_query_chain(hat_list
);
2475 if (conditional_macro_used
) {
2476 target
->conditional_macro_list
= cond_macro_list
;
2477 cond_macro_list
= NULL
;
2478 target
->depends_on_conditional
= true;
2483 * touch_command(line, target, result)
2485 * If this is an "make -t" run we do this.
2486 * We touch all targets in the target group ("foo + fie:") if any.
2489 * Indicates if the command failed or not
2492 * line The command line to update
2493 * target The target we are touching
2494 * result Initial value for the result we return
2496 * Global variables used:
2497 * do_not_exec_rule Indicates that -n is on
2498 * silent Do not echo commands
2501 touch_command(register Property line
, register Name target
, Doname result
)
2504 register Chain target_group
;
2505 String_rec touch_string
;
2506 wchar_t buffer
[MAXPATHLEN
];
2510 for (name
= target
, target_group
= NULL
; name
!= NULL
;) {
2511 if (!name
->is_member
) {
2513 * Build a touch command that can be passed
2514 * to dosys(). If KEEP_STATE is on, "make -t"
2515 * will save the proper command, not the
2516 * "touch" in .make.state.
2518 INIT_STRING_FROM_STACK(touch_string
, buffer
);
2519 MBSTOWCS(wcs_buffer
, "touch ");
2520 append_string(wcs_buffer
, &touch_string
, FIND_LENGTH
);
2522 if (name
->has_vpath_alias_prop
) {
2523 touch_cmd
= get_prop(name
->prop
,
2525 body
.vpath_alias
.alias
;
2527 APPEND_NAME(touch_cmd
,
2530 touch_cmd
= GETNAME(touch_string
.buffer
.start
,
2532 if (touch_string
.free_after_use
) {
2533 retmem(touch_string
.buffer
.start
);
2537 (target_group
== NULL
)) {
2538 (void) printf("%s\n", touch_cmd
->string_mb
);
2540 /* Run the touch command, or simulate it */
2541 if (!do_not_exec_rule
) {
2542 result
= dosys(touch_cmd
,
2554 if (target_group
== NULL
) {
2555 target_group
= line
->body
.line
.target_group
;
2557 target_group
= target_group
->next
;
2559 if (target_group
!= NULL
) {
2560 name
= target_group
->name
;
2569 * update_target(line, result)
2571 * updates the status of a target after executing its commands.
2574 * line The command line block to update
2575 * result Indicates that build is OK so can update
2577 * Global variables used:
2578 * do_not_exec_rule Indicates that -n is on
2579 * touch Fake the new timestamp if we are just touching
2582 update_target(Property line
, Doname result
)
2587 timestruc_t old_stat_time
;
2591 * [tolik] Additional fix for bug 1063790. It was fixed
2592 * for serial make long ago, but DMake dumps core when
2593 * target is a symlink and sccs file is newer then target.
2594 * In this case, finish_children() calls update_target()
2598 /* XXX. Should we do anything here? */
2602 target
= line
->body
.line
.target
;
2604 if ((result
== build_ok
) && (line
->body
.line
.command_used
!= NULL
)) {
2605 if (do_not_exec_rule
||
2607 (target
->is_member
&&
2608 (line
->body
.line
.command_template
!= NULL
) &&
2609 (line
->body
.line
.command_template
->command_line
->string_mb
[0] == 0) &&
2610 (line
->body
.line
.command_template
->next
== NULL
))) {
2611 /* If we are simulating execution we need to fake a */
2612 /* new timestamp for the target we didnt build */
2613 target
->stat
.time
= file_max_time
;
2616 * If we really built the target we read the new
2618 * Fix for bug #1110906: if .c file is newer than
2619 * the corresponding .o file which is in an archive
2620 * file, make will compile the .c file but it won't
2621 * update the object in the .a file.
2623 old_stat_time
= target
->stat
.time
;
2624 target
->stat
.time
= file_no_time
;
2625 (void) exists(target
);
2626 if ((target
->is_member
) &&
2627 (target
->stat
.time
== old_stat_time
)) {
2628 member
= get_prop(target
->prop
, member_prop
);
2629 if (member
!= NULL
) {
2630 target
->stat
.time
= member
->body
.member
.library
->stat
.time
;
2631 target
->stat
.time
.tv_sec
++;
2635 /* If the target is part of a group we need to propagate the */
2636 /* result of the run to all members */
2637 for (target_group
= line
->body
.line
.target_group
;
2638 target_group
!= NULL
;
2639 target_group
= target_group
->next
) {
2640 target_group
->name
->stat
.time
= target
->stat
.time
;
2641 line2
= maybe_append_prop(target_group
->name
,
2643 line2
->body
.line
.command_used
=
2644 line
->body
.line
.command_used
;
2645 line2
->body
.line
.target
= target_group
->name
;
2648 target
->has_built
= true;
2652 * sccs_get(target, command)
2654 * Figures out if it possible to sccs get a file
2655 * and builds the command to do it if it is.
2658 * Indicates if sccs get failed or not
2661 * target Target to get
2662 * command Where to deposit command to use
2664 * Global variables used:
2665 * debug_level Should we trace activities?
2666 * recursion_level Used for tracing
2667 * sccs_get_rule The rule to used for sccs getting
2670 sccs_get(register Name target
, register Property
*command
)
2672 register int result
;
2673 char link
[MAXPATHLEN
];
2675 wchar_t name
[MAXPATHLEN
];
2676 register wchar_t *p
;
2677 timestruc_t sccs_time
;
2678 register Property line
;
2679 int sym_link_depth
= 0;
2681 /* For sccs, we need to chase symlinks. */
2682 while (target
->stat
.is_sym_link
) {
2683 if (sym_link_depth
++ > 90) {
2684 fatal(gettext("Can't read symbolic link `%s': Number of symbolic links encountered during path name traversal exceeds 90."),
2687 /* Read the value of the link. */
2688 result
= readlink_vroot(target
->string_mb
,
2694 fatal(gettext("Can't read symbolic link `%s': %s"),
2695 target
->string_mb
, errmsg(errno
));
2698 /* Use the value to build the proper filename. */
2699 INIT_STRING_FROM_STACK(string
, name
);
2701 Wstring
wcb(target
);
2702 if ((link
[0] != slash_char
) &&
2703 ((p
= (wchar_t *) wcsrchr(wcb
.get_string(), slash_char
)) != NULL
)) {
2704 append_string(wcb
.get_string(), &string
, p
- wcb
.get_string() + 1);
2706 append_string(link
, &string
, result
);
2707 /* Replace the old name with the translated name. */
2708 target
= normalize_name(string
.buffer
.start
, string
.text
.p
- string
.buffer
.start
);
2709 (void) exists(target
);
2710 if (string
.free_after_use
) {
2711 retmem(string
.buffer
.start
);
2716 * read_dir() also reads the ?/SCCS dir and saves information
2717 * about which files have SCSC/s. files.
2719 if (target
->stat
.has_sccs
== DONT_KNOW_SCCS
) {
2720 read_directory_of_file(target
);
2722 switch (target
->stat
.has_sccs
) {
2723 case DONT_KNOW_SCCS
:
2724 /* We dont know by now there is no SCCS/s.* */
2725 target
->stat
.has_sccs
= NO_SCCS
;
2728 * If there is no SCCS/s.* but the plain file exists,
2729 * we say things are OK.
2731 if (target
->stat
.time
> file_doesnt_exist
) {
2734 /* If we cant find the plain file, we give up. */
2735 return build_dont_know
;
2738 * Pay dirt. We now need to figure out if the plain file
2739 * is out of date relative to the SCCS/s.* file.
2741 sccs_time
= exists(get_prop(target
->prop
,
2742 sccs_prop
)->body
.sccs
.file
);
2746 if ((!target
->has_complained
&&
2747 (sccs_time
!= file_doesnt_exist
) &&
2748 (sccs_get_rule
!= NULL
))) {
2750 if (command
== NULL
) {
2754 * We provide a command line for the target. The line is a
2755 * "sccs get" command from default.mk.
2757 line
= maybe_append_prop(target
, line_prop
);
2759 if (sccs_time
> target
->stat
.time
) {
2761 * And only if the plain file is out of date do we
2762 * request execution of the command.
2764 line
->body
.line
.is_out_of_date
= true;
2765 if (debug_level
> 0) {
2766 (void) printf(gettext("%*sSccs getting %s because s. file is younger than source file\n"),
2772 line
->body
.line
.sccs_command
= true;
2773 line
->body
.line
.command_template
= sccs_get_rule
;
2774 if(!svr4
&& (!allrules_read
|| posix
)) {
2775 if((target
->prop
) &&
2776 (target
->prop
->body
.sccs
.file
) &&
2777 (target
->prop
->body
.sccs
.file
->string_mb
)) {
2778 if((strlen(target
->prop
->body
.sccs
.file
->string_mb
) ==
2779 strlen(target
->string_mb
) + 2) &&
2780 (target
->prop
->body
.sccs
.file
->string_mb
[0] == 's') &&
2781 (target
->prop
->body
.sccs
.file
->string_mb
[1] == '.')) {
2783 line
->body
.line
.command_template
= get_posix_rule
;
2787 line
->body
.line
.target
= target
;
2789 * Also make sure the rule is build with $* and $<
2792 line
->body
.line
.star
= NULL
;
2793 line
->body
.line
.less
= NULL
;
2794 line
->body
.line
.percent
= NULL
;
2797 return build_dont_know
;
2801 * read_directory_of_file(file)
2803 * Reads the directory the specified file lives in.
2806 * file The file we need to read dir for
2808 * Global variables used:
2809 * dot The Name ".", used as the default dir
2812 read_directory_of_file(register Name file
)
2815 Wstring
file_string(file
);
2816 wchar_t * wcb
= file_string
.get_string();
2817 wchar_t usr_include_buf
[MAXPATHLEN
];
2818 wchar_t usr_include_sys_buf
[MAXPATHLEN
];
2820 register Name directory
= dot
;
2821 register wchar_t *p
= (wchar_t *) wcsrchr(wcb
,
2823 register int length
= p
- wcb
;
2824 static Name usr_include
;
2825 static Name usr_include_sys
;
2827 if (usr_include
== NULL
) {
2828 MBSTOWCS(usr_include_buf
, "/usr/include");
2829 usr_include
= GETNAME(usr_include_buf
, FIND_LENGTH
);
2830 MBSTOWCS(usr_include_sys_buf
, "/usr/include/sys");
2831 usr_include_sys
= GETNAME(usr_include_sys_buf
, FIND_LENGTH
);
2835 * If the filename contains a "/" we have to extract the path
2836 * Else the path defaults to ".".
2840 * Check some popular directories first to possibly
2841 * save time. Compare string length first to gain speed.
2843 if ((usr_include
->hash
.length
== length
) &&
2844 IS_WEQUALN(usr_include_buf
,
2847 directory
= usr_include
;
2848 } else if ((usr_include_sys
->hash
.length
== length
) &&
2849 IS_WEQUALN(usr_include_sys_buf
,
2852 directory
= usr_include_sys
;
2854 directory
= GETNAME(wcb
, length
);
2857 (void) read_dir(directory
,
2864 * add_pattern_conditionals(target)
2866 * Scan the list of conditionals defined for pattern targets and add any
2867 * that match this target to its list of conditionals.
2870 * target The target we should add conditionals for
2872 * Global variables used:
2873 * conditionals The list of pattern conditionals
2876 add_pattern_conditionals(register Name target
)
2878 register Property conditional
;
2886 Wstring
wcb(target
);
2889 for (conditional
= get_prop(conditionals
->prop
, conditional_prop
);
2890 conditional
!= NULL
;
2891 conditional
= get_prop(conditional
->next
, conditional_prop
)) {
2892 wcb1
.init(conditional
->body
.conditional
.target
);
2893 pattern
= wcb1
.get_string();
2894 if (pattern
[1] != 0) {
2895 percent
= (wchar_t *) wcschr(pattern
, (int) percent_char
);
2896 /* Check for possible buffer under-read */
2897 if ((length
= wcb
.length()-wcslen(percent
+1)) <= 0) {
2900 if (!wcb
.equaln(pattern
, percent
-pattern
) ||
2901 !IS_WEQUAL(wcb
.get_string(length
), percent
+1)) {
2905 for (previous
= &target
->prop
;
2907 previous
= &(*previous
)->next
) {
2908 if (((*previous
)->type
== conditional_prop
) &&
2909 ((*previous
)->body
.conditional
.sequence
>
2910 conditional
->body
.conditional
.sequence
)) {
2914 if (*previous
== NULL
) {
2915 new_prop
= append_prop(target
, conditional_prop
);
2918 new_prop
= append_prop(&dummy
, conditional_prop
);
2919 new_prop
->next
= *previous
;
2920 *previous
= new_prop
;
2922 target
->conditional_cnt
++;
2923 new_prop
->body
.conditional
= conditional
->body
.conditional
;
2928 * set_locals(target, old_locals)
2930 * Sets any conditional macros for the target.
2931 * Each target carries a possibly empty set of conditional properties.
2934 * target The target to set conditional macros for
2935 * old_locals Space to store old values in
2937 * Global variables used:
2938 * debug_level Should we trace activity?
2939 * is_conditional We need to preserve this value
2940 * recursion_level Used for tracing
2943 set_locals(register Name target
, register Property old_locals
)
2945 register Property conditional
;
2947 register Boolean saved_conditional_macro_used
;
2951 if (target
->dont_activate_cond_values
) {
2955 saved_conditional_macro_used
= conditional_macro_used
;
2957 /* Scan the list of conditional properties and apply each one */
2958 for (conditional
= get_prop(target
->prop
, conditional_prop
), i
= 0;
2959 conditional
!= NULL
;
2960 conditional
= get_prop(conditional
->next
, conditional_prop
),
2962 /* Save the old value */
2963 old_locals
[i
].body
.macro
=
2964 maybe_append_prop(conditional
->body
.conditional
.name
,
2965 macro_prop
)->body
.macro
;
2966 if (debug_level
> 1) {
2967 (void) printf(gettext("%*sActivating conditional value: "),
2971 /* Set the conditional value. Macros are expanded when the */
2972 /* macro is refd as usual */
2973 if ((conditional
->body
.conditional
.name
!= virtual_root
) ||
2974 (conditional
->body
.conditional
.value
!= virtual_root
)) {
2975 (void) SETVAR(conditional
->body
.conditional
.name
,
2976 conditional
->body
.conditional
.value
,
2977 (Boolean
) conditional
->body
.conditional
.append
);
2979 cond_name
= ALLOC(Chain
);
2980 cond_name
->name
= conditional
->body
.conditional
.name
;
2982 /* Put this target on the front of the chain of conditional targets */
2983 cond_chain
= ALLOC(Chain
);
2984 cond_chain
->name
= target
;
2985 cond_chain
->next
= conditional_targets
;
2986 conditional_targets
= cond_chain
;
2987 conditional_macro_used
= saved_conditional_macro_used
;
2991 * reset_locals(target, old_locals, conditional, index)
2993 * Removes any conditional macros for the target.
2996 * target The target we are retoring values for
2997 * old_locals The values to restore
2998 * conditional The first conditional block for the target
2999 * index into the old_locals vector
3000 * Global variables used:
3001 * debug_level Should we trace activities?
3002 * recursion_level Used for tracing
3005 reset_locals(register Name target
, register Property old_locals
, register Property conditional
, register int index
)
3007 register Property this_conditional
;
3010 if (target
->dont_activate_cond_values
) {
3014 /* Scan the list of conditional properties and restore the old value */
3015 /* to each one Reverse the order relative to when we assigned macros */
3016 this_conditional
= get_prop(conditional
->next
, conditional_prop
);
3017 if (this_conditional
!= NULL
) {
3018 reset_locals(target
, old_locals
, this_conditional
, index
+1);
3020 /* Remove conditional target from chain */
3021 if (conditional_targets
== NULL
||
3022 conditional_targets
->name
!= target
) {
3023 warning(gettext("Internal error: reset target not at head of condtional_targets chain"));
3025 cond_chain
= conditional_targets
->next
;
3026 retmem_mb((caddr_t
) conditional_targets
);
3027 conditional_targets
= cond_chain
;
3030 get_prop(conditional
->body
.conditional
.name
->prop
,
3031 macro_prop
)->body
.macro
= old_locals
[index
].body
.macro
;
3032 if (conditional
->body
.conditional
.name
== virtual_root
) {
3033 (void) SETVAR(virtual_root
, getvar(virtual_root
), false);
3035 if (debug_level
> 1) {
3036 if (old_locals
[index
].body
.macro
.value
!= NULL
) {
3037 (void) printf(gettext("%*sdeactivating conditional value: %s= %s\n"),
3040 conditional
->body
.conditional
.name
->
3042 old_locals
[index
].body
.macro
.value
->
3045 (void) printf(gettext("%*sdeactivating conditional value: %s =\n"),
3048 conditional
->body
.conditional
.name
->
3055 * check_auto_dependencies(target, auto_count, automatics)
3057 * Returns true if the target now has a dependency
3058 * it didn't previously have (saved on automatics).
3061 * true if new dependency found
3064 * target Target we check
3065 * auto_count Number of old automatic vars
3066 * automatics Saved old automatics
3068 * Global variables used:
3069 * keep_state Indicates that .KEEP_STATE is on
3072 check_auto_dependencies(Name target
, int auto_count
, Name
*automatics
)
3077 Dependency dependency
;
3080 if ((line
= get_prop(target
->prop
, line_prop
)) == NULL
) {
3083 /* Go thru new list of automatic depes */
3084 for (dependency
= line
->body
.line
.dependencies
;
3086 dependency
= dependency
->next
) {
3087 /* And make sure that each one existed before we */
3088 /* built the target */
3089 if (dependency
->automatic
&& !dependency
->stale
) {
3090 for (n
= auto_count
, p
= automatics
;
3093 if (*p
++ == dependency
->name
) {
3094 /* If we can find it on the */
3095 /* saved list of autos we */
3100 /* But if we scan over the old list */
3101 /* of auto. without finding it it is */
3102 /* new and we must check it */
3114 // Recursively delete each of the Chain struct on the chain.
3117 delete_query_chain(Chain ch
)
3122 delete_query_chain(ch
->next
);
3123 retmem_mb((char *) ch
);
3128 target_can_be_built(register Name target
) {
3129 Doname result
= build_dont_know
;
3130 Name true_target
= target
;
3133 if (target
== wait_name
) {
3137 * If the target is a constructed one for a "::" target,
3138 * we need to consider that.
3140 if (target
->has_target_prop
) {
3141 true_target
= get_prop(target
->prop
,
3142 target_prop
)->body
.target
.target
;
3145 (void) exists(true_target
);
3147 if (true_target
->state
== build_running
) {
3148 return(build_running
);
3150 if (true_target
->stat
.time
!= file_doesnt_exist
) {
3154 /* get line property for the target */
3155 line
= get_prop(true_target
->prop
, line_prop
);
3157 /* first check for explicit rule */
3158 if (line
!= NULL
&& line
->body
.line
.command_template
!= NULL
) {
3161 /* try to find pattern rule */
3162 if (result
== build_dont_know
) {
3163 result
= find_percent_rule(target
, NULL
, false);
3166 /* try to find double suffix rule */
3167 if (result
== build_dont_know
) {
3168 if (target
->is_member
) {
3169 Property member
= get_prop(target
->prop
, member_prop
);
3170 if (member
!= NULL
&& member
->body
.member
.member
!= NULL
) {
3171 result
= find_ar_suffix_rule(target
, member
->body
.member
.member
, NULL
, false);
3173 result
= find_double_suffix_rule(target
, NULL
, false);
3176 result
= find_double_suffix_rule(target
, NULL
, false);
3180 /* try to find suffix rule */
3181 if ((result
== build_dont_know
) && second_pass
) {
3182 result
= find_suffix_rule(target
, target
, empty_name
, NULL
, false);
3185 /* check for sccs */
3186 if (result
== build_dont_know
) {
3187 result
= sccs_get(target
, NULL
);
3190 /* try to find dyn target */
3191 if (result
== build_dont_know
) {
3192 Name dtarg
= find_dyntarget(target
);
3193 if (dtarg
!= NULL
) {
3194 result
= target_can_be_built(dtarg
);
3198 /* check whether target was mentioned in makefile */
3199 if (result
== build_dont_know
) {
3200 if (target
->colons
!= no_colon
) {