Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Makefile 如何在另一个带循环的Make recipe中运行Make recipe?_Makefile - Fatal编程技术网

Makefile 如何在另一个带循环的Make recipe中运行Make recipe?

Makefile 如何在另一个带循环的Make recipe中运行Make recipe?,makefile,Makefile,我有一个Makefile,如下所示: run_experiment1: python some_file.py \ --data_file /somewhere/here \ --k ${k} run_all_experiments: for k in 1 2 3 4 5 ; do \ run_experiment1 k=$$k ; \ done 当我运行make run\

我有一个Makefile,如下所示:

run_experiment1:
    python some_file.py \
        --data_file /somewhere/here \
        --k ${k}

run_all_experiments:
    for k in 1 2 3 4 5 ; do \
        run_experiment1 k=$$k ; \
    done                        
当我运行
make run\u所有实验时
我得到:

for k in 1 2 3 4 5 ; do \
    run_experiment1 k= ; \
done
/bin/sh: 2: run_experiment1: not found
/bin/sh: 2: run_experiment1: not found
/bin/sh: 2: run_experiment1: not found
/bin/sh: 2: run_experiment1: not found
/bin/sh: 2: run_experiment1: not found
Makefile:84: recipe for target 'run_all_experiments' failed
make: *** [run_all_experiments] Error 127

我能立即注意到的是,
k
似乎没有像我预期的那样输入值,并且没有找到命令。我该如何着手解决这个问题?谢谢。

这确实是一个反模式。您希望构建您的
Makefile
,以便
make
自己负责

直接而明显的解决方法是,与错误消息提示一样,此处正确的命令是
make run\u experiment1

.PHONY: run_experiment1 run_all_experiments
run_experiment1:
    python some_file.py \
        --data_file /somewhere/here \
        --k $$k  # notice doubled dollar sign to escape it from make

run_all_experiments:
    for k in 1 2 3 4 5 ; do \
        $(MAKE) run_experiment1 k=$$k ; \
    done
然而,如上所述,我可能会将其重构为

.PHONY: run_experiment% run_all_experiments
run_experiment%:
    python some_file.py \
        --data_file /somewhere/here \
        --k $*

run_all_experiments: $(patsubst %,run_experiment%,1 2 3 4 5)

切向而言,应该声明与具有该名称的文件不对应的目标。

谢谢!只是好奇,你放在顶部的
.PHONY
是什么?更新了一个简短的解释和文档链接。