| Setting | Value |
|---|---|
| Architectures | ppc i386 |
| Header Search Paths | . ../include ../../include include |
| Installation Directory | @executable_path/../Frameworks |
| Preprocessor Macros | OPENSSL_NO_ENGINE |
This step involves adding the source files that make up the crypto and ssl libraries, and a couple of additional header files, to the framework. This step is not difficult, but it can be tedious because you need to be selective when including files. Since OpenSSL is designed to build and run on various platforms, it includes many source files that are specific to certain platforms. Those files are not needed for our Mac OS X build, and will generate errors if included.
The simplest way to handle this is to first add all the source files from crypto and ssl, then use the Makefile in each subdirectory to remove files that are not listed. See Figures 5 and 6. Remove readme files, Makefiles, asm folders, .com files, .pl files, .S files, and even .cpp files. Keep only the .c files that are explicitly listed in the Makefiles. Also keep the .h files. Those may not be listed in the Makefiles, but they are necessary and do not generate warnings if included by mistake.
Figure 5: Add Existing Files
Figure 6: Add Source Files To Target
For example, Listing 1 shows a portion of crypto/aes/Makefile. The LIBSRC variable lists the source files needed for this particular library.
Listing 1: Sub-Project Makefile
# # crypto/aes/Makefile # # snip LIB=$(TOP)/libcrypto.a LIBSRC=aes_core.c aes_misc.c aes_ecb.c aes_cbc.c aes_cfb.c aes_ofb.c aes_ctr.c LIBOBJ=aes_misc.o aes_ecb.o aes_cfb.o aes_ofb.o aes_ctr.o $(AES_ASM_OBJ) # snip
In the project, navigate to crypto/aes and remove files not listed in the Makefile, as shown in Figure 7. To remove a file, select it and click the <Delete> key. You should click "Delete References" in order to remove the file from the build, but keep it on the drive. This way, if you accidentally remove a file from the build that should be included, you can easily add the file back. If you instead click ""Delete References & Files", you will need to unpack the OpenSSL archive again to fetch a copy of the deleted file.
Figure 7: Remove Unnecessary Source Files
What you should be left with for this particular folder is shown in Figure 8.
Figure 8: Remaining Files Match the Makefile
Finally, add to the top-level of "Groups & Files" the file MacOS/buildinf.h.
Now that the project is ready, try building the framework using Build > Build. If all goes well it should build without error, as shown in Figure 9. Note the summary of steps in the bottom pane. This is GCC's way of telling you exactly what commands ran during the process.
Figure 9: Build Result
The file command prints information about a file, including its architecture if relevant for that type of file. Listing 2 shows the results of running file in the project build folder. The framework file is "fat", meaning it contains code for multiple architectures.
Listing 2: The file Command
mertz:/Frameworks/OpenSSLFramework.framework/Versions/A asd$ file OpenSSLFramework OpenSSLFramework: Mach-O fat file with 2 architectures OpenSSLFramework (for architecture i386): Mach-O dynamically linked shared library i386 OpenSSLFramework (for architecture ppc): Mach-O dynamically linked shared library ppc mertz:/Frameworks/OpenSSLFramework.framework/Versions/A asd$
If the framework does not build on your first attempt, the most likely cause
is including files that have dependencies on other files that are not included.
Look at any included header files, and make sure there is a path to those files.
You may need to update the User Search Path property in the target
properties window. The makefiles specify individual folders and/or header files
that automatically get added to the search path. In Xcode, you need to specify
the same folders as header search paths.
Some of the makefiles contain targets that include .S (assembly language) files in the build. There are also readme files, makefiles, .com files, and so on. You do not need these files to build the core libraries, so do not include them in the Xcode project targets.
OpenSSL includes a number of test files, usually just a main function that exercises a specific portion of the library. In this section we will create an Xcode target for testing OpenSSL's cast functionality. This target builds a Carbon application that both links against the framework and copies the framework into the application's bundle. This means you do not need to worry about OpenSSL.framework being available on the target system when you run the app.
Integrating a Cocoa framework into a Carbon application provides access to many more features than we use in this example. Read more about it in the Carbon-Cocoa Integration Guide.
Create a new target of type Carbon Application, as shown in Figures 10 and 11.
Figure 10: Create The Target
Figure 11: Name The Target
We then need to modify these phases of the target:
These modifications are discussed in the following sections.
Our first task is to nest the OpenSSLFramework build target in the Cast Test target. This creates a dependency on the framework target. When you build Cast Test, the framework target will be built first. If it needs rebuilding, that will be done automatically. This eliminates the need to manually check whether the framework is up-to-date when you build the application that uses the framework.
As shown in Figure 12, drop the OpenSSLFramework target onto the Cast Test target.
Figure 12: Drag-and-Drop The Framework Target
The result is shown in Figure 13.
Figure 13: The Nested Framework Target
In this phase, we add the file casttest.c to the project. <Control>-Click on the project name and select Add > Existing Files... (see Figure 14).
Figure 14: Add Files
Navigate to crypto/cast/casttest.c, as shown in Figure 15.
Figure 15: Add casttest.c
Using the Assistant, specify that casttest.c should be added to target Cast Test, not OpenSSLFramework.
Figure 16: Select Target
The file casttest.c should be included in the Groups & Files section, and also in the Cast Test target, as shown in Figure 17.
Figure 17: Add Complete
We need to make a simple change at the top of casttest.c. It has a relative path specified to the file e_os.h. Change it as shown in Listing 3.
Listing 3: Change header location in casttest.c
// Change this: "../e_os.h" // to: #include <e_os.h>
The "Link Binary With Libraries" phase is where we specify any frameworks or libraries to link against. Drag the OpenSSLFramework build product to the link phase icon, and then release it, as shown in Figure 18.
Figure 18: Drag The Framework To The Link Phase
We need to add a "Copy Files" phase to explicitly copy the framework into the application's bundle. As shown in Figure 19, select Project > New Build Phase > New Copy Files Build Phase.
Figure 19: Add A Copy Files Phase
Next, select "Frameworks" in the "Destination" popup menu.
Figure 20: Select The Destination For The Copy Files Phase
Finally, drag the OpenSSLFramework.framework build product into this phase. See Figure 21.
Figure 21: Drag The Framework Onto The Phase
Now, make Cast Test the active target, and click Build. It should build without error, and create the application as builds/Release/Cast Test.app.
The casttest.c file runs through several function calls in the framework. Since we built this project as a Universal Binary, it runs the same on either PowerPC or Intel architecture. Figure 22 shows the result of running Cast Test.app in Xcode.
Figure 22: Cast Test Results
The test applications provide an easy path to getting familiar with the libraries and how to use them, in preparation for incorporating OpenSSL into your own application.
Using the techniques discussed in this article, you can migrate other open source projects to the Universal Binary architecture. The sources below will help you find more specific information.
Posted: 2006-5-29