From f0016899eec4ff2ad61ef56a21e4132dd314a37f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 6 Feb 2013 12:12:42 +0200 Subject: Install plugin to pkgexecdir instead of bindir --- configure.ac | 49 +++++++++++++++++++++++++++++++--- odb/Makefile.am | 4 +-- odb/makefile | 2 +- odb/odb.cxx | 82 +++++++++++++++++++++++++++++++++++++-------------------- 4 files changed, 102 insertions(+), 35 deletions(-) diff --git a/configure.ac b/configure.ac index c0d4c30..5c77399 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ AC_LANG(C++) static_plugin="$enable_static" AS_IF([test x$static_plugin = xyes], - AC_DEFINE([STATIC_PLUGIN], [1], [Building static plugin.])) + AC_DEFINE([ODB_STATIC_PLUGIN], [1], [Building static plugin.])) # Check for plugin support in GCC unless we are building a static plugin. # In the latter case the headers normally come from the GCC build directly @@ -37,6 +37,49 @@ AS_IF([test x$static_plugin = xyes], # AS_IF([test x$static_plugin = xno], GCC_PLUGIN) +# Unless we are building a static plugin, try to figure out a relative +# path from the driver (bindir) to the plugin (libexecdir). +# +if test x$static_plugin = xno; then + # Get the expanded values for bindif and libexecdir. + # + if test x$exec_prefix = xNONE; then + if test x$prefix = xNONE; then + e_exec_prefix=$ac_default_prefix + else + e_exec_prefix=$prefix + fi + else + e_exec_prefix=$exec_prefix + fi + + e_pkglibexecdir=`echo "$libexecdir/$PACKAGE_NAME" | sed "s?^\\\${exec_prefix}?$e_exec_prefix?"` + e_bindir=`echo "$bindir" | sed "s?^\\\${exec_prefix}?$e_exec_prefix?"` + + # Try to find a common prefix. + # + common=$e_bindir + odb_plugindir=$e_pkglibexecdir + + while test x$common != x/; do + suffix=`echo "$e_pkglibexecdir" | sed "s?^$common/*??"` + if test x$suffix != x$e_pkglibexecdir; then + # Replace all the remaining directories in bindir with ".." + # and append the suffix. + odb_plugindir=`echo "$e_bindir" | sed "s?^$common/*??"` + odb_plugindir=`echo "$odb_plugindir" | sed ['s?[^/][^/]*?..?g']` + if test x$odb_plugindir != x -a x$suffix != x; then + odb_plugindir="$odb_plugindir/$suffix" + else + odb_plugindir="$odb_plugindir$suffix" + fi + break + fi + common=`AS_DIRNAME(["$common"])` + done + AC_DEFINE_UNQUOTED([ODB_PLUGIN_PATH], ["$odb_plugindir"], [Plugin path.]) +fi + # G++ name. # AC_ARG_WITH( @@ -57,7 +100,7 @@ AC_ARG_WITH( AS_IF( [test "x$gxx_name" != x], - [AC_DEFINE_UNQUOTED([GXX_NAME], ["$gxx_name"], [g++ binary.])]) + [AC_DEFINE_UNQUOTED([ODB_GXX_NAME], ["$gxx_name"], [g++ binary.])]) # Default options file. # @@ -79,7 +122,7 @@ AC_ARG_WITH( AS_IF( [test "x$options_file" != x], - [AC_DEFINE_UNQUOTED([DEFAULT_OPTIONS_FILE], ["$options_file"], [default options file path.])]) + [AC_DEFINE_UNQUOTED([ODB_DEFAULT_OPTIONS_FILE], ["$options_file"], [default options file path.])]) # Create the libtool executable so that we can use it in further tests. # diff --git a/odb/Makefile.am b/odb/Makefile.am index 1fa8298..5b976ea 100644 --- a/odb/Makefile.am +++ b/odb/Makefile.am @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC # license : GNU GPL v3; see accompanying LICENSE file -plugindir = $(bindir) +plugindir = $(pkglibexecdir) bin_PROGRAMS = odb plugin_LTLIBRARIES = odb.la @@ -19,7 +19,7 @@ odb_la_LDFLAGS = -module -shrext .so -avoid-version # Remove the .la file from the final install. # install-data-hook: - rm -f '$(DESTDIR)/$(bindir)/odb.la' + rm -f '$(DESTDIR)$(pkglibexecdir)/odb.la' # Driver. # diff --git a/odb/makefile b/odb/makefile index c127ce5..f60da13 100644 --- a/odb/makefile +++ b/odb/makefile @@ -282,7 +282,7 @@ ifdef cxx_gnu $(cxx_pobj) $(cxx_cobj): cxx_pic_options := -fPIC $(cxx_cobj) $(cxx_cod): cpp_options := -I$(src_root) -$(cxx_dobj) $(cxx_dod): cpp_options := -I$(src_root) '-DGXX_NAME="$(cxx_gnu)"' +$(cxx_dobj) $(cxx_dod): cpp_options := -I$(src_root) '-DODB_GXX_NAME="$(cxx_gnu)"' $(cxx_pobj) $(cxx_pod): cpp_options := -I$(src_root) \ -I$(shell $(cxx_gnu) -print-file-name=plugin)/include diff --git a/odb/odb.cxx b/odb/odb.cxx index 73aa6bd..2aa2ef2 100644 --- a/odb/odb.cxx +++ b/odb/odb.cxx @@ -141,7 +141,7 @@ main (int argc, char* argv[]) // Find the plugin. It should be in the same directory as the // driver. // -#ifndef STATIC_PLUGIN +#ifndef ODB_STATIC_PLUGIN path plugin (plugin_path (path (argv[0]))); #else // Use a dummy name if the plugin is linked into the compiler. @@ -163,8 +163,8 @@ main (int argc, char* argv[]) // The first argument points to the program name, which is // g++ by default. // -#ifdef GXX_NAME - path gxx (GXX_NAME); +#ifdef ODB_GXX_NAME + path gxx (ODB_GXX_NAME); if (gxx.empty ()) { @@ -224,7 +224,7 @@ main (int argc, char* argv[]) #else args.push_back ("g++"); -#endif // GXX_NAME +#endif // ODB_GXX_NAME // Default options. // @@ -240,9 +240,9 @@ main (int argc, char* argv[]) // strings def_inc_dirs; strings def_defines; -#ifdef DEFAULT_OPTIONS_FILE +#ifdef ODB_DEFAULT_OPTIONS_FILE { - path file (DEFAULT_OPTIONS_FILE); + path file (ODB_DEFAULT_OPTIONS_FILE); // If the path is relative, then use the driver's path as a base. // @@ -1389,40 +1389,64 @@ driver_path (path const& drv) return drv.directory ().empty () ? path_search (drv) : drv; } -#ifndef STATIC_PLUGIN +#ifndef ODB_STATIC_PLUGIN static path plugin_path (path const& drv) { + // Figure out the plugin base name which is just the driver name. + // If the driver name starts with 'lt-', then we are running through + // the libtool script. Strip this prefix -- the shared object should + // be in the same directory. + // + string b (drv.leaf ().string ()); + bool lt (b.size () > 3 && b[0] == 'l' && b[1] == 't' && b[2] == '-'); + if (lt) + b = string (b, 3, string::npos); + path dp (driver_path (drv)); - if (!dp.empty ()) - { - // If the driver name starts with 'lt-', then we are running through - // the libtool script. Strip this prefix -- the shared object should - // be in the same directory. - // - { - string n (dp.leaf ().string ()); + if (dp.empty ()) + return path (); // Fail. - if (n.size () > 3 && n[0] == 'l' && n[1] == 't' && n[2] == '-') - dp = dp.directory () / path (string (n, 3, string::npos)); - } + dp = dp.directory (); + struct stat info; - struct stat info; + // Regardless of whether we were given a plugin path, first try + // the current directory for the .la file. This will make sure + // running ODB from the build directory works as expected. + // + path pp (dp / path (b + ".la")); + if (stat (pp.string ().c_str (), &info) == 0) + { + pp = dp / path (".libs") / path (b + ".so"); + if (stat (pp.string ().c_str (), &info) == 0) + return pp; + } - path so (dp + ".so"); - if (stat (so.string ().c_str (), &info) == 0) - return so; +#ifdef ODB_PLUGIN_PATH + // If we were given a plugin path, use that unless we are running + // via libtool. + // + if (!lt) + { + string rp (ODB_PLUGIN_PATH); + pp = dp; + if (!rp.empty ()) + pp /= path (rp); + pp /= path (b + ".so"); - path la (dp + ".la"); - if (stat (la.string ().c_str (), &info) == 0) - { - so = la.directory () / path (".libs") / dp.leaf () + ".so"; + if (stat (pp.string ().c_str (), &info) == 0) + return pp; - if (stat (so.string ().c_str (), &info) == 0) - return so; - } + return path (); // Fail. } +#endif + + // Try .so in the current directory. + // + pp = dp / path (b + ".so"); + if (stat (pp.string ().c_str (), &info) == 0) + return pp; return path (); } -- cgit v1.1