Thomas Kalla, 10.10.2004
#########################

This document contains step-by-step instructions for compiling kvirc on a MacOS X system.
I compiled several versions of kvirc (3.0.0, 3.0.1 and several CVS) on a Powerbook G4, 1.5GHz, 512 MB RAM and MacOS X 10.3.3, 10.3.4, 10.3.5.

Some ideas and the patch for glibtool have been taken from the KVirc mailing list.

All this has worked fine several times for me. I've been using KVirc on Mac since May 2004 without any crashes & faults. Only the sound interface does not work, but I have no use for it within an IRC client. However, I cannot guarantee that this instructions will work for you as they do for me and I'm not responsible for any problems or damage you may encounter after following them. You should always understand what you are doing!




IMPORTANT: There are two different ways to get KVirc compiled. The one uses the native QT-MAC the other the QT-X11 from the Fink project.
Which one you choose is up to you, but I encourage you to compile with QT-MAC. It has an almost native look&feel, does not depend on X11 and Fink and is built as a bundle. However, there still some ugly bugs we are working on.


#########################
Compilation with QT-MAC
#########################

IMPORTANT: When compiled with QT-MAC, kvirc has to be run out of a bundle! Otherwise the application won't dispatch the keyboard events correctly and will be pretty unusable for you.

A bundle is "just" a special directory structure on Mac systems which contains the application binary, dependant libraries, plugins, modules and other resources. So all we have to do is to run configure with proper paths and relink the binary, libraries and modules with relative paths after the compilation.

For details look at http://doc.trolltech.com/qq/qq09-mac-deployment.html and the documentation on http://developer.apple.com, please.

Prerequisites:

1. Apple XCode
Get the latest version from Apple. I've been using only V1.5 for building with QT-MAC

2. QT-MAC
Get the latest version from Trolltech.

Prerequisites installation:

1) Install XCode
If not included on your Panther install media or if you want the latest version, you have to register at http://developer.apple.com (it's free), download XCode and  follow the install instructions in the documentation.

2) Install QT-MAC
You have to compile QT yourself. As far as I know there are no compiled binaries avaiable. Download and unpack the sources and follow the documentation.

I used V3.3.3

Open a terminal window
# cd /Developer
# tar -xjf <your_path_to_the_sources>/qt-mac-free-3.3.3.tar.bz2
# cd qt-mac-free-3.3.3
# configure -thread -qt-gif -fast -no-exceptions -debug
# make sub-tools

(If you don't want to build with debug information, remove the "-debug" switch in te configure line. You may also want to change "QMAKE_CFLAGS_RELEASE = -Os" in the mkspec/macx-g++/qmake.conf file to -O2. If you want the tutorial and examples, run "make" instead of "make sub-tools")

Add "export QTDIR=/Developer/qt-mac-free-3.3.3" to your ~/.profile file.

#########################
KVirc installation:


1) Get the KVirc sources:

IMOPRTANT: Only the CVS sources compile cleanly with QT-MAC for now!

# cvs -d:pserver:anonymous@cvs.kvirc.net:/cvs login

You will be asked for a password: just hit return.

# cvs -z3 -d:pserver:anonymous@cvs.kvirc.net:/cvs co kvirccvs

Run autogen:
# cd kvirccvs/kvirc
# ./autogen.sh


2) Run configure

The application bundle will be built in the kvirc sources directory.
Feel free to remove --enable-debug if you don't want to have a debuggable build and use addictional options like --enable-optimisation=2 or --with-big-channels.

# ./configure --enable-pipes --enable-debug --exec-prefix=$(pwd)/KVirc.app/Contents/Resources --prefix=$(pwd)/KVirc.app/Contents --bindir=$(pwd)/KVirc.app/Contents/MacOS --libdir=$(pwd)/KVirc.app/Contents/Frameworks --datadir=$(pwd)//KVirc.app/Contents/Resources --disable-x-support 


