Firebird 3 was released almost a year ago and it has already got two minor releases. But there is still no official packages for MacOS. So this post is about my humble attempt to build it on MacOs from source code. Most of the instructions are taken from Paul Beach’s Firebird Devel list post or from his blog.
This area is not my expertise so there may be inefficient or even wrong approaches so use it on your own risk and any suggestions, corrections and improvements are always welcomed.
When building needed libraries and Firebird source code, my working directory was /Users/ct/prj so when you see these directory in code blocks below you have change it to your working directory name.
First we should stop firebird service if it is installed:
1 |
sudo launchctl unload /Library/LaunchDaemons/org.firebird.gds.plist |
Building ICU
Firs step is downloading and building ICU library. I’ve used version 54.1, but I think more recent versions can also be used without problem. After downloading and extracting ICU, we have to modify icu/source/config/mh-darwin config file
Edit lines 30-35 from this
1 2 3 4 5 6 |
## Compiler switches to embed a library name and version information ifeq ($(ENABLE_RPATH),YES) LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(libdir)/$(notdir $(MIDDLE_SO_TARGET)) else LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(notdir $(MIDDLE_SO_TARGET)) endif |
to this (note the install path change of LD_SONAME) :
1 2 3 4 5 6 |
## Compiler switches to embed a library name and version information ifeq ($(ENABLE_RPATH),YES) LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name $(libdir)/$(notdir $(MIDDLE_SO_TARGET)) else LD_SONAME = -Wl,-compatibility_version -Wl,$(SO_TARGET_VERSION_MAJOR) -Wl,-current_version -Wl,$(SO_TARGET_VERSION) -install_name /Library/Framework/Firebird.framework/Versions/A/Libraries/$(notdir $(MIDDLE_SO_TARGET)) endif |
then we can build icu.
1 2 3 4 |
cd icu/source ./configure --enable-renaming=no make sudo make install |
Building Firebird
Download Firebird source code and extract it
1 2 3 |
cd ~/prj tar -xzf Firebird-3.0.2.32703-0.tar.bz2 cd Firebird-3.0.2.32703-0 |
File Modifications
I’ve made below modifications to source files in order to get rid of build errors
builds/posix/prefix.darwin_x86_64
1 2 3 4 5 6 7 |
Change line #22 from this DYLD_LIBRARY_PATH=$(HOME)/icu54/icu/source/lib to this DYLD_LIBRARY_PATH=$(HOME)/prj/icu/source/lib |
extern/cloop/src/tests/test1/CTest.c
1 2 3 4 5 6 7 |
Change line #23 to prevent malloc import error from this #include <malloc.h> to this #include <malloc/malloc.h> |
src/common/os/darwin/mod_loader.cpp
Change lines 45-47 from this
1 2 3 |
DlfcnModule(void* m) : module(m) {} |
to this :
1 2 3 4 |
DlfcnModule(MemoryPool& pool, const Firebird::PathName& aFileName, void* m) : ModuleLoader::Module(pool, aFileName), module(m) {} |
Also change line 100 from this
1 |
return FB_NEW_POOL(*getDefaultMemoryPool()) DlfcnModule(module); |
to this :
1 |
return FB_NEW_POOL(*getDefaultMemoryPool()) DlfcnModule(*getDefaultMemoryPool(), modPath, module); |
src/remote/SockAddr.h
Change lines 91-95 from this
1 2 3 4 5 6 7 8 9 |
#define AF_INET6_POSIX 10 #define AF_INET6_WINDOWS 23 inline void SockAddr::checkAndFixFamily() { #if AF_INET6 == AF_INET6_POSIX if (data.sock.sa_family == AF_INET6_WINDOWS) #elif AF_INET6 == AF_INET6_WINDOWS if (data.sock.sa_family == AF_INET6_POSIX) |
to this
1 2 3 4 5 6 7 8 9 10 11 12 |
#define AF_INET6_POSIX 10 #define AF_INET6_WINDOWS 23 #define AF_INET6_DARWIN 30 inline void SockAddr::checkAndFixFamily() { #if AF_INET6 == AF_INET6_POSIX if (data.sock.sa_family == AF_INET6_WINDOWS) #elif AF_INET6 == AF_INET6_WINDOWS if (data.sock.sa_family == AF_INET6_POSIX) #elif AF_INET6 == AF_INET6_DARWIN if (data.sock.sa_family == AF_INET6_WINDOWS) |
Firebird needs libtommath to get built which is also distrubuted with Firebird source, but I’ve preferred pre-built library which can be installed via macports as
1 |
sudo port install libtommath |
After this we can start to build Firebird, first configure
1 |
./autogen.sh CFLAGS="-I/Users/ct/prj/icu/source/common -I/opt/local/include/libtommath" LDFLAGS="-L/Users/ct/prj/icu/source/lib -L/opt/local/lib" --enable-raw-devices=no |
then make
1 |
make CXXFLAGS="-I/Users/ct/prj/icu/source/common -I/Users/ct/prj/icu/source/i18n -I/usr/include/malloc/malloc.h -I/opt/local/include/libtommath -msse4.2" |
Installing
At this point you should have compiled binaries in gen/Release/firebird directory. As I do not know how to make a pkg file for MacOs I’ve manually copied files to Library/Frameworks folder and made setup operations manually as :
1 2 3 4 5 6 7 8 |
sudo cp -r gen/Release/firebird /Library/Frameworks/ sudo cp builds/install/misc/firebird.conf.in /Library/Frameworks/firebird/firebird.conf sudo cp builds/install/misc/fbintl.conf /Library/Frameworks/firebird/intl/ sudo ln -s /Library/Frameworks/firebird/lib/libfbclient.dylib /usr/local/lib/Firebird.dylib sudo /Library/Frameworks/firebird/bin/gsec -add sysdba -pw masterkey -user sysdba |
If you have not installed firebird from an official package then your system does not have firebird user and group. To create them we can use copy user creation code from builds/install/arch-specific/darwin/install-script. Let’s create a temp script file :
1 |
nano /tmp/create_fb_users.sh |
copy and paste below code block :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#!/bin/sh # Now create the firebird group echo "Create the Firebird group 10.7+" if dscl localhost -read /Local/Default/Groups/firebird 2&>1 /dev/null; then echo "Group Found" else gid=501 dscl localhost -search /Local/Default/Groups PrimaryGroupID $gid | grep $gid while [ "$?" = "0" ]; do let "gid =$gid+1" dscl localhost -search /Local/Default/Groups PrimaryGroupID $gid | grep $gid done dscl localhost -create /Local/Default/Groups/firebird dscl localhost -create /Local/Default/Groups/firebird Password "*" dscl localhost -create /Local/Default/Groups/firebird PrimaryGroupID $gid dscl localhost -create /Local/Default/Groups/firebird RecordName firebird fi # Now create the firebird user echo "Create the Firebird user 10.7+" if dscl localhost -read /Local/Default/Users/firebird 2&>1 /dev/null; then echo "User Found" else ugid=501 dscl localhost -search /Local/Default/Users UniqueID $ugid | grep $ugid while [ "$?" = "0" ]; do let "ugid=$ugid+1" dscl localhost -search /Local/Default/Users UniqueID $ugid | grep $ugid done echo "create the firebird user 10.7+" dscl localhost -create /Local/Default/Users/firebird dscl localhost -create /Local/Default/Users/firebird NFSHomeDirectory /Library/Frameworks/firebird dscl localhost -create /Local/Default/Users/firebird Password "*" dscl localhost -create /Local/Default/Users/firebird UserShell /bin/tcsh dscl localhost -create /Local/Default/Users/firebird RecordName firebird dscl localhost -create /Local/Default/Users/firebird PrimaryGroupID $gid dscl localhost -create /Local/Default/Users/firebird UniqueID $ugid dscl localhost -create /Local/Default/Users/firebird RealName "Firebird Database" fi |
Save file and
1 |
sudo sh /tmp/create_fb_users.sh |
As we manually copied binary files we have to modify service loading script too.
1 |
sudo nano /Library/LaunchDaemons/org.firebird.gds.plist |
Edit file contents as :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"> <dict> <key>Label</key> <string>org.firebird.gds</string> <key>ProgramArguments</key> <array> <string>/Library/Frameworks/firebird/bin/fbguard</string> </array> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> </dict> </plist> |
Now we can start Firebird service :
1 |
sudo launchctl load /Library/LaunchDaemons/org.firebird.gds.plist |
You should check /Library/Frameworks/firebird/firebird.log file for any error messages.
As I’ve stated above, although these steps let me build Firebird on MacOs they may not be a hundred percent correct so if you think they should be corrected in any way please do leave a comment.
Socket issue is now fixed upstream in 3.0.x and master branch
https://github.com/FirebirdSQL/firebird/commit/faf9ead0a392e706c096a606e0bf228f8cf65d00#diff-5eac36c95940cd49e647d8dbd776bd88