gnumake的等效命令(for ... do,if exist,del)

时间:2012-02-28 21:58:49

标签: shell makefile cygwin gnu-make

我正在转换一个makefile,因此它可以与gnu make一起使用。在另一个make程序中(找不到版本......),这部分被执行了:

#******************************************************************************
#                                Explicit Rules
#******************************************************************************
#
# This section contents the explicit rules to create the Virtual File system.
# This file system actualy contains the files used by the Web interface.
# 
#******************************************************************************
CFGFILE = $(WEBDST)/vfs.cfg

# Compiling vfsdata
$(OBJDIR)vfsdata.o : vfsdata.c
    @echo .
    @echo ::.   COMPILING1 : vfsdata.c
    @echo ::::.
    $(NOECHOC)$(CC) $(CFLAGS) $(DEBUGFLASG) $(subst \,/,$(VFSDIR))/vfsdata.c -o"$@"     $(INCLUDE)


# Dependance of vfsdata.c
vfsdata.c : $(addprefix $(WEBSRC)\,$(WEBGLOBAL)) $(addprefix $(WEBDST)\,$(WEBLOCAL))

# Make vfsdata.c writable
    @if exist $(VFSDIR)\vfsdata.c \
            chmod 777 $(VFSDIR)\vfsdata.c

#
# Generate the configuration file needed by vfscomp
#
    @echo [general] > $(CFGFILE)
    @echo vfs_root_dir  = $(WEBDST)>> $(CFGFILE)
    @echo vfs_data_file = $(VFSDIR)\vfsdata>> $(CFGFILE)
    @echo vfs_image_var = vfsimage>> $(CFGFILE)
    @echo far_pointer   = yes>> $(CFGFILE)
    @echo compress      = yes>> $(CFGFILE)

    @echo [file] >> $(CFGFILE)
    @echo $(sort $(WEBGLOBAL) $(WEBLOCAL)) | $(TR) -s " " "[\n*]" \
                                       | $(SED) "s/gif/gif -u/g" \
                                       >> $(CFGFILE)

#
# Create the local directory tree
#
    @for %%f in ($(subst /,\,$(dir $(WEBGLOBAL)))) do \
            if not exist $(WEBDST)\%%f mkdir $(WEBDST)\%%f

#
# Copy the WEB pages directory tree localy
#
    @for %%f in ($(subst /,\,$(WEBGLOBAL))) do \
            cp -rf $(WEBSRC)\%%f $(WEBDST)\%%f

#
# Generate the virtual file system
#
    @$(TOOLDIR)/vfscomp $(subst \,/,$(CFGFILE))

#
# Delete the local directory tree
#

#delete the directory recursively exept the one in the exclusion list

    @for %%f in ($(filter-out $(EXCLUSION), $(WEBDIR))) do \
            if exist $(WEBDST)\%%f \
                    rm -rf $(WEBDST)\%%f

#delete the remaining files.

    @for %%f in ($(subst /,\,$(WEBGLOBAL))) do \
            if exist $(WEBDST)\%%f \
                    rm -f $(WEBDST)\%%f

    @del $(subst /,\,$(CFGFILE))

当我构建代码时,我收到此错误

The syntax of the command is incorrect.

我觉得像@for @del @if这样的命令存在于gnu make中不支持(或使用不同语法)的命令。

我查看了在线GNU make文档,但是我没有找到与下面使用的命令类似的命令。

gnu make中是否有与makefile这部分中使用的命令相同的内容?

提前致谢!

编辑:

我删除了@并执行了make。我可以看到消息“命令的语法不正确”出现时:

if exist ../Pa/Filesys\vfsdata.c \
    chmod 777 ../Pa/Filesys\vfsdata.c