3) Run make

Because of a problem with libtool you have to remove or rename the file libqt-mt.la (or libqt.la if you compiled QT without threads). It is located in $QTDIR/lib/. Otherwise the compilation will stop with a link error.

# mv $QTDIR/lib/libqt-mt.la $QTDIR/lib/libqt-mt.la.bak

Now run make and relax :-)

# make

(A debuggable, non-optimized build takes about 40 minutes on my PowerBook.)


4) Run make install

# make install


5) Relinking

KVirc and its modules depend on libkvilib and libqt which are not in the dynamic linker search path by default. The paths set during the compilation are absolute paths and have to be changed to be realtive to the executable path.

The following commands do this for libkvilib:

# install_name_tool -id @executable_path/../Frameworks/libkvilib.3.dylib $(pwd)/KVirc.app/Contents/Frameworks/libkvilib.3.dylib
# install_name_tool -change $(pwd)/KVirc.app/Contents/Frameworks/libkvilib.3.dylib @executable_path/../Frameworks/libkvilib.3.dylib $(pwd)/KVirc.app/Contents/MacOS/kvirc
# find $(pwd)/KVirc.app/Contents -name '*.so' | xargs -n1 install_name_tool -change $(pwd)/KVirc.app/Contents/Frameworks/libkvilib.3.dylib @executable_path/../Frameworks/libkvilib.3.dylib

Now you have to decide whether you want to include libqt within the bundle or not. This is useful if you consider to share your bundle with your friends and they don't want to compile QT themselves.


a) You don't want to include libqt within the bundle

Make sure the dynamic linker is able to find libqt. The easiest way is to make symlinks in the /usr/lib directory.

# ln -sf $QTDIR/lib/libqt-mt.3.dylib /usr/lib
# ln -sf $QTDIR/lib/libqui.1.dylib /usr/lib


b) You want to include libqt within the bundle

Copy libqt into the bundle:

# cp $QTDIR/lib/libqt-mt.3.dylib $(pwd)/KVirc.app/Contents/Frameworks/

Relinking commands for libqt:

# install_name_tool -id @executable_path/../Frameworks/libqt-mt.3.dylib $(pwd)/KVirc.app/Contents/Frameworks/libqt-mt.3.dylib
# install_name_tool -change libqt-mt.3.dylib @executable_path/../Frameworks/libqt-mt.3.dylib $(pwd)/KVirc.app/Contents/MacOS/kvirc
# install_name_tool -change libqt-mt.3.dylib @executable_path/../Frameworks/libqt-mt.3.dylib $(pwd)/KVirc.app/Contents/Frameworks/libkvilib.3.dylib
# find $(pwd)/KVirc.app/Contents -name '*.so' | xargs -n1 install_name_tool -change libqt-mt.3.dylib @executable_path/../Frameworks/libqt-mt.3.dylib

6) Cleaning up

The bundle is funtional but is looks better with a nice icon :-)
Copy the icon file from the data/resources_mac directory to the resources directory and the Info.plist file to the contents directory

# cp data/resources_mac/kvirc.icns $(pwd)/KVirc.app/Contents/Resources
# cp data/resources_mac/Info.plist $(pwd)/KVirc.app/Contents


7) Enjoy :-)

Open Finder, move your bundle into a better location (e.g. /Applications), and double click to start.


#########################
Compilation with QT-X11
#########################

Prerequisites:

1. X11
If not avaiable on your install media, get the latest version from Apple: http://www.apple.com/macosx/features/x11/download/

2. Apple XCode
Get the latest version from Apple (V1.5). Compilations with V1.1, V1.2 worked for me, too. (But I got some addictional undefined reference errors which disappeared in V1.5. Maybe this had also somemething to do with a reinstallation of my system.)

3. QT-X11
I recommend to use the Fink version (http://fink.sf.net), as it is not possible to compile QT-X11 on your mac without patching it (what the Fink people did).


Prerequisites installation:

1) If not already done, install X11 from your Panther media or get the latest version from Apple. Follow the included installation documentation

