Shinichiro Hamaji | 1d545aa | 2015-06-23 15:29:13 +0900 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 15 | // +build ignore |
| 16 | |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 17 | #include <limits.h> |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <string.h> |
Shinichiro Hamaji | 087cecd | 2015-07-06 19:51:58 +0900 | [diff] [blame] | 20 | #include <stdlib.h> |
Shinichiro Hamaji | a4bb774 | 2015-07-31 11:27:30 +0900 | [diff] [blame] | 21 | #include <time.h> |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 22 | #include <unistd.h> |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 23 | |
Shinichiro Hamaji | 1a444a8 | 2016-02-16 13:49:49 +0900 | [diff] [blame] | 24 | #include "affinity.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 25 | #include "dep.h" |
| 26 | #include "eval.h" |
| 27 | #include "exec.h" |
| 28 | #include "file.h" |
| 29 | #include "file_cache.h" |
| 30 | #include "fileutil.h" |
Shinichiro Hamaji | 5f57a99 | 2015-06-30 19:39:39 +0900 | [diff] [blame] | 31 | #include "find.h" |
Shinichiro Hamaji | 08808d3 | 2015-06-26 08:02:45 +0900 | [diff] [blame] | 32 | #include "flags.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 33 | #include "func.h" |
| 34 | #include "log.h" |
Shinichiro Hamaji | 5f86e1a | 2015-06-29 14:25:39 +0900 | [diff] [blame] | 35 | #include "ninja.h" |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 36 | #include "parser.h" |
Shinichiro Hamaji | 8ef0ce5 | 2016-01-19 18:07:43 +0900 | [diff] [blame] | 37 | #include "regen.h" |
Shinichiro Hamaji | 0d8e79b | 2015-06-30 03:29:35 +0900 | [diff] [blame] | 38 | #include "stats.h" |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 39 | #include "stmt.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 40 | #include "string_piece.h" |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 41 | #include "stringprintf.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 42 | #include "strutil.h" |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 43 | #include "symtab.h" |
Shinichiro Hamaji | cbd34cd | 2015-07-05 02:53:04 +0900 | [diff] [blame] | 44 | #include "timeutil.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 45 | #include "var.h" |
| 46 | |
Dan Willemsen | 834c6db | 2017-08-15 14:44:32 -0700 | [diff] [blame] | 47 | // We know that there are leaks in Kati. Turn off LeakSanitizer by default. |
| 48 | extern "C" const char* __asan_default_options() { |
| 49 | return "detect_leaks=0"; |
| 50 | } |
| 51 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 52 | static void Init() { |
| 53 | InitSymtab(); |
| 54 | InitFuncTable(); |
| 55 | InitDepNodePool(); |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 56 | InitParser(); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static void Quit() { |
Shinichiro Hamaji | 0d8e79b | 2015-06-30 03:29:35 +0900 | [diff] [blame] | 60 | ReportAllStats(); |
| 61 | |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 62 | QuitParser(); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 63 | QuitDepNodePool(); |
| 64 | QuitFuncTable(); |
| 65 | QuitSymtab(); |
| 66 | } |
| 67 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 68 | static void ReadBootstrapMakefile(const vector<Symbol>& targets, |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 69 | vector<Stmt*>* stmts) { |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 70 | string bootstrap = ( |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 71 | "CC?=cc\n" |
Shinichiro Hamaji | d749b93 | 2015-07-13 20:51:15 -0700 | [diff] [blame] | 72 | #if defined(__APPLE__) |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 73 | "CXX?=c++\n" |
Shinichiro Hamaji | d749b93 | 2015-07-13 20:51:15 -0700 | [diff] [blame] | 74 | #else |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 75 | "CXX?=g++\n" |
Shinichiro Hamaji | d749b93 | 2015-07-13 20:51:15 -0700 | [diff] [blame] | 76 | #endif |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 77 | "AR?=ar\n" |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 78 | // Pretend to be GNU make 3.81, for compatibility. |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 79 | "MAKE_VERSION?=3.81\n" |
Shinichiro Hamaji | cdcd419 | 2015-09-04 10:06:30 +0900 | [diff] [blame] | 80 | "KATI?=ckati\n" |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 81 | // Overwrite $SHELL environment variable. |
| 82 | "SHELL=/bin/sh\n" |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 83 | // TODO: Add more builtin vars. |
| 84 | |
| 85 | // http://www.gnu.org/software/make/manual/make.html#Catalogue-of-Rules |
| 86 | // The document above is actually not correct. See default.c: |
| 87 | // http://git.savannah.gnu.org/cgit/make.git/tree/default.c?id=4.1 |
| 88 | ".c.o:\n" |
| 89 | "\t$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<\n" |
| 90 | ".cc.o:\n" |
| 91 | "\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<\n" |
| 92 | // TODO: Add more builtin rules. |
| 93 | ); |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 94 | if (g_flags.generate_ninja) { |
Shinichiro Hamaji | b6a0454 | 2015-09-09 17:37:41 +0900 | [diff] [blame] | 95 | bootstrap += StringPrintf("MAKE?=make -j%d\n", |
Shinichiro Hamaji | 9dce444 | 2015-12-05 11:05:00 +0900 | [diff] [blame] | 96 | g_flags.num_jobs <= 1 ? 1 : g_flags.num_jobs / 2); |
Shinichiro Hamaji | b6a0454 | 2015-09-09 17:37:41 +0900 | [diff] [blame] | 97 | } else { |
| 98 | bootstrap += StringPrintf("MAKE?=%s\n", |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 99 | JoinStrings(g_flags.subkati_args, " ").c_str()); |
Shinichiro Hamaji | b6a0454 | 2015-09-09 17:37:41 +0900 | [diff] [blame] | 100 | } |
Shinichiro Hamaji | cdcd419 | 2015-09-04 10:06:30 +0900 | [diff] [blame] | 101 | bootstrap += StringPrintf("MAKECMDGOALS?=%s\n", |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 102 | JoinSymbols(targets, " ").c_str()); |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 103 | |
| 104 | char cwd[PATH_MAX]; |
| 105 | if (!getcwd(cwd, PATH_MAX)) { |
| 106 | fprintf(stderr, "getcwd failed\n"); |
| 107 | CHECK(false); |
| 108 | } |
| 109 | bootstrap += StringPrintf("CURDIR:=%s\n", cwd); |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 110 | Parse(Intern(bootstrap).str(), Loc("*bootstrap*", 0), stmts); |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 111 | } |
| 112 | |
Shinichiro Hamaji | c9b9e5e | 2016-02-18 18:18:54 +0900 | [diff] [blame] | 113 | static void SetVar(StringPiece l, VarOrigin origin) { |
Shinichiro Hamaji | 9db4cb8 | 2015-06-22 16:51:04 +0900 | [diff] [blame] | 114 | size_t found = l.find('='); |
| 115 | CHECK(found != string::npos); |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 116 | Symbol lhs = Intern(l.substr(0, found)); |
Shinichiro Hamaji | 9db4cb8 | 2015-06-22 16:51:04 +0900 | [diff] [blame] | 117 | StringPiece rhs = l.substr(found + 1); |
Shinichiro Hamaji | c9b9e5e | 2016-02-18 18:18:54 +0900 | [diff] [blame] | 118 | lhs.SetGlobalVar( |
| 119 | new RecursiveVar(NewLiteral(rhs.data()), origin, rhs.data())); |
Shinichiro Hamaji | 9db4cb8 | 2015-06-22 16:51:04 +0900 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | extern "C" char** environ; |
Shinichiro Hamaji | 9db4cb8 | 2015-06-22 16:51:04 +0900 | [diff] [blame] | 123 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 124 | static int Run(const vector<Symbol>& targets, |
Shinichiro Hamaji | 998ccf7 | 2015-07-18 12:37:02 +0900 | [diff] [blame] | 125 | const vector<StringPiece>& cl_vars, |
| 126 | const string& orig_args) { |
Shinichiro Hamaji | 90db541 | 2015-08-13 15:03:52 +0900 | [diff] [blame] | 127 | double start_time = GetTime(); |
| 128 | |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 129 | if (g_flags.generate_ninja && (g_flags.regen || g_flags.dump_kati_stamp)) { |
Shinichiro Hamaji | f9e1524 | 2015-07-31 12:50:06 +0900 | [diff] [blame] | 130 | ScopedTimeReporter tr("regen check time"); |
Shinichiro Hamaji | f9869fc | 2015-09-28 17:18:59 +0900 | [diff] [blame] | 131 | if (!NeedsRegen(start_time, orig_args)) { |
Shinichiro Hamaji | ac50ff4 | 2016-02-09 16:23:28 +0900 | [diff] [blame] | 132 | fprintf(stderr, "No need to regenerate ninja file\n"); |
Shinichiro Hamaji | f6df334 | 2015-08-11 14:59:36 +0900 | [diff] [blame] | 133 | return 0; |
| 134 | } |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 135 | if (g_flags.dump_kati_stamp) { |
Shinichiro Hamaji | f6df334 | 2015-08-11 14:59:36 +0900 | [diff] [blame] | 136 | printf("Need to regenerate ninja file\n"); |
Shinichiro Hamaji | a4bb774 | 2015-07-31 11:27:30 +0900 | [diff] [blame] | 137 | return 0; |
| 138 | } |
Shinichiro Hamaji | a09ed28 | 2015-07-31 12:21:54 +0900 | [diff] [blame] | 139 | ClearGlobCache(); |
Shinichiro Hamaji | a4bb774 | 2015-07-31 11:27:30 +0900 | [diff] [blame] | 140 | } |
| 141 | |
Shinichiro Hamaji | 1a444a8 | 2016-02-16 13:49:49 +0900 | [diff] [blame] | 142 | SetAffinityForSingleThread(); |
| 143 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 144 | MakefileCacheManager* cache_mgr = NewMakefileCacheManager(); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 145 | |
Shinichiro Hamaji | c9b9e5e | 2016-02-18 18:18:54 +0900 | [diff] [blame] | 146 | Intern("MAKEFILE_LIST").SetGlobalVar( |
| 147 | new SimpleVar(StringPrintf(" %s", g_flags.makefile), VarOrigin::FILE)); |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 148 | for (char** p = environ; *p; p++) { |
Shinichiro Hamaji | c9b9e5e | 2016-02-18 18:18:54 +0900 | [diff] [blame] | 149 | SetVar(*p, VarOrigin::ENVIRONMENT); |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 150 | } |
Shinichiro Hamaji | c9b9e5e | 2016-02-18 18:18:54 +0900 | [diff] [blame] | 151 | Evaluator* ev = new Evaluator(); |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 152 | |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 153 | vector<Stmt*> bootstrap_asts; |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 154 | ReadBootstrapMakefile(targets, &bootstrap_asts); |
| 155 | ev->set_is_bootstrap(true); |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 156 | for (Stmt* stmt : bootstrap_asts) { |
| 157 | LOG("%s", stmt->DebugString().c_str()); |
| 158 | stmt->Eval(ev); |
Shinichiro Hamaji | 0e74c54 | 2015-06-22 16:17:08 +0900 | [diff] [blame] | 159 | } |
| 160 | ev->set_is_bootstrap(false); |
| 161 | |
Shinichiro Hamaji | 1c3a695 | 2016-05-20 16:35:35 +0900 | [diff] [blame] | 162 | ev->set_is_commandline(true); |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 163 | for (StringPiece l : cl_vars) { |
Shinichiro Hamaji | 1c3a695 | 2016-05-20 16:35:35 +0900 | [diff] [blame] | 164 | vector<Stmt*> asts; |
| 165 | Parse(Intern(l).str(), Loc("*bootstrap*", 0), &asts); |
| 166 | CHECK(asts.size() == 1); |
| 167 | asts[0]->Eval(ev); |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 168 | } |
Shinichiro Hamaji | 1c3a695 | 2016-05-20 16:35:35 +0900 | [diff] [blame] | 169 | ev->set_is_commandline(false); |
Shinichiro Hamaji | 91d1249 | 2015-09-04 09:54:48 +0900 | [diff] [blame] | 170 | |
Shinichiro Hamaji | 54e52dd | 2015-06-27 17:14:06 +0900 | [diff] [blame] | 171 | { |
| 172 | ScopedTimeReporter tr("eval time"); |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 173 | Makefile* mk = cache_mgr->ReadMakefile(g_flags.makefile); |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 174 | for (Stmt* stmt : mk->stmts()) { |
| 175 | LOG("%s", stmt->DebugString().c_str()); |
| 176 | stmt->Eval(ev); |
Shinichiro Hamaji | 54e52dd | 2015-06-27 17:14:06 +0900 | [diff] [blame] | 177 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 178 | } |
| 179 | |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 180 | for (ParseErrorStmt* err : GetParseErrors()) { |
Dan Willemsen | e41c755 | 2017-02-22 14:31:16 -0800 | [diff] [blame] | 181 | WARN_LOC(err->loc(), "warning for parse error in an unevaluated line: %s", |
| 182 | err->msg.c_str()); |
Shinichiro Hamaji | a06bee9 | 2015-08-05 17:13:05 +0900 | [diff] [blame] | 183 | } |
| 184 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 185 | vector<DepNode*> nodes; |
Shinichiro Hamaji | 54e52dd | 2015-06-27 17:14:06 +0900 | [diff] [blame] | 186 | { |
| 187 | ScopedTimeReporter tr("make dep time"); |
| 188 | MakeDep(ev, ev->rules(), ev->rule_vars(), targets, &nodes); |
| 189 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 190 | |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 191 | if (g_flags.is_syntax_check_only) |
Shinichiro Hamaji | ed883ef | 2015-07-31 13:15:04 +0900 | [diff] [blame] | 192 | return 0; |
| 193 | |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 194 | if (g_flags.generate_ninja) { |
Shinichiro Hamaji | ed883ef | 2015-07-31 13:15:04 +0900 | [diff] [blame] | 195 | ScopedTimeReporter tr("generate ninja time"); |
Shinichiro Hamaji | 9c5e60c | 2015-09-29 13:26:45 +0900 | [diff] [blame] | 196 | GenerateNinja(nodes, ev, orig_args, start_time); |
Shinichiro Hamaji | ed883ef | 2015-07-31 13:15:04 +0900 | [diff] [blame] | 197 | return 0; |
| 198 | } |
| 199 | |
Shinichiro Hamaji | 45a0c76 | 2015-06-26 06:47:10 +0900 | [diff] [blame] | 200 | for (const auto& p : ev->exports()) { |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 201 | const Symbol name = p.first; |
Shinichiro Hamaji | 45a0c76 | 2015-06-26 06:47:10 +0900 | [diff] [blame] | 202 | if (p.second) { |
| 203 | Var* v = ev->LookupVar(name); |
Shinichiro Hamaji | fb415ad | 2015-08-14 17:19:34 +0900 | [diff] [blame] | 204 | const string&& value = v->Eval(ev); |
| 205 | LOG("setenv(%s, %s)", name.c_str(), value.c_str()); |
| 206 | setenv(name.c_str(), value.c_str(), 1); |
Shinichiro Hamaji | 45a0c76 | 2015-06-26 06:47:10 +0900 | [diff] [blame] | 207 | } else { |
| 208 | LOG("unsetenv(%s)", name.c_str()); |
| 209 | unsetenv(name.c_str()); |
| 210 | } |
| 211 | } |
| 212 | |
Shinichiro Hamaji | 54e52dd | 2015-06-27 17:14:06 +0900 | [diff] [blame] | 213 | { |
| 214 | ScopedTimeReporter tr("exec time"); |
| 215 | Exec(nodes, ev); |
| 216 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 217 | |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 218 | for (Stmt* stmt : bootstrap_asts) |
| 219 | delete stmt; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 220 | delete ev; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 221 | delete cache_mgr; |
| 222 | |
Shinichiro Hamaji | 64cd806 | 2015-06-27 16:58:36 +0900 | [diff] [blame] | 223 | return 0; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 224 | } |
| 225 | |
Shinichiro Hamaji | 34556cc | 2015-10-05 15:01:46 +0900 | [diff] [blame] | 226 | static void FindFirstMakefie() { |
| 227 | if (g_flags.makefile != NULL) |
| 228 | return; |
| 229 | if (Exists("GNUmakefile")) { |
| 230 | g_flags.makefile = "GNUmakefile"; |
| 231 | #if !defined(__APPLE__) |
| 232 | } else if (Exists("makefile")) { |
| 233 | g_flags.makefile = "makefile"; |
| 234 | #endif |
| 235 | } else if (Exists("Makefile")) { |
| 236 | g_flags.makefile = "Makefile"; |
| 237 | } |
| 238 | } |
| 239 | |
Shinichiro Hamaji | 71cf60b | 2015-10-08 18:00:07 +0900 | [diff] [blame] | 240 | static void HandleRealpath(int argc, char** argv) { |
| 241 | char buf[PATH_MAX]; |
| 242 | for (int i = 0; i < argc; i++) { |
| 243 | if (realpath(argv[i], buf)) |
| 244 | printf("%s\n", buf); |
| 245 | } |
| 246 | } |
| 247 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 248 | int main(int argc, char* argv[]) { |
Shinichiro Hamaji | 71cf60b | 2015-10-08 18:00:07 +0900 | [diff] [blame] | 249 | if (argc >= 2 && !strcmp(argv[1], "--realpath")) { |
| 250 | HandleRealpath(argc - 2, argv + 2); |
| 251 | return 0; |
| 252 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 253 | Init(); |
Shinichiro Hamaji | 998ccf7 | 2015-07-18 12:37:02 +0900 | [diff] [blame] | 254 | string orig_args; |
| 255 | for (int i = 0; i < argc; i++) { |
| 256 | if (i) |
| 257 | orig_args += ' '; |
| 258 | orig_args += argv[i]; |
| 259 | } |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 260 | g_flags.Parse(argc, argv); |
Shinichiro Hamaji | 34556cc | 2015-10-05 15:01:46 +0900 | [diff] [blame] | 261 | FindFirstMakefie(); |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 262 | if (g_flags.makefile == NULL) |
Shinichiro Hamaji | e4ee8ea | 2015-08-15 01:22:23 +0900 | [diff] [blame] | 263 | ERROR("*** No targets specified and no makefile found."); |
Shinichiro Hamaji | 5f57a99 | 2015-06-30 19:39:39 +0900 | [diff] [blame] | 264 | // This depends on command line flags. |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 265 | if (g_flags.use_find_emulator) |
Shinichiro Hamaji | 4e950e6 | 2015-07-02 02:59:55 +0900 | [diff] [blame] | 266 | InitFindEmulator(); |
Shinichiro Hamaji | 003d06e | 2015-09-09 18:22:04 +0900 | [diff] [blame] | 267 | int r = Run(g_flags.targets, g_flags.cl_vars, orig_args); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 268 | Quit(); |
| 269 | return r; |
| 270 | } |