1. Install required dependencies. You need to be logged in as root to do this.
#pkg install devel/ninja devel/swig132. Replace the FreeBSD default linker (ld) with the gold linker. This is important since the default linker (ld) takes up too much memory and usually crashes the building process if you don't have minimum 16GB DRAM and large swap space. You need to be logged in as root to do this.
#cp /usr/local/bin/ld /usr/local/bin/ld.ORIGINAL # backup the original ld linker #cp /usr/local/bin/ld.gold /usr/local/bin/ld # replace with gold linkerAfter this step you can logout as root user.
3. Create a directory for LLVM
$mkdir ~/llvm $cd ~/llvm4. Download the latest version of LLVM sources including clang (C frontend) and compiler RT from http://releases.llvm.org/download.html#5.0.0
$wget http://releases.llvm.org/5.0.0/llvm-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/cfe-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/compiler-rt-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/libcxx-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/libcxxabi-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/libunwind-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/lld-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/lldb-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/openmp-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/polly-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/clang-tools-extra-5.0.0.src.tar.xz $wget http://releases.llvm.org/5.0.0/test-suite-5.0.0.src.tar.xz5. Extract the downloaded sources
$tar xJf ./llvm-5.0.0.src.tar.xz $tar xJf ./cfe-5.0.0.src.tar.xz $tar xJf ./compiler-rt-5.0.0.src.tar.xz $tar xJf ./libcxx-5.0.0.src.tar.xz $tar xJf ./libcxxabi-5.0.0.src.tar.xz $tar xJf ./libunwind-5.0.0.src.tar.xz $tar xJf ./lld-5.0.0.src.tar.xz $tar xJf ./lldb-5.0.0.src.tar.xz $tar xJf ./openmp-5.0.0.src.tar.xz $tar xJf ./polly-5.0.0.src.tar.xz $tar xJf ./clang-tools-extra-5.0.0.src.tar.xz $tar xJf ./test-suite-5.0.0.src.tar.xz6. Rename and move folders to correct location where LLVM expects them to be.
$mv ./llvm-5.0.0.src ./llvm-5.0.0 $mv ./cfe-5.0.0.src ./clang $mv ./clang ./llvm-5.0.0/tools/ $mv ./compiler-rt-5.0.0.src ./compiler-rt $mv ./compiler-rt ./llvm-5.0.0/projects/ $mv ./libcxx-5.0.0.src ./libcxx $mv ./libcxx ./llvm-5.0.0/projects/ $mv ./libcxxabi-5.0.0.src ./libcxxabi $mv ./libcxxabi ./llvm-5.0.0/projects/ $mv ./libunwind-5.0.0.src ./libunwind $mv ./libunwind ./llvm-5.0.0/projects/ $mv ./lld-5.0.0.src ./lld $mv ./lld ./llvm-5.0.0/tools/ $mv ./lldb-5.0.0.src ./lldb $mv ./lldb ./llvm-5.0.0/tools/ $mv ./openmp-5.0.0.src ./openmp $mv ./openmp ./llvm-5.0.0/projects/ $mv ./polly-5.0.0.src ./polly $mv ./polly ./llvm-5.0.0/tools/ $mv ./clang-tools-extra-5.0.0.src ./extra $mv ./extra ./llvm-5.0.0/tools/clang/tools/ $mv ./test-suite-5.0.0.src ./test-suite $mv ./test-suite ./llvm-5.0.0/projects/7. This is how it should look like
LLVM source code => ./llvm Clang source code => ./llvm/tools/clang compiler-rt source code => ./llvm/projects/compiler-rt libc++ source code => ./lvm/projects/libcxx libc++abi source code => ./lvm/projects/libcxxabi libunwind source code => ./lvm/projects/libunwind LLD Source code => ./llvm/tools/lld LLDB Source code => ./llvm/tools/lldb OpenMP Source code => ./llvm/projects/openmp Polly Source code => ./llvm/tools/polly clang-tools-extra => ./llvm/tools/clang/tools/extra LLVM Test Suite => ./llvm/projects/test-suite8. Once everything is in place we create a separate folder for the build and installation process
$mkdir ./llvm-5.0.0-build $mkdir llvm-5.0.0-install $cd ./llvm-5.0.0-build9. Now we start the actual configuration and compilation of LLVM inside the 'llvm-5.0.0-build' folder outside of the main source directory so as to keep the main source tree clean
$cmake -G Ninja -DBUILD_SHARED_LIBS=true -DCMAKE_INSTALL_PREFIX=~/llvm/llvm-5.0.0-install -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" ~/llvm/llvm-5.0.0 $ninja10. If everything is good it will start compiling. Once its done you can install it
$ninja install11. After everything is completed all binaries are available in the '~/llvm/llvm-5.0.0-install/bin' folder and libraries are available in the '~/llvm/llvm-5.0.0-install/lib' folder.
12. To start using LLVM we have to include the LLVM binaries and libraries in our path.
$gedit ~/.bashrcAdd this line to the end of the file
export PATH=$PATH:$HOME/llvm/llvm-5.0.0-install/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/llvm/llvm-5.0.0-install/libTo apply the new settings do
$source ~/.bashrc13. Test a sample program
$cd .. $mkdir test $cd test $gedit test.cAdd 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 testRun it
$./test Hello World from LLVM!Check the version of LLVM
clang --version clang version 5.0.0 (tags/RELEASE_500/final) Target: x86_64-unknown-freebsd11.0 Thread model: posix InstalledDir: /home/USERNAME/llvm/llvm-5.0.0-install/bin
Nice and good article.I have suggested to my friends to go through this blog. Thanks for sharing this useful information. If you want to learn Linux course in online, please visit below site.
ReplyDeleteLinux Online Training
linux course
Linux Online Training in kurnool
Linux Online Training in Hyderabad
Linux Online Training in Bangalore
Linux Online Training in Chennai
online training
online education
online learning
best career courses
trending courses
Linuxkd: Building Llvm 5.X From Source On Bsd >>>>> Download Now
ReplyDelete>>>>> Download Full
Linuxkd: Building Llvm 5.X From Source On Bsd >>>>> Download LINK
>>>>> Download Now
Linuxkd: Building Llvm 5.X From Source On Bsd >>>>> Download Full
>>>>> Download LINK KJ