[riot-notifications] [RIOT-OS/RIOT] makefiles/utils/variables: add functions to help managing variables (#11664)

Gaƫtan Harter notifications at github.com
Fri Jun 7 19:12:27 CEST 2019


### Contribution description

Add functions to set variables and environment for targets
These functions should help replacing immediate evaluation and global 'export'

#### `target-export-variables`

`target-export-variables <target> <variables>` function that exports a list of variables for some targets

This should help exporting variables only for the required targets so not evaluate `shell` calls for nothing.
Like `make clean` does not need `CFLAGS` but if the variable is exported, it will evaluate which options are supported in `CFLAGS` anyway.

#### `memoized`

`VARIABLE = $(call memoized,VARIABLE,<value>)` function that allows only evaluating `value` when the variable is used like a normal deferred variable, but further evaluations will use an immediate value.

This should help not assigning `shell` commands results with `:=` to call it once only, as it result to evaluating even if not needed. Replacing by a direct `=` would result in the command be executed on each evaluation which is not wanted.
This gives the best of both worlds.

The implementation requires to repeat the variable name in the `call memoized` arguments.

### Testing procedure

Review and run the test in `tests/build_system_utils`.

```
make -C tests/build_system_utils/
```
If it executes without error, it is working.


You can also run it with `QUIET=0` to see the executed commands.

### Issues/PRs references

Tracking: remove harmful use of `export` in make and immediate evaluation #10850 
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/11664

-- Commit Summary --

  * makefiles/utils: function to export variables for a target
  * makefiles/utils: function to memoize a variable evaluation
  * makefiles/utils: include in Makefile.include

-- File Changes --

    M Makefile.include (3)
    A makefiles/utils/test-variables.mk (33)
    A makefiles/utils/variables.mk (33)
    M tests/build_system_utils/Makefile (10)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/11664.patch
https://github.com/RIOT-OS/RIOT/pull/11664.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11664
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190607/f8ffa3b3/attachment.html>


More information about the notifications mailing list