Thursday, September 20, 2012

Firebird Embedded on MacOSX


Based on a document written by Fulvio, a while ago, I finally spent time writing a make file that will automatically create an embedded version of Firebird that will run on MacOSX as a bundle. All you do is make a normal build of Firebird Classic and then use this make file to create the Firebird.app folder which is set up in a way that allows you to access a database via isql for example without the need for a full framework. The make file detailed below was written for Firebird 2.5.x

 (updated 15th April 2014)

file embed.darwin - committed to svn B2_5_Release/builds/install/arch-specific/darwin and also to trunk
Code was added to config_root.cpp to simulate binreloc (posix) on MacOSX. Find the name of the excutable in the directory below firebird, strip the executable name, strip the lowest directory, now use the remainder to find the configuration file, firebird.conf, now read the conf file to get the actual RootDirectory for Firebird.

embed.darwin updated below, to fix a couple of other issues.

To make a Classic version of Firebird for MacOSX:
./configure
make
cd gen
make -B -f Makefile.install

Then you can use the following make file to create an embedded version.
copy embed.darwin from builds/install/arch-specific/darwin

make -B -f embed.darwin

# Makefile script to generate an embedded Firebird bundle from an existing Framework

        FBE=../gen/firebird/Firebird.app
        BINLOC=../gen/firebird/Firebird.app/Contents/MacOS/firebird/bin
        LIBLOC=../gen/firebird/Firebird.app/Contents/MacOS/firebird
        INTLOC=../gen/firebird/Firebird.app/Contents/MacOS/firebird/intl
        OLDPATH=/Library/Frameworks/Firebird.framework/Versions/A/Libraries

