Because I like to compile as little software as possible from ports on my already overheating IBM X60 Thinkpad, I devised this little script to run from inside a port folder and tell me a list of package names that I need before this one port will compile.
This does a job which `make missing` fails to do because that lists all the ports to build the dependencies too. I just want the packages. `make run-depends-list' & 'make build-depends-list` don't quite cut it either because they don't take into account ports that are already installed. Also none of them list the package names.
So.. Hopefully I have justified the existence of my script enough...
To get working, copy to your PATH, chmod +x and just make sure that it ends in .cpp or the automatic compiling wont work..
Enjoy
This does a job which `make missing` fails to do because that lists all the ports to build the dependencies too. I just want the packages. `make run-depends-list' & 'make build-depends-list` don't quite cut it either because they don't take into account ports that are already installed. Also none of them list the package names.
So.. Hopefully I have justified the existence of my script enough...
Code:
#ifdef NEVER
g++ $0 -o "$HOME/.port_depends"
"$HOME/.port_depends"
rm "$HOME/.port_depends"
exit
#endif
#include <iostream>
#include <exception>
#include <vector>
#include <string>
using namespace std;
vector<string> packages;
vector<string> ports;
void execute_fetch_list(string command, vector<string>* results)
{
char output[100];
FILE* p = NULL;
string line;
p = popen(command.c_str(), "r");
if(p == NULL)
{
throw exception();
}
while(fgets(output, sizeof(output), p) != NULL)
{
line = output;
results->push_back(line.substr(0, line.length() - 1));
}
if(pclose(p) != 0)
{
throw exception();
}
}
string execute_fetch(string command)
{
char output[100];
FILE* p = NULL;
string line;
vector<string> results;
p = popen(command.c_str(), "r");
if(p == NULL)
{
throw exception();
}
while(fgets(output, sizeof(output), p) != NULL)
{
line = output;
results.push_back(line.substr(0, line.length() - 1));
}
if(pclose(p) != 0)
{
throw exception();
}
return results.at(results.size() - 1);
}
void inspect_port(string port)
{
vector<string> depends;
string package;
for(int portIndex = 0; portIndex < ports.size(); portIndex++)
{
if(ports.at(portIndex) == port)
{
return;
}
}
ports.push_back(port);
execute_fetch_list("make -C " + port + " run-depends-list", &depends);
for(int dependIndex = 0; dependIndex < depends.size(); dependIndex++)
{
inspect_port(depends.at(dependIndex));
}
package = execute_fetch("make -C " + port + " package-name");
for(int packageIndex = 0; packageIndex < packages.size(); packageIndex++)
{
if(packages.at(packageIndex) == package)
{
return;
}
}
cout << package << endl;
}
void safe_main(int argc, char* argv[])
{
vector<string> runDepends;
vector<string> buildDepends;
//populate installedPackages
execute_fetch_list("pkg_info | awk '{print $1}'", &packages);
execute_fetch_list("make build-depends-list", &buildDepends);
execute_fetch_list("make run-depends-list", &runDepends);
for(int dependIndex = 0; dependIndex < buildDepends.size(); dependIndex++)
{
inspect_port(buildDepends.at(dependIndex));
}
for(int dependIndex = 0; dependIndex < runDepends.size(); dependIndex++)
{
inspect_port(runDepends.at(dependIndex));
}
}
int main(int argc, char* argv[])
{
try
{
safe_main(argc, argv);
}
catch(exception& e)
{
cout << "Exception: " << e.what() << "." << endl;
}
return 0;
}
To get working, copy to your PATH, chmod +x and just make sure that it ends in .cpp or the automatic compiling wont work..
Enjoy