Remake
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
User interface

Functions

void usage (int exit_status)
 
int main (int argc, char *argv[])
 

Detailed Description

Function Documentation

int main ( int  argc,
char *  argv[] 
)

This program behaves in two different ways.

  • If the environment contains the REMAKE_SOCKET variable, the client connects to this socket and sends to the server its build targets. It exits once it receives the server reply.
  • Otherwise, it creates a server that waits for build requests. It also creates a pseudo-client that requests the targets passed on the command line.

Definition at line 2721 of file remake.cpp.

2722 {
2723  init_working_dir();
2724 
2725  std::string remakefile = "Remakefile";
2726  string_list targets;
2727  bool indirect_targets = false;
2728 
2729  // Parse command-line arguments.
2730  for (int i = 1; i < argc; ++i)
2731  {
2732  std::string arg = argv[i];
2733  if (arg.empty()) usage(EXIT_FAILURE);
2734  if (arg == "-h" || arg == "--help") usage(EXIT_SUCCESS);
2735  if (arg == "-d")
2736  if (echo_scripts) debug.active = true;
2737  else echo_scripts = true;
2738  else if (arg == "-k" || arg =="--keep-going")
2739  keep_going = true;
2740  else if (arg == "-s" || arg == "--silent" || arg == "--quiet")
2741  show_targets = false;
2742  else if (arg == "-r")
2743  indirect_targets = true;
2744  else if (arg == "-f")
2745  {
2746  if (++i == argc) usage(EXIT_FAILURE);
2747  remakefile = argv[i];
2748  }
2749  else if (arg.compare(0, 2, "-j") == 0)
2750  max_active_jobs = atoi(arg.c_str() + 2);
2751  else if (arg.compare(0, 7, "--jobs=") == 0)
2752  max_active_jobs = atoi(arg.c_str() + 7);
2753  else
2754  {
2755  if (arg[0] == '-') usage(EXIT_FAILURE);
2756  targets.push_back(normalize(arg));
2757  DEBUG << "New target: " << arg << '\n';
2758  }
2759  }
2760 
2761  if (indirect_targets)
2762  {
2763  load_dependencies(std::cin);
2764  string_list l;
2765  targets.swap(l);
2766  if (l.empty() && !dependencies.empty())
2767  {
2768  l.push_back(dependencies.begin()->second->targets.front());
2769  }
2770  for (string_list::const_iterator i = l.begin(),
2771  i_end = l.end(); i != i_end; ++i)
2772  {
2773  dependency_map::const_iterator j = dependencies.find(*i);
2774  if (j == dependencies.end()) continue;
2775  dependency_t const &dep = *j->second;
2776  for (string_set::const_iterator k = dep.deps.begin(),
2777  k_end = dep.deps.end(); k != k_end; ++k)
2778  {
2779  targets.push_back(normalize(*k));
2780  }
2781  }
2782  dependencies.clear();
2783  }
2784 
2785 #ifdef WINDOWS
2786  WSADATA wsaData;
2787  if (WSAStartup(MAKEWORD(2,2), &wsaData))
2788  {
2789  std::cerr << "Unexpected failure while initializing Windows Socket" << std::endl;
2790  return 1;
2791  }
2792 #endif
2793 
2794  // Run as client if REMAKE_SOCKET is present in the environment.
2795  if (char *sn = getenv("REMAKE_SOCKET")) client_mode(sn, targets);
2796 
2797  // Otherwise run as server.
2798  server_mode(remakefile, targets);
2799 }
void usage ( int  exit_status)

Display usage and exit with exit_status.

Definition at line 2695 of file remake.cpp.

Referenced by main().

2696 {
2697  std::cerr << "Usage: remake [options] [target] ...\n"
2698  "Options\n"
2699  " -d Echo script commands.\n"
2700  " -d -d Print lots of debugging information.\n"
2701  " -f FILE Read FILE as Remakefile.\n"
2702  " -h, --help Print this message and exit.\n"
2703  " -j[N], --jobs=[N] Allow N jobs at once; infinite jobs with no arg.\n"
2704  " -k Keep going when some targets cannot be made.\n"
2705  " -r Look up targets from the dependencies on standard input.\n"
2706  " -s, --silent, --quiet Do not echo targets.\n";
2707  exit(exit_status);
2708 }