2014/09/20: shebangfixes

Recently, I created a local port for my forward mail synchronisation. The reason to do this after years of just unpacking and stow(1)ing the scripts is that I wanted to get independent of the perl symlink under /usr/bin (on FreeBSD, perl(1) is not part of the base system and therefore typically installed under /usr/local (or whatever prefix you chose)). In fact, that symlink is deprecated on FreeBSD; however, there is also a solution provided: shebangfix in the ports infrastructure.

The usage of shebangfix is very simple. You specify shebangfix under USES and the source files to be patched under SHEBANG_FILES. This will replace /usr/bin/perl in shebang-lines by ${LOCALBASE}/bin/perl. In my port's Makefile I have the following entries.


USES=           perl5 shebangfix
USE_PERL5=      run
SHEBANG_FILES=  bin/maildirdiff bin/maildirpatch bin/maildirdiff-sync

The whole magic is in Mk/Uses/shebangfix.mk in the ports directory. It also has similar fixes for other interpreters, including bash.

The nice thing is that I can install on my FreeBSD machines and my GNU/Linux machine from the same source—while still having absolute paths (and thus independence of the PATH environment variable). Ironically, that probably will make me write /usr/bin/perl more often (knowing that it's almost automatically fixed when installing on my machines).