bsd sed / make vs bsd sed / make

From: Tomek CEDRO <tomek_at_cedro.info>
Date: Thu, 25 Apr 2024 17:36:19 UTC
Hello world :-)

Are there any SED and MAKE experts around? :-)

There is a piece of Makefile within NuttX RTOS simulator code that
creates the linker scripts. I would like to fix the upstream so it
builds out of the box on FreeBSD (*BSD).

sed -e '/====/,/====/!d;//d' -e 's/__executable_start/_stext/g' \
     -e 's/^\(\s\+\)\(\.init_array\)/\1\2 : { }\n\1.sinit/g' \
     -e 's/^\(\s\+\)\(\.fini_array\)/\1\2 : { }\n\1.einit/g' \
     -e 's/__init_array_start/_sinit/g' -e 's/__init_array_end/_einit/g' \
     -e 's/__fini_array_start/_sfini/g' -e
's/__fini_array_end/_efini/g' >nuttx.ld

It does not work with BSD sed but when I replace this with gsed all works fine.

BSD sed complalins about trailinig backslash:

sed: 1: "s/^\(\s\+\)\(\.init_arr ...": RE error: trailing backslash (\)

Is there a way to fix that part so it works both with GNU sed and BSD
sed? The easiest way would be adding ${SEDCMD} set to "gsed" on BSD
and "sed" for the others (macOS also seems to use gnu sed).


Another question is on Makefile. Project uses thousands of GNU syntax
Makefiles. So I have to use gmake to build. Is there an elegant way to
use BSD make here with no dramatic code modification?

Any hints appreciated :-)
Tomek

--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info