I have finally made it work. To install a gem while compiling the native extensions (like ICU support for sqlite) with specific options one needs to do:
$ gem install sqlite3 --verbose -- \
--with-opt-include=/home/user/local/lib/sqlite-autoconf-3071602/ \
--with-opt-lib=/home/user/local/lib/sqlite-autoconf-3071602/.libs \
--with-cflags='-O3 -DSQLITE_ENABLE_ICU' \
--with-cppflags=`icu-config --cppflags` \
--with-ldflags=`icu-config --ldflags`
Whatever goes after the two 'empty' dashes "--" are parameters going to the build process of the gem. This assumes that the src distribution of sqlite3 was uncompressed at: /home/user/local/lib/sqlite-autoconf-3071602/
Now, since I use bundler I wanted this to be automated. To do that one can use the following command:
bundle config build.sqlite3 --with-opt-include=/home/user/local/lib/sqlite-autoconf-3071602/ ...
... which means that whenever sqlite3 gem is installed pass the following options in the build process. That creates a ~/.bundle/config
file with an entry for that gem, e.g. the file would have:
BUNDLE_BUILD__SQLITE3: --with-opt-include=/home/karask/local/lib/sqlite-autoconf-3071602/ --with-opt-lib=/home/karask/local/lib/sqlite-autoconf-3071602/.libs --with-cflags='-O3 -DSQLITE_ENABLE_ICU' --with-cppflags=`icu-config --cppflags` --with-ldflags=`icu-config --ldflags`
However, that wasn't working properly for me. For some reason the entry in ~/.bundle/config
wasn't correct. I tried quoting and escaping in several combinations with no luck. At the end I create this entry manually in my deployment process (a shell script) by adding the following:
$ mkdir ~/.bundle
$ echo "BUNDLE_BUILD__SQLITE3: --with-opt-include=/home/user/local/lib/sqlite-autoconf-3071602/ --with-opt-lib=/home/user/local/lib/sqlite-autoconf-3071602/.libs --with-cflags='-O3 -DSQLITE_ENABLE_ICU' --with-cppflags=`icu-config --cppflags` --with-ldflags=`icu-config --ldflags`" > ~/.bundle/config