Building LLVM Pass with in Source Tree

Hello ,

I am following http://llvm.org/docs/WritingAnLLVMPass.html this to build a simple pass with in the source tree.

When I try to run make command on my pass directory. I am getting following error:

…/…/…/Makefile.common:60: …/…/…/Makefile.config: No such file or directory

…/…/…/Makefile.common:68: /Makefile.rules: No such file or directory

make: *** No rule to make target `/Makefile.rules’. Stop.

But I think this common as I have not run ./configure on my source tree. When I try to run ./configure on my LLVM source tree I am getting following error:

configure: error: In-source builds are not allowed. Please configure from a separate build directory!

Now I build LLVM with separate source directory and put my pass directory inside of my build tree. Then I run make it builds successfully. opt is able to load my pass correctly.
But here my question is " Is this a correct way to build the pass ?" and if In-source builds are not allowed then http://llvm.org/docs/WritingAnLLVMPass.html needs to be updated.

Please guide !

Hello ,

I am following http://llvm.org/docs/WritingAnLLVMPass.html this to build
a simple pass with in the source tree.

There's two meanings of "in source" here. One of them is "your new pass lives alongside all the other passes in the source directory", and the other is "your build directory is your source directory, i.e. `./configure` not `../llvm/configure`)". The latter is specifically forbidden by the message you encountered. The former is encouraged, but not required (and there are instructions on how to build "out of source" passes in there somewhere too).

When I try to run make command on my pass directory. I am getting
following error:

Make needs to be run from the top level of the _build_ directory, not from one of the subdirs of the _source_ directory.

../../../Makefile.common:60: ../../../Makefile.config: No such file or
directory

../../../Makefile.common:68: /Makefile.rules: No such file or directory

make: *** No rule to make target `/Makefile.rules'. Stop.

But I think this common as I have not run ./configure on my source tree.
When I try to run ./configure on my LLVM source tree I am getting
following error:

configure: error: In-source builds are not allowed. Please configure
from a separate build directory!

Now I build LLVM with separate source directory and put my pass
directory inside of my build tree. Then I run make it builds

Your pass directory should go somewhere in the source dir, not the build dir.

successfully. opt is able to load my pass correctly.
But here my question is " *Is this a correct way to build the pass ?*"
and if In-source builds are not allowed then
http://llvm.org/docs/WritingAnLLVMPass.html needs to be updated.

Can you point me to the specific instructions there that confused you?

Jon

        Hello ,

        I am following http://llvm.org/docs/WritingAnLLVMPass.html this
        to build
        a simple pass with in the source tree.

    There's two meanings of "in source" here. One of them is "your new
    pass lives alongside all the other passes in the source directory",
    and the other is "your build directory is your source directory,
    i.e. `./configure` not `../llvm/configure`)". The latter is
    specifically forbidden by the message you encountered. The former is
    encouraged, but not required (and there are instructions on how to
    build "out of source" passes in there somewhere too).

        When I try to run make command on my pass directory. I am getting
        following error:

    Make needs to be run from the top level of the _build_ directory,
    not from one of the subdirs of the _source_ directory.

         This is contradicting to compile the file with a simple “gmake”
    command in the local directory and you should get a new file
    “Debug+Asserts/lib/Hello.so” as given in tutorial

I've fixed this part of the docs in r251127. If you see any other references to in-source builds in the docs, please let me know.

    running *../llvm/configure* followed by *make* on build directory
    will build the whole llvm again right ?

Yes. Though once you've added the new folder & makefile, and configured, there shouldn't be a need to configure again. Running gmake from the top level of your build directory should re-build only the parts that need it.

Jon