2) Install XCode
If not included on your Panther install media or if you want the latest version, you have to register at http://developer.apple.com (it's free), download XCode and  follow the install instructions in the documentation.
IMPORTANT: You have to choose custom installation and add the X11-SDK to the installation manually!

3) Install Fink
Get the installer (fink.sf.net), follow the install instructions in the readme file.

4) Install QT-X11
I used the binary version (V3.2.2-12)

Open a terminal window:
# sudo apt-get update
# sudo apt-get upgrade
# sudo apt-get install qt3-dev

Close end reopen your Terminal application to get some variables updated ($QTDIR).

#########################

KVirc installation:

1) Get the KVirc sources:
(I used the CVS)

# cvs -d:pserver:anonymous@cvs.kvirc.net:/cvs login

You will be asked for a password: just hit return.

# cvs -z3 -d:pserver:anonymous@cvs.kvirc.net:/cvs co kvirccvs

Run autogen:

# cd kvirccvs/kvirc
# ./autogen.sh


2) Run configure

Feel free to use addictional options: I used --enable-pipes, --enable-optimisation=3 and --with-big-channels.
Remember that the default prefix (/usr/local) is not in the MacOS X standard path! So maybe you want to install KVirc somewhere else, e.g. --prefix=/Applications/KVirc

# ./configure --with-qt-name=qt-mt --with-qt-library-dir=/sw/lib/ --with-qt-include-dir=/sw/include/qt/


3) Replace libtool

You have to replace the KVirc-generated libtool with the one supplied with XCode, otherwise you will end up with a nonworking static application or several link errors: 

# cp /usr/bin/glibtool libtool

Then apply this patch:

--- /usr/bin/glibtool   Sat Sep 13 03:34:37 2003
+++ libtool     Fri Jun 11 18:53:23 2004
@@ -2176,7 +2176,7 @@
             # Search the libtool library
             lib="$searchdir/lib${name}.la"
             if test -f "$lib"; then
-             found=yes
+             found=no
               break
             fi
           done


4) Run make

Start make and enjoy a cup of tea or coffee, it will take some time ;-)

# make

After about 15 minutes (PB G4, 1.5GHz) I got the following compile error:

....
....
ld: can't locate file for: -lkvilib
make[4]: *** [kvirc] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

It happens in src/kvirc/build because (for some unknown reason to me) the linker looks for libkvilib in "src/kvilib/build" but unfortunately it's located in "src/kvilib/build/.libs".

You may edit the Makefile and hardcode the proper path but I made a simple simlink in "src/kvilib/build" so you cannot get the same error somewhere else. Restart the compilation.

# ln -s .libs/libkvilib.dylib  src/kvilib/build/libkvilib.dylib
# make

Wait again about 20 minutes. Now everything should be fine.


4) Install Kvirc

# sudo make install

or if your prefix is somewhrere in your home directory

# make install


5) Starting of KVirc

Open a terminal, type the following line and enjoy :-)

# open <your-path-to>/kvirc


#########################

Troubleshooting:

If you have both, QT-MAC and QT-X11 installed, you may run into linking errors or get lots of warnings about unresolved symbols. The warnings may be ignored and the final binary should run properly (as it did for me) as long as it is built.
If the linker fails while linking the kvirc binary (in src/kvirc/build directory) pointing out some unresolved symbols, try to execute the last g++ command manually (copy & paste) and add "-flat_namespace -undefined warning" to the command line. My interpretation is that the linker is confused about the two QT libraries und does not link to the proper one. While executing KVirc then, the dynamic loader chooses the right library indeed so the application runs fine.
Remember! This is a dirty hack! Such binary may and probably will crash if the symbols are still unresolved at runtime!

Theres only one good solution is: Make sure that ONLY QT-X11 is installed!
