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

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. Unfortunately OS X Mavericks does not use the environment.plist, so you need to set the environment variable using launchctl a simple script like the following should do the trick.

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!

Ahh yes - the other issue that needs addressing, basically its trying to link against the default framework, so let it. If you are building Classic, install 2.5.2 Classic, or SuperServer from its normal pkg and let it link against the relevant framework ICU lib. I really do need to make some time to investigate a fix for this

The file(s) specific to the embedded build were added to SVN after the last 2.5.2 Release. So if you want them, you need to get them from the B2_5_Release branch on Sourceforge. Though to be hosest the latest versions of MacOSX do not use info.plists anymore. So you can happily comment out that line.

Rudie,The compile error "../src/common/fb_exception.cpp:453:8: error: thread-local storage is unsupported for the current targetstatic TLS_DECLARE(sigjmp_buf*, sigjmp_ptr);"refers to the fact that 10.6 of OSX doesn't support Thread Local Storage under the latest versions of XCode (Clang not gcc). To correct the problem, edit prefix.darwin_x86_64 in builds/posix and change MACOSX_DEPLOYMENT_TARGET to 10.7 and also -macosx-version-min. You should also need to do the same to mh-darwin in extern/icu/source/config.

One more question. Do you know if there is a version of the jaybird JDBC driver available for OSX? I'm trying to integrate an embedded Firebase into a Java application and want to use the jaybird jdbc library. There only seems to be a windows and linux version.

I asked Mark Rotteveel (the current maintainer for Jaybird) about your question. Here is his answer:

"Jaybird itself will work on any OS that has Java available,however to use Firebird embedded from Jaybird you need the JNI layer that accessesfbembed.dll/libfbembed.so. This layer is a jaybird22.dll,jaybird22_x64.dll, libjaybird22.so or libjaybird22_x64.so. As I don't have a Mac, I only include a compiled version for windows and linux in the default distribution.

If people need it for a different OS (or if the compiled library doesn't work due to ABI incompatibilities), then they need to compile it themselves. They either need to download the source (in the tar.gz, eg for2.2.5:http://sourceforge.net/projects/firebird/files/firebird-jca-jdbc-driver/2.2.5-release/Jaybird-2.2.5-src.tar.gz/download) or get it from the subversion tag of the release.

They will need a C++ compiler (eg gcc), an installed JDK (which is set in the JAVA_HOME environment variable) for running ant and access to the JNI headers, and they will also need libstdc++ and libdl (or the MacOS X equivalent). It may be necessary to tweak the build-native.xml file for specific config properties (eg current config defaults to gcc, specificsearch locations for - for example - the JNI headers), and to address other compilation related problems.

Compiling would then require executing:

./build.sh compile-native

Which will create the library in

./output/native

However as I don't have a Mac, I can't be sure if this is complete and if it works out of the box.

Note that for Jaybird 3 I am currently working on removing the need for this libjaybird*.so layer."

I succeeded in building the embedded firebase version for OSX. Following the different steps as described in this blog will result in a succesfull built. There was only one thing I had to change:The compiler flag -fno-weak wasn't recognized:

I used to have Firebird embedded into our app as described, but as there's a mix of binaries and resource files in the MacOS/Contents directory of the application, this won't sign and run properly with the OSX 10.9.5/10.10 GateKeeper / v2 signature changes. There shouldn't be resource files in the code directories and vice versa.

I rearranged the files by hand into a valid Firebird.framework, which is probably close to the original framework anyway. Here's the layout

Email me privately, I recently upgraded to Yosemite to fix an issue with SuperServer startup and I have 2.5.3 building on Yosemite. I guess you probably need my copy of prefix.darwin_x86_64 and darwin.defaults.