Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -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 @@ 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 Index: cmd/gllgo/config.h.cmake =================================================================== --- /dev/null +++ cmd/gllgo/config.h.cmake @@ -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: cmd/gllgo/gllgo.go =================================================================== --- cmd/gllgo/gllgo.go +++ cmd/gllgo/gllgo.go @@ -14,6 +14,11 @@ package main +/* +#include "config.h" +*/ +import "C" + import ( "errors" "fmt" @@ -30,6 +35,8 @@ "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 @@ 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 @@ } 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 @@ 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 } } @@ -557,7 +565,7 @@ 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 @@ 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)