GNU Make: using% in a template template macro

I am trying to create a pattern rule that allows me to use % in a macro call and I am not getting the expected results.

Template Rule:

 %.o: %.cpp $(%_H) g++ -o $@ $(FLAGS) -c $< 

The problem is with $ (% _ H)

For some reason, % does not apply to what it is defined for.

When I print the list of dependencies ($^) , only the source file is printed.

I have a very clean way to configure my dependencies that I would like to use:

 # Header Dependencies per object Geometry_H:=Geometry.h $(Error_H) Enemy_H:=Enemy.h $(Geometry_H) $(Error_H) Surface_H:=Surface.h $(Geometry_H) Player_H:=Player.h $(Geometry_H) $(Surface_H) SDLWindow_H:=SDLWindow.h $(Surface_H) $(Error_H) Path_H:=Path.h $(Geometry_H) $(Error_H) Territory_H:=Territory.h $(Geometry_H) Board_H:=Board.h $(Territory_H) $(Geometry_H) $(Player_H) $(Path_H) $(Enemy_H) $(Error_H) Error_H:=Error.h Diminisher_H:=Diminisher.h $(SDLWindow_H) $(Geometry_H) $(Surface_H) $(Board_H) $(Error_H) Main_H:=$(Diminisher_H) 

Another person suggested that I modify these variables into dependency lists.

those. Main_H: = $ (Diminisher_H)

becomes Main.o: $ (Diminisher_H)

This is a good solution, it works. However, the problem still remains that $(%_H) is somehow invalid.

I would like to know how (if possible) to make this a valid expression.

I tried $( $%_H ) , $( $(%)_H ) , $( $(value %)_H ) and many others. It seems that % just loses its meaning when calling a macro.

Can't use % in a macro call?

+4
source share
1 answer

Use the secondary extension :

 .SECONDEXPANSION: %.o: %.cpp $$($$*_H) g++ -o $@ $(FLAGS) -c $< 

Or (IMO, better) use autogeneration of dependency:

+4
source

Source: https://habr.com/ru/post/1415784/


All Articles