2012-10-25 2 views
1

비교적 간단한 Makefile을 작성하려고하지만 패턴을 사용하여 규칙을 가장 효과적으로 압축하는 방법을 모르겠습니다. %을 사용해 보았지만 어려움이있었습니다. 다음은 확장 된 형태의 Makefile입니다 :Makefile 패턴의 사용

all : ./115/combine_m115.root ./116/combine_m116.root ... ./180/combine_m180.root 

./115/combine_m115.root : ./115/comb.root 
    bash make_ASCLS.sh -l 115 comb.root 

./116/combine_m116.root : ./116/comb.root 
    bash make_ASCLS.sh -l 116 comb.root 
... 
./180/combine_m180.root : ./180/comb.root 
    bash make_ASCLS.sh -l 180 comb.root 

답변

2

불행하게도 우리는 Make에서 이것을 할 수있는 명확한 방법이 없습니다. 이 작업은 Make가 잘하지 않는 몇 가지 사항을 결합합니다.

Make는 와일드 카드를 매우 잘 처리 할 수 ​​없으므로 (정규 표현식) 전혀 ./%/combine_m%.root : ./%/comb.root 같은 구조는 작동하지 않습니다. 나는 우리가 얻을 수있는 가장 가까운 함께 생각 canned recipe :

define apply_script 
./$(1)/combine_m$(1).root : ./$(1)/comb.root 
    bash make_ASCLS.sh -l $(1) comb.root 
endef 

$(eval $(call apply_script,115)) 
$(eval $(call apply_script,116)) 
... 
$(eval $(call apply_script,180)) 

우리는 사물을 축소 할 수 있습니다 좀 더 이런 :

NUMBERS := 115 116 # ...180 

TARGS := $(foreach n, $(NUMBERS), ./$(n)/combine_m$(n).root) 

all : $(TARGS) 

... 

$(foreach n, $(NUMBERS), $(eval $(call apply_script,$(n)))) 

NUMBERS를 생성하는 방법이기도하지만 더 추악한 해킹 .