My pulseaudio compiling problem

I was having a problem to compile pulseaudio from “current” pkgsrc for a long time in my setup. It prevented me from compiling gnome environment normally (as it had dependencies in various media packages from pkgsrc). Finally I noticed that it had been crashing on dependency checking at the same place:

=> Full dependency libsndfile>=1.0.20: found libsndfile-1.0.25
[1]   Segmentation fault (core dumped) /usr/pkg/sbin/pk…
*** Error code 139

Next dependency was speex in generated work/.depends file. So I tried to figure out what had been wrong.

Firstly I re-installed speex:
/usr/pkgscr/audio/speex

Deleted dependency in pulseaudio:
/work/.depends find line:
full    speex>=1.2rc1   ../../audio/speex

When I needed to set environment variables:
LIBSPEEX_LIBS=”-L/usr/pkg/lib -lspeex -lspeexdsp”
LIBSPEEX_CFLAGS=”-I/usr/pkg/include/speex”
export LIBSPEEX_LIBS
export LIBSPEEX_CFLAGS

After make command I got a new error:

===> Creating toolchain wrappers for pulseaudio-0.9.21nb15
sh: Syntax error: expecting “in”
*** Error code 2

So I edited newly created work/.wrapper_makevars.mk:
I found a line:
BUILDLINK_PREFIX.speex=
and added          /usr/pkg:
BUILDLINK_PREFIX.speex=         /usr/pkg

After make command compilation finally started but I still got warnings that /usr/pkgsrc/audio/pulseaudio/work/.buildlink/include/  hadn’t existed. Because of this I added to work/.buildlink folder these files:
cp -r /usr/pkg/include/speex/ /usr/pkgsrc/audio/pulseaudio/work/.buildlink/include/
cp /usr/pkg/lib/libspeex* /usr/pkgsrc/audio/pulseaudio/work/.buildlink/lib/

I thought that this would be enough but compiling still ended up with errors at some point. However these errors led me to the solution. It appeared that all speex include files (*.h) had been broken. They hadn’t source code, only lots of meaningless text and echo outputs. It is hard to say why this happened but one more speex re-installation fixed them. After that pulseaudio compilation just worked without any issues and upper mentioned actions. I am quite sure that this problem existed in different NetBSD setups for me during last two or three months. I installed speex at least two times this time too. Was it my fault or pkgsrc scripts one or something else it is hard to say currently. Nevertheless, this solved problem probably will help me to look into pkgsrc crashes even more flexibly and save unnecessary spent time.