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 2722 of file remake.cpp.

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

Display usage and exit with exit_status.

Definition at line 2696 of file remake.cpp.

Referenced by main().

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