CaF2s Webpage

I'm testing NeoCities

The badass tutorial for creating makefiles!

Tutorial 7: Communicating with bash and modifying variables during run time

Now its time to get deep. In this tutorial we just need the makefile.

#Time to get advanced

RES1 = $(shell VAR="Hello World!"; echo $$VAR | grep -Po "He[^\ ]+")

test1:
	echo $(RES1)

test2:
	echo $(RES2)

test3: 
	$(eval RES2 = $(RES1) Globe!)
	echo $(RES2)

How does it work?

The variable RES1 will get the result from the function shell. The function shell will do a shell-command and then return the output from stdout. If you simply do - $(shell echo hello) then it will return hello.

In this case RES1 will be assigned Hello, so if you run make test1, then it should print Hello.

Note:If you have problem understanding how the shell-command: VAR="Hello world"; echo $$VAR | grep -o "Hello" works then i would suggest you to read a shell-script tutorial.

Modifying variables during run-time

If you now try to run test2 (make test2), then you probably wont see any result what so ever.

Then if you run test3 (make test3) it will print Hello World!, as you can see in the target test3 there is the line with: $(eval RES2 = $(RES1) World!). The eval function will be executed during runtime.

See also:

Last modified: 04 April 2017 17:57:32. | CaF2 © (All rights reserved)