Makefile调用带注释字符的sed时出错 [英] Error in Makefile calling sed with comment character

查看:108
本文介绍了Makefile调用带注释字符的sed时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建 lstrip ,一个Lua实用程序,用于压缩Lua源代码.我正在尝试在OS X v10.1.0.3上构建Lua 5.1.3.

I'm trying to build lstrip, a Lua utility for compressing Lua source code. I'm trying to build for Lua 5.1.3 on OS X v10.10.3.

我已经下载并提取了Lua 5.1.3源代码,并修改了lstrip的Makefile以指向该目录.但是,当我运行make时,会得到以下输出:

I have downloaded and extracted the Lua 5.1.3 source code and modified the Makefile for lstrip to point to this directory. However, when I run make, I get this output:

cc -I/usr/local/src/lua-5.1.3/src -I/usr/local/src/lua-5.1.3/src -O2 -Wall -Wextra -O2    -c -o lstrip.o lstrip.c
lstrip.c:33:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char* argv[])
             ^
1 warning generated.
sed '/void luaX_next/i#include "proxy.c"' /usr/local/src/lua-5.1.3/src/llex.c > llex.c
sed: 1: "/void luaX_next/i#inclu ...": command i expects \ followed by text
make: *** [llex.c] Error 1

相关的Makefile命令如下所示:

This is what the relevant Makefile command looks like:

llex.c:
    sed '/void luaX_next/i#include "proxy.c"' $(LUASRC)/$@ > $@

认为,这是因为sed命令中的#被视为实际注释,但是我不确定.

I think that this is because the # in the sed command is being treated like an actual comment, but I'm not sure.

如何修复Makefile或手动运行步骤以构建lstrip?

How can I fix the Makefile, or manually run the steps, to get lstrip built?

紧随其后的是Makefile的完整副本:

Full copy of the Makefile follows, in case it matters:

# makefile for lstrip

# change these to reflect your Lua installation (Lua 5.1!)
LUA= /usr/local/src/lua-5.1.3
LUAINC= $(LUA)/src
LUALIB= $(LUA)/src
LUASRC= $(LUA)/src

# no need to change anything below here
CFLAGS= $(INCS) $(WARN) -O2 $G
WARN= -O2 -Wall -Wextra

INCS= -I$(LUAINC) -I$(LUASRC)
LIBS= -L$(LUALIB) -llua -lm

MYNAME= lstrip
MYLIB= $(MYNAME)
T= $(MYNAME)
OBJS= $(MYNAME).o llex.o
TEST= test.lua

all:    test

test:   $T
    $T $(TEST)

$T: $(OBJS)
    $(CC) -o $@ $(OBJS) $(LIBS)

llex.c:
    sed '/void luaX_next/i#include "proxy.c"' $(LUASRC)/$@ > $@

llex.o: proxy.c

clean:
    -rm -f $(OBJS) core core.* a.out $(MYNAME)

# eof


手工构建解决方案:


Hand-build solution:

  1. cp /usr/local/src/lua-5.1.3/src/llex.c .
  2. 手动编辑llex.c,以将#include "proxy.c"行添加到以void luaX_next开头的行之前(对于我来说是446行).
  3. 现在运行make,它将成功.
  1. cp /usr/local/src/lua-5.1.3/src/llex.c .
  2. Hand-edit llex.c to add the line #include "proxy.c" before the line starting with void luaX_next (line 446 for me).
  3. Now run make, which will succeed.

推荐答案

此行在Mac OS X和Linux中均有效:

This line works in Mac OS X and in Linux:

sed '/void luaX_next/{h;s/.*/#include "proxy.c"/;p;g;}' $(LUASRC)/$@ > $@

这篇关于Makefile调用带注释字符的sed时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