Makefile Helper Function Not Expanding As Expected When Called

  Kiến thức lập trình

Problem Statement

I have a makefile that I’m attempting to make a helper function for. I want to be able to call the defined helper function but when I’m looking at the text expansion for the targets they’re coming out as an empty string.

I’m looking to figure out where I’m messing up my Makefile syntax to cause the empty expansion.

Makefile

# Helper function to instantiate templates.
define render_template
$(eval $@_HOST_URI = "[email protected]:company-name")
$(eval $@_TEMPLATE_NAME = $(1))
$(eval $@_TEMPLATE_DIR = $(1)s)
$(eval $@_NAME = $(2))
cd ${$@_TEMPLATE_DIR}; cookiecutter --no-input [email protected]:company-name/terraform-${$@_TEMPLATE_NAME}.git ${$@_TEMPLATE_NAME}_name=${$@_NAME};
endef

# TODO: Add steps to build a Python3 venv and use it to build the local template.
.PHONY: new-service
new-service: ## Accesses Docker Shell (advanced)
        if [ -z "$(SERVICE_NAME)" ]; then 
            echo "SERVICE_NAME is a required parameter. Example usage 'make new SERVICE_NAME=vpc-networking'"; 
        else 
            $(call render_template,"service",${SERVICE_NAME}) 
        fi

Error Output

% make new-service SERVICE_NAME=example
if [ -z "example" ]; then 
            echo "SERVICE_NAME is a required parameter. Example usage 'make new SERVICE_NAME=vpc-networking'"; 
        else 
             
        fi
/bin/bash: -c: line 0: syntax error near unexpected token `fi'
/bin/bash: -c: line 0: `if [ -z "example" ]; then     echo "SERVICE_NAME is a required parameter. Example usage 'make new SERVICE_NAME=vpc-networking'"; else      fi'
make: *** [new-service] Error 2

LEAVE A COMMENT