Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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_Makefile_Gnu Make - Fatal编程技术网

带有循环和多个条件的Makefile

带有循环和多个条件的Makefile,makefile,gnu-make,Makefile,Gnu Make,我正在尝试创建一个Makefile,以下是我到目前为止得到的: all : for var in 1 2 3 4 5 6 7 8; do \ ifneq ("$(wildcard user0$(var).Z)","") \ //need to add something echo "GNU sort does not exist! Exiting..."; \ else \ //s

我正在尝试创建一个Makefile,以下是我到目前为止得到的:

all : 
    for var in 1 2 3 4 5 6 7 8; do \
        ifneq ("$(wildcard user0$(var).Z)","") \
            //need to add something 
            echo "GNU sort does not exist! Exiting..."; \
        else \
            //some command \
        endif \
    done
目录中的所有文件都命名为user01.x、user01.Y等。 我希望“makeall”具有这样的功能:首先,如果当前目录中不存在这样的user0$(var).Z)文件,则打印错误消息,但它会给出这样的错误:

for var in 1 2 3 4 5 6 7 8; do \
        ifneq ("","") \
            echo "GNU sort does not exist! Exiting..."; \
        else \
            //some command \
        endif \
    done
/bin/sh: 2: Syntax error: word unexpected (expecting ")")
make: *** [all] Error 2

我不知道为什么通配符不起作用。此外,我想添加另一个条件,以便在.Z文件比.X和.Y文件旧时运行(某些命令)。(所有文件都在当前目录中)我知道,如果我事先知道所有文件名,那就没什么大不了的了,我可以在Makefile中硬编码所有文件名,但是我应该如何在循环中这样做(循环中已经有一个关于.Z文件是否存在的条件)?

您可以使用一个函数进行测试,并在其中执行您想要的操作:

list_val=$(shell seq 1 8) 
define test_user
ifeq ("$(wildcard user0$(1).Z)","")
    echo "No file user0$(1).Z";
else
    echo "File user0$(1).Z exists !";
endif
endef
all:
    $(foreach var,$(list_val),$(eval $(call test_user,$(var))))

到目前为止,您所描述的可以这样做:

Z_FILES := $(patsubst %,user0%.Z, 1 2 3 4 5 6 7 8 9)

all: $(Z_FILES)

$(Z_FILES):
    @echo $@ does not exist

在操作中使用shell条件语法。这里混合了bash和makefile,这就是为什么会出现错误。让我给你提个建议,你的问题不仅不包含C代码,甚至你正在展示的makefile摘录都与C有关。如果存在
user01.Z
,你想做什么?