[cmake/multilib] Teach llgo to respect the LLVM_LIBDIR_SUFFIX variable for
authorChandler Carruth <chandlerc@gmail.com>
Mon, 29 Dec 2014 22:57:21 +0000 (22:57 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 29 Dec 2014 22:57:21 +0000 (22:57 +0000)
multilib build and installs.

Summary:
This requires introducing a generated header to encapsulate the
LLVM_LIBDIR_SUFFIX value from the build system and push it into the go
code. From there, I've adjusted the gllgo code to systematically use
this rather than a raw "lib". This requires some awkwardness as one of
the flags *must* be "lib"-relative for compatibility with how gccgo
works. For that flag, we use ".." to back up a directory and then go
into the proper lib directory.

Differential Revision: http://reviews.llvm.org/D6795

llvm-svn: 224964

llgo/CMakeLists.txt
llgo/cmd/gllgo/config.h.cmake [new file with mode: 0644]
llgo/cmd/gllgo/gllgo.go

index 5aaec5a..51d20c2 100644 (file)
@@ -1,6 +1,12 @@
 include(ExternalProject)
 include(ProcessorCount)
 
+# Provide a config.h which exposes build system information.
+configure_file(
+  cmd/gllgo/config.h.cmake
+  ${CMAKE_CURRENT_BINARY_DIR}/cmd/gllgo/config.h)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/cmd/gllgo)
+
 llvm_add_go_executable(llgo llvm.org/llgo/cmd/gllgo ALL DEPENDS
   build/context.go
   cmd/gllgo/gllgo.go
@@ -142,15 +148,17 @@ if(TARGET dfsan)
   add_libgo_variant("_dfsan" "-fsanitize=dataflow" "-fsanitize=dataflow" dfsan TRUE)
 endif()
 
-install(FILES ${CMAKE_BINARY_DIR}/lib/libgo-llgo.a
-              ${CMAKE_BINARY_DIR}/lib/libgo-llgo.so
-              ${CMAKE_BINARY_DIR}/lib/libgo-llgo.so.6
-              ${CMAKE_BINARY_DIR}/lib/libgo-llgo.so.6.0.0
-              ${CMAKE_BINARY_DIR}/lib/libgobegin-llgo.a
-        DESTINATION lib)
+set(LLGO_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
+
+install(FILES ${LLGO_LIBRARY_DIR}/libgo-llgo.a
+              ${LLGO_LIBRARY_DIR}/libgo-llgo.so
+              ${LLGO_LIBRARY_DIR}/libgo-llgo.so.6
+              ${LLGO_LIBRARY_DIR}/libgo-llgo.so.6.0.0
+              ${LLGO_LIBRARY_DIR}/libgobegin-llgo.a
+        DESTINATION lib${LLVM_LIBDIR_SUFFIX})
 
-install(DIRECTORY ${CMAKE_BINARY_DIR}/lib/go
-        DESTINATION lib)
+install(DIRECTORY ${LLGO_LIBRARY_DIR}/go
+        DESTINATION lib${LLVM_LIBDIR_SUFFIX})
 
 add_custom_target(check-libgo
   COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/libgo -j${PROCESSOR_COUNT} check
diff --git a/llgo/cmd/gllgo/config.h.cmake b/llgo/cmd/gllgo/config.h.cmake
new file mode 100644 (file)
index 0000000..4dc0fb9
--- /dev/null
@@ -0,0 +1,11 @@
+/* This generated file is for internal use. Do not include it from headers. */
+
+#ifdef CONFIG_H
+#error config.h can only be included once
+#else
+#define CONFIG_H
+
+/* Multilib suffix for libdir. */
+#define LLVM_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}"
+
+#endif
index db0eee9..db25ccf 100644 (file)
 
 package main
 
+/*
+#include "config.h"
+*/
+import "C"
+
 import (
        "errors"
        "fmt"
@@ -30,6 +35,8 @@ import (
        "llvm.org/llvm/bindings/go/llvm"
 )
 
+const LibDirSuffix = C.LLVM_LIBDIR_SUFFIX
+
 func report(err error) {
        if list, ok := err.(scanner.ErrorList); ok {
                for _, e := range list {
@@ -54,7 +61,7 @@ func initCompiler(opts *driverOptions) (*irgen.Compiler, error) {
        copy(importPaths, opts.importPaths)
        copy(importPaths[len(opts.importPaths):], opts.libPaths)
        if opts.prefix != "" {
-               importPaths = append(importPaths, filepath.Join(opts.prefix, "lib", "go", "llgo-"+llvmVersion()))
+               importPaths = append(importPaths, filepath.Join(opts.prefix, "lib"+LibDirSuffix, "go", "llgo-"+llvmVersion()))
        }
        copts := irgen.CompilerOptions{
                TargetTriple:       opts.triple,
@@ -93,7 +100,7 @@ type sanitizerOptions struct {
 }
 
 func (san *sanitizerOptions) resourcePath() string {
-       return filepath.Join(san.crtPrefix, "lib", "clang", llvmVersion())
+       return filepath.Join(san.crtPrefix, "lib"+LibDirSuffix, "clang", llvmVersion())
 }
 
 func (san *sanitizerOptions) isPIEDefault() bool {
@@ -524,23 +531,24 @@ func getDataInlineAsm(data []byte) string {
        return string(edata)
 }
 
-// Get the lib-relative path to the standard libraries for the given driver
-// options. This is normally '.' but can vary for cross compilation, LTO,
-// sanitizers etc.
-func getVariantDir(opts *driverOptions) string {
+// Get the lib path to the standard libraries for the given driver options.
+// This is normally 'lib' but can vary for cross compilation, LTO, sanitizers
+// etc.
+func getLibDir(opts *driverOptions) string {
+       lib := "lib" + LibDirSuffix
        switch {
        case opts.lto:
-               return "llvm-lto.0"
+               return filepath.Join(lib, "llvm-lto.0")
        case opts.sanitizer.address:
-               return "llvm-asan.0"
+               return filepath.Join(lib, "llvm-asan.0")
        case opts.sanitizer.thread:
-               return "llvm-tsan.0"
+               return filepath.Join(lib, "llvm-tsan.0")
        case opts.sanitizer.memory:
-               return "llvm-msan.0"
+               return filepath.Join(lib, "llvm-msan.0")
        case opts.sanitizer.dataflow:
-               return "llvm-dfsan.0"
+               return filepath.Join(lib, "llvm-dfsan.0")
        default:
-               return "."
+               return lib
        }
 }
 
@@ -549,7 +557,7 @@ func performAction(opts *driverOptions, kind actionKind, inputs []string, output
        case actionPrint:
                switch opts.output {
                case "-dumpversion":
-                       fmt.Println("llgo-"+llvmVersion())
+                       fmt.Println("llgo-" + llvmVersion())
                        return nil
                case "-print-libgcc-file-name":
                        cmd := exec.Command(opts.bprefix+"gcc", "-print-libgcc-file-name")
@@ -557,7 +565,7 @@ func performAction(opts *driverOptions, kind actionKind, inputs []string, output
                        os.Stdout.Write(out)
                        return err
                case "-print-multi-os-directory":
-                       fmt.Println(getVariantDir(opts))
+                       fmt.Println(filepath.Join("..", getLibDir(opts)))
                        return nil
                case "--version":
                        displayVersion()
@@ -710,7 +718,7 @@ func performAction(opts *driverOptions, kind actionKind, inputs []string, output
                        linkerPath = opts.bprefix + "gcc"
 
                        if opts.prefix != "" {
-                               libdir := filepath.Join(opts.prefix, "lib", getVariantDir(opts))
+                               libdir := filepath.Join(opts.prefix, getLibDir(opts))
                                args = append(args, "-L", libdir)
                                if !opts.staticLibgo {
                                        args = append(args, "-Wl,-rpath,"+libdir)