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

Functions

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

2957 {
2958  std::string remakefile;
2959  string_list targets;
2960  bool literal_targets = false;
2961  bool indirect_targets = false;
2962 
2963  // Parse command-line arguments.
2964  for (int i = 1; i < argc; ++i)
2965  {
2966  std::string arg = argv[i];
2967  if (arg.empty()) usage(EXIT_FAILURE);
2968  if (literal_targets) goto new_target;
2969  if (arg == "-h" || arg == "--help") usage(EXIT_SUCCESS);
2970  if (arg == "-d")
2971  if (echo_scripts) debug.active = true;
2972  else echo_scripts = true;
2973  else if (arg == "-k" || arg =="--keep-going")
2974  keep_going = true;
2975  else if (arg == "-s" || arg == "--silent" || arg == "--quiet")
2976  show_targets = false;
2977  else if (arg == "-r")
2978  indirect_targets = true;
2979  else if (arg == "-f")
2980  {
2981  if (++i == argc) usage(EXIT_FAILURE);
2982  remakefile = argv[i];
2983  }
2984  else if (arg == "--")
2985  literal_targets = true;
2986  else if (arg.compare(0, 2, "-j") == 0)
2987  max_active_jobs = atoi(arg.c_str() + 2);
2988  else if (arg.compare(0, 7, "--jobs=") == 0)
2989  max_active_jobs = atoi(arg.c_str() + 7);
2990  else
2991  {
2992  if (arg[0] == '-') usage(EXIT_FAILURE);
2993  if (arg.find('=') != std::string::npos)
2994  {
2995  std::istringstream in(arg);
2996  std::string name = read_word(in);
2997  if (name.empty() || !expect_token(in, Equal)) usage(EXIT_FAILURE);
2998  read_words(in, variables[name]);
2999  continue;
3000  }
3001  new_target:
3002  targets.push_back(arg);
3003  DEBUG << "New target: " << arg << '\n';
3004  }
3005  }
3006 
3007  init_working_dir();
3009 
3010  if (indirect_targets)
3011  {
3012  load_dependencies(std::cin);
3013  string_list l;
3014  targets.swap(l);
3015  if (l.empty() && !dependencies.empty())
3016  {
3017  l.push_back(dependencies.begin()->second->targets.front());
3018  }
3019  for (string_list::const_iterator i = l.begin(),
3020  i_end = l.end(); i != i_end; ++i)
3021  {
3022  dependency_map::const_iterator j = dependencies.find(*i);
3023  if (j == dependencies.end()) continue;
3024  dependency_t const &dep = *j->second;
3025  for (string_set::const_iterator k = dep.deps.begin(),
3026  k_end = dep.deps.end(); k != k_end; ++k)
3027  {
3028  targets.push_back(normalize(*k, working_dir, working_dir));
3029  }
3030  }
3031  dependencies.clear();
3032  }
3033 
3034 #ifdef WINDOWS
3035  WSADATA wsaData;
3036  if (WSAStartup(MAKEWORD(2,2), &wsaData))
3037  {
3038  std::cerr << "Unexpected failure while initializing Windows Socket" << std::endl;
3039  return 1;
3040  }
3041 #endif
3042 
3043  // Run as client if REMAKE_SOCKET is present in the environment.
3044  if (char *sn = getenv("REMAKE_SOCKET")) client_mode(sn, targets);
3045 
3046  // Otherwise run as server.
3047  if (remakefile.empty())
3048  {
3049  remakefile = "Remakefile";
3050  init_prefix_dir();
3051  }
3053  server_mode(remakefile, targets);
3054 }
static std::string normalize(std::string const &s, std::string const &w, std::string const &p)
Definition: remake.cpp:931
static void server_mode(std::string const &remakefile, string_list const &targets)
Definition: remake.cpp:2790
static void init_prefix_dir()
Definition: remake.cpp:875
static variable_map variables
Definition: remake.cpp:602
std::list< std::string > string_list
Definition: remake.cpp:455
static int max_active_jobs
Definition: remake.cpp:644
static std::string read_word(std::istream &in, bool detect_equal=true)
Definition: remake.cpp:1098
static bool read_words(input_generator &in, string_list &res)
Definition: remake.cpp:1264
string_set deps
Definition: remake.cpp:498
static void init_working_dir()
Definition: remake.cpp:853
static bool keep_going
Definition: remake.cpp:650
static bool echo_scripts
Definition: remake.cpp:709
static std::string working_dir
Definition: remake.cpp:719
static std::string prefix_dir
Definition: remake.cpp:724
static bool show_targets
Definition: remake.cpp:704
log debug
Definition: remake.cpp:779
#define DEBUG
Definition: remake.cpp:793
static void normalize_list(string_list &l, std::string const &w, std::string const &p)
Definition: remake.cpp:982
static int expect_token(std::istream &in, int mask)
Definition: remake.cpp:1052
bool active
Definition: remake.cpp:754
static void usage(int exit_status)
Definition: remake.cpp:2930
static void client_mode(char *socket_name, string_list const &targets)
Definition: remake.cpp:2838
static void load_dependencies(std::istream &in)
Definition: remake.cpp:1415
static dependency_map dependencies
Definition: remake.cpp:607
static void usage ( int  exit_status)
static

Display usage and exit with exit_status.

Definition at line 2930 of file remake.cpp.

Referenced by main().

2931 {
2932  std::cerr << "Usage: remake [options] [target] ...\n"
2933  "Options\n"
2934  " -d Echo script commands.\n"
2935  " -d -d Print lots of debugging information.\n"
2936  " -f FILE Read FILE as Remakefile.\n"
2937  " -h, --help Print this message and exit.\n"
2938  " -j[N], --jobs=[N] Allow N jobs at once; infinite jobs with no arg.\n"
2939  " -k Keep going when some targets cannot be made.\n"
2940  " -r Look up targets from the dependencies on stdin.\n"
2941  " -s, --silent, --quiet Do not echo targets.\n";
2942  exit(exit_status);
2943 }