Changeset 137
- Timestamp:
- 05/02/06 14:03:27 (2 years ago)
- Files:
-
- trunk/buildme.d (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/buildme.d
r136 r137 10 10 } 11 11 12 private static const char[] forBuild = "forbuild.txt"; 13 private static const char[] configTxt = "build_debug.txt"; 14 private static const char[] commonTxt = "build_common.txt"; 15 private static const char[] tempBrf = "temp.brf"; 16 17 version(Windows) 18 { 19 private static const char[] delCmd = "del "; 20 } 21 else version(linux) 22 { 23 private static const char[] delCmd = "rm -f "; 24 } 25 else 26 { 27 static assert(0); 28 } 29 12 // build configurations 30 13 enum Mode 31 14 { … … 34 17 } 35 18 19 // name of the text file found in each package directory 20 private static const char[] forBuild = "forbuild.txt"; 21 22 // possible build configuration file names 23 private static const char[][] configs = 24 [ 25 "build_debug.txt", 26 "build_release.txt" 27 ]; 28 29 // the actual build configuration file to use 30 private char[] configTxt; 31 32 // name of the text file containing swtiched common to all configurations 33 private static const char[] commonTxt = "build_common.txt"; 34 35 // buffer to store the contents of commonTxt and configTxt at startup 36 private static char[] brfBuf = ""; 37 38 // name of the temporary Build Response File generated by this script 39 private static const char[] tempBrf = "temp.brf"; 40 41 // build configuration. If none is specified on the command line, Mode.Debug is default 36 42 private Mode mode = Mode.Debug; 43 44 version(Windows) 45 { 46 // Windows delete command 47 private static const char[] delCmd = "del "; 48 } 49 else version(linux) 50 { 51 // Linux delete command 52 private static const char[] delCmd = "rm -f "; 53 } 54 else 55 { 56 static assert(0); 57 } 58 59 37 60 38 61 void main(char[][] args) … … 45 68 else 46 69 { 70 // look for a build configuration in the command line 71 foreach(char[] c; args) 72 { 73 if(c.tolower().cmp("release") == 0) 74 { 75 mode = Mode.Release; 76 break; 77 } 78 else if(c.tolower().cmp("debug") == 0) 79 { 80 mode = Mode.Debug; 81 break; 82 } 83 } 84 85 // set the name of the build configuration text file 86 configTxt = configs[mode]; 87 88 // build a buffer of the commonTxt and configTxt so that it is done 89 // one time only and not once for each file 90 buildBRFBuffer(); 91 47 92 // parse the command line for individual package names and build each package 48 93 foreach(char[] c; args) … … 65 110 private char[] libString(char[] packageName) 66 111 { 112 // build a string which will be used as the name of the library file 67 113 version(Windows) 68 114 { 115 // PackageName.lib 69 116 return packageName ~ ".lib"; 70 117 } 71 118 else version(linux) 72 119 { 120 // libPackageName.a 73 121 return "lib" ~ packageName ~ ".a"; 74 122 } … … 80 128 } 81 129 130 private void buildBRFBuffer() 131 { 132 // if a common switches file is present... 133 if(exists(commonTxt)) 134 { 135 // read it in and assign it to the brf buffer 136 brfBuf = "\n" ~ cast(char[])read(commonTxt); 137 } 138 139 // if a build configuration file is present... 140 if(exists(configTxt)) 141 { 142 // ... read it in and append it to the buffer 143 brfBuf ~= cast(char[])read(configTxt); 144 } 145 } 146 82 147 private void createBRF(char[] packageName, char[] path) 83 148 { 84 149 writefln("Reading build arguments..."); 85 150 151 // read the package forbuild file 86 152 char[] txt = cast(char[])read(path); 87 153 154 // this will store all of the text to be output to the temp build response file 88 155 char[] brf = ""; 89 156 90 if(exists(configTxt)) 91 { 92 brf = cast(char[])read(configTxt); 93 } 94 95 if(exists(commonTxt)) 96 { 97 brf ~= "\n" ~ cast(char[])read(commonTxt); 98 } 99 157 // append the common brf buffer 158 brf ~= brfBuf; 159 160 // the package directory must be on the import path 100 161 brf ~= "\n-I" ~ packageName; 101 162 163 // if the current package is not DerelictUtil, then DerelictUtil must be 164 // on the import path and excluded from being compiled 102 165 if(packageName.cmp("DerelictUtil") != 0) 103 166 { … … 105 168 } 106 169 170 // append a switch to set the output path of the library 107 171 brf ~= "\n-Tlib/" ~ libString(packageName) ~ "\n" ~ txt; 108 172 173 // write the temporary build response file to disk 109 174 writefln("Creating temporary build response file..."); 110 175 write(tempBrf, cast(void[])brf); … … 113 178 private void buildPackage(char[] packageName) 114 179 { 180 // construct a path to the package's forbuild file 115 181 char[] path = packageName ~ sep ~ forBuild; 116 182 if(!exists(path)) 117 183 { 184 // if there is no forbuild file in the subdirectory then this isn't 185 // a Derelict package and there is nothing to do 118 186 return; 119 187 } 188 189 // create the temporary build response file 120 190 writefln("Preparing to build package %s in %s mode...", packageName, modeString); 121 191 createBRF(packageName, path); 122 192 193 // call out to build with the name of the temporary build response file as an arg 123 194 writefln("Building package..."); 124 195 system("build @temp"); 125 196 197 // delete the temporary build response file 126 198 writefln("Deleting temporary build response file...\n\n"); 127 199 system(delCmd ~ tempBrf); … … 130 202 private void scan() 131 203 { 204 // delegate to use as the listdir callback 132 205 bool callback(char[] filename) 133 206 { 207 // if this filename is a directory, pass it to buildpackage for 208 // further processing 134 209 if(isdir(filename)) 135 210 { 136 211 buildPackage(filename); 137 212 } 213 214 // return true to continue listing directories 138 215 return true; 139 216 } 140 217 218 // call listdir to cycle through every Derelict directory 141 219 writefln("\nScanning for buildable packages...\n\n"); 142 220 listdir(".", &callback);
