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

KeyC0de

I want to add another option to the CFLAGS make variable, depending on the result of a shell command that i want to execute outside of a recipe in my "configuration" section of the makefile. This is what i have come up with:

GCC_VERSION := $(shell gcc -dumpversion); \
if [[ ${GCC_VERSION} > 5.0 ]] ; then \
    CFLAGS += -D _POSIX_C_SOURCE=199309L; \
fi

At first i execute the command with the shell make function as you see above. If i execute the above it doesn't add this define flag. I intentionally do this on linux with GCC Version 5.4.0. I believe this is wrong because then i have to create a new shell to execute the conditional statement. In that new shell though the GCC_VERSION variable will not exist. I could be wrong though.

If i do like this then (all in one shell):

$(shell GCC_VERSION=$(gcc -dumpversion); \
if [[ ${GCC_VERSION} > 5.0 ]] ; then \
    CFLAGS += -D _POSIX_C_SOURCE=199309L; \
fi)

i get error:

*** recipe commences before first target.  Stop.

Yeah, very confusing.

If someone could help i would appreciate it. Thanks.

meuh

There are many solutions, including this one. In your Makefile use

VERSION5 := $(shell \
 GCC_VERSION=$$(gcc -dumpversion); \
 [[ $$GCC_VERSION > 5.0 ]]; \
 echo $$? )

ifeq (${VERSION5}, 0)
  CFLAGS += -D _POSIX_C_SOURCE=199309L
endif

Note in particular, that you need to use $$ for every $ in your shell script. This shell echos 0 if the string comparision with 5.0 is true, else 1, and this is saved in make variable VERSION5.

Then the ifeq test in the Makefile compares the variable with 0 and if it matches edits the CFLAGS variable.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to concatenate two command in shell

From Dev

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

From Dev

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

From Dev

How to save command result in variable in Jenkins shell build step

From Dev

What version of GCC is used by the make command?

From Dev

Shell: save ssh command result to local variable

From Dev

How to check version of GNU make in mac terminal?

From Dev

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

From Dev

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

From Dev

How to output a shell command into a variable?

From Dev

How to pipe the stdout of a command, depending on the result of the exit code

From Dev

How is automatic dependency generation with GCC and GNU Make useful?

From Dev

GNU make - how to get complete command line used to invoke make

From Dev

GNU Make gcc, order of options

From Dev

how to assign a query result to a shell variable

From Dev

Why am I not saving the result of the shell command into my variable?

From Dev

GNU screen status bar - how to make it display shell session names?

From Dev

Concatenate the result of a query into a variable in PostgreSQL

From Dev

Make foreach create variable names depending on input? How to use extract()

From Dev

How to make a variable that changes depending on user input in batch

From Dev

how to store result of tail command in variable?

From Dev

How to pass the variable of the result of find command to dd

From Dev

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

From Dev

Run a sed command depending on a variable

From Dev

How to execute sh command set in shell variable?

From Dev

How to use shell script variable in mv command

From Dev

How to assign a variable the output of a shell command in Tupfile?

From Dev

How to pass variable number of parameters to a shell command?

From Dev

how to set an expect variable with output of shell command

Related Related

  1. 1

    How to concatenate two command in shell

  2. 2

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

  3. 3

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

  4. 4

    How to save command result in variable in Jenkins shell build step

  5. 5

    What version of GCC is used by the make command?

  6. 6

    Shell: save ssh command result to local variable

  7. 7

    How to check version of GNU make in mac terminal?

  8. 8

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

  9. 9

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

  10. 10

    How to output a shell command into a variable?

  11. 11

    How to pipe the stdout of a command, depending on the result of the exit code

  12. 12

    How is automatic dependency generation with GCC and GNU Make useful?

  13. 13

    GNU make - how to get complete command line used to invoke make

  14. 14

    GNU Make gcc, order of options

  15. 15

    how to assign a query result to a shell variable

  16. 16

    Why am I not saving the result of the shell command into my variable?

  17. 17

    GNU screen status bar - how to make it display shell session names?

  18. 18

    Concatenate the result of a query into a variable in PostgreSQL

  19. 19

    Make foreach create variable names depending on input? How to use extract()

  20. 20

    How to make a variable that changes depending on user input in batch

  21. 21

    how to store result of tail command in variable?

  22. 22

    How to pass the variable of the result of find command to dd

  23. 23

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

  24. 24

    Run a sed command depending on a variable

  25. 25

    How to execute sh command set in shell variable?

  26. 26

    How to use shell script variable in mv command

  27. 27

    How to assign a variable the output of a shell command in Tupfile?

  28. 28

    How to pass variable number of parameters to a shell command?

  29. 29

    how to set an expect variable with output of shell command

HotTag

Archive