Remake
Loading...
Searching...
No Matches
Functions
User interface

Functions

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

Detailed Description

Function Documentation

◆ main()

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

3054{
3055 std::string remakefile;
3056 string_list targets;
3057 bool literal_targets = false;
3058 bool indirect_targets = false;
3059
3060 // Parse command-line arguments.
3061 for (int i = 1; i < argc; ++i)
3062 {
3063 std::string arg = argv[i];
3064 if (arg.empty()) usage(EXIT_FAILURE);
3065 if (literal_targets) goto new_target;
3066 if (arg == "-h" || arg == "--help") usage(EXIT_SUCCESS);
3067 if (arg == "-d")
3068 if (echo_scripts) debug.active = true;
3069 else echo_scripts = true;
3070 else if (arg == "-k" || arg =="--keep-going")
3071 keep_going = true;
3072 else if (arg == "-s" || arg == "--silent" || arg == "--quiet")
3073 show_targets = false;
3074 else if (arg == "-r")
3075 indirect_targets = true;
3076 else if (arg == "-B" || arg == "--always-make")
3077 obsolete_targets = true;
3078 else if (arg == "-f")
3079 {
3080 if (++i == argc) usage(EXIT_FAILURE);
3081 remakefile = argv[i];
3082 }
3083 else if (arg == "--")
3084 literal_targets = true;
3085 else if (arg.compare(0, 2, "-j") == 0)
3086 max_active_jobs = atoi(arg.c_str() + 2);
3087 else if (arg.compare(0, 7, "--jobs=") == 0)
3088 max_active_jobs = atoi(arg.c_str() + 7);
3089 else
3090 {
3091 if (arg[0] == '-') usage(EXIT_FAILURE);
3092 if (arg.find('=') != std::string::npos)
3093 {
3094 std::istringstream in(arg);
3095 std::string name = read_word(in);
3096 if (name.empty() || !expect_token(in, Equal)) usage(EXIT_FAILURE);
3097 read_words(in, variables[name]);
3098 continue;
3099 }
3100 new_target:
3101 targets.push_back(arg);
3102 DEBUG << "New target: " << arg << '\n';
3103 }
3104 }
3105
3108
3109 if (indirect_targets)
3110 {
3111 load_dependencies(std::cin);
3112 string_list l;
3113 targets.swap(l);
3114 if (l.empty() && !dependencies.empty())
3115 {
3116 l.push_back(dependencies.begin()->second->targets.front());
3117 }
3118 for (string_list::const_iterator i = l.begin(),
3119 i_end = l.end(); i != i_end; ++i)
3120 {
3121 dependency_map::const_iterator j = dependencies.find(*i);
3122 if (j == dependencies.end()) continue;
3123 dependency_t const &dep = *j->second;
3124 for (string_set::const_iterator k = dep.deps.begin(),
3125 k_end = dep.deps.end(); k != k_end; ++k)
3126 {
3127 targets.push_back(normalize(*k, working_dir, working_dir));
3128 }
3129 }
3130 dependencies.clear();
3131 }
3132
3133#ifdef WINDOWS
3135 if (WSAStartup(MAKEWORD(2,2), &wsaData))
3136 {
3137 std::cerr << "Unexpected failure while initializing Windows Socket" << std::endl;
3138 return 1;
3139 }
3140#endif
3141
3142 // Run as client if REMAKE_SOCKET is present in the environment.
3143 if (char *sn = getenv("REMAKE_SOCKET")) client_mode(sn, targets);
3144
3145 // Otherwise run as server.
3146 if (remakefile.empty())
3147 {
3148 remakefile = "Remakefile";
3150 }
3152 server_mode(remakefile, targets);
3153}
static void client_mode(char *socket_name, string_list const &targets)
Definition remake.cpp:2934
static void load_dependencies()
Definition remake.cpp:1473
static int expect_token(std::istream &in, int mask)
Definition remake.cpp:1076
static std::string read_word(std::istream &in, bool detect_equal=true)
Definition remake.cpp:1122
@ Equal
Definition remake.cpp:1062
static std::string normalize(std::string const &s, std::string const &w, std::string const &p)
Definition remake.cpp:955
static void init_working_dir()
Definition remake.cpp:877
static void init_prefix_dir()
Definition remake.cpp:899
static void normalize_list(string_list &l, std::string const &w, std::string const &p)
Definition remake.cpp:1006
static void server_mode(std::string const &remakefile, string_list const &targets)
Definition remake.cpp:2886
static bool read_words(input_generator &in, string_list &res)
Definition remake.cpp:1288
static void usage(int exit_status)
Definition remake.cpp:3026
static bool keep_going
Definition remake.cpp:667
static int max_active_jobs
Definition remake.cpp:661
std::list< std::string > string_list
Definition remake.cpp:471
static std::string working_dir
Definition remake.cpp:736
static dependency_map dependencies
Definition remake.cpp:624
static variable_map variables
Definition remake.cpp:619
static bool obsolete_targets
Definition remake.cpp:756
static bool show_targets
Definition remake.cpp:721
static bool echo_scripts
Definition remake.cpp:726
#define DEBUG
Definition remake.cpp:817
static std::string prefix_dir
Definition remake.cpp:741
static log debug
Definition remake.cpp:803

◆ usage()

static void usage ( int exit_status)
static

Display usage and exit with exit_status.

Definition at line 3026 of file remake.cpp.

3027{
3028 std::cerr << "Usage: remake [options] [target] ...\n"
3029 "Options\n"
3030 " -B, --always-make Unconditionally make all targets.\n"
3031 " -d Echo script commands.\n"
3032 " -d -d Print lots of debugging information.\n"
3033 " -f FILE Read FILE as Remakefile.\n"
3034 " -h, --help Print this message and exit.\n"
3035 " -j[N], --jobs=[N] Allow N jobs at once; infinite jobs with no arg.\n"
3036 " -k, --keep-going Keep going when some targets cannot be made.\n"
3037 " -r Look up targets from the dependencies on stdin.\n"
3038 " -s, --silent, --quiet Do not echo targets.\n";
3040}

Referenced by main().