echo [general] > ../Pa/Filesys/vfs.cfg
echo vfs_root_dir  = ../Pa/Filesys>> ../Pa/Filesys/vfs.cfg
echo vfs_data_file = ../Pa/Filesys\vfsdata>> ../Pa/Filesys/vfs.cfg
echo vfs_image_var = vfsimage>> ../Pa/Filesys/vfs.cfg
echo far_pointer   = yes>> ../Pa/Filesys/vfs.cfg
echo compress      = yes>> ../Pa/Filesys/vfs.cfg
echo [file] >> ../Pa/Filesys/vfs.cfg
echo behavior/datasync/datasync.htc behavior/defered/defered.htc behavior/inputs/indirect.htc behavior/inputs/inputs.htc behavior/progress/progress.htc behavior/slider/slBottom.gif behavior/slider/slLeft.gif behavior/slider/slRight.gif behavior/slider/slTop.gif behavior/slider/slider.htc css/env.css html/cfgmain.html html/changepass.html html/diagpa.html html/firmhlp.html html/firmware.html html/home.html html/logpage.html html/progressend.html html/progressstart.html html/soundhlp.html html/support.html html/uplmain.html html/uploadstart.html img/button.gif img/logo.gif index.html xslt/activate.xslt xslt/main.xslt xslt/netmenu.xslt xslt/page.xslt xslt/page_func.xslt xslt/progress.xslt xslt/tlmenu.xslt xslt/upload.xslt | tr -s " " "[\n*]" \
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
                                       | sed "s/gif/gif -u/g" \
                                       >> ../Pa/Filesys/vfs.cfg
for %%f in (.\ css\ img\ img\ xslt\ xslt\ xslt\ xslt\ xslt\ xslt\ xslt\ xslt\ html\ html\ html\ html\ html\ html\ html\ html\ html\ html\ html\ html\ behavior\slider\ behavior\slider\ behavior\slider\ behavior\slider\ behavior\slider\ behavior\datasync\ behavior\progress\ behavior\inputs\ behavior\inputs\ behavior\defered\) do \

似乎语法错误就在某个地方

echo $(sort $(WEBGLOBAL) $(WEBLOCAL)) | $(TR) -s " " "[\n*]" \
                                       | $(SED) "s/gif/gif -u/g" \

2 个答案:

答案 0 :(得分:2)

要清楚,您提到的命令都不是make命令。它们都是shell命令。 Make正在调用shell并将这些命令传递给shell。正如其他地方所提到的,“@”是一个特殊的命令(由所有基于POSIX的make实现支持,包括GNU make),它告诉make在将命令发送到shell之前不打印命令(“@”被make删除在将命令发送到shell之前。)

其次,错误消息“命令的语法不正确”不是GNU make打印的任何内容。你要么改写错误信息而不是逐字重复(在寻求帮助时从来不是一个好主意),或者不是通过make而是通过调用的一些shell命令来打印消息。

答案 1 :(得分:0)

这需要几次迭代(特别是因为你没有给我们一个完整的样本)。

这里有两条规则;分开试试。

仅使用第一个命令尝试第二个规则:

# Make vfsdata.c writable
        @if exist $(VFSDIR)\vfsdata.c \
            chmod 777 $(VFSDIR)\vfsdata.c

让我们知道这些实验的结果,我们将从那里开始。

修改

有趣。我猜测tr与您的语法不一样,或者该命令的长度超出了Make或OS的某些限制。

尝试从命令行执行此操作:

echo behavior/datasync/datasync.htc behavior/defered/defered.htc behavior/inputs/indirect.htc behavior/inputs/inputs.htc behavior/progress/progress.htc behavior/slider/slBottom.gif behavior/slider/slLeft.gif behavior/slider/slRight.gif behavior/slider/slTop.gif behavior/slider/slider.htc css/env.css html/cfgmain.html html/changepass.html html/diagpa.html html/firmhlp.html html/firmware.html html/home.html html/logpage.html html/progressend.html html/progressstart.html html/soundhlp.html html/support.html html/uplmain.html html/uploadstart.html img/button.gif img/logo.gif index.html xslt/activate.xslt xslt/main.xslt xslt/netmenu.xslt xslt/page.xslt xslt/page_func.xslt xslt/progress.xslt xslt/tlmenu.xslt xslt/upload.xslt | tr -s " " "[\n*]" \
| sed "s/gif/gif -u/g" \
>> ../Pa/Filesys/vfs.cfg

如果成功,那就是制作长度限制;尝试使用较少的文件名。
如果失败,请尝试省略最后一个术语:

echo blah blah blah \
| sed "s/gif/gif -u/g"

告诉我们结果,我们将继续......