This document explains how to compile Alpha from the sources.
It contains detailed explanations in order to compile the necessary
pieces coming into the Alpha application.
The building process is entirely automated and only one instruction
is necessary to launch it. The script controlling this process takes care
of everything, retrieving the necessary external sources from the internet,
building the various pieces, installing them in the final application, etc.
Prerequisites
OS X version
The version of your Mac OS X system must be 10.9 (Mavericks) or greater.
Apple developer tools
You will need to install the Apple developer tools (aka Xcode) in
order to have all the necessary compiling environment. Go to the
Xcode download page at the
Apple Developer Site to get and install Xcode. Xcode is obtained via
the AppStore and is free.
You also need to install the command line developer tools
which are not included in the Xcode package. On Mac OS X 10.9 (Mavericks),
you just have to type the following command in a Terminal window to get them:
xcode-select --install
Unix tools
You also need some very standard Unix tools which could be present
on your machine. In particular curl and svn are needed to
download the sources from the internet in order to build some Tcl
extensions and utilities included in Alpha. In order to compile Aida (which is an utility needed to generate Alpha's documentation),
you need to install some additional tools:
autoheader and autoconf.
Use the command which to check if these tools are present on your
machine: if they are, this command will return the path, otherwise it
returns an empty string. For instance:
which autoconf
If any of the preceding tools is missing, the easiest way to install it is
to use MacPorts (see the MacPorts Project
site). Assuming MacPorts is installed on your
machine and you want to install autoconf, the command is:
sudo port -v install autoconf
All set
Once everything is installed on your machine, you are ready to
compile Alpha.
The guts of Alpha
The Alpha application, like most applications on Mac OS X, is a
bundled application. This means that it contains in a single object all the
resources it needs to work properly. It looks like a file when seen in the
Finder but, as a matter of fact, it is a directory containing various
subdirectories with different kinds of resources.
All you need to know in order to understand what follows
is that Alpha contains not only the executable binary (usually
referred to as the core) but also several important external
libraries and tools:
- the AlphaTcl library
- several Tcl extensions
- a Tcl framework
- an Aida compiler
The AlphaTcl library is written in Tcl and does not have to be compiled.
It is just copied inside the application's bundle.
The Tcl framework and the Tcl extensions are technically shared
libraries written in the C language and they have to be compiled. You will
usually compile them only the first time you build Alpha.
The Tcl framework provides the Tcl interpreter included in
Alpha.
The Tcl extensions bring additional capacities. Alpha currently
embeds the following Tcl extensions:
- Memchan 2.3
- TclAE 3.0.0
- TclAddressBook 1.2.4
- TclAppleScript 2.2
- TclGestalt 1.1
- TclLib 1.19
- TclResource 1.3
- TclX 8.4.1
- Tdom 0.9.1
- Tnc 0.3.0
- Vfs 1.3
The Aida compiler is necessary
to generate Alpha's documentation and help files. Like the
extensions, it has to be built only the first time.
All the resources described above are free and can be obtained from
the internet. This may seem daunting at first sight but you do not have to
fetch anything yourself, every step is automated. The build process
described in the following sections takes care of retrieving all the
necessary parts and assembling them in the final product.
Downloading the sources
Your first step will be to download the sources for the project.
Alpha is an Open Source project and is hosted on SourceForge
(see Alpha's homepage).
All the source code for the core and the AlphaTcl library is under version
control and is stored in a
Subversion repository.
To download the sources from the repository, you need a terminal
window. Open one by launching the Terminal application (located in the Utilities subfolder of the Applications folder). In this
window, use the cd command to go to the directory where you want to
download the Alpha sources. For instance, if you want the sources to
be stored in an Documents/Alpha folder (which you have
already created), type the following command:
cd Documents/Alpha
Then execute the following command (checkout can be abbreviated as
co):
svn checkout https://svn.code.sf.net/p/alphacocoa/code/Current
This command will create a new directory named Current
inside the Alpha folder containing the latest version of the
source code.
Once you have download the Alpha sources for the first time, the
structure of the Alpha folder should look something like this:
You are now ready to compile Alpha.
A tour of the source tree
At the top level of the Alpha folder, there are initially three
subfolders: Branches, Current and Tags. The
Branches and Tags folders are not important for the present
purpose, only the Current folder is concerned to compile
Alpha. This is the main trunk of development.
Its hierarchy looks something like this (some directories may be missing
and will be automatically created later):
--- Current
|--- Core
| | |--- Alpha.xcodeproj
| | |--- Resources
| | |--- Sources
| |--- Doc
| |--- Libraries
| | |--- AidaLib
| | |--- AlphaTcl
| | |--- Binaries
| | |--- Encodings
| | |--- Extensions
| | |--- Frameworks
| |--- Tests
| |--- Tools
| |--- Utils
| |--- AlphaColors
| |--- DiffBOA
Here is a description of the subfolders of the Current
folder :
- the Core folder contains the source code of the core
executable of the Alpha application and the Xcode project file used to
compile and debug the application. This core is written in Objective C and
is based on Apple's Cocoa framework.
- the Doc folder contains the sources of the Alpha
documentation. It is written in the Aida markup language.
- the Libraries folder contains (or rather will contain) all the
external libraries and extensions which will be embedded in the
application's bundle, as well as a few utilities. The Tcl framework and the
Tcl extensions, once they are compiled, will be found there.
- the Tests folder contains test files.
- the Tools folder contains auxiliary tools used to manage
various compiling or administrative tasks. They are mainly shell scripts.
- the Utils folder contains auxiliary tools which will be
embedded in the application's bundle.
The AlphaTcl subfolder of the Libraries folder looks
something like this:
--- AlphaTcl
|--- Examples
|--- Help
|--- Tcl
| |--- Completions
| |--- Menus
| |--- Modes
| |--- Packages
| |--- SystemCode
|--- Tools
If you are already familiar with AlphaTcl, you will recognize the usual
structure.
Initially, the Binaries, Frameworks and Extensions directories are missing or empty. They will be progressively
populated when you start compiling the various components.
The Extensions subfolder of the Libraries folder
can contain different versions of the Tcl extensions. Once the extensions
have been compiled, it might look something like this:
--- Extensions
|--- Memchan2.3
|--- Mk4Tcl2.4.9.7
|--- TclAddressBook1.2.4
|--- TclAE2.0.5
|--- TclAppleScript2.0
|--- TclGestalt1.1
|--- tcllib1.15
|--- TclResource1.3
|--- TclSpeech2.0
|--- TclX8.4
|--- Tdom0.8.3
|--- Tnc0.3.0
|--- Vfs1.3
The Frameworks subfolder of the Libraries folder
can contain different versions of the embedded frameworks (currently only the
Tcl framework but there might be others in the future). Once they
have been compiled, it might look something like this:
--- Frameworks
|--- Tcl
|--- 8.5.11
|--- 8.6.2
Compiling Alpha
There are two methods to compile Alpha: using a Makefile, or using the
Xcode project. The easiest method is the Makefile because it just amounts
to typing the word make on the command line and requires no
knowledge about the Xcode application and its complex interface.
If you compile Alpha for the first time and thus need to
build all the external libraries, the only valid method is the Makefile.
You cannot build the external libraries from the Xcode project.
Using the Xcode project file will be the preferred method if later
you want to contribute to the development of the core or to debug the
application. But you will have to get used to its interface and its working
flow.
Note that you do not have to compile the entire application every
time something changes in the source code of the project. The external
libraries (frameworks, Tcl extensions and utilities), once compiled,
are stored in the Libraries folder (inside the Alpha sources)
and will not need to be rebuilt until a new version is released. If one of
them needs updating, it can be rebuilt separately.
Compiling Alpha with the make file
The compilation of all the different parts of Alpha is driven by a
Makefile. This file contains sets of instructions known as targets
indicating how to execute the different tasks involved by this process. You
will never have to understand how it works under the hoods. All you have to
know is that in order to execute a target of a Makefile, you just have to
execute the command make in a Terminal window followed by the name
of the target.
So we are now going to compile Alpha from scratch. The command
make is in general followed by the name of a target, but if nothing
is specified the first target of the Makefile is used as a default and is
executed which is just what we need now. In the Terminal window which was
opened in the Downloading the sources section,
change the directory to go to the Current subdirectory like this:
cd AlphaCocoa/Current
then type the command:
make
That's all there is to it. This command will launch the whole
process. If you compile for the first time, it takes approximately 10
minutes to complete. You will see a lot of output on the screen. The
command will successively:
- compile the frameworks
- compile the extensions
- compile the core
- compile the utilities
- install everything in the application's bundle
If no error occurs, you will see a victory message announcing that
the Alpha application has been successfully built.
Location of the built application
So where is it ?
The Xcode project creates a directory named build in the Current directory. This build directory has a subdirectory
named Debug which contains Alpha as showed on the following
image.
The exact path is indicated anyway at the end of the compilation.
You can also find it by typing the following command:
make app-path
To be more precise the subdirectory of the build directory
containing the built product is named after the current configuration of
the Alpha target in the Xcode project. It could be Debug or
Release.
You can launch the application by typing the following command:
make open-app
or by double-clicking on its icon in the Finder as usual.
The next section also explains how to find the built product from
the Xcode project.
If you would prefer the newly built application to be in the Applications folder, you can execute the following command in order to
copy it thereto:
make install-app
There is no necessity to do so though and you can launch Alpha from
any location.
The compilation of the frameworks, the extensions and the utilities takes
place in a folder named Externals located at the top level of the
Alpha top directory (at the same level as the Current, Branches and Tags folders). The Externals folder is
just a temporary location where the sources are imported and built. You may
throw it away when everything is finished: the products of these
compilations won't be lost and are found in the Libraries subfolder
of Current.
The Compiling Specific Pieces section
below gives more detailed informations about the available targets and
explains how to use the make command more selectively.
Compiling Alpha with the Xcode project
The present section explains how to compile or recompile the core of the
application (not the external frameworks, extensions and utilities). If you
have been compiling Alpha with the make method, the Xcode
project was invoked automatically at some point. You will need to open the
Xcode project yourself when you already have a built application and you
want to debug it or to make modifications in the core.
The Xcode project lets you compile the core of the application and
install the various (already compiled) external libraries in the
application's bundle. It is responsible for assembling the final product.
You cannot compile the external libraries with the Xcode project, you can
just install them.
In order to recompile Alpha's executable (that is to
say the source code written in Objective C and located in the
Core subfolder of the Current folder), open the Xcode
project named Alpha.xcodeproj which is precisely located
in the AlphaCocoa/Current/Core subfolder. Everything is already
set up for the compilation of the project:
- select the target named Alpha as the active target in the
Scheme popup menu at the top left of the Xcode window;
- select the command Build in the
Product menu (or press
⌘B
).
These two steps are illustrated on the following image:
The Xcode project also has several targets (aka schemes) to
install the various components in the application's bundle:
- the InstallAlphaTcl target installs the AlphaTcl library;
- the InstallTclFmwk target installs the Tcl framework;
- the InstallExtns target installs the Tcl extensions;
- the InstallIcons target installs the menu icons;
- the InstallUtils target installs the utilities.
- the InstallTests target installs the test files.
All the Install targets assume that the libraries have
already been compiled and are present in the Librairies subfolder
of the Current folder. The target called InstallAll is an
umbrella (aka aggregate) target which executes all the
abovementionned targets.
For further development, you will usually select as the active
target in the Schemes popup, either the Alpha target
if the source code has been modified or the InstallAlphaTcl target
if the code of the AlphaTcl library has been updated and you want
to transfer it into the application bundle.
The following image explains how to find, from the Xcode project,
where the built product is located after compilation. Here are step-by-step
instructions:
- make sure the Project Navigator is selected in the left side
bar;
- open the Products disclosure triangle;
- control-click on the name of the application (Alpha.app)
to display the contextual menu;
- in the contextual menu, select Show in Finder.
Compiling specific pieces
There are several Makefiles in the source tree:
--- Current
|--- Makefile
|--- Libraries
| |--- Makefile
|--- Utils
| |--- Makefile
|--- Doc
|--- Makefile
The Makefile located in the Current folder is the master
Makefile and it is the one you should use. The others are called
from the master when necessary.
The master Makefile is not used only to build the entire
application. It has a much finer granularity and can also perform very
specific tasks, like recompiling a particular extension, generating a
particular component. This is done by specifying an appropriate target in
the make command.
On the other hand, most of the rules defined to build the different
components of Alpha are implemented via shell scripts which are
invoked transparently by the make command. These scripts are
located in the Tools subdirectory of the Current directory.
It is possible to use them directly.
The following sections explain the different make rules and how to
use the build scripts directly.
The Makefile rules
The current section explains more advanced uses of the Makefile
driving the build process of Alpha. It assumes that you have already
retrieved Alpha's sources from the Subversion repository at
SourceForge. See the Downloading the sources
section if this is not the case.
There are many different ways to use Alpha's Makefile depending
on which part of the application you want to build or rebuild. The various
possibilities are known as targets which are sets of rules. You
executed a target from the Terminal with the make command followed
by the name of the target.
The make command must always be executed in a Terminal
window from the directory where the Makefile is located. The master
Makefile for Alpha is in the Current folder. Use the
cd command in the Terminal window to go to the Current
folder:
cd /path/to/folder/Alpha/Current
with the appropriate path.
The make command without argument executes the default target
which builds everything from scratch. You use it only the first time as
explained previously.
Later you will not have to recompile all the components but only the
elements which have changed. There are targets for all these elements. You
can get more information about the available targets by typing
make help
Here help is also a target which prints the usage of the make
command in this directory.
All the target names are in lowercase. Here are a few examples.
To compile only the core, the command is:
make core
To retrieve the latest AlphaTcl library from the Subversion repository:
make alphatcl
To build a specific library:
make lib-[name]
where you replace [name]
by the appropriate library name. The possible
extension names are: memchan, mk4tcl, tclae, tcladdressbook (or tclab),
tclapplescript (or tclas), tclgestalt, tcllib, tclresource,
tclspeech, tclx, tdom, vfs.
For the Tcl framework, the name of the target is tcl.
For instance:
make lib-tclae
make lib-tcl
To rebuild all the extensions:
make extensions
To rebuild all the libraries (frameworks and extensions):
make libs
To rebuild all the utilites:
make utils
To rebuild only the aida utility:
make util-aida
To copy all the components (AlphaTcl library, frameworks, extensions) in
the application bundle:
make install-components
To copy a specific component in the application (provided it has already
been built):
make install-[name]
where you replace [name]
by the appropriate component name. The
possible component names are: alphatcl, tclfmwk, tclextns, icons, utils.
For instance:
make install-alphatcl
make install-tclextns
make install-icons
To install a particular extension or utility:
make install-lib-tclae
make install-util-aida
The build scripts
This section documents the direct use of the build scripts.
There are shell scripts for building all the components: they take
care of downloading the source code from the internet, configuring,
compiling, and finally assembling the product as an embedded framework or a
Tcl extension. These scripts are invoked automatically by the rules of the
Makefile but they can also be executed directly. Invoking the scripts
directly instead of using the make command can sometimes be useful
because they give access to more fine grained options.
The scripts are located in the Tools subfolder of the Current folder. For instance the script to build the Tcl framework is
called buildTclFramework and the script to build the TclAE
extension is called buildTclAEExtension.
Build scripts usage
These scripts all share the same syntax which can be displayed
using the option -h. For instance:
The building process of each extension consists of three phases:
- the fetch phase which retrieves the source code from the
internet, either as a distribution or as development code in a Subversion
or a Git repository;
- the build phase which configures some parameters, compiles and
links together the source files;
- the install phase which copies the built products to their
destination inside the Libraries subfolder of the Current
folder.
There is a fourth phase which is the cleaning phase where all the
intermediary files produced by the compiler are removed.
The options supported by all the build scripts have the following meaning:
- the -a option lets specify architectures. For instance, to
build for both the i386 and the x86_64 architectures, specify the option
-a "i386 x86_64"
. By default, the extensions are built for the
architecture of the current machine.
- the -c option tells to perform the cleaning phase. It
disables the other three phases.
- the -f option tells to build the libraries (extensions or
frameworks) as
fat binaries, i-e binaries containing code for several machine
architectures. You should not be concerned by this option. By default, the
libraries are made for the architecture of the machine where they are
built.
- the -g option tells to include the debugging symbols. This is
useful for developers who intend to run the libraries in a debugger so it
is recommended during the development phase.
- the -h option tells to print the usage string.
- the -s option tells to skip some phases. Its value is any
combination of the letters f (for fetch), b for (build) and i for (install).
- the -v option tells to print the version number of the script.
For instance, the following command will just recompile and install the
code, in case the source files have already been download from the
internet:
./buildTclAEExtension -s f
The '-s f' option means that it skips the fetch phase.
Compilation is performed in a separate directory called Externals
located at the top level of the Alpha source tree. This directory is
created by the build scripts and contains subdirectories for all the built
products. Built libraries are finally installed in the Librairies
subfolder of the Current folder and the Externals folder
contains only intermediary files. There is no problem destroying it when
the compilation is finished.
Build scripts configuration
How do the build scripts know which version of the external librairies
they have to build and where to find the source code ? This is set in a
configuration file named buildConfig.inc which is read by all the build
scripts. This configuration file is a simple shell script which defines
environment variables containing the version number and the URL of the
libraries.
If you wish to compile another version of a library (extension,
framework, utility), you just have to adjust the corresponding environment
variables in the buildConfig.inc file. Nothing has to be changed
in the scripts themselves.
The -f and -g options explained in the previous
section can also be set at a global level. You can create a configuration
file named .alphacocoabuild in your home directory and define
there some environment variables:
- the ALPHA_FAT_BIN variable takes the values 1 or 0 and tells
whether to compile fat binaries or not respectively. Its default value is
0.
- the ALPHA_BUILD_ARCH variable lets specify a list of
architectures.
- the ALPHA_DEBUG_SYMBOLS variable takes the values 1 or 0 and
tells whether to include debugging symbols or not respectively. Its default
value is 0.
For instance, during the development of Alpha, the configuration file
.alphacocoabuild could contain the following definitions (using the
bash syntax):
#!/bin/bash
export ALPHA_FAT_BIN=0
export ALPHA_DEBUG_SYMBOLS=1
These environment variables are supported also if you compile the libraries
using the Makefile method rather than the build scripts directly.
Finally you can also specify these variables on the command line
when invoking the make command. For instance, to build the TclAE extension
as a fat library, you can execute the following command:
make lib-tclae ALPHA_FAT_BIN=1
This is the same as executing the following command in the Tools directory:
ALPHA_FAT_BIN=1 ./buildTclAEExtension
Updating the sources
You will regularly want to update your sources directory to keep up with
the latest changes made in the core or in the AlphaTcl library.
This is very simple. From a Terminal window, change directory to the
top Alpha folder and type the following command:
svn update
If there were changes in the core sources (inside the Core directory), you
will need to recompile Alpha. This is done either from the Xcode
project with ⌘R
or from the Terminal (positionned
in the Current directory) like this:
cd Current
make core
If there were changes in the AlphaTcl library, you will just have
to install them in the application. This can be done in the Xcode project
by selecting the InstallAlphaTcl target and executing it with ⌘R
. Alternatively, you can do this from a Terminal
window (in the Current directory as before):
make install-alphatcl
It there were changes done in some utility (like aida, or DiffBOA), you can recompile it like this:
make util-aida
and then install it like this:
make install-util-aida
You will rarely have to update the extensions. The extensions are
third party software and their source code is independant from the
Alpha project. It this ever happens, see the instructions in the
Compiling Specific Pieces section.
Last updated 2019-02-18 17:55:07