On 31.03.2020 12:30, Anthony PERARD wrote:
> The if_changed macro from Linux, in addition to check if any files
> needs an update, check if the command line has changed since the last
> invocation. The latter will force a rebuild if any options to the
> executable have changed.
> 
> if_changed_rule checks dependencies like if_changed, but execute
> rule_$(1) instead of cmd_$(1) when a target needs to be rebuilt. A rule_
> macro can call more than one cmd_ macro. One of the cmd_ macro in a
> rule need to be call using a macro that record the command line, so
> cmd_and_record is introduced. It is similar to cmd_and_fixup from
> Linux but without a call to fixdep which we don't have yet. (We will
> later replace cmd_and_record by cmd_and_fixup.)
> 
> Example of a rule_ macro:
> define rule_cc_o_c
>     $(call cmd_and_record,cc_o_o)
>     $(call cmd,objcopy)
> endef
> 
> This needs one of the call to use cmd_and_record, otherwise no .*.cmd
> file will be created, and the target will keep been rebuilt.
> 
> In order for if_changed to works correctly, we need to load the .%.cmd
> files that the macro generates, this is done by adding targets in to
> the $(targets) variable. We use intermediate_targets to add %.init.o
> dependency %.o to target since there aren't in obj-y.
> 
> We also add $(MAKECMDGOALS) to targets so that when running for
> example `make common/memory.i`, make will load the associated .%.cmd
> dependency file.
> 
> Beside the if_changed*, we import the machinery used for a "beautify
> output". The important one is when running make with V=2 which help to
> debug the makefiles by printing why a target is been rebuilt, via the
> $(echo-why) macro.
> 
> if_changed and if_changed_rule aren't used yet.
> 
> Most of this code is copied from Linux v5.4, including the
> documentation.
> 
> Signed-off-by: Anthony PERARD <anthony.per...@citrix.com>

Acked-by: Jan Beulich <jbeul...@suse.com>
with ...

> --- a/docs/misc/xen-makefiles/makefiles.rst
> +++ b/docs/misc/xen-makefiles/makefiles.rst
> @@ -85,3 +85,102 @@ Compilation flags
>  
>       CFLAGS-y specifies options for compiling with $(CC).
>       AFLAGS-y specifies assembler options.
> +
> +
> +Build system infrastructure
> +===========================
> +
> +This chapter describe some of the macro used when building Xen.
> +
> +Macros
> +------
> +
> +
> +    if_changed
> +     if_changed is the infrastructure used for the following commands.
> +
> +     Usage::
> +
> +             target: source(s) FORCE
> +                     $(call if_changed,ld/objcopy/...)
> +
> +     When the rule is evaluated, it is checked to see if any files
> +     need an update, or the command line has changed since the last
> +     invocation. The latter will force a rebuild if any options
> +     to the executable have changed.
> +     Any target that utilises if_changed must be listed in $(targets),
> +     otherwise the command line check will fail, and the target will
> +     always be built.
> +     if_changed may be used in conjunction with custom commands as
> +     defined in "Custom commands".
> +
> +     Note: It is a typical mistake to forget the FORCE prerequisite.
> +     Another common pitfall is that whitespace is sometimes
> +     significant; for instance, the below will fail (note the extra space
> +     after the comma)::
> +
> +             target: source(s) FORCE
> +
> +     **WRONG!**      $(call if_changed, ld/objcopy/...)
> +
> +        Note:
> +           if_changed should not be used more than once per target.
> +              It stores the executed command in a corresponding .cmd

... the odd mixing of tabs and spaces here taken care of (I didn't
check if there are more) and ...

> +
> +        file and multiple calls would result in overwrites and

... the apparently stray blank like here dropped.

Jan

Reply via email to