Else command not working inside in make file

huangapple go评论58阅读模式
英文:

Else command not working inside in make file

问题

I have this make file that checks if a file is present in a folder or not. If not that it should download that file from JFrog artifactory using the curl command. if the file exists then it should not do anything.

si_file := ms_auix
extract_path := C:\si
si_url := https://artifact.com/artifactory/aksi/SI/$(si_file).zip

.PHONY: download-si
download-si:
    @echo "Checking for $(si_file) in $(extract_path)..."
    @if not exist "$(extract_path)$(si_file)" (
        echo "Downloading $(si_file) from Artifactory...";
        curl -u te14:cmVXluNkVJ -O "$(si_url)";
    ) else (
        echo "$(si_file) already exists in $(extract_path).";
    )

When i run this code the package is downloaded from the artifactory but the code still runs the else loop and i get this in the terminal
) else ( process_begin: CreateProcess(NULL, ) else (, ...) failed. make (e=2): The system cannot find the file specified. make: *** [Makefile:11: download-si] Error 2 the if loop is working fine but why does it executes the else loop regardless. Can someone guide me here what is wrong with code?

英文:

I have this make file that checks if a file is present in a folder or not. If not that it should download that file from JFrog artifactory using the curl command. if the file exists then it should not do anything.

si_file := ms_auix
extract_path := C:\si
si_url := https://artifact.com/artifactory/aksi/SI/$(si_file).zip

.PHONY: download-si
download-si:
	@echo "Checking for $(si_file) in $(extract_path)..."
	@if not exist "$(extract_path)$(si_file)" (
		echo "Downloading $(si_file) from Artifactory...";
		curl -u te14:cmVXluNkVJ -O "$(si_url)";
	) else (
		echo "$(si_file) already exists in $(extract_path).";
	)

When i run this code the package is downloaded from the artifactory but the code still runs the else loop and i get this in the terminal

) else (
process_begin: CreateProcess(NULL, ) else (, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [Makefile:11: download-si] Error 2

the if loop is working fine but why does it executes the else loop regardless. Can someone guide me here what is wrong with code?

答案1

得分: 1

Here is the translated content without the code:

For multi-line commands you need to escape the newlines:

A possible culprit here being the lack of .zip file ending when checking for file existence.

HOWEVER, I can't get the parenthesis working, so I'll instead propose order-only dependencies to handle the conditional instead (albeit omitting "already exists"-message, also ignoring the .zip-file aspect):

Alternatively you can put the section in a script (with proper arguments):

英文:

For multi-line commands you need to escape the newlines:

    @if not exist "$(extract_path)$(si_file)" ( \
        echo "Downloading $(si_file) from Artifactory..."; \
        curl -u te14:cmVXluNkVJ -O "$(si_url)"; \
    ) else ( \
        echo "$(si_file) already exists in $(extract_path)."; \
    )

A possible culprit here being the lack of .zip file ending when checking for file existence.

HOWEVER, I can't get the parenthesis working, so I'll instead propose order-only dependencies to handle the conditional instead (albeit omitting "already exists"-message, also ignoring the .zip-file aspect):

# the target file
SI_FILE := $(extract_path)\$(si_file)

# order-only dependency - create if not existing
download-si: | $(SI_FILE)

# target specific variable (repeat for other files)
$(SI_FILE): SI_URL := https://artifact.com/artifactory/aksi/SI/$(SI_FILE).zip

# rule for downloading the file (optionally add other files)
$(SI_FILE):
    echo "Downloading $@ from Artifactory..."
    curl -u te14:cmVXluNkVJ -O "$(SI_URL)"

Alternatively you can put the section in a script (with proper arguments):

download-si:
    .\download-si.bat

答案2

得分: 0

si_file := ms_auix
extract_path := C:\si
si_url := https://artifact.com/artifactory/aksi/SI/$(si_file).zip

$(extract_path)$(sip_version):
echo "Downloading $(si_file) from Artifactory..."
curl -u te14:cmVXluNkVJ -O "$(si_url)"

.PHONY: download-si
download-si:
echo "$(si_file) already exists in $(extract_path)."

英文:

found the solution:-

si_file := ms_auix
extract_path := C:\si
si_url := https://artifact.com/artifactory/aksi/SI/$(si_file).zip

$(extract_path)$(sip_version):
    echo "Downloading $(si_file) from Artifactory..." 
    curl -u te14:cmVXluNkVJ -O "$(si_url)"   

.PHONY: download-si
download-si:
    echo "$(si_file) already exists in $(extract_path)."

huangapple
  • 本文由 发表于 2023年3月31日 02:27:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75891755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定