Wednesday, October 21, 2009

Section 24.2.  Preparing the Project










24.2. Preparing the Project


Now for some work in the Terminal application. Before it can be taken over by Xcode, the Graphviz project has to be unpacked from its archive and configured to the tools and libraries available on your system. First, extract the archive; point the command interface at the directory that contains the archive, and invoke tar. The example here assumes that we're working with version 2.2 of Graphviz:


$ cd Projects
$ tar xzvf graphviz-2.2.tar.gz
graphviz-2.2/
graphviz-2.2/agraph/
graphviz-2.2/agraph/README
graphviz-2.2/agraph/aghdr.h
graphviz-2.2/agraph/agraph.h
graphviz-2.2/agraph/malloc.h
graphviz-2.2/agraph/vmstub.h
.
.
.


The options to tar(xzvf) told it to extract the contents after unzipping them from the named file and to be verbose, or print the name of each file. The verbosity isn't strictly necessary, but the extraction takes time, and it's nice to have something to show what's going on.


Next, the project has to be configured. If you point your command line interface at the newly created graphviz-2.2 directory and list the contents of the current directory, you'll find files named INSTALL and README and a script named configure. I can't promise that these files will be at the root of every open-source project you download, but you'll usually find them.


$ cd graphviz-2.2
$ ls
AUTHORS config graphviz.spec.in
COPYING config.h.in iffe
ChangeLog config.h.old lefty
Config.mk configure lneato
INSTALL configure.ac m4
.
.
.
README dotty tclhandle
.
.
.
$ cat README
Graphviz - Graph Drawing Programs from AT&T Research and
Lucent Bell Labs

See doc/build.html for prerequisites and detailed build notes.
$ open doc/build.html
$


The usual scenario is that if a project has a configure script, you must execute ./configure from the root of the project in order to adapt the project's makefiles and headers to the architecture, tool set, and library suite of your machine. The INSTALL file will usually contain annotations of any special flags or features this particular configure script accepts.


However, in this case, INSTALL appears to be unchanged from its generic content. Examining the README file shows that the build instructions are in graphviz-2.2/doc/build.html.


The build.html file confirms that Graphviz shares the same build-and-install recipe as almost every other open-source project (do not type this in):


./configure
make
make install


It also says that ./configure --help will show us all the available options, which are numerous. For the purposes of this tutorial, we'll take none of them.


So now we invoke ./configure. A glance at its voluminous output suggests why it is necessary:


$ ./configure
checking build system type... powerpc-apple-darwin8.0.0
checking host system type... powerpc-apple-darwin8.0.0
checking target system type... powerpc-apple-darwin8.0.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
.
.
.
$



During this process, the configuration script fails to find the header for the FreeType typographic library. As Graphviz relies on FreeType, not only for labeling but also for scaling objects, this will cripple our version of the package. In real life, we'd take the trouble to make up the gapit involves installing X Window support and adding --with_freetype=/usr/X11R6 to the parameters of configurebut we're doing this only for the exercise.




By the end of this process, all the makefiles in graphviz-2.2 and its subdirectories will have been created and the header files adjusted to the peculiarities of your development environment. If all you cared about was obtaining Graphviz, the easiest thing would be simply to type make at the next command prompt and, assuming all went well, sudo make install at the command prompt after that.


But in our scenario, you want to bring Xcode into the picture. Maybe you want to modify Graphviz, or you think you'll have to edit its source for it to compile properly. Maybe you just want to study it. You need an interactive, integrated development environment. It's at this point in the life cycleafter configuration but before the first makethat Xcode can enter.












No comments: