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) void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
{ {
// for main lib file // for main lib file
std::string command = std::string("install_name_tool -change ") + changeInstallName(file_to_fix, getOriginalPath(), getInnerPath());
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);
}
// for symlinks // for symlinks
const int symamount = symlinks.size(); const int symamount = symlinks.size();
for(int n=0; n<symamount; n++) for(int n=0; n<symamount; n++)
{ {
command = std::string("install_name_tool -change ") + changeInstallName(file_to_fix, symlinks[n], getInnerPath());
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);
} }
}
// FIXME - hackish // FIXME - hackish
if(missing_prefixes) if(missing_prefixes)
{ {
// for main lib file // for main lib file
command = std::string("install_name_tool -change ") + changeInstallName(file_to_fix, filename, getInnerPath());
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);
}
// for symlinks // for symlinks
const int symamount = symlinks.size(); const int symamount = symlinks.size();
for(int n=0; n<symamount; n++) for(int n=0; n<symamount; n++)
{ {
command = std::string("install_name_tool -change ") + changeInstallName(file_to_fix, symlinks[n], getInnerPath());
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);
} }
}//next
}// end if(missing_prefixes)
} }

View File

@ -167,6 +167,16 @@ int systemp(std::string& cmd)
return system(cmd.c_str()); 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) std::string getUserInputDirForFile(const std::string& filename)
{ {
const int searchPathAmount = Settings::searchPathAmount(); 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. // like 'system', runs a command on the system shell, but also prints the command to stdout.
int systemp(std::string& cmd); 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); std::string getUserInputDirForFile(const std::string& filename);
#endif #endif