create changeInstallName function

This commit is contained in:
SCG82 2020-01-14 01:01:14 -08:00
parent c589a4fcaf
commit 02ce7f927e
3 changed files with 17 additions and 37 deletions

View File

@ -210,55 +210,24 @@ void Dependency::copyYourself()
void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
{
// for main lib file
std::string command = std::string("install_name_tool -change ") +
getOriginalPath() + " " + getInnerPath() + " " + file_to_fix;
if( systemp( command ) != 0 )
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
changeInstallName(file_to_fix, getOriginalPath(), getInnerPath());
// for symlinks
const int symamount = symlinks.size();
for(int n=0; n<symamount; n++)
{
command = std::string("install_name_tool -change ") +
symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
if( systemp( command ) != 0 )
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
changeInstallName(file_to_fix, symlinks[n], getInnerPath());
}
}
// FIXME - hackish
if(missing_prefixes)
{
// for main lib file
command = std::string("install_name_tool -change ") +
filename + " " + getInnerPath() + " " + file_to_fix;
if( systemp( command ) != 0 )
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
changeInstallName(file_to_fix, filename, getInnerPath());
// for symlinks
const int symamount = symlinks.size();
for(int n=0; n<symamount; n++)
{
command = std::string("install_name_tool -change ") +
symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
if( systemp( command ) != 0 )
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
changeInstallName(file_to_fix, symlinks[n], getInnerPath());
}
}
}//next
}// end if(missing_prefixes)
}

View File

@ -167,6 +167,16 @@ int systemp(std::string& cmd)
return system(cmd.c_str());
}
void changeInstallName(const std::string& binary_file, const std::string& old_name, const std::string& new_name)
{
std::string command = std::string("install_name_tool -change ") + old_name + " " + new_name + " " + binary_file;
if( systemp( command ) != 0 )
{
std::cerr << "\n\nError: An error occured while trying to fix dependencies of " << binary_file << std::endl;
exit(1);
}
}
std::string getUserInputDirForFile(const std::string& filename)
{
const int searchPathAmount = Settings::searchPathAmount();

View File

@ -41,6 +41,7 @@ std::string system_get_output(std::string cmd);
// like 'system', runs a command on the system shell, but also prints the command to stdout.
int systemp(std::string& cmd);
void changeInstallName(const std::string& binary_file, const std::string& old_name, const std::string& new_name);
std::string getUserInputDirForFile(const std::string& filename);
#endif