SH_PROGRAM=xxx yyy SHSRC=xxx.sh yyy.sh .PHONY: xxx.sh yyy.sh yyy: PKGIFY_MODE=644 PKGIFY=echo $@ comes from $< all: ${SH_PROGRAM} echo all done indices=$(shell (( i= 0 )); while (( i < $(words ${${1}}) )); do (( i += 1 )); l="$${l} $$i"; done; echo $${l}) define pkgify_rule $(1): PKGIFY_MODE?=+x ${1}: ${2} $${PKGIFY} @chmod $${PKGIFY_MODE} $$@ endef # if the blank line above the endef is removed the target assignment becomes # part of the chmod line define pkgify_template $(foreach idx,$(call indices,${1}), $(call pkgify_rule,$(word ${idx},${$(1)}),$(word ${idx},${${2}}))) endef # this ifdef works 3.81 but not 3.80. if function works 3.80 and 3.81 ifdef SH_PROGRAM $(eval $(call pkgify_template,SH_PROGRAM,SHSRC)) endif xyz: xyz.sh echo xyz