LEFT | RIGHT |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "a.h" | 5 #include "a.h" |
6 #include "arg.h" | 6 #include "arg.h" |
7 | 7 |
8 /* | 8 /* |
9 * Initialization for any invocation. | 9 * Initialization for any invocation. |
10 */ | 10 */ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 goos = btake(&b); | 92 goos = btake(&b); |
93 if(find(goos, okgoos, nelem(okgoos)) < 0) | 93 if(find(goos, okgoos, nelem(okgoos)) < 0) |
94 fatal("unknown $GOOS %s", goos); | 94 fatal("unknown $GOOS %s", goos); |
95 | 95 |
96 p = bpathf(&b, "%s/include/u.h", goroot); | 96 p = bpathf(&b, "%s/include/u.h", goroot); |
97 if(!isfile(p)) { | 97 if(!isfile(p)) { |
98 fatal("$GOROOT is not set correctly or not exported\n" | 98 fatal("$GOROOT is not set correctly or not exported\n" |
99 "\tGOROOT=%s\n" | 99 "\tGOROOT=%s\n" |
100 "\t%s does not exist", goroot, p); | 100 "\t%s does not exist", goroot, p); |
101 } | 101 } |
102 » | 102 |
103 xgetenv(&b, "GOHOSTARCH"); | 103 xgetenv(&b, "GOHOSTARCH"); |
104 if(b.len > 0) | 104 if(b.len > 0) |
105 gohostarch = btake(&b); | 105 gohostarch = btake(&b); |
106 | 106 |
107 if(find(gohostarch, okgoarch, nelem(okgoarch)) < 0) | 107 if(find(gohostarch, okgoarch, nelem(okgoarch)) < 0) |
108 fatal("unknown $GOHOSTARCH %s", gohostarch); | 108 fatal("unknown $GOHOSTARCH %s", gohostarch); |
109 | 109 |
110 xgetenv(&b, "GOARCH"); | 110 xgetenv(&b, "GOARCH"); |
111 if(b.len == 0) | 111 if(b.len == 0) |
112 bwritestr(&b, gohostarch); | 112 bwritestr(&b, gohostarch); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 {"zgoos_", mkzgoos}, | 475 {"zgoos_", mkzgoos}, |
476 {"zruntime_defs_", mkzruntimedefs}, | 476 {"zruntime_defs_", mkzruntimedefs}, |
477 {"zversion.go", mkzversion}, | 477 {"zversion.go", mkzversion}, |
478 }; | 478 }; |
479 | 479 |
480 // install installs the library, package, or binary associated with dir, | 480 // install installs the library, package, or binary associated with dir, |
481 // which is relative to $GOROOT/src. | 481 // which is relative to $GOROOT/src. |
482 static void | 482 static void |
483 install(char *dir) | 483 install(char *dir) |
484 { | 484 { |
485 » char *name, *p, *elem, *prefix; | 485 » char *name, *p, *elem, *prefix, *exe; |
486 bool islib, ispkg, isgo, stale; | 486 bool islib, ispkg, isgo, stale; |
487 Buf b, b1, path; | 487 Buf b, b1, path; |
488 Vec compile, files, link, go, missing, clean, lib, extra; | 488 Vec compile, files, link, go, missing, clean, lib, extra; |
489 Time ttarg, t; | 489 Time ttarg, t; |
490 int i, j, k, n; | 490 int i, j, k, n; |
491 | 491 |
492 binit(&b); | 492 binit(&b); |
493 binit(&b1); | 493 binit(&b1); |
494 binit(&path); | 494 binit(&path); |
495 vinit(&compile); | 495 vinit(&compile); |
496 vinit(&files); | 496 vinit(&files); |
497 vinit(&link); | 497 vinit(&link); |
498 vinit(&go); | 498 vinit(&go); |
499 vinit(&missing); | 499 vinit(&missing); |
500 vinit(&clean); | 500 vinit(&clean); |
501 vinit(&lib); | 501 vinit(&lib); |
502 vinit(&extra); | 502 vinit(&extra); |
503 ········ | 503 ········ |
504 // path = full path to dir. | 504 // path = full path to dir. |
505 bpathf(&path, "%s/src/%s", goroot, dir); | 505 bpathf(&path, "%s/src/%s", goroot, dir); |
506 name = lastelem(dir); | 506 name = lastelem(dir); |
507 | 507 |
508 islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd
/gc"); | 508 islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd
/gc"); |
509 ispkg = hasprefix(dir, "pkg"); | 509 ispkg = hasprefix(dir, "pkg"); |
510 isgo = ispkg || streq(dir, "cmd/go"); | 510 isgo = ispkg || streq(dir, "cmd/go"); |
511 | 511 |
| 512 exe = ""; |
| 513 if(streq(gohostos, "windows")) |
| 514 exe = ".exe"; |
512 ········ | 515 ········ |
513 // Start final link command line. | 516 // Start final link command line. |
514 // Note: code below knows that link.p[2] is the target. | 517 // Note: code below knows that link.p[2] is the target. |
515 if(islib) { | 518 if(islib) { |
516 // C library. | 519 // C library. |
517 vadd(&link, "ar"); | 520 vadd(&link, "ar"); |
518 vadd(&link, "rsc"); | 521 vadd(&link, "rsc"); |
519 prefix = ""; | 522 prefix = ""; |
520 if(!hasprefix(name, "lib")) | 523 if(!hasprefix(name, "lib")) |
521 prefix = "lib"; | 524 prefix = "lib"; |
522 vadd(&link, bpathf(&b, "%s/pkg/obj/%s%s.a", goroot, prefix, name
)); | 525 vadd(&link, bpathf(&b, "%s/pkg/obj/%s%s.a", goroot, prefix, name
)); |
523 } else if(ispkg) { | 526 } else if(ispkg) { |
524 // Go library (package). | 527 // Go library (package). |
525 vadd(&link, bpathf(&b, "%s/bin/tool/pack", goroot)); | 528 vadd(&link, bpathf(&b, "%s/bin/tool/pack", goroot)); |
526 vadd(&link, "grc"); | 529 vadd(&link, "grc"); |
527 p = bprintf(&b, "%s/pkg/%s_%s/%s", goroot, goos, goarch, dir+4); | 530 p = bprintf(&b, "%s/pkg/%s_%s/%s", goroot, goos, goarch, dir+4); |
528 *xstrrchr(p, '/') = '\0'; | 531 *xstrrchr(p, '/') = '\0'; |
529 xmkdirall(p); | 532 xmkdirall(p); |
530 vadd(&link, bpathf(&b, "%s/pkg/%s_%s/%s.a", goroot, goos, goarch
, dir+4)); | 533 vadd(&link, bpathf(&b, "%s/pkg/%s_%s/%s.a", goroot, goos, goarch
, dir+4)); |
531 } else if(streq(dir, "cmd/go")) { | 534 } else if(streq(dir, "cmd/go")) { |
532 // Go command. | 535 // Go command. |
533 vadd(&link, bpathf(&b, "%s/bin/tool/%sl", goroot, gochar)); | 536 vadd(&link, bpathf(&b, "%s/bin/tool/%sl", goroot, gochar)); |
534 vadd(&link, "-o"); | 537 vadd(&link, "-o"); |
535 » » vadd(&link, bpathf(&b, "%s/bin/tool/go_bootstrap", goroot)); | 538 » » vadd(&link, bpathf(&b, "%s/bin/tool/go_bootstrap%s", goroot, exe
)); |
536 } else { | 539 } else { |
537 // C command. | 540 // C command. |
538 vadd(&link, "gcc"); | 541 vadd(&link, "gcc"); |
539 vadd(&link, "-o"); | 542 vadd(&link, "-o"); |
540 » » vadd(&link, bpathf(&b, "%s/bin/tool/%s", goroot, name)); | 543 » » vadd(&link, bpathf(&b, "%s/bin/tool/%s%s", goroot, name, exe)); |
541 } | 544 } |
542 ttarg = mtime(link.p[2]); | 545 ttarg = mtime(link.p[2]); |
543 | 546 |
544 // Gather files that are sources for this target. | 547 // Gather files that are sources for this target. |
545 // Everything in that directory, and any target-specific | 548 // Everything in that directory, and any target-specific |
546 // additions. | 549 // additions. |
547 xreaddir(&files, bstr(&path)); | 550 xreaddir(&files, bstr(&path)); |
548 for(i=0; i<nelem(deptab); i++) { | 551 for(i=0; i<nelem(deptab); i++) { |
549 if(hasprefix(dir, deptab[i].prefix)) { | 552 if(hasprefix(dir, deptab[i].prefix)) { |
550 for(j=0; (p=deptab[i].dep[j])!=nil; j++) { | 553 for(j=0; (p=deptab[i].dep[j])!=nil; j++) { |
551 breset(&b1); | 554 breset(&b1); |
552 bwritestr(&b1, p); | 555 bwritestr(&b1, p); |
553 bsubst(&b1, "$GOROOT", goroot); | 556 bsubst(&b1, "$GOROOT", goroot); |
554 bsubst(&b1, "$GOOS", goos); | 557 bsubst(&b1, "$GOOS", goos); |
555 bsubst(&b1, "$GOARCH", goarch); | 558 bsubst(&b1, "$GOARCH", goarch); |
556 p = bstr(&b1); | 559 p = bstr(&b1); |
557 if(hassuffix(p, ".a")) { | 560 if(hassuffix(p, ".a")) { |
558 » » » » » vadd(&lib, p); | 561 » » » » » vadd(&lib, bpathf(&b, "%s", p)); |
559 continue; | 562 continue; |
560 } | 563 } |
561 if(hassuffix(p, "/*")) { | 564 if(hassuffix(p, "/*")) { |
562 bpathf(&b, "%s/%s", bstr(&path), p); | 565 bpathf(&b, "%s/%s", bstr(&path), p); |
563 b.len -= 2; | 566 b.len -= 2; |
564 xreaddir(&extra, bstr(&b)); | 567 xreaddir(&extra, bstr(&b)); |
565 bprintf(&b, "%s", p); | 568 bprintf(&b, "%s", p); |
566 b.len -= 2; | 569 b.len -= 2; |
567 for(k=0; k<extra.len; k++) | 570 for(k=0; k<extra.len; k++) |
568 vadd(&files, bpathf(&b1, "%s/%s"
, bstr(&b), extra.p[k])); | 571 vadd(&files, bpathf(&b1, "%s/%s"
, bstr(&b), extra.p[k])); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 copy(bpathf(&b, "%s/signals_GOOS.h", workdir), | 645 copy(bpathf(&b, "%s/signals_GOOS.h", workdir), |
643 bpathf(&b1, "%s/signals_%s.h", bstr(&path), goos)); | 646 bpathf(&b1, "%s/signals_%s.h", bstr(&path), goos)); |
644 } | 647 } |
645 | 648 |
646 // Generate any missing files; regenerate existing ones. | 649 // Generate any missing files; regenerate existing ones. |
647 for(i=0; i<files.len; i++) { | 650 for(i=0; i<files.len; i++) { |
648 p = files.p[i]; | 651 p = files.p[i]; |
649 elem = lastelem(p); | 652 elem = lastelem(p); |
650 for(j=0; j<nelem(gentab); j++) { | 653 for(j=0; j<nelem(gentab); j++) { |
651 if(hasprefix(elem, gentab[j].nameprefix)) { | 654 if(hasprefix(elem, gentab[j].nameprefix)) { |
| 655 if(vflag > 1) |
| 656 xprintf("generate %s\n", p); |
652 gentab[j].gen(bstr(&path), p); | 657 gentab[j].gen(bstr(&path), p); |
653 // Do not add generated file to clean list. | 658 // Do not add generated file to clean list. |
654 // In pkg/runtime, we want to be able to | 659 // In pkg/runtime, we want to be able to |
655 // build the package with the go tool, | 660 // build the package with the go tool, |
656 // and it assumes these generated files already | 661 // and it assumes these generated files already |
657 // exist (it does not know how to build them). | 662 // exist (it does not know how to build them). |
658 // The 'clean' command can remove | 663 // The 'clean' command can remove |
659 // the generated files. | 664 // the generated files. |
660 goto built; | 665 goto built; |
661 } | 666 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 vadd(&compile, "-I"); | 715 vadd(&compile, "-I"); |
711 vadd(&compile, bpathf(&b, "%s/include", goroot)); | 716 vadd(&compile, bpathf(&b, "%s/include", goroot)); |
712 ························ | 717 ························ |
713 vadd(&compile, "-I"); | 718 vadd(&compile, "-I"); |
714 vadd(&compile, bstr(&path)); | 719 vadd(&compile, bstr(&path)); |
715 ········ | 720 ········ |
716 // runtime/goos.c gets the default constants hard-coded. | 721 // runtime/goos.c gets the default constants hard-coded. |
717 if(streq(name, "goos.c")) { | 722 if(streq(name, "goos.c")) { |
718 vadd(&compile, bprintf(&b, "-DGOOS=\"%s\"", goos
)); | 723 vadd(&compile, bprintf(&b, "-DGOOS=\"%s\"", goos
)); |
719 vadd(&compile, bprintf(&b, "-DGOARCH=\"%s\"", go
arch)); | 724 vadd(&compile, bprintf(&b, "-DGOARCH=\"%s\"", go
arch)); |
720 » » » » vadd(&compile, bprintf(&b, "-DGOROOT=\"%s\"", go
root)); | 725 » » » » bprintf(&b1, "%s", goroot); |
| 726 » » » » bsubst(&b1, "\\", "\\\\"); // turn into C strin
g |
| 727 » » » » vadd(&compile, bprintf(&b, "-DGOROOT=\"%s\"", bs
tr(&b1))); |
721 vadd(&compile, bprintf(&b, "-DGOVERSION=\"%s\"",
goversion)); | 728 vadd(&compile, bprintf(&b, "-DGOVERSION=\"%s\"",
goversion)); |
722 } | 729 } |
723 ········ | 730 ········ |
724 // gc/lex.c records the GOEXPERIMENT setting used during
the build. | 731 // gc/lex.c records the GOEXPERIMENT setting used during
the build. |
725 if(streq(name, "lex.c")) { | 732 if(streq(name, "lex.c")) { |
726 xgetenv(&b, "GOEXPERIMENT"); | 733 xgetenv(&b, "GOEXPERIMENT"); |
727 vadd(&compile, bprintf(&b1, "-DGOEXPERIMENT=\"%s
\"", bstr(&b))); | 734 vadd(&compile, bprintf(&b1, "-DGOEXPERIMENT=\"%s
\"", bstr(&b))); |
728 } | 735 } |
729 } else { | 736 } else { |
730 // Supporting files for a Go package. | 737 // Supporting files for a Go package. |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 /* | 1113 /* |
1107 * command implementations | 1114 * command implementations |
1108 */ | 1115 */ |
1109 | 1116 |
1110 void | 1117 void |
1111 usage(void) | 1118 usage(void) |
1112 { | 1119 { |
1113 xprintf("usage: go tool dist [command]\n" | 1120 xprintf("usage: go tool dist [command]\n" |
1114 "Commands are:\n" | 1121 "Commands are:\n" |
1115 "\n" | 1122 "\n" |
1116 » » "banner print installation banner\n" | 1123 » » "banner print installation banner\n" |
1117 » » "bootstrap rebuild everything\n" | 1124 » » "bootstrap rebuild everything\n" |
1118 » » "clean deletes all built files\n" | 1125 » » "clean deletes all built files\n" |
1119 » » "env [-p] print environment (-p: include $PATH)\n" | 1126 » » "env [-p] print environment (-p: include $PATH)\n" |
1120 » » "install install individual directory\n" | 1127 » » "install [dir] install individual directory\n" |
1121 » » "version print Go version\n" | 1128 » » "version print Go version\n" |
1122 "\n" | 1129 "\n" |
1123 "All commands take -v flags to emit extra information.\n" | 1130 "All commands take -v flags to emit extra information.\n" |
1124 ); | 1131 ); |
1125 xexit(2); | 1132 xexit(2); |
1126 } | 1133 } |
1127 | 1134 |
1128 // The env command prints the default environment. | 1135 // The env command prints the default environment. |
1129 void | 1136 void |
1130 cmdenv(int argc, char **argv) | 1137 cmdenv(int argc, char **argv) |
1131 { | 1138 { |
1132 bool pflag; | 1139 bool pflag; |
1133 » Buf b; | 1140 » char *sep; |
1134 »······· | 1141 » Buf b, b1; |
| 1142 » char *format; |
| 1143 |
1135 binit(&b); | 1144 binit(&b); |
1136 | 1145 » binit(&b1); |
| 1146 |
| 1147 » format = "%s=\"%s\""; |
1137 pflag = 0; | 1148 pflag = 0; |
1138 ARGBEGIN{ | 1149 ARGBEGIN{ |
1139 case 'p': | 1150 case 'p': |
1140 pflag = 1; | 1151 pflag = 1; |
1141 break; | 1152 break; |
1142 case 'v': | 1153 case 'v': |
1143 vflag++; | 1154 vflag++; |
1144 break; | 1155 break; |
| 1156 case 'w': |
| 1157 format = "set %s=%s\n"; |
| 1158 break; |
1145 default: | 1159 default: |
1146 usage(); | 1160 usage(); |
1147 }ARGEND | 1161 }ARGEND |
1148 | 1162 |
1149 if(argc > 0) | 1163 if(argc > 0) |
1150 usage(); | 1164 usage(); |
1151 ········ | 1165 ········ |
1152 » xprintf("GOROOT=\"%s\"\n", goroot); | 1166 » xprintf(format, "GOROOT", goroot); |
1153 » xprintf("GOARCH=%s\n", goarch); | 1167 » xprintf(format, "GOARCH", goarch); |
1154 » xprintf("GOOS=%s\n", goos); | 1168 » xprintf(format, "GOOS", goos); |
1155 if(pflag) { | 1169 if(pflag) { |
| 1170 sep = ":"; |
| 1171 if(streq(gohostos, "windows")) |
| 1172 sep = ";"; |
1156 xgetenv(&b, "PATH"); | 1173 xgetenv(&b, "PATH"); |
1157 » » xprintf("PATH=%s:%s\n", gobin, bstr(&b)); | 1174 » » bprintf(&b1, "%s%s%s", gobin, sep, bstr(&b)); |
| 1175 » » xprintf(format, "PATH", bstr(&b1)); |
1158 } | 1176 } |
1159 | 1177 |
1160 bfree(&b); | 1178 bfree(&b); |
| 1179 bfree(&b1); |
1161 } | 1180 } |
1162 | 1181 |
1163 // The bootstrap command runs a build from scratch, | 1182 // The bootstrap command runs a build from scratch, |
1164 // stopping at having installed the go_bootstrap command. | 1183 // stopping at having installed the go_bootstrap command. |
1165 void | 1184 void |
1166 cmdbootstrap(int argc, char **argv) | 1185 cmdbootstrap(int argc, char **argv) |
1167 { | 1186 { |
1168 int i; | 1187 int i; |
1169 Buf b; | 1188 Buf b; |
1170 char *p; | 1189 char *p; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 | 1253 |
1235 for(i=0; i<argc; i++) | 1254 for(i=0; i<argc; i++) |
1236 install(argv[i]); | 1255 install(argv[i]); |
1237 } | 1256 } |
1238 | 1257 |
1239 // Clean deletes temporary objects. | 1258 // Clean deletes temporary objects. |
1240 // Clean -i deletes the installed objects too. | 1259 // Clean -i deletes the installed objects too. |
1241 void | 1260 void |
1242 cmdclean(int argc, char **argv) | 1261 cmdclean(int argc, char **argv) |
1243 { | 1262 { |
1244 bool iflag; | |
1245 ········ | |
1246 iflag = 0; | |
1247 ARGBEGIN{ | 1263 ARGBEGIN{ |
1248 case 'v': | 1264 case 'v': |
1249 vflag++; | 1265 vflag++; |
1250 break; | 1266 break; |
1251 default: | 1267 default: |
1252 usage(); | 1268 usage(); |
1253 }ARGEND | 1269 }ARGEND |
1254 | 1270 |
1255 if(argc > 0) | 1271 if(argc > 0) |
1256 usage(); | 1272 usage(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 break; | 1338 break; |
1323 default: | 1339 default: |
1324 usage(); | 1340 usage(); |
1325 }ARGEND | 1341 }ARGEND |
1326 | 1342 |
1327 if(argc > 0) | 1343 if(argc > 0) |
1328 usage(); | 1344 usage(); |
1329 | 1345 |
1330 xprintf("%s\n", findgoversion()); | 1346 xprintf("%s\n", findgoversion()); |
1331 } | 1347 } |
LEFT | RIGHT |