Error trying to compile libsigsegv

Hello,
I am trying to build a package of libsigsegv, but something goes wrong during compilation. This is the Makefile I have written (partially done only, there are TODOs there, but they are not related to the problem):

include $(TOPDIR)/rules.mk

PKG_NAME:=libsigsegv
PKG_VERSION=2.12
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/libsigsegv-$(PKG_VERSION)
PKG_SOURCE:=libsigsegv-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://ftp.gnu.org/gnu/libsigsegv/
PKG_HASH:=3ae1af359eebaa4ffc5896a1aee3568c052c99879316a1ab57f8fe1789c390b6

include $(INCLUDE_DIR)/package.mk

define Package/libsigsegv
SECTION:=libs
CATEGORY:=Libraries
TITLE:=libsigsegv
URL:=https://www.gnu.org/software/libsigsegv/
MAINTAINER:=Jeronimo Pellegrini <j_p@aleph0.info>
endef

define Package/libsigsegv/description
  TODO: describe it
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/include
	$(CP) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include/
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libsigsegv.{a,so*} $(1)/usr/lib/
endef

define Package/libsigsegv/install
	$(MAKE) -C $(PKG_BUILD_DIR) DESTDIT=$(1) install
        # TODO: install only the library files
endef

$(eval $(call BuildPackage,libsigsegv))

When compiling, I get this:

libtool: compile:  mips-openwrt-linux-musl-gcc -DHAVE_CONFIG_H -I. -I.. -I. -I. -I/home/jeronimo/pkg/openwrt/staging_dir/target-mips_24kc_musl/usr/include -I/home/jeronimo/pkg/openwrt/staging_dir/target-mips_24kc_musl/include -I/home/jeronimo/pkg/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/usr/include -I/home/jeronimo/pkg/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/include/fortify -I/home/jeronimo/pkg/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/include -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -iremap/home/jeronimo/pkg/openwrt/build_dir/target-mips_24kc_musl/libsigsegv-2.12:libsigsegv-2.12 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -c handler.c -o handler.o
In file included from handler-unix.c:62:0,
                 from handler.c:20:
/home/jeronimo/pkg/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/include/sys/signal.h:1:2: warning: #warning redirecting incorrect #include <sys/signal.h> to <signal.h> [-Wcpp]
 #warning redirecting incorrect #include <sys/signal.h> to <signal.h>
  ^~~~~~~
In file included from fault-linux-mips-old.h:18:0,
                 from fault.h:37,
                 from handler-unix.c:71,
                 from handler.c:20:
/home/jeronimo/pkg/openwrt/staging_dir/toolchain-mips_24kc_gcc-7.4.0_musl/include/asm/sigcontext.h:34:8: error: redefinition of 'struct sigcontext'
 struct sigcontext {
        ^~~~~~~~~~
In file included from handler-unix.c:22:0,
                 from handler.c:20:
sigsegv.h:146:16: note: originally defined here
 typedef struct sigcontext *stackoverflow_context_t;
                ^~~~~~~~~~
In file included from handler.c:20:0:
handler-unix.c: In function 'sigsegv_handler':
handler-unix.c:353:57: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
                       stackoverflow_context_t context = (SIGSEGV_FAULT_CONTEXT);
                                                         ^
make[5]: *** [Makefile:487: handler.lo] Error 1
make[5]: Leaving directory '/home/jeronimo/pkg/openwrt/build_dir/target-mips_24kc_musl/libsigsegv-2.12/src'
make[4]: *** [Makefile:430: all-recursive] Error 1
make[4]: Leaving directory '/home/jeronimo/pkg/openwrt/build_dir/target-mips_24kc_musl/libsigsegv-2.12'
make[3]: *** [Makefile:362: all] Error 2
make[3]: Leaving directory '/home/jeronimo/pkg/openwrt/build_dir/target-mips_24kc_musl/libsigsegv-2.12'
make[2]: *** [Makefile:40: /home/jeronimo/pkg/openwrt/build_dir/target-mips_24kc_musl/libsigsegv-2.12/.built] Error 2
make[2]: Leaving directory '/home/jeronimo/pkg/openwrt/package/libsigsegv'
time: package/libsigsegv/compile#0.29#0.14#0.39
make[1]: *** [package/Makefile:109: package/libsigsegv/compile] Error 2
make[1]: Leaving directory '/home/jeronimo/pkg/openwrt'
make: *** [/home/jeronimo/pkg/openwrt/include/toplevel.mk:218: package/clisp/compile] Error 2

A conflict having to do with two header files -- probably one from libsigsegv, and one already included by the gcc that OpenWRT provides.
The same sources will compile without problem on the host machine, if I use gcc that comes with my Linux distro (Debian sid).

I'm not sure what I could do here. Any ideas?

Thanks!

You may need to create a patch to change the signal include. There have been also other packages that have been incompatible with the signal define in musl.
See examples:
https://git.openwrt.org/?p=feed/packages.git;a=commit;h=768f1a42ae47d526fc5a53c3ad7e779584e4cde9

https://git.openwrt.org/?p=feed/packages.git;a=commit;h=fce4da5b67266572825187090cb88a21b1465959

A good start is to look at what Alpine and Arch Linux does as they both use musl

https://git.alpinelinux.org/aports/tree/testing/libsigsegv?h=master
https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=libsigsegv-git (defaults to glibc)

Sorry to bring this back after such a long time. I couldn't yet find a solution.

I took another look at this. It seems that the include path of signal.h is nto a problem (the wrong path is detected and corrected automatically).

But the error message seems strange to me:

In file included from fault-linux-mips-old.h:18:0,
                 from fault.h:37,
                 from handler-unix.c:71,
                 from handler.c:20:
/home/jeronimo/pkg/openwrt-19.07-mips-old/staging_dir/toolchain-mips_24kc_gcc-7.5.0_musl/include/asm/sigcontext.h:34:8: error: redefinition of 'struct sigcontext'
 struct sigcontext {
        ^~~~~~~~~~
In file included from handler-unix.c:22:0,
                 from handler.c:20:
sigsegv.h:146:16: note: originally defined here
 typedef struct sigcontext *stackoverflow_context_t;
                ^~~~~~~~~~
In file included from handler.c:20:0:
handler-unix.c: In function 'sigsegv_handler':
handler-unix.c:353:57: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
                       stackoverflow_context_t context = (SIGSEGV_FAULT_CONTEXT);
                                                         ^

gcc complains that in sigsegv.h:146:16, the structure is redefined. It doesn't look like that. What that line contains is

 typedef struct sigcontext *stackoverflow_context_t;

which uses the struct sigcontext already defined, when creating a type alias (stackoverflow_context_t).

And this does not flag an error when compiling outside of the OpenWRT buildroot (but then, outside the buildroot it does not use struct sigcontext, but ucontext_t instead, because it's a different architecture).

Could this be the gcc version being used? Is it possible to use a different version of gcc in the buildroot?

I have also checked the packaging in Alpine and Arch, and they just compile without patching!