all:
        -$(RM) -rf $(FBE) ../gen/firebird/Firebird.app
        mkdir -p $(FBE)/Contents
        mkdir -p $(FBE)/Contents/MacOS
        mkdir -p $(FBE)/Contents/MacOS/firebird
        mkdir -p $(FBE)/Contents/Resources
        mkdir -p $(FBE)/Contents/Frameworks
        mkdir -p $(FBE)/Contents/Plugins
        mkdir -p $(FBE)/Contents/SharedSupport
        mkdir -p $(FBE)/Contents/MacOS/firebird/bin
        mkdir -p $(FBE)/Contents/MacOS/firebird/intl

        cp ../gen/install/misc/firebird.conf $(FBE)/Contents/MacOS/firebird/firebird.edit
        cp ../gen/firebird/firebird.msg $(FBE)/Contents/MacOS/firebird/firebird.msg
        cp ../gen/firebird/lib/libfbembed.dylib $(FBE)/Contents/MacOS/firebird/libfbembed.dylib
        cp ../gen/firebird/lib/libicudata.dylib $(FBE)/Contents/MacOS/firebird/libicudata.dylib
        cp ../gen/firebird/lib/libicui18n.dylib $(FBE)/Contents/MacOS/firebird/libicui18n.dylib
        cp ../gen/firebird/lib/libicuuc.dylib $(FBE)/Contents/MacOS/firebird/libicuuc.dylib
        cp ../gen/firebird/lib/libib_util.dylib $(FBE)/Contents/MacOS/firebird/libib_util.dylib
        cp ../gen/firebird/security2.fdb $(FBE)/Contents/MacOS/firebird/security2.fdb
        cp ../gen/firebird/bin/gbak $(FBE)/Contents/MacOS/firebird/bin/gbak
        cp ../gen/firebird/bin/isql $(FBE)/Contents/MacOS/firebird/bin/isql
        cp ../builds/install/misc/fbintl.conf $(FBE)/Contents/MacOS/firebird/intl/fbintl.conf
        cp ../gen/firebird/intl/libfbintl.dylib $(FBE)/Contents/MacOS/firebird/intl/fbintl.dylib
        cp ../builds/install/arch-specific/darwin/embed.Info.plist $(FBE)/Contents/Info.plist

        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Firebird \
         ../libfbembed.dylib $(BINLOC)/isql
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicuuc.dylib \
        ../libicuuc.dylib $(BINLOC)/isql
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicudata.dylib \
        ../libicudata.dylib $(BINLOC)/isql
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicui18n.dylib \
        ../libicui18n.dylib $(BINLOC)/isql
      
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Firebird \
         ../libfbembed.dylib $(BINLOC)/gbak
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicuuc.dylib \
        ../libicuuc.dylib $(BINLOC)/gbak
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicudata.dylib \
        ../libicudata.dylib $(BINLOC)/gbak
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicui18n.dylib \
        ../libicui18n.dylib $(BINLOC)/gbak
      
        install_name_tool -change $(OLDPATH)/libicuuc.dylib @loader_path/libicuuc.dylib \
        $(LIBLOC)/libfbembed.dylib
        install_name_tool -change $(OLDPATH)/libicudata.dylib @loader_path/libicudata.dylib \
        $(LIBLOC)/libfbembed.dylib
        install_name_tool -change $(OLDPATH)/libicui18n.dylib @loader_path/libicui18n.dylib \
        $(LIBLOC)/libfbembed.dylib
        install_name_tool -change $(OLDPATH)/libicudata.dylib @loader_path/libicudata.dylib \
        $(LIBLOC)/libicuuc.dylib
        install_name_tool -change $(OLDPATH)/libicuuc.dylib @loader_path/libicuuc.dylib \
        $(LIBLOC)/libicui18n.dylib
        install_name_tool -change $(OLDPATH)/libicudata.dylib @loader_path/libicudata.dylib \
        $(LIBLOC)/libicui18n.dylib

        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicuuc.dylib \
        ../libicuuc.dylib $(INTLOC)/fbintl.dylib
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicudata.dylib \
        ../libicudata.dylib $(INTLOC)/fbintl.dylib
        install_name_tool -change /Library/Frameworks/Firebird.framework/Versions/A/Libraries/libicui18n.dylib \
        ../libicui18n.dylib $(INTLOC)/fbintl.dylib

        install_name_tool -id @rpath/libfbembed.dylib $(LIBLOC)/libfbembed.dylib
        install_name_tool -id @rpath/libicudata.dylib $(LIBLOC)/libicudata.dylib
        install_name_tool -id @rpath/libicui18n.dylib $(LIBLOC)/libicui18n.dylib
        install_name_tool -id @rpath/libicudata.dylib $(LIBLOC)/libicudata.dylib
        install_name_tool -id @rpath/libicuuc.dylib $(LIBLOC)/libicuuc.dylib
        install_name_tool -id @rpath/libicudata.dylib $(LIBLOC)/libicudata.dylib
        install_name_tool -id @rpath/libib_util.dylib $(LIBLOC)/libib_util.dylib


You can now tar a copy of the Firebird.app directory (and underlying), place anywhere on your system,
and set the RootDirectory in the firebird.conf (17th July 2013 - this now works, previously it didn't), or set the FIREBIRD environment variable to the relevant location of the firebird directory in Firebird.app, If your application is under launchctl, you can set the FIREBIRD variable in the Info.plist file provided and your application should run if placed in the same directory.

Should we produce a dedicated MacOSX embedded build along with the others (32bit/64bit/lipo)?

The (Firebird.app) can be downloaded from www.ibphoenix.com/downloads/firebirdApp.zip should anybody want it.

4 comments:

getmem said...

Can you please upload somewhere a working version of firebird.app? I can't make it to work.
Thanks in advance!

Paul Beach said...

For MacOSX? For Firebird 2.5.2? Whats the problem? Have you tried building Firebird and using the code in CVS?

getmem said...

Yes for MacOSX(Mountain Lion 10.8.4)and Firebird 2.5.2. I did exactly as you described in the blog post: I made a classic version of firebird, I downloaded embed.darwin from the SVN, then run the "make -B -f embed.darwin" command(successfully, no error message), but I'm unable to connect to the database. That's why I want to test your embeded "firebird.app". Probably I'm doing something wrong. I code in Lazarus 1.0.8/FB 2.5.2, if I install firebird everything is working as it should, but I would like an embeded version(I'm new to OSX).
Thank you!

Paul Beach said...

Email me privately and I will see if I can work out whats happening.
http://www.ibphoenix.com/about/contact