1

I am new to llvm, am trying to write a pass for llvm Hello I have downloaded and built llvm in linux machine by following the link http://llvm.org/docs/GettingStarted.html

I have tried to write a pass by following the link http://llvm.org/docs/WritingAnLLVMPass.html

I have copied the makefile specified in the link to the Hello folder in llvm and tried to perform a make. But I encounter the below error. Makefile:14: ../../../Makefile.common: No such file or directory make: *** No rule to make target `../../../Makefile.common'. Stop.

I understand that it is not able to find the Makefile.common. But most of the stuff in llvm is readonly and downloaded from the svn repository.

Can anyone assist me with this issue? Am I missing anything, am I following the correct way?

Is there any better tutorial anyone can refer? TIA

Spu
  • 11
  • 4

2 Answers2

2

LLVM now builds with CMake, so that old Makefile won't work. The same tutorial you linked points out how to write the CMakeLists.txt.

Out-of-tree build

Set up a directory structure like this:

HelloPassProject
├── build
├── CMakeLists.txt
└── HelloPass
    ├── CMakeLists.txt
    └── HelloPass.cpp

So there's a top-level HelloPassProject, which contains the root CMakeLists.txt, a build directory where we'll build our pass and a HelloPass directory containing the actual pass source and the pass CMakeLists.txt.

Contents of HelloPassProject/CMakeLists.txt:

find_package(LLVM REQUIRED CONFIG)

list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)

add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})

add_subdirectory(HelloPass)

Contents of HelloPassProject/HelloPass/CMakeLists.txt (list your sources here):

add_llvm_loadable_module(LLVMHelloPass HelloPass.cpp)

To build against an installed LLVM:

cd HelloPassProject/build
cmake ..
make

To build against an LLVM you've built from source (let's say it's been built in ~/llvm-project/build):

cd HelloPassProject/build
cmake -DCMAKE_PREFIX_PATH=~/llvm-project/build ..
make

In-tree build

You just need the HelloPass subdirectory from the out-of-tree build. Copy that inside <LLVM root>/lib/Transform. Add a add_subdirectory(HelloPass) line to <LLVM root>/lib/Transform/CMakeLists.txt. Build LLVM as usual.

Andrea Biondo
  • 1,626
  • 14
  • 13
  • 1
    Thanks for the response Andrea , I have tried doing a cmake by editing the CMakeLists.txt file in the and the one in the directory that contains the I see the following error message (minksy)% sudo cmake ../ CMake Error at CMakeLists.txt:13 (add_llvm_loadable_module): Unknown CMake command "add_llvm_loadable_module". I have included these lines in CMakeLists.txt list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") include(AddLLVM) May I know where I might be wrong – Spu Sep 23 '16 at 21:39
  • Thanks for the detailed answer! This is much better than the llvm guide. Specifically, what helped me was the prefix path when llvm is built from source. – OrenIshShalom Jun 20 '18 at 17:05
0

There is a Makefile.common under llvm.3.9.0-src, i.e. your llvm source root. So that should not be your problem.

Note that there are some make variables to set in Makefile.common.

zaizen
  • 1
  • 4