1 module gccbuild.main;
2 
3 import scriptlike, gccbuild;
4 
5 void buildToolchain()
6 {
7     final switch (mode)
8     {
9     case BuildMode.all:
10         downloadSources();
11         extractSources();
12         patchSources();
13         buildHostLibs();
14 
15         startSectionLog("Removing old toolchain directory");
16         toolchainDir.tryRmdirRecurse();
17         endSectionLog();
18 
19         final switch (build.type)
20         {
21         case ToolchainType.cross:
22         case ToolchainType.canadian:
23             installLinuxHeaders();
24             buildBinutils();
25 
26             /**
27                      * In a canadian build we don't have to boostrap a stage 1 compiler
28                      * as we already have a working $BUILD => $TARGET compiler to compile
29                      * the C library
30                      */
31             if (build.type != ToolchainType.canadian)
32             {
33                 startSectionLog("Creating stage1 directory from toolchain directory");
34                 toolchainDirStage1.tryRmdirRecurse();
35                 runCollectLog(
36                     "cp -R --reflink=auto " ~ toolchainDir.toString() ~ " " ~ toolchainDirStage1.toString());
37                 endSectionLog();
38 
39                 buildStage1GCC();
40                 detectMultilib();
41             }
42             else
43             {
44                 /**
45                          * We have to ask the $BUILD => $TARGET compiler for supported multilibs,
46                          * and this must match with the final GCCs multilib configuration / paths!
47                          */
48                 detectMultilib(targetGCC,
49                     "Detecting available multilibs from BUILD=>TARGET compiler");
50             }
51             buildGlibc();
52             buildFinalGCC();
53             break;
54         case ToolchainType.native:
55             toolchainDirStage1.tryRmdirRecurse();
56             if (build.linux.hasBuildCommands)
57                 installLinuxHeaders();
58             if (build.binutils.hasBuildCommands)
59                 buildBinutils();
60             if (build.glibc.hasBuildCommands)
61             {
62                 buildStage1GCC();
63                 detectMultilib();
64                 buildGlibc();
65                 // For now we do not copy stage1 binutils or glibc to the final toolchain,
66                 // just use it when building final GCC
67                 buildFinalGCC();
68             }
69             else
70             {
71                 buildFinalGCC();
72                 // Just print the multilib of the final compiler for debugging
73                 detectMultilib((binDir ~ (build.target ~ "-gcc")).toString());
74             }
75             break;
76         case ToolchainType.cross_native:
77             //if binutils ...
78             //if stage1
79             // buildStage1GCC
80             //if glibc...
81             // detectMultilib(system-compiler);
82             // buildGlibc
83 
84             /**
85                      * Can't run the built compiler, detect multilib from $BUILD => $TARGET compiler.
86                      * For debugging only, but this must match the final compiler multilib configuration,
87                      * otherwise the built toolchain will not work correctly.
88                      */
89             detectMultilib(targetGCC,
90                 "Info: multilibs support in BUILD=>TARGET compiler");
91             buildFinalGCC();
92             break;
93         }
94         break;
95     case BuildMode.download:
96         downloadSources();
97         break;
98     case BuildMode.extract:
99         extractSources();
100         break;
101     case BuildMode.patch:
102         break;
103     }
104 }