Run a command in GNU and BSD Makefile and store the result into a variable

Dereckson

I would like to execute a command in a Makefile, store the result to a variable and reuse the result later.

In BSD Makefile, I can use the != operator:

PASSWORD != openssl rand -base64 48

In GNU Makefile, I can use the shell function:

PASSWORD := $(shell openssl rand -base64 48)

Is there a way to write this in such a way this is compatible with the two make?


Expected output

In both case, result of the command is assigned to PASSWORD, so I can reuse the same PASSWORD value in the Makefile:

quux:
    @echo $(PASSWORD)
    @echo $(PASSWORD)

If I run make quux, this will output twice the same password.

For example:

$ gmake quux
Y0ZrQQqLF9JK98x9UiIwWwcCN2Cq1wNqzph3ShG1RK0NeqbxWn6p4XB5zgHvfnbY
Y0ZrQQqLF9JK98x9UiIwWwcCN2Cq1wNqzph3ShG1RK0NeqbxWn6p4XB5zgHvfnbY

This is different than to use the backtick operator. In such cases, compatible with the two make, it will run the command each time.

MadScientist

In GNU make 4.0, the BSD operator != has been added for compatibility. For versions of GNU make prior to that, you're out of luck. You'll have to use the "poor man's" method, which is a recursive make invocation.

Be very careful because the BSD operator and the GNU make $(shell ...) function have slightly different semantics. In your specific situation you'll not notice any difference because the output from the shell command doesn't contain any variable references (no $).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Run a command in GNU and BSD Makefile and store the result into a variable

From Dev

Store the result of a command in a variable

From Dev

Store Result of SVN Command in Variable

From Dev

Setting Makefile variable to result of command in rule

From Dev

Put command result in variable within makefile target

From Dev

store a result of a command into a variable using csh

From Dev

how to store result of tail command in variable?

From Dev

Get the result of a WMIC command and store it in a variable

From Dev

store a result of a command into a variable using csh

From Dev

Why does this BSD grep result differ from GNU grep?

From Dev

Why does this BSD grep result differ from GNU grep?

From Dev

Run makefile with command in order

From Dev

Why GNU find -execdir command behave differently than BSD find?

From Dev

how to make my sed command work in GNU works in BSD

From Dev

Shell script -- how to store curl command WITH variables result into another variable?

From Dev

GNU Make - Set MAKEFILE variable from shell command output within a rule/target

From Dev

Store column result in variable

From Dev

Store function result into variable

From Dev

store into variable a sudo result

From Dev

Store function result into variable

From Dev

GNU make - How to concatenate to variable depending on shell command result (GCC version)?

From Java

What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?

From Dev

Variable assignment issue in multiline macro in GNU Makefile

From Dev

Assign result of command in a variable

From Dev

Cannot store result into variable SQL

From Dev

Store the assert failure result in a variable

From Dev

Store the result of a Dynamic Query in a variable

From Dev

Store into variable result of function VBA

From Dev

Store cmd Find result to a variable

Related Related

  1. 1

    Run a command in GNU and BSD Makefile and store the result into a variable

  2. 2

    Store the result of a command in a variable

  3. 3

    Store Result of SVN Command in Variable

  4. 4

    Setting Makefile variable to result of command in rule

  5. 5

    Put command result in variable within makefile target

  6. 6

    store a result of a command into a variable using csh

  7. 7

    how to store result of tail command in variable?

  8. 8

    Get the result of a WMIC command and store it in a variable

  9. 9

    store a result of a command into a variable using csh

  10. 10

    Why does this BSD grep result differ from GNU grep?

  11. 11

    Why does this BSD grep result differ from GNU grep?

  12. 12

    Run makefile with command in order

  13. 13

    Why GNU find -execdir command behave differently than BSD find?

  14. 14

    how to make my sed command work in GNU works in BSD

  15. 15

    Shell script -- how to store curl command WITH variables result into another variable?

  16. 16

    GNU Make - Set MAKEFILE variable from shell command output within a rule/target

  17. 17

    Store column result in variable

  18. 18

    Store function result into variable

  19. 19

    store into variable a sudo result

  20. 20

    Store function result into variable

  21. 21

    GNU make - How to concatenate to variable depending on shell command result (GCC version)?

  22. 22

    What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?

  23. 23

    Variable assignment issue in multiline macro in GNU Makefile

  24. 24

    Assign result of command in a variable

  25. 25

    Cannot store result into variable SQL

  26. 26

    Store the assert failure result in a variable

  27. 27

    Store the result of a Dynamic Query in a variable

  28. 28

    Store into variable result of function VBA

  29. 29

    Store cmd Find result to a variable

HotTag

Archive