It avoids the need to use LD_LIBRARY_PATH when running programs linked
against custom libraries. The default build types have been amended so
that debug builds use an absolute rpath. This allows them to be run from
the source tree. Release builds use a relative rpath to make them more
easily relocatable in the filesystem.
define "DEBUG" "1";
warning_level 3;
fatal_warnings true;
define "DEBUG" "1";
warning_level 3;
fatal_warnings true;
+ runtime_path_mode ABSOLUTE;
optimize 2;
warning_level 3;
fatal_warnings true;
optimize 2;
warning_level 3;
fatal_warnings true;
+ runtime_path_mode ABSOLUTE;
optimize 3;
strip true;
warning_level 1;
optimize 3;
strip true;
warning_level 1;
+ runtime_path_mode RELATIVE;
BuildInfo::BuildInfo():
libmode(DYNAMIC),
BuildInfo::BuildInfo():
libmode(DYNAMIC),
threads(false),
debug(false),
optimize(0),
threads(false),
debug(false),
optimize(0),
sysroot = bi.sysroot;
local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
libmode = bi.libmode;
sysroot = bi.sysroot;
local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
libmode = bi.libmode;
+ rpath_mode = bi.rpath_mode;
for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
libmodes[i->first] = i->second;
keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end());
for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
libmodes[i->first] = i->second;
keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end());
add("libmode", &Loader::libmode_for_lib);
add("local_incpath", &Loader::local_incpath);
add("optimize", &BuildInfo::optimize);
add("libmode", &Loader::libmode_for_lib);
add("local_incpath", &Loader::local_incpath);
add("optimize", &BuildInfo::optimize);
+ add("runtime_path_mode", &BuildInfo::rpath_mode);
add("standard", &Loader::standard);
add("strip", &BuildInfo::strip);
add("sysroot", &Loader::sysroot);
add("standard", &Loader::standard);
add("strip", &BuildInfo::strip);
add("sysroot", &Loader::sysroot);
else
throw lexical_error(format("Conversion of '%s' to LibraryMode", conv.get()));
}
else
throw lexical_error(format("Conversion of '%s' to LibraryMode", conv.get()));
}
+
+
+void operator>>(const LexicalConverter &conv, BuildInfo::RuntimePathMode &rpath_mode)
+{
+ if(conv.get()=="NONE")
+ rpath_mode = BuildInfo::NO_RPATH;
+ else if(conv.get()=="RELATIVE")
+ rpath_mode = BuildInfo::RELATIVE;
+ else if(conv.get()=="ABSOLUTE")
+ rpath_mode = BuildInfo::ABSOLUTE;
+ else
+ throw lexical_error(format("Conversion of '%s' to RuntimePathMode", conv.get()));
+}
FORCE_DYNAMIC //< Only accept dynamic libraries
};
FORCE_DYNAMIC //< Only accept dynamic libraries
};
+ enum RuntimePathMode
+ {
+ NO_RPATH, //< Do not record rpath in binaries
+ RELATIVE, //< Record relative rpath in binaries
+ ABSOLUTE //< Record absolute rpath in binaries
+ };
+
class Loader: public Msp::DataFile::ObjectLoader<BuildInfo>
{
public:
class Loader: public Msp::DataFile::ObjectLoader<BuildInfo>
{
public:
PathList libpath;
WordList libs;
Tracked<LibraryMode> libmode;
PathList libpath;
WordList libs;
Tracked<LibraryMode> libmode;
+ Tracked<RuntimePathMode> rpath_mode;
LibModeMap libmodes;
WordList keep_symbols;
StandardMap standards;
LibModeMap libmodes;
WordList keep_symbols;
StandardMap standards;
if(!sysroot.empty())
argv.push_back("--sysroot="+sysroot.str());
if(!sysroot.empty())
argv.push_back("--sysroot="+sysroot.str());
+ FS::Path lib_dir = builder.get_prefix()/"lib";
+ if(binfo.rpath_mode==BuildInfo::ABSOLUTE)
+ argv.push_back("-Wl,-rpath,"+lib_dir.str());
+ else
+ {
+ if(binfo.rpath_mode==BuildInfo::RELATIVE)
+ argv.push_back("-Wl,-rpath,$ORIGIN/../lib");
+ argv.push_back("-Wl,-rpath-link,"+lib_dir.str());
+ }
+
for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
argv.push_back("-L"+i->str());
if(binfo.strip)
for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
argv.push_back("-L"+i->str());
if(binfo.strip)