Remake
Loading...
Searching...
No Matches
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 3052 of file remake.cpp.

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

◆ usage()

static void usage ( int exit_status)
static

Display usage and exit with exit_status.

Definition at line 3025 of file remake.cpp.

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

Referenced by main().