Archive for August 7th, 2007
Geek Speak 1: Libcurl.framework Hearts LibSSH2
Disclaimer: This is Mac-only talk, and I’m really sorry I can’t post any Geek Speak topics concerning Linux, for now.
Last week was a tedious week, aside from having organized two birthdays in my family (my Dad’s, last August 2, and my sis’, last August 4). I had celebrated births and burps (from excessive alcohol), and I even find time to build libssh2 using the XCode open source instruction I found in the net. It was really hard, considering my drunken state, and the pressure of meeting a deadline (which I missed by a day). I figured I could share this note with you guys, who have difficulties coming up with a Universal build of libcurl and libssh for their apps. With about 38 cigarette butts and 3 slices of Party-size Black Forest (they are 50% smaller than the usual pie-like slice), I came up with this.
Sshhhh…
1. Download libssh2 from the links in its official site. I downloaded a tarball (either a tar.gz or a tar.bz) of version 0.15 because it was the most stable and was most compatible for libcurl version 7.16.4. Extract the downloaded tarball. Let’s assume your extracted directory is located at ~/libssh2-0.15
2. Using the instructions from the XCode open source universal binary building site (Whew! That was long!), create an empty XCode project, with no setting whatsoever, inside the extracted libssh2 directory. Let’s name the project UniversalSSH2. You should now be having a UniversalSSH2.xcodeproj file inside the ~/libssh2-0.15 directory.
3. Create the i386 build phase. Since I’m using a MBP, the instructions don’t really apply to me. So I started with creating the i386 build for libssh2. To do this, create an aggregate target named “Build i386″ (Project -> New Target -> Special Targets -> Aggregate). Add a “New Run Script Build Phase” inside the traget by Ctrl-clicking the “Build i386 Target”, select “New Build Phase -> New Run Script Build Phase”. You should be putting this code inside the “General Tab”.
# shell script goes here
BUILD_ARCH=build/i386
make clean
./configure
make “CC=gcc -arch i386″
mkdir -p $BUILD_ARCH
mv src/.libs/*.a $BUILD_ARCH
echo “Done”
exit 0

4. Repeat step 3, but this time, name the target “Build PPC”, and have the contents of the build phase be:
# shell script goes here
ARCH_DIR=build/ppc
make clean
./configure
make “CC=cc -arch ppc”
mkdir -p $ARCH_DIR
ls src/.libs/*.a > libnames.tmp
mv src/.libs/*.a $ARCH_DIR
exit 0

5. Repeat step 3, but this time, name it “Build Universal”, add dependencies being targets “Build i386″ and “Build PPC”, and have the following entries as script content:
# shell script goes here
lipo -create build/*/libssh2.a -output libssh2.a
exit 0

6. Select “Build Universal” as the Active Target, and do “Build / Run”. Hope this one doesn’t give you errors.
7. You can have your universal libssh2.a binary under the ~/libssh2-0.15 directory. You can use this as a static library / framework inside your projects.
No cheese for cURL
1. We now build cURL. Download the latest stable curl source tarball, and extract it anywhere you like. Let’s assume you extracted the source tarball to make a ~/curl-7.16.4/ directory.
2. Go inside, using Terminal, ~/curl-7.16.4/lib/. Copy your built libssh2.a and all the header files found in ~/libssh2-0.15/include to this directory.
3. Open ~/curl-7.16.4/lib/config.h and find instances where you can find HAVE_LIBSSH2, HAVE_LIBSSH2_H, and USE_LIBSSH2. Below thos lines, insert a #define {whatever match you find from the three enumerated above} 1. Save the file.
4. Open ~/curl-7.16.4/lib/libcurl.framework.make, and add this line just above the -libz line (where the LIBRARIES variable is defined), in such a way that it will look like this:
LIBRARIES = $(SDK)/usr/lib/libssl.dylib \
$(SDK)/usr/lib/libcrypto.dylib \
./libssh2.a \
-lz
Then add “ssh.o” to the list of objects being compiled (environment variable OBJECTS).
5. Run make, by invoking “make -e -f libcurl.framework.make” (without quotes) inside terminal, under the ~/curl-7.16.4/lib/ directory.
6. Get the finished product under the ~/curl-7.16.4/lib/ (it is a framework directory named libcurl.framework).
Midnight Delight
To use your built universal binaries, just add them to your projects as frameworks, together. That’s it.
Tell me if it works, or if it doesn’t work.
News: 


