Skip to content

Instantly share code, notes, and snippets.

@alexandnpu
Forked from k-takata/gist:5124445
Last active August 25, 2017 05:48
Show Gist options
  • Save alexandnpu/44aacb0c42feac6d5848947808c30c21 to your computer and use it in GitHub Desktop.
Save alexandnpu/44aacb0c42feac6d5848947808c30c21 to your computer and use it in GitHub Desktop.
Build The Silver Searcher

Build The Silver Searcher

the silver searcher

For Win32/64 using MSYS2

Install Packages

Install the following packages using pacman -S package-name:

  • base-devel
  • mingw-w64-{i686,x86_64}-toolchain
    (mingw-w64-{i686,x86_64}-gcc, mingw-w64-{i686,x86_64}-pkg-config)
  • mingw-w64-{i686,x86_64}-pcre
  • mingw-w64-{i686,x86_64}-xz
  • git

Build The Silver Searcher

Open "MSYS2 MinGW 32-bit" or "MSYS2 MinGW 64-bit" from the start menu.

$ git clone https://github.com/ggreer/the_silver_searcher.git
$ cd the_silver_searcher/
$ ./build.sh PCRE_CFLAGS=-DPCRE_STATIC LDFLAGS=-static
$ strip ag.exe

For Win32 using Cygwin-MinGW

(This is an old way. Using MSYS2 is easier.)

Install Packages

Install the following packages using Cygwin's setup-x86.exe:

  • mingw-gcc-g++
  • mingw-zlib-devel
  • pkg-config
  • autoconf
  • automake
  • gettext
  • gettext-devel
  • liblzma-devel
  • git
  • wget

Build PCRE

Build PCRE for static link. I don't want to install it to the system.

$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.bz2
$ tar xvf pcre-8.34.tar.bz2
$ cd pcre-8.34/
$ ./configure CC=i686-pc-mingw32-gcc CXX=i686-pc-mingw32-g++ --enable-jit --enable-unicode-properties --disable-shared
$ make
$ cd ..

Build XZ Utils

Build XZ Utils (liblzma) for static link. I don't want to install it to the system.

$ wget http://tukaani.org/xz/xz-5.0.5.tar.xz
$ tar xvf xz-5.0.5.tar.xz
$ cd xz-5.0.5
$ ./configure CC=i686-pc-mingw32-gcc
$ make
$ cd ..

Build The Silver Searcher

PCRE, zlib and liblzma are statically linked with this configuration but pthread is dynamically linked.

$ git clone https://github.com/ggreer/the_silver_searcher.git
$ cd the_silver_searcher/
$ aclocal && autoconf && autoheader && automake --add-missing
$ ./configure CC=i686-pc-mingw32-gcc PCRE_CFLAGS='-DPCRE_STATIC -I../pcre-8.34 -I../xz-5.0.5/src/liblzma/api' PCRE_LIBS='-static -L../pcre-8.34/.libs -lpcre' LZMA_LIBS='-L../xz-5.0.5/src/liblzma/.libs -llzma' LIBS='-lshlwapi'
$ make
$ strip ag

Pthread's DLL will be found at: C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\bin\pthreadGC2.dll

For Ubuntu

Build PCRE

Build PCRE and install it to $HOME/opt/pcre. Ubuntu has PCRE but sometimes it is old. I want to use the latest PCRE to enable JIT.

$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.bz2
$ tar xvf pcre-8.34.tar.bz2
$ cd pcre-8.34/
$ ./configure --prefix=$HOME/opt/pcre --enable-jit --enable-unicode-properties
$ make
$ make install

Build The Silver Searcher

PCRE is statically linked with this configuration.

$ aclocal && autoconf && autoheader && automake --add-missing
$ ./configure PCRE_CFLAGS="-I $HOME/opt/pcre/include" PCRE_LIBS="-L $HOME/opt/pcre/lib -Wl,-Bstatic -lpcre -Wl,-Bdynamic"
$ make

For those who donot have root privilege and build lzma themselves

$ aclocal && autoconf && autoheader && automake --add-missing
$ ./configure --prefix=$HOME/local PCRE_CFLAGS="-I $HOME/opt/pcre/include" PCRE_LIBS="-L $HOME/opt/pcre/lib -Wl,-Bstatic -lpcre -Wl,-Bdynamic" LZMA_CFLAGS="-I $HOME/opt/lzma/include" LZMA_LIBS="-L $HOME/opt/lzma/lib -Wl,-Bstatic -llzma -Wl,-Bdynamic"
$ make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment