# Sed in port makefile. Insert newline



## dinsdale (Nov 11, 2018)

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:


```
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:


```
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:


```
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

```
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:

```
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


----------



## rigoletto@ (Nov 11, 2018)

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.


----------



## dinsdale (Nov 13, 2018)

Rigoletto said:


> 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!


----------



## VladiBG (Nov 13, 2018)

diff(1) and patch(1) are used in many ports for this job.


----------

