Pages

Saturday, December 19, 2020

How to use output from shell commands on a Makefile

The way I found the simplest: by using eval to declare a new variable.

Example:

test: test.c flags

    gcc -o test test.c $(FLAGS)

flags:

    $(eval FLAGS=$(shell echo "-lm"))

And test.c being:

#include <math.h>
#include <stdio.h>

int main() {
  printf("%.0f squared is: %.0f.\n", 2.0, pow(2, 2));
  return 0;

}

It correctly prints: 

 2 squared is: 4.




No comments:

Post a Comment