Skip to content

Instantly share code, notes, and snippets.

@andyjack
Last active October 13, 2017 21:26
Show Gist options
  • Save andyjack/a2d8684c13d81adbba6ca550a8d9f54b to your computer and use it in GitHub Desktop.
Save andyjack/a2d8684c13d81adbba6ca550a8d9f54b to your computer and use it in GitHub Desktop.

Installing Locale::gettext with gettext from homebrew (macOS)

brew install gettext

And you will get the "keg-only formula" message - that's ok!

==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

macOS provides the BSD gettext library and some software gets confused if both are in the library path.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/gettext/lib
    CPPFLAGS: -I/usr/local/opt/gettext/include

We'll be building the module against the homebrew-supplied library. First download the distribution file for Locale::gettext, e.g. from MetaCPAN, and unpack it:

cd /tmp
wget 'https://cpan.metacpan.org/authors/id/P/PV/PVANDRY/gettext-1.07.tar.gz'
tar xzvf gettext-1.07.tar.gz
cd Locale-gettext-1.07/

You'll need to specify the include and library paths when creating the Makefile (done on macOS 10.12):

CC='cc -I/usr/local/opt/gettext/include -L/usr/local/opt/gettext/lib' perl Makefile.PL

The following options are copied from the Makefile and modified to specify the homebrew gettext, before passing to make -e (-e lets environment variables override Makefile variables):

INC=-I/usr/local/opt/gettext/include                                                    \
LD="env MACOSX_DEPLOYMENT_TARGET=10.12 cc"                                              \
LDDLFLAGS="-bundle -undefined dynamic_lookup -lintl                                     \
    -L/usr/local/lib -fstack-protector-strong -L/usr/local/opt/gettext/lib"             \
LDFLAGS="-fstack-protector-strong -lintl -L/usr/local/lib -L/usr/local/opt/gettext/lib" \
make -e

Then run the tests - you have to specify the PATH to msgfmt, find out your particular version with brew info gettext:

PATH="$PATH:/usr/local/Cellar/gettext/0.19.8.1/bin/" prove -I. -bl t

The tests should pass, e.g.:

$ PATH="$PATH:/usr/local/Cellar/gettext/0.19.8.1/bin/" prove -I. -bl t
t/bind.t ....... ok
t/frconvert.t .. ok
t/jaconvert.t .. ok
t/raw.t ........ ok
t/use.t ........ ok
All tests successful.
Files=5, Tests=5,  1 wallclock secs ( 0.04 usr  0.02 sys +  0.17 cusr  0.06 csys =  0.29 CPU)
Result: PASS

And finally install the module with make install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment