One of the things that Daniel J. Bernstein did in his packages is merge steps two and three. There would be makefile/redo rules for detecting the presence of operating-system-specific stuff, and linking the appropriate source/header files into place.
Here's an example from ucspi-tcp that auto-configures whether the platform supports waitpid():
* https://github.com/comotion/ucspi-tcp/blob/master/Makefile#L...
* https://github.com/comotion/ucspi-tcp/blob/master/choose.sh
* https://github.com/comotion/ucspi-tcp/blob/master/trywaitp.c
* https://github.com/comotion/ucspi-tcp/blob/master/haswaitp.h...
* https://github.com/comotion/ucspi-tcp/blob/master/haswaitp.h...
When I extended redo to the whole of djbwares, this system was fairly simple to convert. Here is haswaitp.h.do which is what redo ends up running whenever something reveals a dependency from haswaitp.h :
#!/bin/sh -e
redo-ifchange trywaitp.c compile link
if ( ./compile trywaitp.o trywaitp.c trywaitp.d && ./link trywaitp trywaitp.o ) >/dev/null 2>&1
then
echo \#define HASWAITPID 1 > "$3"
else
echo '/* sysdep: -waitpid */' > "$3"
fi
* http://jdebp.eu./Softwares/djbwares/