1

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.

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

This is what the relevant Makefile command looks like:

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

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

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


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. 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.
Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • 1
    I'm sorry about that. It does work in Linux, but not in Mac OS X. I'll try to fix it soon. Thanks for the report. – lhf Jul 01 '15 at 00:19

2 Answers2

2

You can find the answer in the sed manual, and it is in the Makefile lines

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

Some variable expansion takes place here: $(LUASRC) is expanded to the variable set above -> $(LUA)/src. Recurse as needed. $@ is replaced with the current target (llex.c)

So this recipe says: In order to obtain the target llex.c (which will be processed later through other recipes), apply a stream editing command to the file $LUASRC/llex.c and write it to llex.c.

The stream editing command is: look for text "void luaX_next", before printing it, insert line "#include "proxy.c"". Problem is, the command to do this is not "i" but "i\(newline)", which conflicts with a requirement of Makefiles that recipes must be on a single line.

I suspect that in order to fix your Makefile you need to use a different command than sed; awk can fit the bill although it's a bit more complex.

  • Interesting. I can't +1 this without verification; further, I'd be surprised if this is the problem, since I'm certain that I was able to successfully build `lstrip` in the past, and further I do not think that (seasoned programming veteran) lhf made a mistake that would prevent this from compiling. This program has been around for almost 9 years. What you are describing sounds like it would never have worked; I doubt that's true. I suspect it's a problem related to recent OS X utility changes. – Phrogz Jun 30 '15 at 21:52
  • Ah! However, your English-language decoding of the sed command allowed me to perform it myself by hand, and at that point the program compiled. That alone is worth a +1, and perhaps the acceptance. :) – Phrogz Jun 30 '15 at 21:56
  • 2
    @Phrogz: There is a GNU extension that allows you to omit the first backslash-newline combo. See [here](http://www.gnu.org/software/sed/manual/sed.html#index-Text_002c-appending-129) (it is documented under the `a` command). – siffiejoe Jun 30 '15 at 22:41
1

This line works in Mac OS X and in Linux:

sed '/void luaX_next/{h;s/.*/#include "proxy.c"/;p;g;}' $(LUASRC)/$@ > $@
lhf
  • 70,581
  • 9
  • 108
  • 149