OS X Command Line Tools

Mac users may know of Xcode, the IDE (Integrated Development Environment) by Apple, which is used to develop software for OS X and iOS. One of its main components is Command-Line Tools, which this article covers.

Xcode was first seen in 2003; the latest stable release is v4.4, which is available free for Mac OS X Lion and OS X Mountain Lion in the Mac App Store. Xcode includes a modified version of the GNU Compiler Collection. Apple recently introduced the Command-Line Tools (CLT) as open source; these include the Apple LLVM compiler, linker and Make. The CLT can be used with or without Xcode. Along with these, Xcode also supports dozens of other programming languages, which include C, C++, Objective-C, Objective-C++, AppleScript, Java, Python, Ruby, Ada, Cocoa and Carbon. Apple claims to be the first major computer company to make open source a key part of its software strategy, and so has continued to use and release open source software.

Command line tools
Let’s take a look at the major CLT utilities.

LLVM compiler
LLVM (Low-Level Virtual Machine) is a huge collection of tools and libraries that make it easy to build new compilers, and compile-time, link-time, run-time and idle-time optimisers; Just-In-Time compilers (similar to Java); and a large, powerful and distinctive variety of compiler category programs. Some key features of the LLVM compiler include an extremely simple design, source-language independence, automated compiler debugging support, extensibility, stability and reliability. Apart from this, LLVM is also capable of generating relocatable machine code at any time of the program’s life cycle. Initially written to replace the existing code generator in the GNU Compiler Collection (GCC) stack, it now supports various programming languages, including Ada, C, C++, Fortran, the use of many front-ends and has had many GCC front-ends modified to work with it.

Linkers
A linker combines libraries and compiler-generated objects into an executable program. On UNIX-like systems, we use the term loader in place of linker. The linker is capable of including only the required objects from the library collection, when the library has diverse purposes. Hence, the linker plays a vital role in the CLT.
Make
Make is a build automation tool. It builds executable programs and libraries from source code by following instructions in Makefiles to derive the target program. As IDEs and language-specific compilers find prominent use on Windows and other platforms, make is widely used on UNIX (-like) systems. Make also decides whether the target needs to be regenerated or not, by comparing file modification times and thus avoiding rebuilding files that are already up-to-date.
Git
Initially designed by Linus Torvalds for the Linux kernel source, Git is a distributed revision control and source-code management system with an emphasis on speed. Each Git working directory is a full-fledged repository with complete revision-tracking capabilities, which does not need network access or a central server for history and other functions. Git’s main features include distributed development, compatibility with existing systems and protocols, efficient handling of large products, a tool-kit based design, and periodic explicit object packing.

Installation
Now let’s move on to installation.
Xcode on Lion and Mountain Lion
Visit https://developer.apple.com/xcode/ and go to View in Mac App Store. This will automatically redirect you to the Xcode page of the App Store on your Mac. Just click Free, then Install App.
Xcode on Snow Leopard
On Leopard, it’s preferable to install Xcode 4.2. Go to http://developer.apple.com/downloads/ and sign in with your Apple ID. If you are not registered yet, do it now. Search for Xcode 4.2, click Xcode 4.2 for Snow Leopard and then click on the .dmg link to download it. Once the download is finished, it will automatically launch a window in your Finder, as shown in Figure 1. Double-click the Xcode package installer to launch it. See that all checkboxes are selected. Wait till the installation completes.

Installing CLT
Once the Xcode installation is complete, you can install any further components from Xcode. Launching Xcode from the Applications folder and from the menu bar go to Xcode > Preferences. Click the Install button for Command Line Tools to install it.

Installing Git
Installing Git is simple; visit http://git-scm.com/downloads/; click Mac OS X, and your .dmg is downloaded. From your Finder, launch it to install Git on your system. After you’ve installed Git, configure it! Launch the Git Bash shell and run the following commands:

$ git config --global user.name your name 
$ git config --global user.email [email protected]

These commands set the name and email address for Git to use when you commit. Git commit is a utility which helps record a snapshot of staging content.
Usage
The CLT can be used from Xcode, and also independently from the terminal. For usage and parameters, please do check the documentation for these tools, which is available online. Happy developing!

References
[1]  http://en.wikipedia.org
[2]  http://www.moncefbelyamani.com

All published articles are released under Creative Commons Attribution-NonCommercial 3.0 Unported License, unless otherwise noted.
Open Source For You is powered by WordPress, which gladly sits on top of a CentOS-based LEMP stack.

Creative Commons License.