Sed in port makefile. Insert newline

Hello,

I'm attempting to patch the devel/lua-luarocks port and have run into some difficulty using sed in the makefile.
The issue: I need to insert an option into the config-3.0.4.lua configuration file that is generated at install time. The block of text (the lua table) looks like this:

Code:
variables = {
   LUA_DIR = "/usr/local";
   LUA_INCDIR = "/usr/local/include/lua53";
   LUA_BINDIR = "/usr/local/bin";
}

and I need to insert UNZIP = "/usr/local/bin/unzip"; so that it looks like this:

Code:
variables = {
   UNZIP = "/usr/local/bin/unzip";
   LUA_DIR = "/usr/local";
   LUA_INCDIR = "/usr/local/include/lua53";
   LUA_BINDIR = "/usr/local/bin";
}

I've managed to make that work using sed on the command line:

Code:
sudo sed -i -- '/variables = {/ a \
UNZIP = "/usr/local/bin/unzip";\
' /usr/local/etc/luarocks/config-5.3.lua

but when I try that in the makefile, I get
Code:
gmake[2]: Leaving directory '/usr/home/russellh/freebsd/ports/devel/lua-luarocks_304/work/luarocks-3.0.4'
/usr/bin/sed -i.bak -i -- '/variables = {/ a  UNZIP = "/usr/local/bin/unzip"; ' /usr/home/russellh/freebsd/ports/devel/lua-luarocks_304/work/stage/usr/local/etc/luarocks/config-5.3.lua
sed: 1: "/variables = {/ a  UNZI ...": command a expects \ followed by text
*** Error code 1

Stop.
make[1]: stopped in /usr/home/russellh/freebsd/ports/devel/lua-luarocks_304
*** Error code 1

Stop.
make: stopped in /usr/home/russellh/freebsd/ports/devel/lua-luarocks_304
My incomplete pre install target looks like this:
Code:
pre-install:
    ${REINPLACE_CMD} -i -- '/variables = {/ a \
        UNZIP = "${PREFIX}/bin/unzip";\
        ' ${STAGEDIR}${ETCDIR}/config-${LUA_VER}.lua

Can anyone give me a clue on how to insert a line of text using BSD sed in a makefile? I'm running on FreeBSD11.1
 
Last edited by a moderator:
Better patch the file, because if something chage upstream you will know because the patch won't apply. I usually just use ${REINPLACE_CMD} for things that are simple and/or repetitive.
 
Better patch the file, because if something chage upstream you will know because the patch won't apply. I usually just use ${REINPLACE_CMD} for things that are simple and/or repetitive.
I would have thought that inserting a single line of text in a config file would have been easy to do but I appear to have been defeated by the task. I can't patch the config file because it doesn't exist until after the build process.

I have a different work around that I will look into. Thanks!
 
Back
Top