Automatic Variables: $@ and $< pair

note:

  • $@ is the file name of the target of the rule. Also it apply the pattern rules for multiple files.
  • $< is the name of the first prerequiste. It also follow the implicit rule.
  • $@ can not be used within the prerequisites list except secondary expansion feature is applied

case study

*.o: *.c dependency.h 
	gcc -c -o $@ $< -I. 

In this case, I define the rule that if each file suffixed with .c or named denpendency.h are updated. Here the new file with the same prefixed name but ended with .o should be generated by gcc with -I option acting on current directory. For coder in c, it should be known that gcc -c generate only object file (.o).

comments powered by Disqus