[LLVMdev] How to additionally compile the source files in subdirectories when using Makefile?

Hongxu Chen leftcopy.chx at gmail.com
Mon Jul 22 03:00:25 PDT 2013


Hi guys,

I am writing a LLVM pass plugin, and just simply add a directory mypass into llvm/lib/Transforms. But since I don't hope this directory to contain too many source files, I add some subdirectories.

For instance, there are 2 files inside *mypass/sub: basic.h, basic.cpp. Here is the structure of the directory llvm/lib/Transforms/mypass

  $tree mypass
  mypass
  ├── Makefile
  ├── mypass.c
  └── sub
      ├── basic.cpp
      ├── basic.h
      └── Makefile

The problem is that basic.cpp will never be compiled into the loadable module which mypass.c symbols lies in. And LLVMLIBS USEDLIBS doesn't work either.

Here is mypass/Makefile

  LEVEL = ../../..
  DIRS = sub
  LIBRARYNAME = mypass
  LOADABLE_MODULE = 1

  include $(LEVEL)/Makefile.common

And mypass/sub/Makefile

  LEVEL = ../../../..
  # LIBRARYNAME = test_sub
  # ARCHIVE_LIBRARY = 1
  # LOADABLE_MODULE = 1
  
  include $(LEVEL)/Makefile.common

When mypss/sub/Makefile uses LOADABLE_MODULE = 1 with another library name(test_sub), and by additionally loading it when using opt, it does work but I think there is a better way.

Also AFAIK, using cmake is much easier for this case since it only needs to use this configuration in mypass/Makefile:

  add_llvm_loadable_module( mypass
    mypass.cpp
    sub/basic.cpp
    )

But for some reasons I have to use GNU make to do this. Is there a good way?


-- 
Regards,
Hongxu Chen




More information about the llvm-dev mailing list