Makefile调用带注释字符的sed时出错 [英] Error in Makefile calling sed with comment character
问题描述
我正在尝试构建 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:
-
cp /usr/local/src/lua-5.1.3/src/llex.c .
- 手动编辑llex.c,以将
#include "proxy.c"
行添加到以void luaX_next
开头的行之前(对于我来说是446行). - 现在运行
make
,它将成功.
cp /usr/local/src/lua-5.1.3/src/llex.c .
- Hand-edit llex.c to add the line
#include "proxy.c"
before the line starting withvoid luaX_next
(line 446 for me). - 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屋!