LEFT | RIGHT |
(no file at all) | |
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 */ |
11 | 11 |
12 // The usual variables. | 12 // The usual variables. |
13 char *goarch; | 13 char *goarch; |
14 char *gobin; | 14 char *gobin; |
15 char *gohostarch; | 15 char *gohostarch; |
16 char *gohostchar; | 16 char *gohostchar; |
17 char *gohostos; | 17 char *gohostos; |
18 char *goos; | 18 char *goos; |
19 char *goarm; | 19 char *goarm; |
20 char *go386; | 20 char *go386; |
21 char *goroot = GOROOT_FINAL; | 21 char *goroot = GOROOT_FINAL; |
22 char *goroot_final = GOROOT_FINAL; | 22 char *goroot_final = GOROOT_FINAL; |
23 char *goextlinkenabled = ""; | 23 char *goextlinkenabled = ""; |
24 char *workdir; | 24 char *workdir; |
25 char *tooldir; | 25 char *tooldir; |
26 char *gochar; | 26 char *gochar; |
27 char *goversion; | 27 char *goversion; |
28 char *slash; // / for unix, \ for windows | 28 char *slash; // / for unix, \ for windows |
29 char *defaultcc; | 29 char *defaultcc; |
| 30 char *defaultcflags; |
| 31 char *defaultldflags; |
30 char *defaultcxxtarget; | 32 char *defaultcxxtarget; |
31 char *defaultcctarget; | 33 char *defaultcctarget; |
32 bool rebuildall; | 34 bool rebuildall; |
33 bool defaultclang; | 35 bool defaultclang; |
34 | 36 |
35 static bool shouldbuild(char*, char*); | 37 static bool shouldbuild(char*, char*); |
36 static void copy(char*, char*, int); | 38 static void copy(char*, char*, int); |
37 static void dopack(char*, char*, char**, int); | 39 static void dopack(char*, char*, char**, int); |
38 static char *findgoversion(void); | 40 static char *findgoversion(void); |
39 | 41 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Xcode for OS X 10.9 Mavericks will ship a fake "gcc" binary t
hat | 163 // Xcode for OS X 10.9 Mavericks will ship a fake "gcc" binary t
hat |
162 // actually runs clang. We prepare different command | 164 // actually runs clang. We prepare different command |
163 // lines for the two binaries, so it matters what we call it. | 165 // lines for the two binaries, so it matters what we call it. |
164 // See golang.org/issue/5822. | 166 // See golang.org/issue/5822. |
165 if(defaultclang) | 167 if(defaultclang) |
166 bprintf(&b, "clang"); | 168 bprintf(&b, "clang"); |
167 else | 169 else |
168 bprintf(&b, "gcc"); | 170 bprintf(&b, "gcc"); |
169 } | 171 } |
170 defaultcc = btake(&b); | 172 defaultcc = btake(&b); |
| 173 |
| 174 xgetenv(&b, "CFLAGS"); |
| 175 defaultcflags = btake(&b); |
| 176 |
| 177 xgetenv(&b, "LDFLAGS"); |
| 178 defaultldflags = btake(&b); |
171 | 179 |
172 xgetenv(&b, "CC_FOR_TARGET"); | 180 xgetenv(&b, "CC_FOR_TARGET"); |
173 if(b.len == 0) { | 181 if(b.len == 0) { |
174 bprintf(&b, defaultcc); | 182 bprintf(&b, defaultcc); |
175 } | 183 } |
176 defaultcctarget = btake(&b); | 184 defaultcctarget = btake(&b); |
177 | 185 |
178 xgetenv(&b, "CXX_FOR_TARGET"); | 186 xgetenv(&b, "CXX_FOR_TARGET"); |
179 if(b.len == 0) { | 187 if(b.len == 0) { |
180 xgetenv(&b, "CXX"); | 188 xgetenv(&b, "CXX"); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 "-Wno-comment", | 466 "-Wno-comment", |
459 "-Wno-missing-field-initializers", | 467 "-Wno-missing-field-initializers", |
460 "-Werror", | 468 "-Werror", |
461 "-fno-common", | 469 "-fno-common", |
462 "-ggdb", | 470 "-ggdb", |
463 "-pipe", | 471 "-pipe", |
464 #if defined(__NetBSD__) && defined(__arm__) | 472 #if defined(__NetBSD__) && defined(__arm__) |
465 // GCC 4.5.4 (NetBSD nb1 20120916) on ARM is known to mis-optimize gc/mp
arith3.c | 473 // GCC 4.5.4 (NetBSD nb1 20120916) on ARM is known to mis-optimize gc/mp
arith3.c |
466 // Fix available at http://patchwork.ozlabs.org/patch/64562/. | 474 // Fix available at http://patchwork.ozlabs.org/patch/64562/. |
467 "-O1", | 475 "-O1", |
| 476 #endif |
| 477 }; |
| 478 |
| 479 // gccargs2 is the second part of gccargs. |
| 480 // it is used if the environment isn't defining CFLAGS. |
| 481 static char *proto_gccargs2[] = { |
| 482 #if defined(__NetBSD__) && defined(__arm__) |
468 #else | 483 #else |
469 "-O2", | 484 "-O2", |
470 #endif | 485 #endif |
471 }; | 486 }; |
472 | 487 |
473 static Vec gccargs; | 488 static Vec gccargs, ldargs; |
474 | 489 |
475 // deptab lists changes to the default dependencies for a given prefix. | 490 // deptab lists changes to the default dependencies for a given prefix. |
476 // deps ending in /* read the whole directory; deps beginning with - | 491 // deps ending in /* read the whole directory; deps beginning with - |
477 // exclude files with that prefix. | 492 // exclude files with that prefix. |
478 static struct { | 493 static struct { |
479 char *prefix; // prefix of target | 494 char *prefix; // prefix of target |
480 char *dep[20]; // dependency tweaks for targets with that prefix | 495 char *dep[20]; // dependency tweaks for targets with that prefix |
481 } deptab[] = { | 496 } deptab[] = { |
482 {"lib9", { | 497 {"lib9", { |
483 "$GOROOT/include/u.h", | 498 "$GOROOT/include/u.h", |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 690 |
676 // For release, cmd/prof is not included. | 691 // For release, cmd/prof is not included. |
677 if((streq(dir, "cmd/prof")) && !isdir(bstr(&path))) { | 692 if((streq(dir, "cmd/prof")) && !isdir(bstr(&path))) { |
678 if(vflag > 1) | 693 if(vflag > 1) |
679 errprintf("skipping %s - does not exist\n", dir); | 694 errprintf("skipping %s - does not exist\n", dir); |
680 goto out; | 695 goto out; |
681 } | 696 } |
682 | 697 |
683 // set up gcc command line on first run. | 698 // set up gcc command line on first run. |
684 if(gccargs.len == 0) { | 699 if(gccargs.len == 0) { |
685 » » bprintf(&b, "%s", defaultcc); | 700 » » bprintf(&b, "%s %s", defaultcc, defaultcflags); |
686 splitfields(&gccargs, bstr(&b)); | 701 splitfields(&gccargs, bstr(&b)); |
687 for(i=0; i<nelem(proto_gccargs); i++) | 702 for(i=0; i<nelem(proto_gccargs); i++) |
688 vadd(&gccargs, proto_gccargs[i]); | 703 vadd(&gccargs, proto_gccargs[i]); |
| 704 if(defaultcflags[0] == '\0') { |
| 705 for(i=0; i<nelem(proto_gccargs2); i++) |
| 706 vadd(&gccargs, proto_gccargs2[i]); |
| 707 } |
689 if(contains(gccargs.p[0], "clang")) { | 708 if(contains(gccargs.p[0], "clang")) { |
690 // disable ASCII art in clang errors, if possible | 709 // disable ASCII art in clang errors, if possible |
691 vadd(&gccargs, "-fno-caret-diagnostics"); | 710 vadd(&gccargs, "-fno-caret-diagnostics"); |
692 // clang is too smart about unused command-line argument
s | 711 // clang is too smart about unused command-line argument
s |
693 vadd(&gccargs, "-Qunused-arguments"); | 712 vadd(&gccargs, "-Qunused-arguments"); |
694 } | 713 } |
695 // disable word wrapping in error messages | 714 // disable word wrapping in error messages |
696 vadd(&gccargs, "-fmessage-length=0"); | 715 vadd(&gccargs, "-fmessage-length=0"); |
697 if(streq(gohostos, "darwin")) { | 716 if(streq(gohostos, "darwin")) { |
698 // golang.org/issue/5261 | 717 // golang.org/issue/5261 |
699 vadd(&gccargs, "-mmacosx-version-min=10.6"); | 718 vadd(&gccargs, "-mmacosx-version-min=10.6"); |
700 } | 719 } |
| 720 } |
| 721 if(ldargs.len == 0 && defaultldflags[0] != '\0') { |
| 722 bprintf(&b, "%s", defaultldflags); |
| 723 splitfields(&ldargs, bstr(&b)); |
701 } | 724 } |
702 | 725 |
703 islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd
/gc"); | 726 islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd
/gc"); |
704 ispkg = hasprefix(dir, "pkg"); | 727 ispkg = hasprefix(dir, "pkg"); |
705 isgo = ispkg || streq(dir, "cmd/go") || streq(dir, "cmd/cgo"); | 728 isgo = ispkg || streq(dir, "cmd/go") || streq(dir, "cmd/cgo"); |
706 | 729 |
707 exe = ""; | 730 exe = ""; |
708 if(streq(gohostos, "windows")) | 731 if(streq(gohostos, "windows")) |
709 exe = ".exe"; | 732 exe = ".exe"; |
710 | 733 |
(...skipping 24 matching lines...) Expand all Loading... |
735 } else if(streq(dir, "cmd/go") || streq(dir, "cmd/cgo")) { | 758 } else if(streq(dir, "cmd/go") || streq(dir, "cmd/cgo")) { |
736 // Go command. | 759 // Go command. |
737 vadd(&link, bpathf(&b, "%s/%sl", tooldir, gochar)); | 760 vadd(&link, bpathf(&b, "%s/%sl", tooldir, gochar)); |
738 vadd(&link, "-o"); | 761 vadd(&link, "-o"); |
739 elem = name; | 762 elem = name; |
740 if(streq(elem, "go")) | 763 if(streq(elem, "go")) |
741 elem = "go_bootstrap"; | 764 elem = "go_bootstrap"; |
742 targ = link.len; | 765 targ = link.len; |
743 vadd(&link, bpathf(&b, "%s/%s%s", tooldir, elem, exe)); | 766 vadd(&link, bpathf(&b, "%s/%s%s", tooldir, elem, exe)); |
744 } else { | 767 } else { |
745 » » // C command. Use gccargs. | 768 » » // C command. Use gccargs and ldargs. |
746 if(streq(gohostos, "plan9")) { | 769 if(streq(gohostos, "plan9")) { |
747 vadd(&link, bprintf(&b, "%sl", gohostchar)); | 770 vadd(&link, bprintf(&b, "%sl", gohostchar)); |
748 vadd(&link, "-o"); | 771 vadd(&link, "-o"); |
749 targ = link.len; | 772 targ = link.len; |
750 vadd(&link, bpathf(&b, "%s/%s", tooldir, name)); | 773 vadd(&link, bpathf(&b, "%s/%s", tooldir, name)); |
751 } else { | 774 } else { |
752 vcopy(&link, gccargs.p, gccargs.len); | 775 vcopy(&link, gccargs.p, gccargs.len); |
| 776 vcopy(&link, ldargs.p, ldargs.len); |
753 if(sflag) | 777 if(sflag) |
754 vadd(&link, "-static"); | 778 vadd(&link, "-static"); |
755 vadd(&link, "-o"); | 779 vadd(&link, "-o"); |
756 targ = link.len; | 780 targ = link.len; |
757 vadd(&link, bpathf(&b, "%s/%s%s", tooldir, name, exe)); | 781 vadd(&link, bpathf(&b, "%s/%s%s", tooldir, name, exe)); |
758 if(streq(gohostarch, "amd64")) | 782 if(streq(gohostarch, "amd64")) |
759 vadd(&link, "-m64"); | 783 vadd(&link, "-m64"); |
760 else if(streq(gohostarch, "386")) | 784 else if(streq(gohostarch, "386")) |
761 vadd(&link, "-m32"); | 785 vadd(&link, "-m32"); |
762 } | 786 } |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 break; | 1810 break; |
1787 default: | 1811 default: |
1788 usage(); | 1812 usage(); |
1789 }ARGEND | 1813 }ARGEND |
1790 | 1814 |
1791 if(argc > 0) | 1815 if(argc > 0) |
1792 usage(); | 1816 usage(); |
1793 | 1817 |
1794 xprintf("%s\n", goversion); | 1818 xprintf("%s\n", goversion); |
1795 } | 1819 } |
LEFT | RIGHT |