/**
* Initialize #working_dir.
*/
-void init_working_dir()
+void init_working_dir(const char* argv0)
{
char buf[1024];
+#ifdef WINDOWS
+ char const *delim = "/\\";
+#else
+ char delim = '/';
+#endif
+ if (!getenv("REMAKE_SOCKET"))
+ {
+ std::string path = argv0;
+
+ size_t found = path.find_last_of(delim);
+ if (found != std::string::npos)
+ {
+ path = path.substr(0, found);
+ std::cout << "Entering directory `" << path << "'" << std::endl;
+ if (chdir(path.c_str()))
+ {
+ perror("Failed to change working directory");
+ exit(EXIT_FAILURE);
+ }
+ }
+ }
+
char *res = getcwd(buf, sizeof(buf));
if (!res)
{
*/
int main(int argc, char *argv[])
{
- init_working_dir();
+ init_working_dir(argv[0]);
string_list targets;
bool indirect_targets = false;