Sunday, September 23, 2012

Do a git checkout of Dragonfly BSD Hammer2 File System

1. Clone the main Dragonfly BSD git repo (approx. 750MB)
$git clone git://git.dragonflybsd.org/dragonfly.git dragonfly
$cd dragonfly
2. List all branches
$git branch -a
* master
  remotes/origin/DragonFly_RELEASE_1_10
  remotes/origin/DragonFly_RELEASE_1_12
  remotes/origin/DragonFly_RELEASE_1_2
  remotes/origin/DragonFly_RELEASE_1_4
  remotes/origin/DragonFly_RELEASE_1_6
  ....
  remotes/origin/HEAD -> origin/master
  remotes/origin/doc
  remotes/origin/hammer2   <======================== HAMMER2
  remotes/origin/master
  remotes/origin/netmp
  ....
3. Checkout the Hammer2 branch
$git checkout hammer2
cd sys/vfs/hammer2

Friday, September 21, 2012

Compiling LLVM on Ubuntu

A short guide on how to compile latest version of LLVM a low level compiler infrastructure with Clang on Ubuntu 12.04 (64bit).

1. Create a directory for LLVM
$mkdir ~/llvm
$cd ~/llvm
Install required dependencies (Note : my system is already setup for development so I cannot find out the exact packages required, if you know them post them as comments)
$sudo apt-get install build-essential
2. Download the latest version of LLVM sources including clang (C frontend) and compiler RT from http://llvm.org/releases/download.html#3.1
$wget http://llvm.org/releases/3.1/llvm-3.1.src.tar.gz
$wget http://llvm.org/releases/3.1/clang-3.1.src.tar.gz
$wget http://llvm.org/releases/3.1/compiler-rt-3.1.src.tar.gz
$wget http://llvm.org/releases/3.1/test-suite-3.1.src.tar.gz
3. Extract the downloaded sources
$tar zxvf ./llvm-3.1.src.tar.gz
$tar zxvf ./clang-3.1.src.tar.gz
$tar zxvf ./compiler-rt-3.1.src.tar.gz
4. Move folders to correct location. We start by renaming 'llvm-3.1.src' to 'llvm-3.1' and moving 'clang' inside the LLVM 'tools' folder and compiler-rt under the LLVM 'projects' folder. This is where LLVM expects them to be.
$mv ./llvm-3.1.src ./llvm-3.1
$mv ./clang-3.1.src ./clang
$mv ./clang ./llvm-3.1/tools/
$mv ./compiler-rt-3.1.src ./compiler-rt
$mv ./compiler-rt ./llvm-3.1/projects/
5. Once everything is in place we create a separate folder for the build process
$mkdir ./build
$cd ./build
6. Now we start the actual configuration and compilation of LLVM inside the 'build' folder
$../llvm-3.1/configure
If there are any missing packages required to compile LLVM it will ask you here. If everything is ok we can go ahead and compile it and also keep track of the time taken. Note that all binaries are available in the 'build/Release+Asserts/bin' folder including llvm, clang, clang++
$time make
.....
llvm[0]: ***** Completed Release+Asserts Build
real 44m17.244s
user 41m42.572s
sys 2m5.592s
That's it ! We are done :)

7. To start using LLVM we have to include the binaries in our path. Add the following lines to your bash profile
$gedit ~/.bashrc
Add this line to the end of the file
export PATH=$PATH:~/llvm/build/Release+Asserts/bin
To apply the new settings close the terminal and start a new one or you can do
$source ~/.bashrc
8. Test a sample program
$cd ..
$mkdir test
$cd test
$gedit test.c
Add the following lines of a simple C program and save it
#include <stdio.h>
int main(void)
{
 printf("Hello World from LLVM!\n");
 return 0;
}
Compile it using clang the C frontend to LLVM
$clang test.c -o test
Run it
$./test
Hello World from LLVM!