2012-01-18

How to enable `git grep -P` on OS X using Homebrew

If you're using Homebrew to manage software on your OS X Lion box, and using the version of git it provides, you may have noticed that you can't use the -P flag to git grep to enable Perl-compatible regular expressions (PCRE). It turns out the default formula doesn't enable that option when building git. Rather than have to override this every single time you upgrade git, it's far easier to add this line to your .bashrc (or .zshrc):


export USE_LIBPCRE=yes

After you do that, you also need to brew install pcre, because if you don't you'll get a build error when you next attempt to build git. It will look something like:


==> Upgrading git
==> Downloading http://git-core.googlecode.com/files/git-1.7.8.3.tar.gz
File already downloaded in /Users/hank/Library/Caches/Homebrew
==> make prefix=/usr/local/Cellar/git/1.7.8.3 install
GIT_VERSION = 1.7.8.3
    * new build flags or prefix
    * new link flags
./generate-cmdlist.sh > common-cmds.h+ && mv common-cmds.h+ common-cmds.h
/usr/bin/llvm-gcc -o hex.o -c -MF ./.depend/hex.o.d -MMD -MP  -O3 -w -pipe  -march=core2 -msse4.1 -I. -DUSE_LIBPCRE -DUSE_ST_TIMESPEC  -DSHA1_HEADER=''  -DNO_MEMMEM  hex.c
/usr/bin/llvm-gcc -o ident.o -c -MF ./.depend/ident.o.d -MMD -MP  -O3 -w -pipe  -march=core2 -msse4.1 -I. -DUSE_LIBPCRE -DUSE_ST_TIMESPEC  -DSHA1_HEADER=''  -DNO_MEMMEM  ident.c
/usr/bin/llvm-gcc -o kwset.o -c -MF ./.depend/kwset.o.d -MMD -MP  -O3 -w -pipe  -march=core2 -msse4.1 -I. -DUSE_LIBPCRE -DUSE_ST_TIMESPEC  -DSHA1_HEADER=''  -DNO_MEMMEM  kwset.c
/usr/bin/llvm-gcc -o levenshtein.o -c -MF ./.depend/levenshtein.o.d -MMD -MP  -O3 -w -pipe  -march=core2 -msse4.1 -I. -DUSE_LIBPCRE -DUSE_ST_TIMESPEC  -DSHA1_HEADER=''  -DNO_MEMMEM  levenshtein.c
/usr/bin/llvm-gcc -o list-objects.o -c -MF ./.depend/list-objects.o.d -MMD -MP  -O3 -w -pipe  -march=core2 -msse4.1 -I. -DUSE_LIBPCRE -DUSE_ST_TIMESPEC  -DSHA1_HEADER=''  -DNO_MEMMEM  list-objects.c
/usr/bin/llvm-gcc -o ll-merge.o -c -MF ./.depend/ll-merge.o.d -MMD -MP  -O3 -w -pipe  -march=core2 -msse4.1 -I. -DUSE_LIBPCRE -DUSE_ST_TIMESPEC  -DSHA1_HEADER=''  -DNO_MEMMEM  ll-merge.c
In file included from revision.h:5,
                 from list-objects.c:8:
grep.h:43: error: expected specifier-qualifier-list before ‘pcre’
make: *** [list-objects.o] Error 1
make: *** Waiting for unfinished jobs....
==> Exit Status: 2
http://github.com/mxcl/homebrew/blob/master/Library/Formula/git.rb#L51
==> Environment
HOMEBREW_VERSION: 0.8.1
HEAD: 730f9b7fbc30a74348223fa78e1ede295dc73340
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
Hardware: dual-core 64-bit penryn
OS X: 10.7.2
Kernel Architecture: x86_64
Ruby: 1.8.7-249
/usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
Xcode: 4.2.1
GCC-4.0: N/A
GCC-4.2: N/A
LLVM: build 2336
Clang: 3.0 build 211
MacPorts or Fink? false
X11 installed? true
==> Build Flags
CC: /usr/bin/llvm-gcc => /usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
CXX: /usr/bin/llvm-g++ => /usr/llvm-gcc-4.2/bin/llvm-g++-4.2
LD: /usr/bin/llvm-gcc => /usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
CFLAGS: -O3 -w -pipe  -march=core2 -msse4.1
CXXFLAGS: -O3 -w -pipe  -march=core2 -msse4.1
MAKEFLAGS: -j2

Error: Failed executing: make prefix=/usr/local/Cellar/git/1.7.8.3 install
These existing issues may help you:
    https://github.com/mxcl/homebrew/issues/6820
    https://github.com/mxcl/homebrew/issues/6971
    https://github.com/mxcl/homebrew/issues/7462
    https://github.com/mxcl/homebrew/issues/8030
    https://github.com/mxcl/homebrew/issues/8913
    https://github.com/mxcl/homebrew/issues/8977
    https://github.com/mxcl/homebrew/issues/9017
    https://github.com/mxcl/homebrew/issues/9023
    https://github.com/mxcl/homebrew/issues/9435
    https://github.com/mxcl/homebrew/issues/9538
    https://github.com/mxcl/homebrew/issues/9574
    https://github.com/mxcl/homebrew/issues/9618
Otherwise, please report the bug:
    https://github.com/mxcl/homebrew/wiki/checklist-before-filing-a-new-issue

It's that little line grep.h:43: error: expected specifier-qualifier-list before ‘pcre’ that clues you in that you have a PCRE problem.

Back to flipping out...