I've tried different ideas for this but haven't been successful yet. Hence this post.
Some background: I am trying to decipher a Makefile that might include variables from a separate file. I've managed to read all the variables in Makefile and also its includes successfully into a python dictionary. But now I find that each of the values essentially reference other variables that are part of the dictionary. What I want to do is to unroll all the values in the dictionary to have text that are independent of other key/value pairs. This definitely involves recursion (IMHO) but I am very interested in hearing any other suggestions.
Note that not all variables might have a value associated with it. In this case, replace the key with a NULL string.
Now for some code to demonstrate what is said above:
Let a list of key,value pair be
*A = -L${F} ${B} ${D},
*B = -L/myhome,
*F = /usr/lib
I want to write a python script (possibly with regex) to recursively replace the values matching '${XXX}' with the corresponding key until there are no more values available that match the prescribed pattern (i.e., everything is unrolled). Since D doesn't have a value associated with it, I want the value of A to eventually be (for example)
*A = -L/usr/lib -L/myhome
Thanks in advance. Any help would be much appreciated.