From: Kim Nguyễn Date: Sat, 30 Nov 2013 08:25:47 +0000 (+0100) Subject: Make remake print "Entering/Leaving directory `foo'" if it changes the current workin... X-Git-Tag: v0.1~28 X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=commitdiff_plain;h=d8be1edd45c23e180d0ea810fa6ef1bc69519b6c Make remake print "Entering/Leaving directory `foo'" if it changes the current working dir. --- diff --git a/remake.cpp b/remake.cpp index b8387be..b6c3c6b 100644 --- a/remake.cpp +++ b/remake.cpp @@ -724,6 +724,12 @@ static std::string prefix_dir; */ static bool propagate_vars = false; + +/** + * Whether to print that we changed working directory (to be nice with emacs) + */ +static bool print_change_working_dir = false; + #ifndef WINDOWS static volatile sig_atomic_t got_SIGCHLD = 0; @@ -865,13 +871,28 @@ static void init_working_dir() */ static void init_prefix_dir() { + std::string old_prefix_dir = prefix_dir; for (;;) { struct stat s; if (stat((prefix_dir + "/Remakefile").c_str(), &s) == 0) { - chdir(prefix_dir.c_str()); - return; + if (0 == chdir(prefix_dir.c_str())) + { + if (old_prefix_dir != prefix_dir) + { + std::cout << "remake: Entering directory `" + << prefix_dir << "'" + << std::endl; + print_change_working_dir = true; + } + return; + } + else + { + std::cerr << "Cannot change working directory to '" << prefix_dir << "'"; + exit(EXIT_FAILURE); + } } size_t pos = prefix_dir.find_last_of('/'); if (pos == std::string::npos) @@ -2792,6 +2813,9 @@ static void server_mode(std::string const &remakefile, string_list const &target free(socket_name); #endif save_dependencies(); + if (print_change_working_dir) + std::cout << "remake: Leaving directory `" << prefix_dir + << "'" <