[2] | 1 | //----------------------------------------------------------- |
---|
| 2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
| 3 | // arnault@lal.in2p3.fr |
---|
| 4 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
| 5 | //----------------------------------------------------------- |
---|
| 6 | |
---|
| 7 | #include "cmt_generators.h" |
---|
| 8 | #include "cmt_awk.h" |
---|
| 9 | #include "cmt_use.h" |
---|
| 10 | #include "cmt_symbol.h" |
---|
| 11 | #include "cmt_log.h" |
---|
[527] | 12 | #include "cmt_error.h" |
---|
[428] | 13 | #include <assert.h> |
---|
[588] | 14 | #include "cmt_project.h" |
---|
[2] | 15 | |
---|
| 16 | //-------------------------------------------------- |
---|
| 17 | AnyDocumentGenerator::AnyDocumentGenerator () |
---|
| 18 | { |
---|
| 19 | m_TITLE.set ("TITLE"); |
---|
[197] | 20 | m_STRUCTURED_OUTPUT.set ("STRUCTURED_OUTPUT"); |
---|
[2] | 21 | |
---|
| 22 | make_header_fragment.set ("make_header"); |
---|
| 23 | cleanup_header_fragment.set ("cleanup_header"); |
---|
| 24 | cleanup_fragment.set ("cleanup"); |
---|
| 25 | dependencies_fragment.set ("dependencies"); |
---|
| 26 | dependencies_and_triggers_fragment.set ("dependencies_and_triggers"); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void AnyDocumentGenerator::reset () |
---|
| 30 | { |
---|
| 31 | CmtGenerator::reset (); |
---|
| 32 | m_TITLE = ""; |
---|
| 33 | |
---|
| 34 | make_header_fragment.reset (); |
---|
| 35 | cleanup_header_fragment.reset (); |
---|
| 36 | cleanup_fragment.reset (); |
---|
| 37 | dependencies_fragment.reset (); |
---|
| 38 | dependencies_and_triggers_fragment.reset (); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | //-------------------------------------------------- |
---|
| 42 | LibraryGenerator::LibraryGenerator () |
---|
| 43 | { |
---|
| 44 | library_header_fragment.set ("library_header"); |
---|
| 45 | application_header_fragment.set ("application_header"); |
---|
| 46 | java_header_fragment.set ("java_header"); |
---|
| 47 | jar_header_fragment.set ("jar_header"); |
---|
| 48 | protos_header_fragment.set ("protos_header"); |
---|
| 49 | library_fragment.set ("library"); |
---|
| 50 | library_no_share_fragment.set ("library_no_share"); |
---|
[466] | 51 | library_no_static_fragment.set ("library_no_static"); |
---|
[2] | 52 | application_fragment.set ("application"); |
---|
| 53 | jar_fragment.set ("jar"); |
---|
| 54 | java_fragment.set ("java"); |
---|
| 55 | java_copy_fragment.set ("java_copy"); |
---|
| 56 | cleanup_library_fragment.set ("cleanup_library"); |
---|
| 57 | cleanup_application_fragment.set ("cleanup_application"); |
---|
| 58 | cleanup_java_fragment.set ("cleanup_java"); |
---|
| 59 | cleanup_objects_fragment.set ("cleanup_objects"); |
---|
| 60 | buildproto_fragment.set ("buildproto"); |
---|
| 61 | check_application_fragment.set ("check_application"); |
---|
| 62 | check_java_fragment.set ("check_java"); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | //-------------------------------------------------- |
---|
| 66 | void LibraryGenerator::reset () |
---|
| 67 | { |
---|
| 68 | AnyDocumentGenerator::reset (); |
---|
| 69 | library_header_fragment.reset (); |
---|
| 70 | application_header_fragment.reset (); |
---|
| 71 | java_header_fragment.reset (); |
---|
| 72 | jar_header_fragment.reset (); |
---|
| 73 | protos_header_fragment.reset (); |
---|
| 74 | library_fragment.reset (); |
---|
| 75 | library_no_share_fragment.reset (); |
---|
[466] | 76 | library_no_static_fragment.reset (); |
---|
[2] | 77 | jar_fragment.reset (); |
---|
| 78 | application_fragment.reset (); |
---|
| 79 | java_fragment.reset (); |
---|
| 80 | java_copy_fragment.reset (); |
---|
| 81 | cleanup_library_fragment.reset (); |
---|
| 82 | cleanup_application_fragment.reset (); |
---|
| 83 | cleanup_java_fragment.reset (); |
---|
| 84 | cleanup_objects_fragment.reset (); |
---|
| 85 | buildproto_fragment.reset (); |
---|
| 86 | check_application_fragment.reset (); |
---|
| 87 | check_java_fragment.reset (); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | //-------------------------------------------------- |
---|
| 91 | bool LibraryGenerator::analyze_file (const Constituent& constituent, |
---|
| 92 | const cmt_string& file) |
---|
| 93 | { |
---|
| 94 | static cmt_string suffix; |
---|
| 95 | static cmt_string name; |
---|
| 96 | static cmt_string obj; |
---|
| 97 | |
---|
| 98 | bool file_not_found = false; |
---|
| 99 | bool can_build = true; |
---|
| 100 | |
---|
| 101 | obj = file; |
---|
| 102 | |
---|
| 103 | if (Cmt::get_debug ()) |
---|
| 104 | { |
---|
| 105 | cout << "CmtGenerator::analyze_file> constituent=" << |
---|
[400] | 106 | constituent.name << |
---|
| 107 | " file=" << file << endl; |
---|
[2] | 108 | } |
---|
| 109 | |
---|
| 110 | if (!CmtSystem::test_file (file) && !CmtSystem::test_directory (file)) |
---|
| 111 | { |
---|
| 112 | file_not_found = true; |
---|
[459] | 113 | CmtMessage::warning ("Source file " + file + " not found"); |
---|
| 114 | // cerr << "#CMT> Warning: Source file " << file << " not found" << endl; |
---|
[2] | 115 | } |
---|
| 116 | |
---|
| 117 | CmtSystem::get_suffix (file, suffix); |
---|
| 118 | CmtSystem::basename (file, suffix, name); |
---|
| 119 | |
---|
| 120 | Language& language = Language::find_with_suffix (suffix); |
---|
| 121 | |
---|
| 122 | if (m_LINKMACRO == "") |
---|
| 123 | { |
---|
| 124 | m_LINKMACRO = language.linker; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | if (language == "java") |
---|
| 128 | { |
---|
| 129 | static Packager packager; |
---|
| 130 | |
---|
| 131 | obj = "$(javabin)"; |
---|
| 132 | obj += m_CONSTITUENT; |
---|
| 133 | obj += CmtSystem::file_separator (); |
---|
| 134 | |
---|
| 135 | cmt_regexp exp ("^package[ \t][ \t]*[a-zA-Z0-9_.][a-zA-Z0-9_.][ \t]*;"); |
---|
| 136 | |
---|
| 137 | packager.run (file, exp); |
---|
| 138 | if (packager.package_name () != "") |
---|
| 139 | { |
---|
| 140 | obj += packager.package_name (); |
---|
| 141 | obj += CmtSystem::file_separator (); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | obj += name; |
---|
| 145 | obj += ".class"; |
---|
| 146 | } |
---|
| 147 | else if (language != Language::null ()) |
---|
| 148 | { |
---|
[197] | 149 | obj = "$(bin)"; |
---|
| 150 | |
---|
| 151 | if (CmtSystem::getenv("STRUCTURED_OUTPUT")!="" || Cmt::build_nmake ()) |
---|
[400] | 152 | { |
---|
[197] | 153 | obj += m_CONSTITUENT; |
---|
| 154 | obj += CmtSystem::file_separator (); |
---|
[400] | 155 | } |
---|
[197] | 156 | |
---|
[2] | 157 | obj += name; |
---|
| 158 | obj += language.output_suffix; |
---|
| 159 | obj += constituent.suffix; |
---|
| 160 | if (Cmt::build_nmake ()) obj += ".obj"; |
---|
| 161 | else obj += ".o"; |
---|
| 162 | |
---|
| 163 | for (int i = 0; i < language.extra_output_suffixes.size (); i++) |
---|
| 164 | { |
---|
| 165 | cmt_string& extra_suffix = language.extra_output_suffixes[i]; |
---|
| 166 | |
---|
| 167 | obj += " $(bin)"; |
---|
| 168 | obj += name; |
---|
| 169 | obj += extra_suffix; |
---|
| 170 | obj += language.output_suffix; |
---|
| 171 | obj += constituent.suffix; |
---|
| 172 | if (Cmt::build_nmake ()) obj += ".obj"; |
---|
| 173 | else obj += ".o"; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
| 178 | if (m_LINKMACRO == "java") |
---|
| 179 | { |
---|
| 180 | obj = "$(javabin)"; |
---|
| 181 | obj += m_CONSTITUENT; |
---|
| 182 | obj += CmtSystem::file_separator (); |
---|
| 183 | obj += file; |
---|
| 184 | |
---|
| 185 | obj.replace ("../src/", ""); |
---|
| 186 | obj.replace ("..\\src\\", ""); |
---|
| 187 | } |
---|
| 188 | else if (file_not_found) |
---|
| 189 | { |
---|
| 190 | can_build = false; |
---|
| 191 | obj = ""; |
---|
[459] | 192 | CmtMessage::warning ("Source file " + name + " cannot be rebuilt"); |
---|
| 193 | // cerr << "#CMT> Warning: Source file " << name << " cannot be rebuilt" << endl; |
---|
[2] | 194 | } |
---|
| 195 | else |
---|
| 196 | { |
---|
| 197 | obj = ""; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | if (Cmt::get_debug ()) |
---|
| 202 | { |
---|
[588] | 203 | cout << "LibraryGenerator::analyze_file> constituent=" << |
---|
[400] | 204 | constituent.name << |
---|
| 205 | " obj=" << obj << endl; |
---|
[2] | 206 | } |
---|
| 207 | |
---|
| 208 | if (can_build) |
---|
| 209 | { |
---|
| 210 | SourceFile& source = m_source_files.add (); |
---|
| 211 | source.set (file, language, obj); |
---|
| 212 | return (true); |
---|
| 213 | } |
---|
| 214 | else |
---|
| 215 | { |
---|
| 216 | return (false); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | //-------------------------------------------------- |
---|
| 221 | void LibraryGenerator::java_file_action (SourceFile& file, const Constituent& constituent) |
---|
| 222 | { |
---|
| 223 | static cmt_string suffix; |
---|
| 224 | |
---|
| 225 | m_FULLNAME = file.name (); |
---|
| 226 | m_OUTPUTNAME = file.output (); |
---|
| 227 | |
---|
| 228 | CmtSystem::get_dot_suffix (m_FULLNAME, suffix); |
---|
| 229 | |
---|
| 230 | CmtSystem::basename (m_FULLNAME, suffix, m_NAME.value); |
---|
| 231 | CmtSystem::basename (m_FULLNAME, m_FILENAME.value); |
---|
| 232 | |
---|
[561] | 233 | // if (CmtSystem::test_file (m_FULLNAME)) |
---|
| 234 | // { |
---|
[2] | 235 | java_fragment.copy (m_output_file, constituent.variables, 5, |
---|
| 236 | &m_NAME, |
---|
| 237 | &m_FULLNAME, |
---|
| 238 | &m_OUTPUTNAME, |
---|
| 239 | &m_CONSTITUENT, |
---|
| 240 | &m_CONSTITUENTSUFFIX); |
---|
[561] | 241 | /* |
---|
[2] | 242 | } |
---|
| 243 | else |
---|
| 244 | { |
---|
[459] | 245 | CmtMessage::warning ("file " + m_FULLNAME + " not found"); |
---|
| 246 | // cerr << "#CMT> Warning: file " << m_FULLNAME << " not found" << endl; |
---|
[2] | 247 | } |
---|
[561] | 248 | */ |
---|
[2] | 249 | } |
---|
| 250 | |
---|
| 251 | //-------------------------------------------------- |
---|
| 252 | void LibraryGenerator::proto_file_action (const cmt_string& file, const Constituent& constituent) |
---|
| 253 | { |
---|
| 254 | static cmt_string suffix; |
---|
| 255 | |
---|
| 256 | CmtSystem::dirname (file, m_FILEPATH.value); |
---|
| 257 | if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator (); |
---|
| 258 | |
---|
| 259 | filter_path (m_FILEPATH.value); |
---|
| 260 | |
---|
| 261 | CmtSystem::basename (file, m_FILENAME.value); |
---|
| 262 | CmtSystem::get_dot_suffix (m_FILENAME, suffix); |
---|
| 263 | |
---|
| 264 | CmtSystem::basename (m_FILENAME, suffix, m_NAME.value); |
---|
| 265 | |
---|
[613] | 266 | buildproto_fragment.copy (m_output_file, constituent.variables, 4, |
---|
| 267 | &m_CONSTITUENT, |
---|
[2] | 268 | &m_NAME, |
---|
| 269 | &m_FILEPATH, |
---|
| 270 | &m_FILENAME); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | //-------------------------------------------------- |
---|
| 274 | void LibraryGenerator::prepare_proto_file (const cmt_string& file) |
---|
| 275 | { |
---|
| 276 | static cmt_string name; |
---|
| 277 | static cmt_string pp; |
---|
| 278 | |
---|
| 279 | CmtSystem::name (file, name); |
---|
| 280 | |
---|
| 281 | if (CmtSystem::test_file (file)) |
---|
| 282 | { |
---|
| 283 | pp = incdir; |
---|
| 284 | pp += name; |
---|
| 285 | pp += ".pp"; |
---|
| 286 | |
---|
| 287 | if (!CmtSystem::test_file (pp)) |
---|
| 288 | { |
---|
| 289 | //Generator::build_prototype (file); |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | protos += " "; |
---|
| 294 | protos += inc; |
---|
| 295 | protos += name; |
---|
| 296 | protos += ".ph"; |
---|
| 297 | |
---|
| 298 | protonames += " "; |
---|
| 299 | protonames += name; |
---|
| 300 | protonames += ".ph"; |
---|
| 301 | |
---|
| 302 | m_PROTOSTAMPS += " "; |
---|
| 303 | m_PROTOSTAMPS += inc; |
---|
| 304 | m_PROTOSTAMPS += name; |
---|
| 305 | m_PROTOSTAMPS += ".pp"; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | //-------------------------------------------------- |
---|
| 309 | void LibraryGenerator::module_file_action (SourceFile& file, const Constituent& constituent) |
---|
| 310 | { |
---|
| 311 | cmt_string name = file.name (); |
---|
| 312 | Language& language = file.language (); |
---|
| 313 | |
---|
| 314 | static cmt_string suffix; |
---|
| 315 | static cmt_string prefix; |
---|
| 316 | static cmt_string preproc; |
---|
| 317 | |
---|
| 318 | m_FULLNAME = name; |
---|
| 319 | |
---|
| 320 | CmtSystem::get_dot_suffix (name, suffix); |
---|
| 321 | |
---|
| 322 | CmtSystem::basename (name, suffix, m_NAME.value); |
---|
| 323 | |
---|
| 324 | CmtSystem::dirname (name, prefix); |
---|
| 325 | CmtSystem::basename (name, m_FILENAME.value); |
---|
| 326 | |
---|
| 327 | FragmentHandle* fragment; |
---|
| 328 | |
---|
| 329 | if (language != Language::null ()) |
---|
| 330 | { |
---|
| 331 | preproc = language.preprocessor_command; |
---|
| 332 | fragment = (is_library) ? &(language.library) : &(language.application); |
---|
[486] | 333 | m_DEPENDENCIESOPTS = language.dependencies_options (); |
---|
[2] | 334 | } |
---|
| 335 | else |
---|
| 336 | { |
---|
| 337 | // |
---|
| 338 | // What happens when the language is not known??? |
---|
| 339 | // |
---|
| 340 | // |
---|
| 341 | preproc = "-I"; |
---|
| 342 | fragment = 0; |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | if ((prefix == "../src") || (prefix == "..\\src")) |
---|
| 346 | { |
---|
| 347 | m_ADDINCLUDE = ""; |
---|
| 348 | } |
---|
| 349 | else if (prefix != "") |
---|
| 350 | { |
---|
| 351 | m_ADDINCLUDE = preproc; |
---|
| 352 | m_ADDINCLUDE += prefix; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | m_FILEPATH = prefix; |
---|
| 356 | if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator (); |
---|
| 357 | filter_path (m_FILEPATH.value); |
---|
| 358 | |
---|
[474] | 359 | /* |
---|
[2] | 360 | m_LINE = m_FULLNAME.value; |
---|
| 361 | m_LINE += " "; |
---|
[474] | 362 | */ |
---|
[2] | 363 | |
---|
| 364 | filter_path (m_FULLNAME.value); |
---|
| 365 | |
---|
| 366 | CmtSystem::get_suffix (name, m_FILESUFFIX.value); |
---|
| 367 | |
---|
| 368 | if (fragment != 0) |
---|
| 369 | { |
---|
[483] | 370 | // fragment->copy (m_output_file, constituent.variables, 10, |
---|
| 371 | fragment->copy (m_output_file, constituent.variables, 11, |
---|
[2] | 372 | &m_CONSTITUENT, |
---|
| 373 | &m_CONSTITUENTSUFFIX, |
---|
| 374 | &m_FILENAME, |
---|
| 375 | &m_NAME, |
---|
| 376 | &m_LINE, |
---|
| 377 | &m_ADDINCLUDE, |
---|
| 378 | &m_FULLNAME, |
---|
| 379 | &m_FILEPATH, |
---|
| 380 | &m_FILESUFFIX, |
---|
[483] | 381 | &m_PACKAGE, |
---|
| 382 | &m_DEPENDENCIESOPTS); |
---|
[2] | 383 | } |
---|
| 384 | else if (file.output () != "") |
---|
| 385 | { |
---|
| 386 | m_OUTPUTNAME = file.output (); |
---|
| 387 | CmtSystem::dirname (m_OUTPUTNAME.value, m_FILEPATH.value); |
---|
| 388 | |
---|
| 389 | java_copy_fragment.copy (m_output_file, constituent.variables, 11, |
---|
| 390 | &m_CONSTITUENT, |
---|
| 391 | &m_CONSTITUENTSUFFIX, |
---|
| 392 | &m_FILENAME, |
---|
| 393 | &m_NAME, |
---|
| 394 | &m_LINE, |
---|
| 395 | &m_ADDINCLUDE, |
---|
| 396 | &m_FULLNAME, |
---|
| 397 | &m_FILEPATH, |
---|
| 398 | &m_FILESUFFIX, |
---|
| 399 | &m_PACKAGE, |
---|
| 400 | &m_OUTPUTNAME); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | if (m_PACKOS9) |
---|
| 404 | { |
---|
[474] | 405 | // os9sources += m_LINE; |
---|
| 406 | os9sources += m_FULLNAME.value; |
---|
[2] | 407 | os9sources += " "; |
---|
| 408 | } |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | //-------------------------------------------------- |
---|
[588] | 412 | void LibraryGenerator::fill_names_outputs () |
---|
| 413 | { |
---|
| 414 | bool l_first = true; |
---|
| 415 | bool o_first = true; |
---|
| 416 | |
---|
| 417 | m_LINE = ""; |
---|
| 418 | m_OBJS = ""; |
---|
| 419 | |
---|
| 420 | for (int i = 0; i < m_source_files.size (); i++) |
---|
| 421 | { |
---|
| 422 | const SourceFile& file = m_source_files[i]; |
---|
| 423 | const cmt_string name = file.name (); |
---|
| 424 | const cmt_string output = file.output (); |
---|
| 425 | Language& language = file.language (); |
---|
| 426 | |
---|
| 427 | if (output != "") |
---|
| 428 | { |
---|
| 429 | if (o_first) |
---|
| 430 | { |
---|
| 431 | o_first = false; |
---|
| 432 | } |
---|
| 433 | else |
---|
| 434 | { |
---|
| 435 | m_OBJS += " "; |
---|
| 436 | } |
---|
| 437 | m_OBJS += output; |
---|
| 438 | |
---|
| 439 | if (language == Language::null () || !language.native_dependencies ()) |
---|
| 440 | { |
---|
| 441 | if (l_first) |
---|
| 442 | { |
---|
| 443 | l_first = false; |
---|
| 444 | } |
---|
| 445 | else |
---|
| 446 | { |
---|
| 447 | m_LINE += " "; |
---|
| 448 | } |
---|
| 449 | m_LINE += name; |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | if (Cmt::get_debug ()) |
---|
| 454 | { |
---|
| 455 | cout << "LibraryGenerator::fill_names_outputs>" << endl; |
---|
| 456 | cout << "name=" << name << " LINE=" << m_LINE << endl; |
---|
| 457 | cout << "output=" << output << " OBJS=" << m_OBJS << endl; |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | filter_path (m_LINE.value); |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | //-------------------------------------------------- |
---|
[2] | 465 | void LibraryGenerator::build (const cmt_string& package, |
---|
[428] | 466 | const Constituent& constituent, |
---|
[588] | 467 | bool& dependencies, |
---|
[428] | 468 | const cmt_string& file_name) |
---|
[2] | 469 | { |
---|
[628] | 470 | //static cmt_string lib; |
---|
[2] | 471 | static cmt_string allsources; |
---|
| 472 | static cmt_string file; |
---|
| 473 | static cmt_string full_name; |
---|
| 474 | static cmt_string compressed_name; |
---|
| 475 | static cmt_string suffix; |
---|
| 476 | int i; |
---|
| 477 | bool need_prototypes; |
---|
| 478 | |
---|
| 479 | reset (); |
---|
| 480 | |
---|
[428] | 481 | if (!prepare_output (package, constituent, file_name)) return; |
---|
[2] | 482 | |
---|
| 483 | switch (constituent.type) |
---|
| 484 | { |
---|
| 485 | case Application: |
---|
| 486 | is_library = false; |
---|
| 487 | is_application = true; |
---|
| 488 | m_TITLE = "Application"; |
---|
| 489 | break; |
---|
| 490 | case Library: |
---|
| 491 | is_library = true; |
---|
| 492 | is_application = false; |
---|
| 493 | m_TITLE = "Library"; |
---|
| 494 | break; |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | m_source_files.clear (); |
---|
| 498 | |
---|
| 499 | need_prototypes = constituent.need_prototypes; |
---|
| 500 | |
---|
[628] | 501 | if (constituent.need_prototypes) |
---|
| 502 | { |
---|
| 503 | m_HASPROTOTYPES = "has_prototypes"; |
---|
| 504 | } |
---|
| 505 | else |
---|
| 506 | { |
---|
| 507 | m_HASPROTOTYPES = "has_no_prototypes"; |
---|
| 508 | } |
---|
| 509 | |
---|
[459] | 510 | // cout << m_TITLE << " " << m_CONSTITUENT << endl; |
---|
| 511 | CmtMessage::info (m_TITLE + " " + m_CONSTITUENT); |
---|
[2] | 512 | |
---|
[628] | 513 | /* |
---|
[2] | 514 | lib = "$("; |
---|
| 515 | lib += m_CONSTITUENT; |
---|
| 516 | lib += "lib)"; |
---|
[628] | 517 | */ |
---|
[2] | 518 | // |
---|
| 519 | // Prepare the include paths |
---|
| 520 | // |
---|
| 521 | |
---|
| 522 | const CmtSystem::cmt_string_vector& includes = constituent.includes; |
---|
| 523 | |
---|
| 524 | for (i = 0; i < includes.size (); i++) |
---|
| 525 | { |
---|
| 526 | const cmt_string& subdir = includes[i]; |
---|
| 527 | |
---|
| 528 | m_PACKINCLUDES += " -I"; |
---|
| 529 | m_PACKINCLUDES += subdir; |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | // |
---|
| 533 | // Scan the sources. |
---|
| 534 | // |
---|
| 535 | |
---|
| 536 | const CmtSystem::cmt_string_vector& sources = constituent.modules; |
---|
| 537 | const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs; |
---|
| 538 | const cmt_vector<cmt_regexp>& selects = constituent.select_exprs; |
---|
| 539 | |
---|
[474] | 540 | // m_LINE = ""; |
---|
[2] | 541 | |
---|
| 542 | for (i = 0; i < sources.size (); i++) |
---|
| 543 | { |
---|
| 544 | file = sources[i]; |
---|
| 545 | |
---|
| 546 | set_full_name (full_name, file); |
---|
| 547 | if (full_name == "") continue; |
---|
| 548 | |
---|
| 549 | CmtSystem::compress_path (full_name, compressed_name); |
---|
| 550 | full_name = compressed_name; |
---|
| 551 | |
---|
| 552 | static CmtSystem::cmt_string_vector files; |
---|
| 553 | |
---|
| 554 | int count = get_all_files (full_name, excludes, selects, files); |
---|
| 555 | |
---|
| 556 | filter_path (full_name); |
---|
| 557 | |
---|
| 558 | for (int j = 0; j < files.size (); j++) |
---|
| 559 | { |
---|
| 560 | const cmt_string& name = files[j]; |
---|
| 561 | |
---|
| 562 | if (name != "") |
---|
| 563 | { |
---|
| 564 | if (!analyze_file (constituent, name)) |
---|
| 565 | { |
---|
| 566 | count = 0; |
---|
| 567 | break; |
---|
| 568 | } |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
[474] | 572 | /* |
---|
[2] | 573 | if (count > 0) |
---|
| 574 | { |
---|
| 575 | m_LINE += full_name; |
---|
| 576 | m_LINE += " "; |
---|
| 577 | } |
---|
[474] | 578 | */ |
---|
[2] | 579 | } |
---|
| 580 | |
---|
[474] | 581 | fill_names_outputs (); |
---|
| 582 | //fill_outputs (); |
---|
[2] | 583 | |
---|
[561] | 584 | //prepare_use_context (); |
---|
[2] | 585 | |
---|
| 586 | m_DATE = CmtSystem::now (); |
---|
| 587 | m_USER = CmtSystem::user (); |
---|
| 588 | m_PACKAGE = package; |
---|
| 589 | |
---|
| 590 | if (constituent.has_target_tag) |
---|
| 591 | { |
---|
| 592 | m_HASTARGETTAG = "has_target_tag"; |
---|
| 593 | } |
---|
| 594 | else |
---|
| 595 | { |
---|
| 596 | m_HASTARGETTAG = "has_no_target_tag"; |
---|
| 597 | } |
---|
[197] | 598 | |
---|
[488] | 599 | m_HASDEPENDENCIES = "has_dependencies"; |
---|
| 600 | |
---|
[197] | 601 | m_STRUCTURED_OUTPUT = "STRUCTURED_OUTPUT"; |
---|
[2] | 602 | |
---|
[488] | 603 | make_header_fragment.copy (m_output_file, constituent.variables, 9, |
---|
[400] | 604 | &m_TITLE, |
---|
[2] | 605 | &m_CONSTITUENT, |
---|
| 606 | &m_CONSTITUENTSUFFIX, |
---|
[400] | 607 | &m_USER, |
---|
[2] | 608 | &m_DATE, |
---|
| 609 | &m_PACKAGE, |
---|
[400] | 610 | &m_HASTARGETTAG, |
---|
[488] | 611 | &m_HASDEPENDENCIES, |
---|
[400] | 612 | &m_STRUCTURED_OUTPUT |
---|
[197] | 613 | ); |
---|
[2] | 614 | |
---|
| 615 | if (need_prototypes) |
---|
| 616 | { |
---|
| 617 | need_prototypes = false; |
---|
| 618 | |
---|
| 619 | for (i = 0; i < m_source_files.size (); i++) |
---|
| 620 | { |
---|
| 621 | const SourceFile& file = m_source_files[i]; |
---|
| 622 | Language& language = file.language (); |
---|
| 623 | if (language.prototypes) |
---|
| 624 | { |
---|
| 625 | need_prototypes = true; |
---|
| 626 | break; |
---|
| 627 | } |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | //------------------------------------------- |
---|
| 632 | // |
---|
| 633 | // Specific targets (application, library or java) |
---|
| 634 | // Prepare in case prototype files are needed |
---|
| 635 | // |
---|
| 636 | //------------------------------------------- |
---|
| 637 | |
---|
| 638 | m_PROTOTARGET = ""; |
---|
| 639 | |
---|
| 640 | //if ((Cmt::current_build_strategy & PrototypesMask) == Prototypes) |
---|
| 641 | if (need_prototypes) |
---|
| 642 | { |
---|
| 643 | m_PROTOTARGET = m_CONSTITUENT; |
---|
| 644 | m_PROTOTARGET += "PROTOS"; |
---|
| 645 | } |
---|
| 646 | |
---|
| 647 | if (m_LINKMACRO == "java") |
---|
| 648 | { |
---|
| 649 | if (is_library) |
---|
| 650 | { |
---|
[628] | 651 | jar_header_fragment.copy (m_output_file, constituent.variables, 5, |
---|
[2] | 652 | &m_CONSTITUENT, |
---|
| 653 | &m_CONSTITUENTSUFFIX, |
---|
[628] | 654 | &m_OBJS, |
---|
| 655 | &m_PROTOTARGET, |
---|
| 656 | &m_HASPROTOTYPES); |
---|
[2] | 657 | } |
---|
| 658 | else |
---|
| 659 | { |
---|
[628] | 660 | java_header_fragment.copy (m_output_file, constituent.variables, 5, |
---|
[2] | 661 | &m_CONSTITUENT, |
---|
| 662 | &m_CONSTITUENTSUFFIX, |
---|
[628] | 663 | &m_OBJS, |
---|
| 664 | &m_PROTOTARGET, |
---|
| 665 | &m_HASPROTOTYPES); |
---|
[2] | 666 | } |
---|
| 667 | } |
---|
| 668 | else |
---|
| 669 | { |
---|
| 670 | if (is_library) |
---|
| 671 | { |
---|
[628] | 672 | library_header_fragment.copy (m_output_file, constituent.variables, 5, |
---|
[2] | 673 | &m_CONSTITUENT, |
---|
| 674 | &m_CONSTITUENTSUFFIX, |
---|
[628] | 675 | &m_OBJS, |
---|
| 676 | &m_PROTOTARGET, |
---|
| 677 | &m_HASPROTOTYPES); |
---|
[2] | 678 | } |
---|
| 679 | else |
---|
| 680 | { |
---|
[628] | 681 | application_header_fragment.copy (m_output_file, constituent.variables, 5, |
---|
| 682 | &m_CONSTITUENT, |
---|
| 683 | &m_CONSTITUENTSUFFIX, |
---|
| 684 | &m_OBJS, |
---|
| 685 | &m_PROTOTARGET, |
---|
| 686 | &m_HASPROTOTYPES); |
---|
[2] | 687 | } |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | |
---|
| 691 | //---------------------------------------------------- |
---|
| 692 | // |
---|
| 693 | // Preparing prototype files. |
---|
| 694 | // |
---|
| 695 | //---------------------------------------------------- |
---|
| 696 | |
---|
| 697 | //if ((Cmt::current_build_strategy & PrototypesMask) == Prototypes) |
---|
| 698 | if (need_prototypes) |
---|
| 699 | { |
---|
| 700 | for (i = 0; i < m_source_files.size (); i++) |
---|
| 701 | { |
---|
| 702 | const SourceFile& file = m_source_files[i]; |
---|
| 703 | Language& language = file.language (); |
---|
| 704 | if (language.prototypes) |
---|
| 705 | { |
---|
| 706 | prepare_proto_file (file.name ()); |
---|
| 707 | } |
---|
| 708 | } |
---|
| 709 | |
---|
| 710 | if (m_PROTOSTAMPS != "") |
---|
| 711 | { |
---|
[613] | 712 | protos_header_fragment.copy (m_output_file, constituent.variables, 4, |
---|
[2] | 713 | &m_CONSTITUENT, |
---|
| 714 | &m_CONSTITUENTSUFFIX, |
---|
[613] | 715 | &m_PROTOSTAMPS, |
---|
| 716 | &m_OBJS); |
---|
[2] | 717 | } |
---|
| 718 | |
---|
| 719 | if (protonames != "") |
---|
| 720 | { |
---|
| 721 | for (i = 0; i < m_source_files.size (); i++) |
---|
| 722 | { |
---|
| 723 | const SourceFile& file = m_source_files[i]; |
---|
| 724 | Language& language = file.language (); |
---|
| 725 | if (language.prototypes) |
---|
| 726 | { |
---|
| 727 | proto_file_action (file.name (), constituent); |
---|
| 728 | } |
---|
| 729 | } |
---|
| 730 | } |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | //---------------------------------------------------- |
---|
| 734 | // |
---|
| 735 | // Preparing the library. |
---|
| 736 | // |
---|
| 737 | //---------------------------------------------------- |
---|
| 738 | |
---|
| 739 | if (m_OBJS != "") |
---|
| 740 | { |
---|
| 741 | if (m_LINKMACRO == "java") |
---|
| 742 | { |
---|
| 743 | if (is_library) |
---|
| 744 | { |
---|
| 745 | cmt_string classes = m_OBJS.value; |
---|
| 746 | |
---|
| 747 | classes.replace_all ("$(javabin)", ""); |
---|
| 748 | classes.replace_all (srcdir.c_str (), ""); |
---|
| 749 | |
---|
| 750 | m_CLASSES = classes; |
---|
| 751 | |
---|
| 752 | jar_fragment.copy (m_output_file, constituent.variables, 4, |
---|
| 753 | &m_CONSTITUENT, |
---|
| 754 | &m_CONSTITUENTSUFFIX, |
---|
| 755 | &m_OBJS, |
---|
| 756 | &m_CLASSES); |
---|
| 757 | } |
---|
| 758 | } |
---|
| 759 | else |
---|
| 760 | { |
---|
| 761 | if (is_library) |
---|
| 762 | { |
---|
[466] | 763 | if (constituent.no_share && constituent.no_static) |
---|
| 764 | { |
---|
| 765 | CmtMessage::warning (constituent.name + ": No shared or static library"); |
---|
| 766 | } |
---|
| 767 | else if (constituent.no_share) |
---|
[2] | 768 | { |
---|
| 769 | library_no_share_fragment.copy (m_output_file, constituent.variables, 3, |
---|
| 770 | &m_CONSTITUENT, |
---|
| 771 | &m_CONSTITUENTSUFFIX, |
---|
| 772 | &m_OBJS); |
---|
| 773 | } |
---|
[466] | 774 | else if (constituent.no_static) |
---|
| 775 | { |
---|
| 776 | library_no_static_fragment.copy (m_output_file, constituent.variables, 3, |
---|
| 777 | &m_CONSTITUENT, |
---|
| 778 | &m_CONSTITUENTSUFFIX, |
---|
| 779 | &m_OBJS); |
---|
| 780 | } |
---|
[2] | 781 | else |
---|
| 782 | { |
---|
| 783 | library_fragment.copy (m_output_file, constituent.variables, 3, |
---|
| 784 | &m_CONSTITUENT, |
---|
| 785 | &m_CONSTITUENTSUFFIX, |
---|
| 786 | &m_OBJS); |
---|
| 787 | } |
---|
| 788 | } |
---|
| 789 | else |
---|
| 790 | { |
---|
| 791 | application_fragment.copy (m_output_file, constituent.variables, 4, |
---|
| 792 | &m_CONSTITUENT, |
---|
| 793 | &m_CONSTITUENTSUFFIX, |
---|
| 794 | &m_OBJS, |
---|
| 795 | &m_LINKMACRO); |
---|
| 796 | } |
---|
| 797 | } |
---|
| 798 | } |
---|
| 799 | |
---|
[483] | 800 | bool need_dependencies = false; |
---|
| 801 | |
---|
| 802 | for (i = 0; i < m_source_files.size (); i++) |
---|
| 803 | { |
---|
| 804 | const SourceFile& file = m_source_files[i]; |
---|
| 805 | Language& language = file.language (); |
---|
[486] | 806 | if (language == Language::null () || !language.native_dependencies ()) |
---|
[483] | 807 | { |
---|
| 808 | need_dependencies = true; |
---|
| 809 | break; |
---|
| 810 | } |
---|
| 811 | } |
---|
[588] | 812 | dependencies = need_dependencies; |
---|
[483] | 813 | |
---|
[2] | 814 | if (constituent.build_triggers) |
---|
| 815 | { |
---|
| 816 | dependencies_and_triggers_fragment.copy (m_output_file, |
---|
| 817 | constituent.variables, 3, |
---|
| 818 | &m_CONSTITUENT, |
---|
| 819 | &m_CONSTITUENTSUFFIX, |
---|
| 820 | &m_LINE); |
---|
| 821 | } |
---|
| 822 | else |
---|
| 823 | { |
---|
[483] | 824 | if (need_dependencies) |
---|
| 825 | { |
---|
[628] | 826 | dependencies_fragment.copy (m_output_file, |
---|
| 827 | constituent.variables, 3, |
---|
| 828 | &m_CONSTITUENT, |
---|
| 829 | &m_CONSTITUENTSUFFIX, |
---|
| 830 | &m_LINE); |
---|
[483] | 831 | } |
---|
[2] | 832 | } |
---|
| 833 | |
---|
| 834 | //---------------------------------------------------- |
---|
| 835 | // |
---|
| 836 | // Building actual individual targets. |
---|
| 837 | // |
---|
| 838 | //---------------------------------------------------- |
---|
| 839 | |
---|
| 840 | for (i = 0; i < m_source_files.size (); i++) |
---|
| 841 | { |
---|
| 842 | SourceFile& file = m_source_files[i]; |
---|
| 843 | Language& language = file.language (); |
---|
| 844 | |
---|
| 845 | if (language == "java") |
---|
| 846 | { |
---|
| 847 | java_file_action (file, constituent); |
---|
| 848 | } |
---|
| 849 | else |
---|
| 850 | { |
---|
| 851 | module_file_action (file, constituent); |
---|
| 852 | } |
---|
| 853 | } |
---|
| 854 | |
---|
| 855 | if (m_PACKOS9) |
---|
| 856 | { |
---|
| 857 | if (os9sources != "") |
---|
| 858 | { |
---|
| 859 | // |
---|
| 860 | // Generate transfers to the OS9 area. |
---|
| 861 | // |
---|
| 862 | |
---|
| 863 | m_ALLOS9SOURCES = ""; |
---|
| 864 | allsources = ""; |
---|
| 865 | } |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | /* |
---|
| 869 | for file in `cmt_sort_line.csh ${os9sources}` ; do |
---|
| 870 | if test `echo ${file} | grep '$(src)'` ; then |
---|
| 871 | name=`echo ${file} | sed 's#$(src)##'` |
---|
| 872 | ALLOS9SOURCES="${ALLOS9SOURCES} ../OS9/${name}" |
---|
| 873 | allsources="${allsources} ${file}" |
---|
| 874 | elif test `echo ${file} | grep '$(inc)'` ; then |
---|
| 875 | name=`echo ${file} | sed 's#$(inc)##'` |
---|
| 876 | ALLOS9SOURCES="${ALLOS9SOURCES} ../OS9/${name}" |
---|
| 877 | allsources="${allsources} ${file}" |
---|
| 878 | fi |
---|
| 879 | done |
---|
| 880 | |
---|
| 881 | if test ! "${ALLOS9SOURCES}" = "" ; then |
---|
| 882 | |
---|
| 883 | sed -e "`subs_vars ALLOS9SOURCES`" \ |
---|
| 884 | ${os9_header_fragment} \ |
---|
| 885 | >>${output} |
---|
| 886 | |
---|
| 887 | for FULLNAME in ${allsources} ; do |
---|
| 888 | |
---|
| 889 | NAME=`echo ${FULLNAME} | sed -e 's#$(src)##' -e 's#$(inc)##'` |
---|
| 890 | |
---|
| 891 | sed -e "`subs_vars NAME FULLNAME`" \ |
---|
| 892 | ${os9_fragment} \ |
---|
| 893 | >>${output} |
---|
| 894 | |
---|
| 895 | done |
---|
| 896 | fi |
---|
| 897 | fi |
---|
| 898 | fi |
---|
| 899 | */ |
---|
| 900 | |
---|
| 901 | // |
---|
| 902 | // Generate package cleanup operations. |
---|
| 903 | // |
---|
| 904 | |
---|
| 905 | cleanup_header_fragment.copy (m_output_file, constituent.variables, 2, |
---|
| 906 | &m_CONSTITUENT, |
---|
| 907 | &m_CONSTITUENTSUFFIX); |
---|
| 908 | |
---|
| 909 | //if ((Cmt::current_build_strategy & PrototypesMask) == Prototypes) |
---|
| 910 | if (need_prototypes) |
---|
| 911 | { |
---|
| 912 | if (protos != "") |
---|
| 913 | { |
---|
| 914 | m_FULLNAME = protos; |
---|
| 915 | cleanup_fragment.copy (m_output_file, constituent.variables, 1, &m_FULLNAME); |
---|
| 916 | m_FULLNAME = m_PROTOSTAMPS; |
---|
| 917 | cleanup_fragment.copy (m_output_file, constituent.variables, 1, &m_FULLNAME); |
---|
| 918 | } |
---|
| 919 | } |
---|
| 920 | |
---|
| 921 | if (m_LINKMACRO == "java") |
---|
| 922 | { |
---|
| 923 | cleanup_java_fragment.copy (m_output_file, constituent.variables, 1, &m_OBJS); |
---|
| 924 | |
---|
| 925 | if (!is_library) |
---|
| 926 | { |
---|
| 927 | if (constituent.need_check) |
---|
| 928 | { |
---|
| 929 | check_java_fragment.copy (m_output_file, constituent.variables, 2, |
---|
| 930 | &m_CONSTITUENT, |
---|
| 931 | &m_CONSTITUENTSUFFIX); |
---|
| 932 | } |
---|
| 933 | } |
---|
| 934 | } |
---|
| 935 | else |
---|
| 936 | { |
---|
| 937 | if (is_library) |
---|
| 938 | { |
---|
| 939 | cleanup_library_fragment.copy (m_output_file, constituent.variables, 2, |
---|
| 940 | &m_CONSTITUENT, |
---|
| 941 | &m_CONSTITUENTSUFFIX); |
---|
| 942 | } |
---|
| 943 | else |
---|
| 944 | { |
---|
| 945 | cleanup_application_fragment.copy (m_output_file, constituent.variables, 2, |
---|
| 946 | &m_CONSTITUENT, |
---|
| 947 | &m_CONSTITUENTSUFFIX); |
---|
| 948 | if (m_OBJS != "") |
---|
| 949 | { |
---|
| 950 | cleanup_objects_fragment.copy (m_output_file, constituent.variables, 3, |
---|
| 951 | &m_OBJS, |
---|
| 952 | &m_CONSTITUENT, |
---|
| 953 | &m_CONSTITUENTSUFFIX); |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | if (constituent.need_check) |
---|
| 957 | { |
---|
| 958 | check_application_fragment.copy (m_output_file, constituent.variables, 2, |
---|
| 959 | &m_CONSTITUENT, |
---|
| 960 | &m_CONSTITUENTSUFFIX); |
---|
| 961 | } |
---|
| 962 | } |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | terminate (); |
---|
| 966 | } |
---|
| 967 | |
---|
| 968 | //-------------------------------------------------- |
---|
| 969 | DocumentGenerator::DocumentGenerator () |
---|
| 970 | { |
---|
[588] | 971 | m_FILEEXTENSION.set ("FILEEXTENSION"); |
---|
| 972 | |
---|
[2] | 973 | document_header_fragment.set ("document_header"); |
---|
[588] | 974 | dependency_fragment.set ("dependency"); |
---|
[2] | 975 | } |
---|
| 976 | |
---|
| 977 | //-------------------------------------------------- |
---|
| 978 | void DocumentGenerator::reset () |
---|
| 979 | { |
---|
| 980 | AnyDocumentGenerator::reset (); |
---|
[588] | 981 | m_FILEEXTENSION = ""; |
---|
| 982 | |
---|
[2] | 983 | document_header_fragment.reset (); |
---|
[588] | 984 | dependency_fragment.reset (); |
---|
[2] | 985 | } |
---|
| 986 | |
---|
| 987 | //-------------------------------------------------- |
---|
| 988 | void DocumentGenerator::build (const cmt_string& package, |
---|
[428] | 989 | const Constituent& constituent, |
---|
[588] | 990 | bool& dependencies, |
---|
[428] | 991 | const cmt_string& file_name) |
---|
[2] | 992 | { |
---|
| 993 | static cmt_string names; |
---|
| 994 | static cmt_string output_dir; |
---|
| 995 | static cmt_string name; |
---|
| 996 | static cmt_string full_name; |
---|
| 997 | static cmt_string compressed_name; |
---|
| 998 | static cmt_string suffix; |
---|
| 999 | static cmt_string output_suffix; |
---|
| 1000 | static cmt_string fragment_suffix; |
---|
| 1001 | |
---|
| 1002 | reset (); |
---|
| 1003 | |
---|
[428] | 1004 | if (!prepare_output (package, constituent, file_name)) return; |
---|
[2] | 1005 | |
---|
| 1006 | is_library = false; |
---|
| 1007 | is_application = false; |
---|
| 1008 | m_GENERATOR = constituent.generator; |
---|
| 1009 | m_TITLE = "Document"; |
---|
| 1010 | |
---|
| 1011 | int i; |
---|
| 1012 | |
---|
[459] | 1013 | // cout << m_TITLE << " " << m_CONSTITUENT << endl; |
---|
| 1014 | CmtMessage::info (m_TITLE + " " + m_CONSTITUENT); |
---|
[2] | 1015 | |
---|
| 1016 | // |
---|
| 1017 | // Prepare the include paths. |
---|
| 1018 | // |
---|
| 1019 | |
---|
| 1020 | const CmtSystem::cmt_string_vector& includes = constituent.includes; |
---|
| 1021 | |
---|
| 1022 | for (i = 0; i < includes.size (); i++) |
---|
| 1023 | { |
---|
| 1024 | const cmt_string& subdir = includes[i]; |
---|
| 1025 | |
---|
| 1026 | m_PACKINCLUDES += " -I"; |
---|
| 1027 | m_PACKINCLUDES += subdir; |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | // |
---|
| 1031 | // Get the fragment associated with the document style |
---|
| 1032 | // |
---|
| 1033 | |
---|
| 1034 | FragmentHandle fragment (m_GENERATOR); |
---|
| 1035 | |
---|
| 1036 | fragment_suffix = fragment.suffix (); |
---|
| 1037 | |
---|
| 1038 | output_suffix = "."; |
---|
| 1039 | |
---|
| 1040 | if (fragment_suffix == "") |
---|
| 1041 | { |
---|
| 1042 | output_suffix += fragment.name (); |
---|
| 1043 | } |
---|
| 1044 | else |
---|
| 1045 | { |
---|
| 1046 | output_suffix += fragment_suffix; |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | // |
---|
| 1050 | // Scan the sources. |
---|
| 1051 | // |
---|
| 1052 | |
---|
| 1053 | const CmtSystem::cmt_string_vector& sources = constituent.modules; |
---|
| 1054 | const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs; |
---|
| 1055 | const cmt_vector<cmt_regexp>& selects = constituent.select_exprs; |
---|
| 1056 | |
---|
[474] | 1057 | // m_LINE = ""; |
---|
[2] | 1058 | |
---|
| 1059 | for (i = 0; i < sources.size (); i++) |
---|
| 1060 | { |
---|
| 1061 | cmt_string& file = sources[i]; |
---|
| 1062 | |
---|
| 1063 | set_full_name (full_name, file); |
---|
| 1064 | if (full_name == "") continue; |
---|
| 1065 | |
---|
| 1066 | CmtSystem::compress_path (full_name, compressed_name); |
---|
| 1067 | full_name = compressed_name; |
---|
| 1068 | |
---|
| 1069 | static CmtSystem::cmt_string_vector files; |
---|
| 1070 | |
---|
| 1071 | int count = get_all_files (full_name, excludes, selects, files); |
---|
| 1072 | |
---|
[561] | 1073 | // filter_path (full_name); |
---|
[2] | 1074 | |
---|
[474] | 1075 | /* |
---|
[2] | 1076 | if (count > 0) |
---|
| 1077 | { |
---|
| 1078 | m_LINE += full_name; |
---|
| 1079 | m_LINE += " "; |
---|
| 1080 | } |
---|
[474] | 1081 | */ |
---|
[2] | 1082 | |
---|
| 1083 | for (int j = 0; j < files.size (); j++) |
---|
| 1084 | { |
---|
| 1085 | const cmt_string& name = files[j]; |
---|
| 1086 | |
---|
| 1087 | if (name != "") |
---|
| 1088 | { |
---|
| 1089 | analyze_file (name, constituent.name, output_suffix); |
---|
| 1090 | } |
---|
| 1091 | } |
---|
| 1092 | } |
---|
| 1093 | |
---|
[474] | 1094 | fill_names_outputs (); |
---|
| 1095 | // fill_outputs (); |
---|
[2] | 1096 | |
---|
[561] | 1097 | // prepare_use_context (); |
---|
[2] | 1098 | |
---|
| 1099 | m_DATE = CmtSystem::now (); |
---|
| 1100 | m_USER = CmtSystem::user (); |
---|
| 1101 | m_PACKAGE = package; |
---|
| 1102 | |
---|
| 1103 | if (constituent.has_target_tag) |
---|
| 1104 | { |
---|
| 1105 | m_HASTARGETTAG = "has_target_tag"; |
---|
| 1106 | } |
---|
| 1107 | else |
---|
| 1108 | { |
---|
| 1109 | m_HASTARGETTAG = "has_no_target_tag"; |
---|
| 1110 | } |
---|
| 1111 | |
---|
[488] | 1112 | m_HASDEPENDENCIES = fragment.need_dependencies () ? "has_dependencies" : "has_no_dependencies" ; |
---|
| 1113 | |
---|
| 1114 | make_header_fragment.copy (m_output_file, constituent.variables, 8, |
---|
[2] | 1115 | &m_TITLE, |
---|
| 1116 | &m_CONSTITUENT, |
---|
| 1117 | &m_CONSTITUENTSUFFIX, |
---|
| 1118 | &m_USER, |
---|
| 1119 | &m_DATE, |
---|
| 1120 | &m_PACKAGE, |
---|
[488] | 1121 | &m_HASTARGETTAG, |
---|
| 1122 | &m_HASDEPENDENCIES |
---|
| 1123 | ); |
---|
[2] | 1124 | |
---|
| 1125 | const cmt_string& header = fragment.header (); |
---|
| 1126 | |
---|
| 1127 | // |
---|
| 1128 | // If the document type specifies a header, use it . |
---|
| 1129 | // otherwise, use the default document header fragment. |
---|
| 1130 | // |
---|
| 1131 | if (header != "") |
---|
| 1132 | { |
---|
| 1133 | FragmentHandle header_fragment (header); |
---|
[626] | 1134 | header_fragment.copy (m_output_file, constituent.variables, 4, |
---|
[2] | 1135 | &m_CONSTITUENT, |
---|
| 1136 | &m_CONSTITUENTSUFFIX, |
---|
[626] | 1137 | &m_OBJS, |
---|
| 1138 | &m_LINE); |
---|
[2] | 1139 | } |
---|
| 1140 | else |
---|
| 1141 | { |
---|
| 1142 | document_header_fragment.copy (m_output_file, constituent.variables, 3, |
---|
| 1143 | &m_CONSTITUENT, |
---|
| 1144 | &m_CONSTITUENTSUFFIX, |
---|
| 1145 | &m_OBJS); |
---|
| 1146 | } |
---|
| 1147 | |
---|
[588] | 1148 | dependencies = fragment.need_dependencies (); |
---|
[2] | 1149 | if (fragment.need_dependencies ()) |
---|
| 1150 | { |
---|
| 1151 | dependencies_fragment.copy (m_output_file, constituent.variables, 3, |
---|
| 1152 | &m_CONSTITUENT, |
---|
| 1153 | &m_CONSTITUENTSUFFIX, |
---|
| 1154 | &m_LINE); |
---|
| 1155 | } |
---|
| 1156 | else |
---|
| 1157 | { |
---|
[561] | 1158 | /* |
---|
[2] | 1159 | for (i = 0; i < sources.size (); i++) |
---|
| 1160 | { |
---|
| 1161 | cmt_string& file = sources[i]; |
---|
| 1162 | |
---|
| 1163 | set_full_name (full_name, file); |
---|
| 1164 | if (full_name == "") continue; |
---|
| 1165 | |
---|
| 1166 | CmtSystem::compress_path (full_name, compressed_name); |
---|
| 1167 | full_name = compressed_name; |
---|
| 1168 | |
---|
| 1169 | static CmtSystem::cmt_string_vector files; |
---|
| 1170 | |
---|
| 1171 | get_all_files (full_name, excludes, selects, files); |
---|
| 1172 | |
---|
| 1173 | for (int j = 0; j < files.size (); j++) |
---|
| 1174 | { |
---|
| 1175 | const cmt_string& name = files[j]; |
---|
[561] | 1176 | */ |
---|
| 1177 | for (i = 0; i < m_source_files.size (); i++) |
---|
| 1178 | { |
---|
| 1179 | SourceFile& file = m_source_files[i]; |
---|
| 1180 | const cmt_string& name = file.name (); |
---|
[2] | 1181 | if (name != "") |
---|
| 1182 | { |
---|
| 1183 | static cmt_string s; |
---|
| 1184 | static cmt_string n; |
---|
| 1185 | |
---|
| 1186 | CmtSystem::get_dot_suffix (name, s); |
---|
| 1187 | CmtSystem::basename (name, s, n); |
---|
| 1188 | CmtSystem::get_suffix (name, s); |
---|
| 1189 | |
---|
| 1190 | fprintf (m_output_file, "%s_%s_dependencies = %s\n", |
---|
| 1191 | n.c_str (), |
---|
| 1192 | s.c_str (), |
---|
| 1193 | name.c_str ()); |
---|
| 1194 | } |
---|
[561] | 1195 | // } |
---|
[2] | 1196 | } |
---|
| 1197 | } |
---|
| 1198 | |
---|
| 1199 | m_SUFFIX = fragment_suffix; |
---|
| 1200 | for (i = 0; i < m_source_files.size (); i++) |
---|
| 1201 | { |
---|
| 1202 | SourceFile& file = m_source_files[i]; |
---|
| 1203 | const cmt_string& file_name = file.name (); |
---|
[626] | 1204 | m_OUTPUTNAME = file.output (); |
---|
[2] | 1205 | m_FULLNAME = file_name; |
---|
| 1206 | CmtSystem::get_dot_suffix (file_name, suffix); |
---|
| 1207 | CmtSystem::basename (file_name, suffix, m_NAME.value); |
---|
| 1208 | CmtSystem::dirname (file_name, m_FILEPATH.value); |
---|
| 1209 | if (m_FILEPATH.value != "") m_FILEPATH.value += CmtSystem::file_separator (); |
---|
| 1210 | filter_path (m_FILEPATH.value); |
---|
[588] | 1211 | m_FILENAME.value = m_NAME.value + suffix; |
---|
| 1212 | //CmtSystem::basename (file_name, m_FILENAME.value); |
---|
| 1213 | m_FILESUFFIX.value = suffix; |
---|
| 1214 | //CmtSystem::get_dot_suffix (m_FILENAME.value, m_FILESUFFIX.value); |
---|
[626] | 1215 | CmtSystem::get_suffix (m_FILENAME.value, m_FILEEXTENSION.value); |
---|
[561] | 1216 | /* |
---|
[2] | 1217 | if (!CmtSystem::test_file (file_name) && !CmtSystem::test_directory (file_name)) |
---|
| 1218 | { |
---|
[459] | 1219 | CmtMessage::warning ("Source file " + file_name + " not found"); |
---|
[2] | 1220 | } |
---|
[561] | 1221 | */ |
---|
[2] | 1222 | filter_path (m_FULLNAME.value); |
---|
| 1223 | |
---|
[588] | 1224 | if (fragment.need_dependencies ()) |
---|
| 1225 | { |
---|
| 1226 | // ensure that ${CONSTITUENT}_dependencies.make gets rebuilt |
---|
| 1227 | // whenever source file OR its dependencies change |
---|
[626] | 1228 | if (!dependency_fragment.copy (m_output_file, constituent.variables, 10, |
---|
[595] | 1229 | &m_FILEPATH, |
---|
| 1230 | &m_SUFFIX, |
---|
[626] | 1231 | &m_OUTPUTNAME, |
---|
[595] | 1232 | &m_CONSTITUENT, |
---|
| 1233 | &m_CONSTITUENTSUFFIX, |
---|
| 1234 | &m_FILENAME, |
---|
| 1235 | &m_NAME, |
---|
| 1236 | &m_FULLNAME, |
---|
| 1237 | &m_FILESUFFIX, |
---|
| 1238 | &m_FILEEXTENSION)) return; |
---|
[588] | 1239 | } |
---|
| 1240 | |
---|
[626] | 1241 | fragment.copy (m_output_file, constituent.variables, 10, |
---|
[2] | 1242 | &m_FILEPATH, |
---|
| 1243 | &m_SUFFIX, |
---|
[626] | 1244 | &m_OUTPUTNAME, |
---|
[2] | 1245 | &m_CONSTITUENT, |
---|
| 1246 | &m_CONSTITUENTSUFFIX, |
---|
| 1247 | &m_FILENAME, |
---|
| 1248 | &m_NAME, |
---|
| 1249 | &m_FULLNAME, |
---|
[588] | 1250 | &m_FILESUFFIX, |
---|
| 1251 | &m_FILEEXTENSION); |
---|
[2] | 1252 | } |
---|
| 1253 | |
---|
| 1254 | const cmt_string& trailer = fragment.trailer (); |
---|
| 1255 | if (trailer != "") |
---|
| 1256 | { |
---|
| 1257 | FragmentHandle trailer_fragment (trailer); |
---|
[626] | 1258 | trailer_fragment.copy (m_output_file, constituent.variables, 4, |
---|
[2] | 1259 | &m_CONSTITUENT, |
---|
| 1260 | &m_CONSTITUENTSUFFIX, |
---|
[626] | 1261 | &m_OBJS, |
---|
| 1262 | &m_LINE); |
---|
[2] | 1263 | } |
---|
| 1264 | |
---|
| 1265 | // |
---|
| 1266 | // Generate package cleanup operations. |
---|
| 1267 | // |
---|
| 1268 | |
---|
| 1269 | cleanup_header_fragment.copy (m_output_file, constituent.variables, 2, |
---|
| 1270 | &m_CONSTITUENT, |
---|
| 1271 | &m_CONSTITUENTSUFFIX); |
---|
| 1272 | |
---|
| 1273 | terminate (); |
---|
| 1274 | } |
---|
| 1275 | |
---|
| 1276 | //-------------------------------------------------- |
---|
| 1277 | bool DocumentGenerator::analyze_file (const cmt_string& file, |
---|
| 1278 | const cmt_string& constituent_name, |
---|
| 1279 | const cmt_string& output_suffix) |
---|
| 1280 | { |
---|
[561] | 1281 | //static cmt_string output_dir; |
---|
[2] | 1282 | static cmt_string suffix; |
---|
| 1283 | static cmt_string name; |
---|
| 1284 | static cmt_string obj; |
---|
| 1285 | |
---|
| 1286 | if (!CmtSystem::test_file (file) && !CmtSystem::test_directory (file)) |
---|
| 1287 | { |
---|
[459] | 1288 | CmtMessage::warning ("Source file " + file + " not found"); |
---|
[2] | 1289 | } |
---|
| 1290 | |
---|
[561] | 1291 | //CmtSystem::dirname (file, output_dir); |
---|
| 1292 | //output_dir += CmtSystem::file_separator (); |
---|
[2] | 1293 | |
---|
[561] | 1294 | //filter_path (output_dir); |
---|
[2] | 1295 | |
---|
| 1296 | CmtSystem::get_suffix (file, suffix); |
---|
| 1297 | CmtSystem::basename (file, suffix, name); |
---|
| 1298 | |
---|
| 1299 | //obj = output_dir; |
---|
| 1300 | obj = "$("; |
---|
| 1301 | obj += constituent_name; |
---|
| 1302 | obj += "_output)"; |
---|
| 1303 | obj += name; |
---|
| 1304 | obj += output_suffix; |
---|
| 1305 | |
---|
| 1306 | SourceFile& source = m_source_files.add (); |
---|
| 1307 | source.set (file, Language::null (), obj); |
---|
| 1308 | |
---|
| 1309 | return (true); |
---|
| 1310 | } |
---|
| 1311 | |
---|
[588] | 1312 | //-------------------------------------------------- |
---|
[2] | 1313 | ReadmeGenerator::ReadmeGenerator () |
---|
| 1314 | { |
---|
| 1315 | readme_header_fragment.set ("readme_header"); |
---|
| 1316 | readme_fragment.set ("readme"); |
---|
| 1317 | readme_doc_fragment.set ("readme_doc"); |
---|
| 1318 | readme_use_fragment.set ("readme_use"); |
---|
| 1319 | readme_trailer_fragment.set ("readme_trailer"); |
---|
| 1320 | } |
---|
| 1321 | |
---|
| 1322 | void ReadmeGenerator::reset () |
---|
| 1323 | { |
---|
| 1324 | CmtGenerator::reset (); |
---|
| 1325 | |
---|
| 1326 | readme_header_fragment.reset (); |
---|
| 1327 | readme_fragment.reset (); |
---|
| 1328 | readme_doc_fragment.reset (); |
---|
| 1329 | readme_use_fragment.reset (); |
---|
| 1330 | readme_trailer_fragment.reset (); |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | //-------------------------------------------------- |
---|
| 1334 | void ReadmeGenerator::build (const CmtSystem::cmt_string_vector& arguments) |
---|
| 1335 | { |
---|
| 1336 | reset (); |
---|
| 1337 | |
---|
| 1338 | m_PACKAGE = Cmt::get_current_package (); |
---|
| 1339 | m_VERSION = Cmt::get_current_version (); |
---|
| 1340 | m_DATE = CmtSystem::now (); |
---|
| 1341 | m_USER = CmtSystem::user (); |
---|
| 1342 | |
---|
| 1343 | cmt_string url; |
---|
| 1344 | cmt_string doc; |
---|
| 1345 | |
---|
| 1346 | for (int i = 0; i < arguments.size (); i++) |
---|
| 1347 | { |
---|
| 1348 | cmt_string arg = arguments[i]; |
---|
| 1349 | |
---|
| 1350 | if (arg.substr (0, 5) == "-url=") |
---|
| 1351 | { |
---|
| 1352 | arg.substr (5, url); |
---|
| 1353 | } |
---|
| 1354 | else if (arg.substr (0, 5) == "-doc=") |
---|
| 1355 | { |
---|
| 1356 | arg.substr (5, doc); |
---|
| 1357 | } |
---|
| 1358 | } |
---|
| 1359 | |
---|
| 1360 | m_output_file_name = cmtdir + "README.html"; |
---|
| 1361 | |
---|
| 1362 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 1363 | if (m_output_file != NULL) |
---|
| 1364 | { |
---|
| 1365 | readme_header_fragment.copy (m_output_file, 2, |
---|
| 1366 | &m_PACKAGE, &m_VERSION); |
---|
| 1367 | |
---|
| 1368 | if (doc != "") |
---|
| 1369 | { |
---|
| 1370 | m_DOCPATH = doc; |
---|
| 1371 | readme_doc_fragment.copy (m_output_file, 3, |
---|
| 1372 | &m_PACKAGE, |
---|
| 1373 | &m_VERSION, |
---|
| 1374 | &m_DOCPATH); |
---|
| 1375 | } |
---|
| 1376 | |
---|
| 1377 | readme_fragment.copy (m_output_file, 2, |
---|
| 1378 | &m_PACKAGE, |
---|
| 1379 | &m_VERSION); |
---|
| 1380 | |
---|
| 1381 | int number; |
---|
| 1382 | const Use::UsePtrVector& uses = Use::get_ordered_uses (); |
---|
| 1383 | |
---|
| 1384 | for (number = 0; number < uses.size (); number++) |
---|
| 1385 | { |
---|
| 1386 | const Use* use = uses[number]; |
---|
| 1387 | |
---|
| 1388 | if (use == 0) continue; |
---|
| 1389 | if (use->discarded) continue; |
---|
| 1390 | |
---|
| 1391 | Package* p = use->get_package (); |
---|
| 1392 | if (p->is_cmt ()) continue; |
---|
| 1393 | |
---|
| 1394 | cmt_string selected_path; |
---|
| 1395 | |
---|
| 1396 | if (url == "") |
---|
| 1397 | { |
---|
| 1398 | selected_path = use->real_path; |
---|
| 1399 | |
---|
| 1400 | if (use->specified_path != "") |
---|
| 1401 | { |
---|
| 1402 | int pos = selected_path.find_last_of (use->specified_path); |
---|
| 1403 | if (pos != cmt_string::npos) |
---|
| 1404 | { |
---|
| 1405 | selected_path.erase (pos); |
---|
| 1406 | } |
---|
| 1407 | } |
---|
| 1408 | } |
---|
| 1409 | else |
---|
| 1410 | { |
---|
| 1411 | selected_path = url; |
---|
| 1412 | |
---|
| 1413 | if (use->specified_path != "") |
---|
| 1414 | { |
---|
| 1415 | selected_path += CmtSystem::file_separator (); |
---|
| 1416 | } |
---|
| 1417 | } |
---|
| 1418 | |
---|
| 1419 | m_PACKAGEPATH = selected_path; |
---|
| 1420 | m_PACKAGEPREFIX = use->specified_path; |
---|
| 1421 | m_PACKAGE = use->get_package_name (); |
---|
| 1422 | m_VERSION = use->version; |
---|
| 1423 | m_MGRSTYLE = (use->style == mgr_style) ? "mgr" : "cmt"; |
---|
| 1424 | readme_use_fragment.copy (m_output_file, 5, |
---|
| 1425 | &m_PACKAGEPATH, |
---|
| 1426 | &m_PACKAGEPREFIX, |
---|
| 1427 | &m_PACKAGE, |
---|
| 1428 | &m_VERSION, |
---|
| 1429 | &m_MGRSTYLE); |
---|
| 1430 | } |
---|
| 1431 | |
---|
| 1432 | m_PACKAGE = Cmt::get_current_package (); |
---|
| 1433 | m_VERSION = Cmt::get_current_version (); |
---|
| 1434 | readme_trailer_fragment.copy (m_output_file, 4, |
---|
| 1435 | &m_PACKAGE, |
---|
| 1436 | &m_VERSION, |
---|
| 1437 | &m_DATE, |
---|
| 1438 | &m_USER); |
---|
| 1439 | |
---|
| 1440 | terminate (); |
---|
| 1441 | } |
---|
[527] | 1442 | else |
---|
| 1443 | { |
---|
| 1444 | CmtError::set (CmtError::file_access_error, m_output_file_name); |
---|
| 1445 | } |
---|
[2] | 1446 | } |
---|
| 1447 | |
---|
| 1448 | //-------------------------------------------------- |
---|
| 1449 | class Prototyper : public FAwk |
---|
| 1450 | { |
---|
| 1451 | public: |
---|
| 1452 | Prototyper (bool static_functions = false) : |
---|
| 1453 | m_static_functions(static_functions) |
---|
| 1454 | { |
---|
| 1455 | if (m_static_functions) |
---|
| 1456 | { |
---|
| 1457 | m_suffix = "_static.phnew"; |
---|
| 1458 | m_define_suffix = "_static_ph"; |
---|
| 1459 | } |
---|
| 1460 | else |
---|
| 1461 | { |
---|
| 1462 | m_suffix = ".phnew"; |
---|
| 1463 | m_define_suffix = "_ph"; |
---|
| 1464 | } |
---|
| 1465 | } |
---|
| 1466 | |
---|
| 1467 | void begin () |
---|
| 1468 | { |
---|
| 1469 | m_running = false; |
---|
| 1470 | |
---|
| 1471 | static cmt_string suffix; |
---|
| 1472 | static cmt_string name; |
---|
| 1473 | |
---|
| 1474 | CmtSystem::get_dot_suffix (m_file_name, suffix); |
---|
| 1475 | CmtSystem::basename (m_file_name, suffix, name); |
---|
| 1476 | |
---|
| 1477 | m_out_file_name = ""; |
---|
| 1478 | |
---|
| 1479 | if (m_dir_name != "") |
---|
| 1480 | { |
---|
| 1481 | m_out_file_name = m_dir_name; |
---|
| 1482 | m_out_file_name += CmtSystem::file_separator (); |
---|
| 1483 | } |
---|
| 1484 | |
---|
| 1485 | m_out_file_name += name; |
---|
| 1486 | m_out_file_name += m_suffix; |
---|
| 1487 | |
---|
| 1488 | CmtSystem::basename (m_file_name, suffix, m_file_name); |
---|
| 1489 | |
---|
| 1490 | m_output = fopen (m_out_file_name.c_str (), "wb"); |
---|
| 1491 | |
---|
| 1492 | if (m_output != 0) |
---|
| 1493 | { |
---|
| 1494 | fprintf (m_output, "#ifndef __%s%s__\n", m_file_name.c_str (), |
---|
| 1495 | m_define_suffix.c_str ()); |
---|
| 1496 | fprintf (m_output, "#define __%s%s__\n", m_file_name.c_str (), |
---|
| 1497 | m_define_suffix.c_str ()); |
---|
| 1498 | |
---|
| 1499 | fprintf (m_output, "\n"); |
---|
| 1500 | fprintf (m_output, "#ifdef __cplusplus\n"); |
---|
| 1501 | fprintf (m_output, "extern \"C\" {\n"); |
---|
| 1502 | fprintf (m_output, "#endif\n"); |
---|
| 1503 | fprintf (m_output, "\n"); |
---|
| 1504 | } |
---|
| 1505 | else |
---|
| 1506 | { |
---|
| 1507 | stop (); |
---|
| 1508 | } |
---|
| 1509 | } |
---|
| 1510 | |
---|
| 1511 | void filter (const cmt_string& line) |
---|
| 1512 | { |
---|
| 1513 | char c = line[0]; |
---|
| 1514 | |
---|
| 1515 | if (!m_running) |
---|
| 1516 | { |
---|
| 1517 | if ((c == ' ') || |
---|
| 1518 | (c == '/') || |
---|
| 1519 | (c == '|') || |
---|
| 1520 | (c == '\t') || |
---|
| 1521 | (c == '#')) return; |
---|
| 1522 | if (line.find ('(') == cmt_string::npos) |
---|
| 1523 | { |
---|
| 1524 | m_prev_line = line; |
---|
| 1525 | return; |
---|
| 1526 | } |
---|
| 1527 | |
---|
| 1528 | m_running = true; |
---|
| 1529 | m_full_line = line; |
---|
| 1530 | m_full_line.replace ("(", " ("); |
---|
| 1531 | |
---|
| 1532 | static CmtSystem::cmt_string_vector words; |
---|
| 1533 | |
---|
| 1534 | CmtSystem::split (m_full_line, " \t", words); |
---|
| 1535 | |
---|
| 1536 | const cmt_string& second = words[1]; |
---|
| 1537 | if (second[0] == '(') |
---|
| 1538 | { |
---|
| 1539 | m_full_line = m_prev_line; |
---|
| 1540 | m_full_line += " "; |
---|
| 1541 | m_full_line += line; |
---|
| 1542 | |
---|
| 1543 | m_prev_line = ""; |
---|
| 1544 | } |
---|
| 1545 | } |
---|
| 1546 | else |
---|
| 1547 | { |
---|
| 1548 | m_full_line += line; |
---|
| 1549 | } |
---|
| 1550 | if (line.find (')') == cmt_string::npos) return; |
---|
| 1551 | m_running = false; |
---|
| 1552 | |
---|
| 1553 | if (m_full_line.find (';') != cmt_string::npos) return; |
---|
| 1554 | if (m_full_line.find ("::") != cmt_string::npos) return; |
---|
| 1555 | if (m_full_line.find ('<') != cmt_string::npos) return; |
---|
| 1556 | if (m_full_line.find ('>') != cmt_string::npos) return; |
---|
| 1557 | if (m_full_line.find ('{') != cmt_string::npos) return; |
---|
| 1558 | if (m_full_line.find ('}') != cmt_string::npos) return; |
---|
| 1559 | if (m_full_line.find ("typedef") != cmt_string::npos) return; |
---|
| 1560 | if (m_full_line.find ("yy") != cmt_string::npos) return; |
---|
| 1561 | if (m_full_line.find ("YY") != cmt_string::npos) return; |
---|
| 1562 | if (m_static_functions) |
---|
| 1563 | { |
---|
| 1564 | if (m_full_line.find ("static") == cmt_string::npos) return; |
---|
| 1565 | } |
---|
| 1566 | else |
---|
| 1567 | { |
---|
| 1568 | if (m_full_line.find ("static") != cmt_string::npos) return; |
---|
| 1569 | } |
---|
| 1570 | |
---|
| 1571 | m_full_line += ";"; |
---|
| 1572 | |
---|
| 1573 | if (m_output != 0) |
---|
| 1574 | { |
---|
| 1575 | fprintf (m_output, "%s\n", m_full_line.c_str ()); |
---|
| 1576 | } |
---|
| 1577 | } |
---|
| 1578 | |
---|
| 1579 | void end () |
---|
| 1580 | { |
---|
| 1581 | if (m_output != 0) |
---|
| 1582 | { |
---|
| 1583 | fprintf (m_output, "\n"); |
---|
| 1584 | fprintf (m_output, "#ifdef __cplusplus\n"); |
---|
| 1585 | fprintf (m_output, "}\n"); |
---|
| 1586 | fprintf (m_output, "#endif\n"); |
---|
| 1587 | fprintf (m_output, "\n"); |
---|
| 1588 | fprintf (m_output, "#endif\n"); |
---|
| 1589 | fprintf (m_output, "\n"); |
---|
| 1590 | |
---|
| 1591 | fclose (m_output); |
---|
| 1592 | } |
---|
| 1593 | |
---|
| 1594 | CmtGenerator::check (m_out_file_name); |
---|
| 1595 | } |
---|
| 1596 | |
---|
| 1597 | private: |
---|
| 1598 | bool m_running; |
---|
| 1599 | cmt_string m_out_file_name; |
---|
| 1600 | FILE* m_output; |
---|
| 1601 | bool m_static_functions; |
---|
| 1602 | cmt_string m_full_line; |
---|
| 1603 | cmt_string m_prev_line; |
---|
| 1604 | cmt_string m_suffix; |
---|
| 1605 | cmt_string m_define_suffix; |
---|
| 1606 | }; |
---|
| 1607 | //-------------------------------------------------- |
---|
| 1608 | |
---|
| 1609 | //-------------------------------------------------- |
---|
| 1610 | void PrototypeGenerator::build (const cmt_string& file_name) |
---|
| 1611 | { |
---|
| 1612 | Prototyper prototyper; |
---|
| 1613 | |
---|
| 1614 | reset (); |
---|
| 1615 | |
---|
| 1616 | prototyper.run (file_name); |
---|
| 1617 | } |
---|
| 1618 | |
---|
| 1619 | //-------------------------------------------------- |
---|
| 1620 | void DefaultMakefileGenerator::build () |
---|
| 1621 | { |
---|
| 1622 | cmt_string makefile; |
---|
| 1623 | |
---|
| 1624 | //reset (); |
---|
| 1625 | |
---|
| 1626 | //--- Build a simple Makefile if none is installed |
---|
| 1627 | |
---|
| 1628 | #ifndef WIN32 |
---|
| 1629 | |
---|
| 1630 | bool need_makefile = false; |
---|
| 1631 | |
---|
| 1632 | makefile = cmtdir + "Makefile"; |
---|
| 1633 | |
---|
| 1634 | if (!CmtSystem::test_file (makefile)) |
---|
| 1635 | { |
---|
| 1636 | need_makefile = true; |
---|
| 1637 | } |
---|
| 1638 | else |
---|
| 1639 | { |
---|
| 1640 | static cmt_string s; |
---|
| 1641 | |
---|
| 1642 | s.read (makefile); |
---|
| 1643 | if ((s.find ("METHODSROOT") != cmt_string::npos) || |
---|
| 1644 | (s.find ("$(CMTROOT)/src/constituents.make") == cmt_string::npos)) |
---|
| 1645 | { |
---|
| 1646 | static cmt_string backup = makefile; |
---|
| 1647 | backup += "_backup"; |
---|
| 1648 | |
---|
| 1649 | makefile += ".cmt"; |
---|
| 1650 | |
---|
| 1651 | if (!CmtSystem::test_file (makefile)) |
---|
| 1652 | { |
---|
| 1653 | FILE* file = fopen (backup.c_str (), "wb"); |
---|
| 1654 | if (file != NULL) |
---|
| 1655 | { |
---|
[459] | 1656 | CmtMessage::warning ("\n" |
---|
| 1657 | "# A Makefile already exists " |
---|
| 1658 | "but it does not provide\n" |
---|
| 1659 | "# the recommended features " |
---|
| 1660 | "for a full benefit of CMT\n" |
---|
| 1661 | "#\n" |
---|
| 1662 | "# CMT is now building " |
---|
| 1663 | "a new 'Makefile.cmt' which you can use\n" |
---|
| 1664 | "# to upgrade your current one."); |
---|
| 1665 | /* |
---|
[2] | 1666 | cerr << "# " << endl; |
---|
| 1667 | cerr << "#CMT> Warning: " << endl; |
---|
| 1668 | cerr << "# A Makefile already exists " |
---|
| 1669 | "but it does not provides " << endl; |
---|
| 1670 | cerr << "# the recommended features " |
---|
| 1671 | "for a full benefit of CMT" << endl; |
---|
| 1672 | cerr << "# " << endl; |
---|
| 1673 | cerr << "# CMT is now building " |
---|
| 1674 | "a new 'Makefile.cmt' which you can use" << endl; |
---|
| 1675 | cerr << "# to upgrade your current one." << endl; |
---|
| 1676 | cerr << "# " << endl; |
---|
[459] | 1677 | */ |
---|
[2] | 1678 | s.write (file); |
---|
[527] | 1679 | CmtSystem::close_ostream (file, backup); |
---|
| 1680 | // fclose (file); |
---|
[2] | 1681 | |
---|
| 1682 | need_makefile = true; |
---|
| 1683 | } |
---|
[527] | 1684 | else |
---|
| 1685 | { |
---|
| 1686 | CmtError::set (CmtError::file_access_error, backup); |
---|
| 1687 | } |
---|
[2] | 1688 | } |
---|
| 1689 | } |
---|
| 1690 | } |
---|
| 1691 | |
---|
| 1692 | if (need_makefile) |
---|
| 1693 | { |
---|
| 1694 | FILE* file = fopen (makefile.c_str (), "wb"); |
---|
| 1695 | if (file != NULL) |
---|
| 1696 | { |
---|
[527] | 1697 | fprintf (file, |
---|
| 1698 | "include $(CMTROOT)/src/Makefile.header\n" |
---|
| 1699 | "\n" |
---|
| 1700 | "include $(CMTROOT)/src/constituents.make\n" |
---|
| 1701 | "\n"); |
---|
| 1702 | CmtSystem::close_ostream (file, makefile); |
---|
| 1703 | // fclose (file); |
---|
[2] | 1704 | } |
---|
[527] | 1705 | else |
---|
| 1706 | { |
---|
| 1707 | CmtError::set (CmtError::file_access_error, makefile); |
---|
| 1708 | } |
---|
[2] | 1709 | } |
---|
| 1710 | |
---|
| 1711 | #endif |
---|
| 1712 | |
---|
| 1713 | #ifdef WIN32 |
---|
| 1714 | |
---|
| 1715 | makefile = cmtdir + "NMake"; |
---|
| 1716 | |
---|
| 1717 | if (Cmt::get_debug ()) |
---|
| 1718 | { |
---|
| 1719 | cout << "DefaultMakefileGenerator::build> pwd=" << CmtSystem::pwd () << " cmtdir=" << cmtdir << endl; |
---|
| 1720 | } |
---|
| 1721 | |
---|
| 1722 | if (!CmtSystem::test_file (makefile)) |
---|
| 1723 | { |
---|
| 1724 | FILE* file = fopen (makefile.c_str (), "wb"); |
---|
| 1725 | if (file != NULL) |
---|
| 1726 | { |
---|
[527] | 1727 | fprintf (file, |
---|
| 1728 | "!include $(CMTROOT)\\src\\NMakefile.header\n" |
---|
| 1729 | "\n" |
---|
| 1730 | "!include $(CMTROOT)\\src\\constituents.nmake\n" |
---|
| 1731 | "\n"); |
---|
| 1732 | CmtSystem::close_ostream (file, makefile); |
---|
| 1733 | // fclose (file); |
---|
[2] | 1734 | } |
---|
[527] | 1735 | else |
---|
| 1736 | { |
---|
| 1737 | CmtError::set (CmtError::file_access_error, makefile); |
---|
| 1738 | } |
---|
[2] | 1739 | } |
---|
| 1740 | |
---|
| 1741 | #endif |
---|
| 1742 | |
---|
| 1743 | } |
---|
| 1744 | |
---|
| 1745 | MSDEVGenerator::MSDEVGenerator () |
---|
| 1746 | { |
---|
| 1747 | dsw_header_fragment.set ("dsw_header"); |
---|
| 1748 | dsw_project_fragment.set ("dsw_project"); |
---|
| 1749 | dsw_all_project_header_fragment.set ("dsw_all_project_header"); |
---|
| 1750 | dsw_all_project_dependency_fragment.set ("dsw_all_project_dependency"); |
---|
| 1751 | dsw_all_project_trailer_fragment.set ("dsw_all_project_trailer"); |
---|
| 1752 | dsw_trailer_fragment.set ("dsw_trailer"); |
---|
| 1753 | |
---|
| 1754 | dsp_all_fragment.set ("dsp_all"); |
---|
| 1755 | dsp_library_header_fragment.set ("dsp_library_header"); |
---|
| 1756 | dsp_application_header_fragment.set ("dsp_application_header"); |
---|
| 1757 | dsp_windows_header_fragment.set ("dsp_windows_header"); |
---|
| 1758 | dsp_contents_fragment.set ("dsp_contents"); |
---|
| 1759 | dsp_trailer_fragment.set ("dsp_trailer"); |
---|
| 1760 | } |
---|
| 1761 | |
---|
| 1762 | void MSDEVGenerator::reset () |
---|
| 1763 | { |
---|
| 1764 | CmtGenerator::reset (); |
---|
| 1765 | |
---|
| 1766 | dsw_header_fragment.reset (); |
---|
| 1767 | dsw_project_fragment.reset (); |
---|
| 1768 | dsw_all_project_header_fragment.reset (); |
---|
| 1769 | dsw_all_project_dependency_fragment.reset (); |
---|
| 1770 | dsw_all_project_trailer_fragment.reset (); |
---|
| 1771 | dsw_trailer_fragment.reset (); |
---|
| 1772 | |
---|
| 1773 | dsp_all_fragment.reset (); |
---|
| 1774 | dsp_library_header_fragment.reset (); |
---|
| 1775 | dsp_application_header_fragment.reset (); |
---|
| 1776 | dsp_windows_header_fragment.reset (); |
---|
| 1777 | dsp_contents_fragment.reset (); |
---|
| 1778 | dsp_trailer_fragment.reset (); |
---|
| 1779 | |
---|
| 1780 | CmtSystem::cd (Cmt::get_current_dir ()); |
---|
| 1781 | |
---|
| 1782 | cmt_string branch = CmtSystem::current_branch (); |
---|
| 1783 | |
---|
| 1784 | if ((branch == "mgr") || (branch == "cmt")) |
---|
| 1785 | { |
---|
| 1786 | #ifdef WIN32 |
---|
| 1787 | msdevdir = ".."; |
---|
| 1788 | msdevdir += CmtSystem::file_separator (); |
---|
| 1789 | msdevdir += "Visual"; |
---|
| 1790 | |
---|
| 1791 | if (!CmtSystem::test_directory (msdevdir)) |
---|
| 1792 | { |
---|
| 1793 | CmtSystem::mkdir (msdevdir); |
---|
| 1794 | } |
---|
| 1795 | |
---|
| 1796 | msdevdir += CmtSystem::file_separator (); |
---|
| 1797 | #endif |
---|
| 1798 | } |
---|
| 1799 | else |
---|
| 1800 | { |
---|
| 1801 | #ifdef WIN32 |
---|
| 1802 | msdevdir = "."; |
---|
| 1803 | msdevdir += CmtSystem::file_separator (); |
---|
| 1804 | #endif |
---|
| 1805 | } |
---|
| 1806 | |
---|
| 1807 | } |
---|
| 1808 | |
---|
| 1809 | int MSDEVGenerator::build_workspace (const Constituent::ConstituentVector& constituents) |
---|
| 1810 | { |
---|
| 1811 | reset (); |
---|
| 1812 | |
---|
| 1813 | const cmt_string& package = Cmt::get_current_package (); |
---|
| 1814 | |
---|
| 1815 | m_output_file_name = msdevdir + package + ".dswnew"; |
---|
| 1816 | |
---|
| 1817 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 1818 | if (m_output_file != NULL) |
---|
| 1819 | { |
---|
| 1820 | m_PACKAGE = package; |
---|
| 1821 | dsw_header_fragment.wincopy (m_output_file, 1, |
---|
| 1822 | &m_PACKAGE); |
---|
| 1823 | |
---|
| 1824 | int i; |
---|
| 1825 | |
---|
| 1826 | dsw_all_project_header_fragment.wincopy (m_output_file, 1, |
---|
| 1827 | &m_PACKAGE); |
---|
| 1828 | |
---|
| 1829 | for (i = 0; i < constituents.size (); i++) |
---|
| 1830 | { |
---|
| 1831 | const Constituent& constituent = constituents[i]; |
---|
| 1832 | |
---|
| 1833 | if (constituent.type == Library) |
---|
| 1834 | { |
---|
| 1835 | m_CONSTITUENT = constituent.name; |
---|
| 1836 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 1837 | dsw_all_project_dependency_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 1838 | &m_PACKAGE, |
---|
| 1839 | &m_CONSTITUENT, |
---|
| 1840 | &m_CONSTITUENTSUFFIX); |
---|
| 1841 | } |
---|
| 1842 | else |
---|
| 1843 | { |
---|
| 1844 | m_CONSTITUENT = constituent.name; |
---|
| 1845 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 1846 | dsw_all_project_dependency_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 1847 | &m_PACKAGE, |
---|
| 1848 | &m_CONSTITUENT, |
---|
| 1849 | &m_CONSTITUENTSUFFIX); |
---|
| 1850 | } |
---|
| 1851 | |
---|
| 1852 | } |
---|
| 1853 | |
---|
| 1854 | dsw_all_project_trailer_fragment.wincopy (m_output_file, |
---|
| 1855 | 1, &m_PACKAGE); |
---|
| 1856 | |
---|
| 1857 | for (i = 0; i < constituents.size (); i++) |
---|
| 1858 | { |
---|
| 1859 | const Constituent& constituent = constituents[i]; |
---|
| 1860 | |
---|
| 1861 | if (constituent.type == Library) |
---|
| 1862 | { |
---|
| 1863 | m_CONSTITUENT = constituent.name; |
---|
| 1864 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 1865 | dsw_project_fragment.wincopy (m_output_file, |
---|
| 1866 | constituent.variables, 3, |
---|
| 1867 | &m_PACKAGE, |
---|
| 1868 | &m_CONSTITUENT, |
---|
| 1869 | &m_CONSTITUENTSUFFIX); |
---|
| 1870 | } |
---|
| 1871 | else |
---|
| 1872 | { |
---|
| 1873 | m_CONSTITUENT = constituent.name; |
---|
| 1874 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 1875 | dsw_project_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 1876 | &m_PACKAGE, |
---|
| 1877 | &m_CONSTITUENT, |
---|
| 1878 | &m_CONSTITUENTSUFFIX); |
---|
| 1879 | } |
---|
| 1880 | } |
---|
| 1881 | |
---|
| 1882 | dsw_trailer_fragment.wincopy (m_output_file, 1, &m_PACKAGE); |
---|
| 1883 | |
---|
| 1884 | terminate (); |
---|
| 1885 | } |
---|
[527] | 1886 | else |
---|
| 1887 | { |
---|
| 1888 | CmtError::set (CmtError::file_access_error, m_output_file_name); |
---|
| 1889 | } |
---|
[2] | 1890 | |
---|
| 1891 | m_output_file_name = msdevdir + "all.dspnew"; |
---|
| 1892 | |
---|
| 1893 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 1894 | if (m_output_file != NULL) |
---|
| 1895 | { |
---|
| 1896 | dsp_all_fragment.wincopy (m_output_file, 1, &m_PACKAGE); |
---|
| 1897 | terminate (); |
---|
| 1898 | } |
---|
[527] | 1899 | else |
---|
| 1900 | { |
---|
| 1901 | CmtError::set (CmtError::file_access_error, m_output_file_name); |
---|
| 1902 | } |
---|
[2] | 1903 | |
---|
| 1904 | return (0); |
---|
| 1905 | } |
---|
| 1906 | |
---|
| 1907 | //-------------------------------------------------- |
---|
| 1908 | int MSDEVGenerator::build_project (const Constituent& constituent) |
---|
| 1909 | { |
---|
| 1910 | reset (); |
---|
| 1911 | |
---|
| 1912 | const cmt_string& package = Cmt::get_current_package (); |
---|
| 1913 | static cmt_string file; |
---|
| 1914 | static cmt_string full_name; |
---|
| 1915 | static cmt_string suffix; |
---|
| 1916 | |
---|
| 1917 | int i; |
---|
| 1918 | |
---|
| 1919 | m_CONSTITUENT = constituent.name; |
---|
| 1920 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 1921 | |
---|
| 1922 | for (i = 0; i < constituent.includes.size (); i++) |
---|
| 1923 | { |
---|
| 1924 | const cmt_string& include = constituent.includes[i]; |
---|
| 1925 | m_PACKINCLUDES += " -I" + include; |
---|
| 1926 | } |
---|
| 1927 | |
---|
| 1928 | switch (constituent.type) |
---|
| 1929 | { |
---|
| 1930 | case Application: |
---|
| 1931 | is_application = true; |
---|
| 1932 | m_TITLE = "Application"; |
---|
| 1933 | break; |
---|
| 1934 | case Library: |
---|
| 1935 | is_library = true; |
---|
| 1936 | m_TITLE = "Library"; |
---|
| 1937 | break; |
---|
| 1938 | case Document: |
---|
| 1939 | m_GENERATOR = constituent.generator; |
---|
| 1940 | m_TITLE = "Document"; |
---|
| 1941 | break; |
---|
| 1942 | } |
---|
| 1943 | |
---|
| 1944 | m_PACKOS9 = constituent.need_OS9; |
---|
| 1945 | |
---|
| 1946 | const CmtSystem::cmt_string_vector& sources = constituent.modules; |
---|
| 1947 | const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs; |
---|
| 1948 | const cmt_vector<cmt_regexp>& selects = constituent.select_exprs; |
---|
| 1949 | |
---|
| 1950 | //--- Build the constituents fragment ----- |
---|
| 1951 | |
---|
| 1952 | m_output_file_name = msdevdir + m_CONSTITUENT + ".dspnew"; |
---|
| 1953 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 1954 | |
---|
| 1955 | if (m_output_file == NULL) return (0); |
---|
| 1956 | |
---|
| 1957 | m_PACKAGE = package; |
---|
| 1958 | |
---|
| 1959 | if (is_library) |
---|
| 1960 | { |
---|
| 1961 | if (constituent.no_share) |
---|
| 1962 | { |
---|
| 1963 | m_LIBRARYSUFFIX = "lib"; |
---|
| 1964 | } |
---|
| 1965 | else |
---|
| 1966 | { |
---|
| 1967 | m_LIBRARYSUFFIX = "arc"; |
---|
| 1968 | } |
---|
| 1969 | |
---|
| 1970 | dsp_library_header_fragment.wincopy (m_output_file, constituent.variables, 4, |
---|
| 1971 | &m_PACKAGE, |
---|
| 1972 | &m_CONSTITUENT, |
---|
| 1973 | &m_CONSTITUENTSUFFIX, |
---|
| 1974 | &m_LIBRARYSUFFIX); |
---|
| 1975 | } |
---|
| 1976 | else |
---|
| 1977 | { |
---|
| 1978 | if (constituent.windows) |
---|
| 1979 | { |
---|
| 1980 | dsp_windows_header_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 1981 | &m_PACKAGE, |
---|
| 1982 | &m_CONSTITUENT, |
---|
| 1983 | &m_CONSTITUENTSUFFIX); |
---|
| 1984 | } |
---|
| 1985 | else |
---|
| 1986 | { |
---|
| 1987 | dsp_application_header_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 1988 | &m_PACKAGE, |
---|
| 1989 | &m_CONSTITUENT, |
---|
| 1990 | &m_CONSTITUENTSUFFIX); |
---|
| 1991 | } |
---|
| 1992 | } |
---|
| 1993 | |
---|
| 1994 | for (i = 0; i < sources.size (); i++) |
---|
| 1995 | { |
---|
| 1996 | file = sources[i]; |
---|
| 1997 | |
---|
| 1998 | set_full_name (full_name, file); |
---|
| 1999 | if (full_name == "") continue; |
---|
| 2000 | |
---|
| 2001 | static CmtSystem::cmt_string_vector files; |
---|
| 2002 | |
---|
| 2003 | get_all_files (full_name, excludes, selects, files); |
---|
| 2004 | |
---|
| 2005 | for (int j = 0; j < files.size (); j++) |
---|
| 2006 | { |
---|
| 2007 | const cmt_string& name = files[j]; |
---|
| 2008 | |
---|
| 2009 | if (name != "") |
---|
| 2010 | { |
---|
| 2011 | m_FULLNAME = name; |
---|
| 2012 | |
---|
| 2013 | if (m_output_file != NULL) |
---|
| 2014 | { |
---|
| 2015 | dsp_contents_fragment.wincopy (m_output_file, constituent.variables, 2, |
---|
| 2016 | &m_PACKAGE, |
---|
| 2017 | &m_FULLNAME); |
---|
| 2018 | } |
---|
| 2019 | } |
---|
| 2020 | } |
---|
| 2021 | } |
---|
| 2022 | |
---|
| 2023 | if (m_output_file != NULL) |
---|
| 2024 | { |
---|
| 2025 | dsp_trailer_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 2026 | &m_PACKAGE, |
---|
| 2027 | &m_CONSTITUENT, |
---|
| 2028 | &m_CONSTITUENTSUFFIX); |
---|
| 2029 | |
---|
| 2030 | terminate (); |
---|
| 2031 | } |
---|
| 2032 | |
---|
| 2033 | return (0); |
---|
| 2034 | } |
---|
| 2035 | |
---|
| 2036 | |
---|
| 2037 | VSNETGenerator::VSNETGenerator () |
---|
| 2038 | { |
---|
| 2039 | sln_header_fragment.set ("sln_header"); |
---|
| 2040 | sln_project_fragment.set ("sln_project"); |
---|
| 2041 | sln_dependency_header_fragment.set ("sln_dependency_header"); |
---|
| 2042 | sln_dependency_project_fragment.set ("sln_dependency_project"); |
---|
| 2043 | sln_dependency_trailer_fragment.set ("sln_dependency_trailer"); |
---|
| 2044 | sln_project_config_fragment.set ("sln_project_config"); |
---|
| 2045 | sln_trailer_fragment.set ("sln_trailer"); |
---|
| 2046 | |
---|
| 2047 | vcproj_all_fragment.set ("vcproj_all"); |
---|
| 2048 | vcproj_library_header_fragment.set ("vcproj_library_header"); |
---|
| 2049 | vcproj_application_header_fragment.set ("vcproj_application_header"); |
---|
| 2050 | vcproj_windows_header_fragment.set ("vcproj_windows_header"); |
---|
| 2051 | vcproj_contents_fragment.set ("vcproj_contents"); |
---|
| 2052 | vcproj_directory_header_fragment.set ("vcproj_directory_header"); |
---|
| 2053 | vcproj_directory_trailer_fragment.set ("vcproj_directory_trailer"); |
---|
| 2054 | vcproj_trailer_fragment.set ("vcproj_trailer"); |
---|
| 2055 | } |
---|
| 2056 | |
---|
| 2057 | void VSNETGenerator::reset () |
---|
| 2058 | { |
---|
| 2059 | CmtGenerator::reset (); |
---|
| 2060 | |
---|
| 2061 | CmtSystem::cd (Cmt::get_current_dir ()); |
---|
| 2062 | |
---|
| 2063 | cmt_string branch = CmtSystem::current_branch (); |
---|
| 2064 | |
---|
| 2065 | if ((branch == "mgr") || (branch == "cmt")) |
---|
| 2066 | { |
---|
| 2067 | #ifdef WIN32 |
---|
| 2068 | vsnetdir = ".."; |
---|
| 2069 | vsnetdir += CmtSystem::file_separator (); |
---|
| 2070 | vsnetdir += "Visual"; |
---|
| 2071 | |
---|
| 2072 | if (!CmtSystem::test_directory (vsnetdir)) |
---|
| 2073 | { |
---|
| 2074 | CmtSystem::mkdir (vsnetdir); |
---|
| 2075 | } |
---|
| 2076 | |
---|
| 2077 | vsnetdir += CmtSystem::file_separator (); |
---|
| 2078 | #endif |
---|
| 2079 | } |
---|
| 2080 | else |
---|
| 2081 | { |
---|
| 2082 | #ifdef WIN32 |
---|
| 2083 | vsnetdir = "."; |
---|
| 2084 | vsnetdir += CmtSystem::file_separator (); |
---|
| 2085 | #endif |
---|
| 2086 | } |
---|
| 2087 | } |
---|
| 2088 | |
---|
| 2089 | void VSNETGenerator::pseudoGUID (const cmt_string& a, |
---|
| 2090 | const cmt_string& b, |
---|
| 2091 | const cmt_string& c, |
---|
| 2092 | cmt_string& d) |
---|
| 2093 | { |
---|
| 2094 | char buf[64]; // make the guid in here |
---|
| 2095 | static char hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; |
---|
| 2096 | int k = 0; |
---|
| 2097 | int i; |
---|
| 2098 | |
---|
| 2099 | for (i = 0; (i < c.size()) && (k < sizeof(buf)); ++i, ++k) buf[k] = c[i]; |
---|
| 2100 | for (i = 0; (i < a.size()) && (k < sizeof(buf)); ++i, ++k) buf[k] = a[i]; |
---|
| 2101 | for (i = 0; (i < b.size()) && (k < sizeof(buf)); ++i, ++k) buf[k] = b[i]; |
---|
| 2102 | for (; k < sizeof(buf); ++k) buf[k] = 0; |
---|
| 2103 | |
---|
| 2104 | // now use the buffer to format the output string |
---|
| 2105 | // example: {3FE091FC-3738-4F2E-9723-E846B43F77AB} |
---|
| 2106 | d = '{'; |
---|
| 2107 | k = 0; |
---|
| 2108 | |
---|
| 2109 | for (i = 0; i < 4; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-'; |
---|
| 2110 | for (i = 0; i < 2; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-'; |
---|
| 2111 | for (i = 0; i < 2; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-'; |
---|
| 2112 | for (i = 0; i < 2; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '-'; |
---|
| 2113 | for (i = 0; i < 6; ++i, ++k) { d += hex[buf[k]&15]; d += hex[buf[k] >> 4]; } d += '}'; |
---|
| 2114 | } |
---|
| 2115 | |
---|
| 2116 | int VSNETGenerator::build_workspace (const Constituent::ConstituentVector& constituents) |
---|
| 2117 | { |
---|
| 2118 | reset (); |
---|
| 2119 | |
---|
| 2120 | const cmt_string& package = Cmt::get_current_package (); |
---|
| 2121 | |
---|
| 2122 | m_output_file_name = vsnetdir + package + ".slnnew"; |
---|
| 2123 | |
---|
| 2124 | Variable PACKAGE_GUID ("PACKAGE_GUID"); |
---|
| 2125 | Variable CONSTITUENT_GUID ("CONSTITUENT_GUID"); |
---|
| 2126 | Variable NUMBER ("NUMBER"); |
---|
| 2127 | |
---|
| 2128 | cmt_string guid; |
---|
| 2129 | pseudoGUID (package, Cmt::get_current_version(), "", guid); |
---|
| 2130 | PACKAGE_GUID = guid; |
---|
| 2131 | |
---|
| 2132 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 2133 | |
---|
| 2134 | if (m_output_file != NULL) |
---|
| 2135 | { |
---|
| 2136 | m_PACKAGE = package; |
---|
| 2137 | sln_header_fragment.wincopy (m_output_file, 2, |
---|
| 2138 | &m_PACKAGE, |
---|
| 2139 | &PACKAGE_GUID); |
---|
| 2140 | |
---|
| 2141 | int i; |
---|
| 2142 | |
---|
| 2143 | for (i = 0; i < constituents.size (); i++) |
---|
| 2144 | { |
---|
| 2145 | const Constituent& constituent = constituents[i]; |
---|
| 2146 | |
---|
| 2147 | pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid); |
---|
| 2148 | CONSTITUENT_GUID = guid; |
---|
| 2149 | |
---|
| 2150 | if (constituent.type == Library) |
---|
| 2151 | { |
---|
| 2152 | m_CONSTITUENT = constituent.name; |
---|
| 2153 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 2154 | sln_project_fragment.wincopy (m_output_file, |
---|
| 2155 | constituent.variables, 4, |
---|
| 2156 | &m_PACKAGE, |
---|
| 2157 | &m_CONSTITUENT, |
---|
| 2158 | &PACKAGE_GUID, |
---|
| 2159 | &CONSTITUENT_GUID); |
---|
| 2160 | } |
---|
| 2161 | else |
---|
| 2162 | { |
---|
| 2163 | m_CONSTITUENT = constituent.name; |
---|
| 2164 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 2165 | sln_project_fragment.wincopy (m_output_file, constituent.variables, 4, |
---|
| 2166 | &m_PACKAGE, |
---|
| 2167 | &m_CONSTITUENT, |
---|
| 2168 | &PACKAGE_GUID, |
---|
| 2169 | &CONSTITUENT_GUID); |
---|
| 2170 | } |
---|
| 2171 | } |
---|
| 2172 | |
---|
| 2173 | sln_dependency_header_fragment.wincopy (m_output_file, |
---|
| 2174 | 1, &m_PACKAGE); |
---|
| 2175 | |
---|
| 2176 | for (i = 0; i < constituents.size (); i++) |
---|
| 2177 | { |
---|
| 2178 | const Constituent& constituent = constituents[i]; |
---|
| 2179 | pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid); |
---|
| 2180 | CONSTITUENT_GUID = guid; |
---|
| 2181 | |
---|
| 2182 | cmt_string num; |
---|
| 2183 | num = (char)('0' + i); |
---|
| 2184 | NUMBER = num; |
---|
| 2185 | if (constituent.type == Library) |
---|
| 2186 | { |
---|
| 2187 | m_CONSTITUENT = constituent.name; |
---|
| 2188 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 2189 | |
---|
| 2190 | sln_dependency_project_fragment.wincopy (m_output_file, constituent.variables, 5, |
---|
| 2191 | &m_PACKAGE, |
---|
| 2192 | &m_CONSTITUENT, |
---|
| 2193 | &PACKAGE_GUID, |
---|
| 2194 | &CONSTITUENT_GUID, |
---|
| 2195 | &NUMBER); |
---|
| 2196 | } |
---|
| 2197 | else |
---|
| 2198 | { |
---|
| 2199 | m_CONSTITUENT = constituent.name; |
---|
| 2200 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 2201 | sln_dependency_project_fragment.wincopy (m_output_file, constituent.variables, 5, |
---|
| 2202 | &m_PACKAGE, |
---|
| 2203 | &m_CONSTITUENT, |
---|
| 2204 | &PACKAGE_GUID, |
---|
| 2205 | &CONSTITUENT_GUID, |
---|
| 2206 | &NUMBER); |
---|
| 2207 | } |
---|
| 2208 | } |
---|
| 2209 | |
---|
| 2210 | sln_dependency_trailer_fragment.wincopy (m_output_file, |
---|
| 2211 | 1, &m_PACKAGE); |
---|
| 2212 | |
---|
| 2213 | for (i = 0; i < constituents.size (); i++) |
---|
| 2214 | { |
---|
| 2215 | const Constituent& constituent = constituents[i]; |
---|
| 2216 | pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid); |
---|
| 2217 | CONSTITUENT_GUID = guid; |
---|
| 2218 | |
---|
| 2219 | if (constituent.type == Library) |
---|
| 2220 | { |
---|
| 2221 | m_CONSTITUENT = constituent.name; |
---|
| 2222 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 2223 | sln_project_config_fragment.wincopy (m_output_file, |
---|
| 2224 | constituent.variables, 3, |
---|
| 2225 | &m_PACKAGE, |
---|
| 2226 | &m_CONSTITUENT, |
---|
| 2227 | &CONSTITUENT_GUID); |
---|
| 2228 | } |
---|
| 2229 | else |
---|
| 2230 | { |
---|
| 2231 | m_CONSTITUENT = constituent.name; |
---|
| 2232 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 2233 | sln_project_config_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 2234 | &m_PACKAGE, |
---|
| 2235 | &m_CONSTITUENT, |
---|
| 2236 | &CONSTITUENT_GUID); |
---|
| 2237 | } |
---|
| 2238 | } |
---|
| 2239 | |
---|
| 2240 | sln_trailer_fragment.wincopy (m_output_file, 1, &m_PACKAGE); |
---|
| 2241 | |
---|
| 2242 | terminate (); |
---|
| 2243 | } |
---|
| 2244 | |
---|
| 2245 | m_output_file_name = vsnetdir + "all.vcprojnew"; |
---|
| 2246 | |
---|
| 2247 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 2248 | if (m_output_file != NULL) |
---|
| 2249 | { |
---|
| 2250 | vcproj_all_fragment.wincopy (m_output_file, 1, &m_PACKAGE); |
---|
| 2251 | |
---|
| 2252 | terminate (); |
---|
| 2253 | } |
---|
| 2254 | |
---|
| 2255 | return (0); |
---|
| 2256 | } |
---|
| 2257 | |
---|
| 2258 | int VSNETGenerator::build_project (const Constituent& constituent) |
---|
| 2259 | { |
---|
| 2260 | reset (); |
---|
| 2261 | |
---|
| 2262 | const cmt_string& package = Cmt::get_current_package(); |
---|
| 2263 | static cmt_string file; |
---|
| 2264 | static cmt_string full_name; |
---|
| 2265 | static cmt_string suffix; |
---|
| 2266 | |
---|
| 2267 | static Variable GUID("GUID"); |
---|
| 2268 | int i; |
---|
| 2269 | |
---|
| 2270 | // Directory Support |
---|
| 2271 | int dir_pos; |
---|
| 2272 | int file_pos; |
---|
| 2273 | int src_pos; |
---|
| 2274 | int iSFFilter = 0; |
---|
| 2275 | cmt_string directory; |
---|
| 2276 | cmt_string new_dir; |
---|
| 2277 | bool need_trailer = false; |
---|
| 2278 | |
---|
| 2279 | m_CONSTITUENT = constituent.name; |
---|
| 2280 | // make up a pseudo-GUID from the constituent-pacakge-version combination |
---|
| 2281 | |
---|
| 2282 | cmt_string guid; |
---|
| 2283 | pseudoGUID (package, Cmt::get_current_version(), constituent.name, guid); |
---|
| 2284 | |
---|
| 2285 | GUID = guid; |
---|
| 2286 | |
---|
| 2287 | for (i = 0; i < constituent.includes.size (); i++) |
---|
| 2288 | { |
---|
| 2289 | const cmt_string& include = constituent.includes[i]; |
---|
| 2290 | m_PACKINCLUDES += " -I" + include; |
---|
| 2291 | } |
---|
| 2292 | |
---|
| 2293 | switch (constituent.type) |
---|
| 2294 | { |
---|
| 2295 | case Application: |
---|
| 2296 | is_application = true; |
---|
| 2297 | m_TITLE = "Application"; |
---|
| 2298 | break; |
---|
| 2299 | case Library: |
---|
| 2300 | is_library = true; |
---|
| 2301 | m_TITLE = "Library"; |
---|
| 2302 | break; |
---|
| 2303 | case Document: |
---|
| 2304 | m_GENERATOR = constituent.generator; |
---|
| 2305 | m_TITLE = "Document"; |
---|
| 2306 | break; |
---|
| 2307 | } |
---|
| 2308 | |
---|
| 2309 | m_PACKOS9 = constituent.need_OS9; |
---|
| 2310 | |
---|
| 2311 | const CmtSystem::cmt_string_vector& sources = constituent.modules; |
---|
| 2312 | const cmt_vector<cmt_regexp>& excludes = constituent.exclude_exprs; |
---|
| 2313 | const cmt_vector<cmt_regexp>& selects = constituent.select_exprs; |
---|
| 2314 | |
---|
| 2315 | //--- Build the constituents fragment ----- |
---|
| 2316 | cmt_string output; |
---|
| 2317 | |
---|
| 2318 | m_output_file_name = vsnetdir + m_CONSTITUENT + ".vcprojnew"; |
---|
| 2319 | m_output_file = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 2320 | |
---|
| 2321 | if (m_output_file == NULL) return (0); |
---|
| 2322 | |
---|
| 2323 | m_PACKAGE = package; |
---|
| 2324 | |
---|
| 2325 | if (is_library) |
---|
| 2326 | { |
---|
| 2327 | if (constituent.no_share) |
---|
| 2328 | { |
---|
| 2329 | m_LIBRARYSUFFIX = "lib"; |
---|
| 2330 | } |
---|
| 2331 | else |
---|
| 2332 | { |
---|
| 2333 | m_LIBRARYSUFFIX = "arc"; |
---|
| 2334 | } |
---|
| 2335 | |
---|
| 2336 | vcproj_library_header_fragment.wincopy (m_output_file, constituent.variables, 4, |
---|
| 2337 | &m_PACKAGE, |
---|
| 2338 | &m_CONSTITUENT, |
---|
| 2339 | &GUID, |
---|
| 2340 | &m_LIBRARYSUFFIX); |
---|
| 2341 | } |
---|
| 2342 | else |
---|
| 2343 | { |
---|
| 2344 | if (constituent.windows) |
---|
| 2345 | { |
---|
| 2346 | vcproj_windows_header_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 2347 | &m_PACKAGE, |
---|
| 2348 | &m_CONSTITUENT, |
---|
| 2349 | &GUID); |
---|
| 2350 | } |
---|
| 2351 | else |
---|
| 2352 | { |
---|
| 2353 | vcproj_application_header_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 2354 | &m_PACKAGE, |
---|
| 2355 | &m_CONSTITUENT, |
---|
| 2356 | &GUID); |
---|
| 2357 | } |
---|
| 2358 | } |
---|
| 2359 | |
---|
| 2360 | for (i = 0; i < sources.size (); i++) |
---|
| 2361 | { |
---|
| 2362 | file = sources[i]; |
---|
| 2363 | |
---|
| 2364 | set_full_name (full_name, file); |
---|
| 2365 | if (full_name == "") continue; |
---|
| 2366 | |
---|
| 2367 | static CmtSystem::cmt_string_vector files; |
---|
| 2368 | |
---|
| 2369 | get_all_files (full_name, excludes, selects, files); |
---|
| 2370 | |
---|
| 2371 | for (int j = 0; j < files.size (); j++) |
---|
| 2372 | { |
---|
| 2373 | const cmt_string& name = files[j]; |
---|
| 2374 | |
---|
| 2375 | if (name != "") |
---|
| 2376 | { |
---|
| 2377 | m_FULLNAME = name; |
---|
| 2378 | |
---|
| 2379 | // Add Directory Support here |
---|
| 2380 | // Step 1: Parse into "..\src\" "directory" "\filename.cxx" |
---|
| 2381 | |
---|
| 2382 | // find ..\ ; |
---|
| 2383 | src_pos = name.find('\\'); |
---|
| 2384 | // Finds ..\src\ ; |
---|
| 2385 | dir_pos = name.find(src_pos+1, '\\') + 1; |
---|
| 2386 | // Finds ..\src\..\astro\ ; |
---|
| 2387 | file_pos = name.find_last_of('\\'); |
---|
| 2388 | |
---|
| 2389 | // Debug only |
---|
| 2390 | //printf("%40s, %i, %i, %i;\n", name src_pos, dir_pos, file_pos); |
---|
| 2391 | // If dir_pos == file_pos, then we have ../src/filename.cxx |
---|
| 2392 | // If dir_pos > file_pos, then we have ../filename.cxx or something odd. |
---|
| 2393 | |
---|
| 2394 | // Step 2: see if it is or is not a ../src/ directory. |
---|
| 2395 | if ((dir_pos < file_pos) && (dir_pos > src_pos)) |
---|
| 2396 | { |
---|
| 2397 | new_dir = name.substr (dir_pos, file_pos-dir_pos); |
---|
| 2398 | new_dir.replace( "..\\", ""); // All names are relative to package/Visual, |
---|
| 2399 | // so we want to ditch the prevailing ..\ ; |
---|
| 2400 | // which all of them have. |
---|
| 2401 | } |
---|
| 2402 | else |
---|
| 2403 | { |
---|
| 2404 | new_dir = "Source Files NN"; |
---|
| 2405 | } |
---|
| 2406 | |
---|
| 2407 | // Step 3: Add directory structure to vcproj file. |
---|
| 2408 | if (new_dir != directory) // Detects a change in directory |
---|
| 2409 | { |
---|
| 2410 | directory = new_dir; |
---|
| 2411 | // Step 3a: Add a </Filter> when neccessary. |
---|
| 2412 | if (need_trailer == false) |
---|
| 2413 | { |
---|
| 2414 | // Ensure that no trailing </Filter> is placed incorrectly. |
---|
| 2415 | need_trailer = true; |
---|
| 2416 | } |
---|
| 2417 | else |
---|
| 2418 | { |
---|
| 2419 | vcproj_directory_trailer_fragment.wincopy (m_output_file, |
---|
| 2420 | constituent.variables, 1, |
---|
| 2421 | &m_PACKAGE); |
---|
| 2422 | } |
---|
| 2423 | |
---|
| 2424 | // Step 3b: Add a <Filter> when neccessary. |
---|
| 2425 | if ((dir_pos < file_pos) && (dir_pos > src_pos)) |
---|
| 2426 | { |
---|
| 2427 | // Add <Filter Name="directory"> |
---|
| 2428 | m_DIRNAME = new_dir; |
---|
| 2429 | vcproj_directory_header_fragment.wincopy (m_output_file, constituent.variables, 2, |
---|
| 2430 | &m_PACKAGE, |
---|
| 2431 | &m_DIRNAME); |
---|
| 2432 | } |
---|
| 2433 | else |
---|
| 2434 | { |
---|
| 2435 | // Ensure that no </Filter> is placed incorrectly. |
---|
| 2436 | // This is the case of the file being in ../src |
---|
| 2437 | // which requires no directory. Thus no filter start or end tag is needed. |
---|
| 2438 | |
---|
| 2439 | need_trailer = false; |
---|
| 2440 | } |
---|
| 2441 | } |
---|
| 2442 | |
---|
| 2443 | if (m_output_file != NULL) |
---|
| 2444 | { |
---|
| 2445 | vcproj_contents_fragment.wincopy (m_output_file, constituent.variables, 2, |
---|
| 2446 | &m_PACKAGE, |
---|
| 2447 | &m_FULLNAME); |
---|
| 2448 | } |
---|
| 2449 | } |
---|
| 2450 | } |
---|
| 2451 | } |
---|
| 2452 | |
---|
| 2453 | if (need_trailer == true) |
---|
| 2454 | { |
---|
| 2455 | // Add a trailing </Filter> for directory support. |
---|
| 2456 | vcproj_directory_trailer_fragment.wincopy (m_output_file, constituent.variables, 1, |
---|
| 2457 | &m_PACKAGE); |
---|
| 2458 | } |
---|
| 2459 | |
---|
| 2460 | if (m_output_file != NULL) |
---|
| 2461 | { |
---|
| 2462 | vcproj_trailer_fragment.wincopy (m_output_file, constituent.variables, 3, |
---|
| 2463 | &m_PACKAGE, |
---|
| 2464 | &m_CONSTITUENT, |
---|
| 2465 | &m_CONSTITUENTSUFFIX); |
---|
| 2466 | |
---|
| 2467 | terminate (); |
---|
| 2468 | } |
---|
| 2469 | |
---|
| 2470 | return (0); |
---|
| 2471 | } |
---|
| 2472 | |
---|
| 2473 | MakeSetupGenerator::MakeSetupGenerator () |
---|
| 2474 | { |
---|
| 2475 | make_setup_header_fragment.set ("make_setup_header"); |
---|
| 2476 | make_setup_fragment.set ("make_setup"); |
---|
| 2477 | } |
---|
| 2478 | |
---|
| 2479 | void MakeSetupGenerator::reset () |
---|
| 2480 | { |
---|
| 2481 | CmtGenerator::reset (); |
---|
| 2482 | |
---|
| 2483 | make_setup_header_fragment.reset (); |
---|
| 2484 | make_setup_fragment.reset (); |
---|
| 2485 | } |
---|
| 2486 | |
---|
| 2487 | void MakeSetupGenerator::build (const cmt_string& package) |
---|
| 2488 | { |
---|
| 2489 | reset (); |
---|
| 2490 | |
---|
| 2491 | m_PACKAGE = package; |
---|
| 2492 | |
---|
| 2493 | cmt_string file_name = "setup."; |
---|
| 2494 | |
---|
| 2495 | if (Cmt::build_nmake ()) |
---|
| 2496 | { |
---|
| 2497 | file_name += "nmake"; |
---|
| 2498 | } |
---|
| 2499 | else |
---|
| 2500 | { |
---|
| 2501 | file_name += "make"; |
---|
| 2502 | } |
---|
| 2503 | |
---|
| 2504 | cmt_string new_file_name = file_name; |
---|
| 2505 | new_file_name += "new"; |
---|
| 2506 | |
---|
| 2507 | m_output_file = fopen (new_file_name, "wb"); |
---|
| 2508 | |
---|
| 2509 | if (m_output_file != NULL) |
---|
| 2510 | { |
---|
| 2511 | int number; |
---|
| 2512 | |
---|
| 2513 | const Use::UsePtrVector& uses = Use::get_ordered_uses (); |
---|
| 2514 | |
---|
| 2515 | const Constituent::ConstituentVector& constituents = |
---|
| 2516 | Constituent::constituents (); |
---|
| 2517 | |
---|
| 2518 | cmt_string temp; |
---|
| 2519 | |
---|
| 2520 | make_setup_header_fragment.copy (m_output_file, 1, &m_PACKAGE); |
---|
| 2521 | |
---|
| 2522 | for (number = 0; number < uses.size (); number++) |
---|
| 2523 | { |
---|
| 2524 | const Use* use = uses[number]; |
---|
| 2525 | |
---|
| 2526 | if (use->discarded) continue; |
---|
| 2527 | |
---|
| 2528 | if (use->real_path != "") |
---|
| 2529 | { |
---|
| 2530 | temp = use->prefix; |
---|
| 2531 | temp += "ROOT = "; |
---|
| 2532 | temp += use->get_full_path (); |
---|
| 2533 | |
---|
| 2534 | fprintf (m_output_file, "%s\n", temp.c_str()); |
---|
| 2535 | } |
---|
| 2536 | } |
---|
| 2537 | |
---|
| 2538 | temp = "use_requirements = "; |
---|
| 2539 | temp += "requirements "; |
---|
| 2540 | |
---|
| 2541 | for (number = 0; number < uses.size (); number++) |
---|
| 2542 | { |
---|
| 2543 | const Use* use = uses[number]; |
---|
| 2544 | |
---|
| 2545 | if (use->discarded) continue; |
---|
| 2546 | |
---|
| 2547 | if (use->real_path != "") |
---|
| 2548 | { |
---|
| 2549 | temp += "$("; |
---|
| 2550 | temp += use->prefix; |
---|
| 2551 | temp += "ROOT)"; |
---|
| 2552 | temp += CmtSystem::file_separator (); |
---|
| 2553 | switch (use->style) |
---|
| 2554 | { |
---|
| 2555 | case cmt_style: |
---|
| 2556 | temp += "cmt"; |
---|
| 2557 | break; |
---|
| 2558 | case mgr_style: |
---|
| 2559 | temp += "mgr"; |
---|
| 2560 | break; |
---|
| 2561 | } |
---|
| 2562 | temp += CmtSystem::file_separator (); |
---|
| 2563 | temp += "requirements "; |
---|
| 2564 | } |
---|
| 2565 | } |
---|
| 2566 | |
---|
| 2567 | fprintf (m_output_file, "%s\n", temp.c_str()); |
---|
| 2568 | |
---|
| 2569 | temp = "constituents = $(constituents)"; |
---|
| 2570 | Symbol::expand (temp); |
---|
| 2571 | |
---|
| 2572 | fprintf (m_output_file, "%s\n", temp.c_str()); |
---|
| 2573 | |
---|
| 2574 | make_setup_fragment.copy (m_output_file, 1, &m_PACKAGE); |
---|
| 2575 | |
---|
[527] | 2576 | CmtSystem::close_ostream (m_output_file, new_file_name); |
---|
| 2577 | // fclose (m_output_file); |
---|
[2] | 2578 | |
---|
| 2579 | //--- Complete the operation -------------- |
---|
| 2580 | |
---|
| 2581 | commit (new_file_name); |
---|
| 2582 | } |
---|
[527] | 2583 | else |
---|
| 2584 | { |
---|
| 2585 | CmtError::set (CmtError::file_access_error, new_file_name); |
---|
| 2586 | } |
---|
[2] | 2587 | |
---|
| 2588 | /* |
---|
| 2589 | for option in $* |
---|
| 2590 | do |
---|
| 2591 | case ${option} in |
---|
| 2592 | args-tag=*) |
---|
| 2593 | tag=${option} |
---|
| 2594 | tag=`echo "${tag}" | sed -e 's/args.tag=//'` |
---|
| 2595 | ;; |
---|
| 2596 | -tag=*) |
---|
| 2597 | tag=args${option} |
---|
| 2598 | tag=`echo "${tag}" | sed -e 's/args.tag=//'` |
---|
| 2599 | ;; |
---|
| 2600 | esac |
---|
| 2601 | done |
---|
| 2602 | |
---|
| 2603 | if test "${tag}" = "" ; then |
---|
| 2604 | tag=${CMTCONFIG} |
---|
| 2605 | fi |
---|
| 2606 | |
---|
| 2607 | build_shell_setup_files ${tag} |
---|
| 2608 | |
---|
| 2609 | now=`date` |
---|
| 2610 | |
---|
| 2611 | */ |
---|
| 2612 | } |
---|
| 2613 | |
---|
| 2614 | ConstituentsMakefileGenerator::ConstituentsMakefileGenerator () |
---|
| 2615 | { |
---|
| 2616 | constituents_header_fragment.set ("constituents_header"); |
---|
| 2617 | constituents_trailer_fragment.set ("constituents_trailer"); |
---|
| 2618 | group_fragment.set ("group"); |
---|
| 2619 | constituent_fragment.set ("constituent"); |
---|
[429] | 2620 | constituent_lock_fragment.set ("constituent_lock"); |
---|
[628] | 2621 | constituent_app_lib_fragment.set ("constituent_app_lib"); |
---|
[2] | 2622 | check_application_header_fragment.set ("check_application_header"); |
---|
| 2623 | } |
---|
| 2624 | |
---|
| 2625 | void ConstituentsMakefileGenerator::reset () |
---|
| 2626 | { |
---|
| 2627 | CmtGenerator::reset (); |
---|
| 2628 | constituents_header_fragment.reset (); |
---|
| 2629 | constituents_trailer_fragment.reset (); |
---|
| 2630 | group_fragment.reset (); |
---|
| 2631 | constituent_fragment.reset (); |
---|
[429] | 2632 | constituent_lock_fragment.reset (); |
---|
[628] | 2633 | constituent_app_lib_fragment.reset (); |
---|
[2] | 2634 | check_application_header_fragment.reset (); |
---|
| 2635 | } |
---|
| 2636 | |
---|
| 2637 | //-------------------------------------------------- |
---|
| 2638 | void ConstituentsMakefileGenerator::build (const cmt_string& package, |
---|
[561] | 2639 | const cmt_string& file) |
---|
| 2640 | // const CmtSystem::cmt_string_vector& arguments) |
---|
[2] | 2641 | { |
---|
| 2642 | reset (); |
---|
| 2643 | |
---|
[561] | 2644 | cmt_string file_name (file); |
---|
| 2645 | //, dir_name; |
---|
[2] | 2646 | |
---|
[561] | 2647 | // if (arguments.size () > 0) |
---|
| 2648 | // { |
---|
| 2649 | // cmt_string arg = arguments[0]; |
---|
| 2650 | // if (arg.substr (0, 5) == "-out=") |
---|
| 2651 | // { |
---|
| 2652 | // arg.erase (0, 5); |
---|
| 2653 | // file_name = arg; |
---|
| 2654 | // } |
---|
| 2655 | // else if (arg.substr (0, 8) == "-outdir=") |
---|
| 2656 | // { |
---|
| 2657 | // arg.erase (0, 8); |
---|
| 2658 | // dir_name = arg; |
---|
| 2659 | // } |
---|
| 2660 | // } |
---|
[2] | 2661 | |
---|
| 2662 | if (file_name == "") |
---|
| 2663 | { |
---|
| 2664 | file_name = "constituents."; |
---|
| 2665 | |
---|
| 2666 | //--- Build the constituents fragment ----- |
---|
| 2667 | |
---|
| 2668 | if (Cmt::build_nmake ()) |
---|
| 2669 | { |
---|
| 2670 | file_name += "nmake"; |
---|
| 2671 | } |
---|
| 2672 | else |
---|
| 2673 | { |
---|
| 2674 | file_name += "make"; |
---|
| 2675 | } |
---|
| 2676 | } |
---|
| 2677 | |
---|
[561] | 2678 | // if (dir_name != "") |
---|
| 2679 | // { |
---|
| 2680 | // if (dir_name [dir_name.size () - 1] != CmtSystem::file_separator ()) |
---|
| 2681 | // dir_name += CmtSystem::file_separator (); |
---|
| 2682 | // file_name = dir_name + file_name; |
---|
| 2683 | // } |
---|
[547] | 2684 | |
---|
[2] | 2685 | cmt_string save_file_name = file_name; |
---|
[429] | 2686 | save_file_name += "cmtsave"; |
---|
[2] | 2687 | |
---|
| 2688 | if (CmtSystem::test_file (file_name)) |
---|
| 2689 | { |
---|
| 2690 | rename (file_name, save_file_name); |
---|
| 2691 | } |
---|
| 2692 | |
---|
| 2693 | cmt_string new_file_name = file_name; |
---|
| 2694 | new_file_name += "new"; |
---|
| 2695 | |
---|
| 2696 | m_output_file = fopen (new_file_name, "wb"); |
---|
| 2697 | if (m_output_file != NULL) |
---|
| 2698 | { |
---|
| 2699 | int number; |
---|
| 2700 | const Constituent::ConstituentVector& |
---|
| 2701 | constituents = Constituent::constituents (); |
---|
| 2702 | |
---|
| 2703 | m_PACKAGE = package; |
---|
| 2704 | |
---|
| 2705 | constituents_header_fragment.copy (m_output_file, 1, &m_PACKAGE); |
---|
| 2706 | |
---|
| 2707 | m_GROUP = "all"; |
---|
| 2708 | group_fragment.copy (m_output_file, 1, &m_GROUP); |
---|
| 2709 | |
---|
| 2710 | const Group::GroupVector& groups = Group::groups (); |
---|
| 2711 | |
---|
| 2712 | for (number = 0; number < groups.size (); number++) |
---|
| 2713 | { |
---|
| 2714 | const Group& group = groups[number]; |
---|
| 2715 | |
---|
| 2716 | m_GROUP = group.name (); |
---|
| 2717 | |
---|
| 2718 | group_fragment.copy (m_output_file, 1, &m_GROUP); |
---|
| 2719 | } |
---|
| 2720 | |
---|
[429] | 2721 | bool lock = false; |
---|
| 2722 | Symbol* lock_command_macro = Symbol::find ("lock_command"); |
---|
| 2723 | if (lock_command_macro != 0) |
---|
| 2724 | { |
---|
| 2725 | cmt_string lock_command = lock_command_macro->resolve_macro_value (); |
---|
| 2726 | if (lock_command != "") |
---|
| 2727 | { |
---|
| 2728 | Symbol* unlock_command_macro = Symbol::find ("unlock_command"); |
---|
| 2729 | if (unlock_command_macro != 0) |
---|
| 2730 | { |
---|
| 2731 | cmt_string unlock_command = unlock_command_macro->resolve_macro_value (); |
---|
| 2732 | if (unlock_command != "") |
---|
| 2733 | { |
---|
| 2734 | lock = true; |
---|
| 2735 | } |
---|
| 2736 | } |
---|
| 2737 | } |
---|
| 2738 | } |
---|
[2] | 2739 | for (number = 0; number < constituents.size (); number++) |
---|
| 2740 | { |
---|
| 2741 | const Constituent& constituent = constituents[number]; |
---|
| 2742 | |
---|
| 2743 | m_CONSTITUENT = constituent.name; |
---|
| 2744 | m_CONSTITUENTSUFFIX = constituent.suffix; |
---|
| 2745 | |
---|
| 2746 | m_LINE = ""; |
---|
| 2747 | |
---|
| 2748 | if (constituent.has_target_tag) |
---|
| 2749 | { |
---|
| 2750 | m_HASTARGETTAG = "has_target_tag"; |
---|
| 2751 | } |
---|
| 2752 | else |
---|
| 2753 | { |
---|
| 2754 | m_HASTARGETTAG = "has_no_target_tag"; |
---|
| 2755 | } |
---|
| 2756 | |
---|
[488] | 2757 | switch (constituent.type) |
---|
| 2758 | { |
---|
| 2759 | case Application: |
---|
| 2760 | case Library: |
---|
| 2761 | m_HASDEPENDENCIES = "has_dependencies"; |
---|
[628] | 2762 | m_HASPROTOTYPES = constituent.need_prototypes ? "has_prototypes" : "has_no_prototypes" ; |
---|
[488] | 2763 | break; |
---|
| 2764 | case Document: |
---|
| 2765 | m_HASDEPENDENCIES = FragmentHandle (constituent.generator).need_dependencies () ? "has_dependencies" : "has_no_dependencies" ; |
---|
| 2766 | break; |
---|
| 2767 | } |
---|
| 2768 | |
---|
[429] | 2769 | if (constituent.type == Document && lock == true) |
---|
| 2770 | { |
---|
| 2771 | constituent_lock_fragment.copy (m_output_file, constituent.variables, |
---|
[488] | 2772 | 6, |
---|
[429] | 2773 | &m_PACKAGE, |
---|
| 2774 | &m_CONSTITUENT, |
---|
| 2775 | &m_CONSTITUENTSUFFIX, |
---|
| 2776 | &m_LINE, |
---|
[488] | 2777 | &m_HASDEPENDENCIES, |
---|
[429] | 2778 | &m_HASTARGETTAG); |
---|
| 2779 | } |
---|
[628] | 2780 | else if (constituent.type == Application || |
---|
| 2781 | constituent.type == Library) |
---|
| 2782 | { |
---|
| 2783 | constituent_app_lib_fragment.copy (m_output_file, constituent.variables, |
---|
| 2784 | 7, |
---|
| 2785 | &m_PACKAGE, |
---|
| 2786 | &m_CONSTITUENT, |
---|
| 2787 | &m_CONSTITUENTSUFFIX, |
---|
| 2788 | &m_LINE, |
---|
| 2789 | &m_HASDEPENDENCIES, |
---|
| 2790 | &m_HASTARGETTAG, |
---|
| 2791 | &m_HASPROTOTYPES); |
---|
| 2792 | } |
---|
[429] | 2793 | else |
---|
| 2794 | { |
---|
| 2795 | constituent_fragment.copy (m_output_file, constituent.variables, |
---|
[488] | 2796 | 6, |
---|
[429] | 2797 | &m_PACKAGE, |
---|
| 2798 | &m_CONSTITUENT, |
---|
| 2799 | &m_CONSTITUENTSUFFIX, |
---|
| 2800 | &m_LINE, |
---|
[488] | 2801 | &m_HASDEPENDENCIES, |
---|
[429] | 2802 | &m_HASTARGETTAG); |
---|
| 2803 | } |
---|
[2] | 2804 | |
---|
| 2805 | if (constituent.need_check) |
---|
| 2806 | { |
---|
[627] | 2807 | if (constituent.group != 0 && |
---|
| 2808 | constituent.group->name () == "check") |
---|
| 2809 | m_ISCHECKGROUP = "is_check_group"; |
---|
| 2810 | else |
---|
| 2811 | m_ISCHECKGROUP = "is_not_check_group"; |
---|
| 2812 | |
---|
[2] | 2813 | check_application_header_fragment.copy (m_output_file, |
---|
[627] | 2814 | constituent.variables, 4, |
---|
[2] | 2815 | &m_PACKAGE, |
---|
| 2816 | &m_CONSTITUENT, |
---|
[627] | 2817 | &m_CONSTITUENTSUFFIX, |
---|
| 2818 | &m_ISCHECKGROUP); |
---|
[2] | 2819 | } |
---|
| 2820 | } |
---|
| 2821 | |
---|
| 2822 | constituents_trailer_fragment.copy (m_output_file, 0); |
---|
| 2823 | |
---|
[527] | 2824 | CmtSystem::close_ostream (m_output_file, new_file_name); |
---|
| 2825 | // fclose (m_output_file); |
---|
[2] | 2826 | |
---|
| 2827 | commit (new_file_name); |
---|
| 2828 | } |
---|
[527] | 2829 | else |
---|
| 2830 | { |
---|
| 2831 | CmtError::set (CmtError::file_access_error, new_file_name); |
---|
| 2832 | } |
---|
[2] | 2833 | } |
---|
| 2834 | |
---|
[588] | 2835 | //-------------------------------------------------- |
---|
[2] | 2836 | |
---|
[588] | 2837 | PackagesMakefileGenerator::PackagesMakefileGenerator () |
---|
| 2838 | { |
---|
| 2839 | m_DEPENDENCIES.set ("DEPENDENCIES"); |
---|
| 2840 | m_PACKAGEMGRPATH.set ("PACKAGEMGRPATH"); |
---|
| 2841 | m_PACKAGEFULLNAME.set ("PACKAGEFULLNAME"); |
---|
| 2842 | m_ISLOCAL.set ("ISLOCAL"); |
---|
[2] | 2843 | |
---|
[588] | 2844 | packages_header_fragment.set ("packages_header"); |
---|
| 2845 | packages_trailer_fragment.set ("packages_trailer"); |
---|
| 2846 | package_fragment.set ("package"); |
---|
| 2847 | } |
---|
[2] | 2848 | |
---|
[588] | 2849 | void PackagesMakefileGenerator::reset () |
---|
| 2850 | { |
---|
| 2851 | CmtGenerator::reset (); |
---|
| 2852 | m_DEPENDENCIES = ""; |
---|
| 2853 | m_PACKAGEMGRPATH = ""; |
---|
| 2854 | m_PACKAGEFULLNAME = ""; |
---|
| 2855 | m_ISLOCAL = ""; |
---|
| 2856 | |
---|
| 2857 | packages_header_fragment.reset (); |
---|
| 2858 | packages_trailer_fragment.reset (); |
---|
| 2859 | package_fragment.reset (); |
---|
| 2860 | } |
---|
| 2861 | |
---|
| 2862 | //-------------------------------------------------- |
---|
| 2863 | void PackagesMakefileGenerator::build (const cmt_string& package, |
---|
| 2864 | const cmt_string& file) |
---|
| 2865 | { |
---|
| 2866 | reset (); |
---|
| 2867 | |
---|
| 2868 | cmt_string file_name (file); |
---|
| 2869 | if (file_name == "") |
---|
| 2870 | { |
---|
| 2871 | file_name = "packages."; |
---|
| 2872 | |
---|
| 2873 | if (Cmt::build_nmake ()) |
---|
| 2874 | { |
---|
| 2875 | file_name += "nmake"; |
---|
| 2876 | } |
---|
| 2877 | else |
---|
| 2878 | { |
---|
| 2879 | file_name += "make"; |
---|
| 2880 | } |
---|
| 2881 | } |
---|
| 2882 | |
---|
| 2883 | cmt_string save_file_name = file_name; |
---|
| 2884 | save_file_name += "cmtsave"; |
---|
| 2885 | |
---|
| 2886 | if (CmtSystem::test_file (file_name)) |
---|
| 2887 | { |
---|
| 2888 | rename (file_name, save_file_name); |
---|
| 2889 | } |
---|
| 2890 | |
---|
| 2891 | cmt_string new_file_name = file_name; |
---|
| 2892 | new_file_name += "new"; |
---|
| 2893 | |
---|
| 2894 | m_output_file = fopen (new_file_name, "wb"); |
---|
| 2895 | if (m_output_file != NULL) |
---|
| 2896 | { |
---|
| 2897 | m_PACKAGE = package; |
---|
| 2898 | |
---|
[595] | 2899 | if (!packages_header_fragment.copy (m_output_file, 1, &m_PACKAGE)) return; |
---|
[588] | 2900 | |
---|
| 2901 | Project* cur = Project::get_current (); |
---|
| 2902 | Use::UsePtrVector uses (Use::get_ordered_uses ()); |
---|
| 2903 | uses.push_back (&Use::current ()); |
---|
| 2904 | cmt_string temp; |
---|
| 2905 | for (int i = uses.size () - 1; i >= 0; i--) |
---|
| 2906 | { |
---|
| 2907 | Use* use = uses[i]; |
---|
| 2908 | if (use->discarded) continue; |
---|
| 2909 | if (use->m_hidden) continue; |
---|
| 2910 | if (!use->located ()) continue; |
---|
| 2911 | if (use->get_package ()->is_cmt ()) continue; |
---|
| 2912 | |
---|
| 2913 | if (use->get_project () == cur) |
---|
| 2914 | m_ISLOCAL = "is_local"; |
---|
| 2915 | else |
---|
| 2916 | m_ISLOCAL = "is_not_local"; |
---|
| 2917 | |
---|
| 2918 | temp = use->get_full_path (); |
---|
| 2919 | switch (use->style) |
---|
| 2920 | { |
---|
| 2921 | case cmt_style: |
---|
| 2922 | temp += CmtSystem::file_separator (); |
---|
| 2923 | temp += "cmt"; |
---|
| 2924 | break; |
---|
| 2925 | case mgr_style: |
---|
| 2926 | temp += CmtSystem::file_separator (); |
---|
| 2927 | temp += "mgr"; |
---|
| 2928 | break; |
---|
| 2929 | } |
---|
| 2930 | #ifdef WIN32 |
---|
| 2931 | temp += " "; |
---|
| 2932 | #endif |
---|
| 2933 | m_PACKAGEMGRPATH = temp; |
---|
| 2934 | // fprintf (m_output_file, "%s\n", temp.c_str()); |
---|
| 2935 | |
---|
| 2936 | temp = ""; |
---|
| 2937 | if (Symbol* s = Symbol::find (use->get_package_name () + "_offset")) |
---|
| 2938 | { |
---|
| 2939 | cmt_string o = s->build_macro_value (); |
---|
| 2940 | if (o != "") |
---|
| 2941 | { |
---|
| 2942 | temp += o; |
---|
| 2943 | temp += CmtSystem::file_separator (); |
---|
| 2944 | } |
---|
| 2945 | } |
---|
| 2946 | else |
---|
| 2947 | { |
---|
| 2948 | CmtMessage::warning |
---|
| 2949 | (CmtError::get_error_name (CmtError::symbol_not_found) |
---|
| 2950 | + ": macro " + use->get_package_name () + "_offset"); |
---|
| 2951 | } |
---|
| 2952 | temp += use->get_package_name (); |
---|
| 2953 | temp.replace_all (CmtSystem::file_separator (), "_"); |
---|
| 2954 | #ifdef WIN32 |
---|
| 2955 | temp += " "; |
---|
| 2956 | #endif |
---|
| 2957 | m_PACKAGEFULLNAME = temp; |
---|
| 2958 | // fprintf (m_output_file, "%s\n", temp.c_str()); |
---|
| 2959 | |
---|
| 2960 | m_PACKAGE = use->get_package_name (); |
---|
[599] | 2961 | m_PACKAGEPREFIX = use->prefix; |
---|
[588] | 2962 | |
---|
| 2963 | Use::UsePtrVector subuses; |
---|
| 2964 | for (int i = 0; i < use->sub_uses.size (); i++) |
---|
| 2965 | { |
---|
| 2966 | if (use->sub_uses[i]->m_index >= 0 && !use->sub_uses[i]->discarded) |
---|
| 2967 | { |
---|
| 2968 | if (use->sub_uses[i]->m_hidden) continue; |
---|
| 2969 | subuses.push_back (use->sub_uses[i]); |
---|
| 2970 | } |
---|
| 2971 | else |
---|
| 2972 | { |
---|
| 2973 | Use* au (Use::find_valid (use->sub_uses[i]->get_package_name ())); |
---|
| 2974 | if (au) |
---|
| 2975 | { |
---|
| 2976 | subuses.push_back (au); |
---|
| 2977 | } |
---|
| 2978 | } |
---|
| 2979 | } |
---|
| 2980 | m_DEPENDENCIES = ""; |
---|
| 2981 | for (int i = 0; i < subuses.size (); i++) |
---|
| 2982 | { |
---|
| 2983 | if (i != 0) |
---|
| 2984 | { |
---|
| 2985 | m_DEPENDENCIES += " " + subuses[i]->get_package_name (); |
---|
| 2986 | } |
---|
| 2987 | else |
---|
| 2988 | { |
---|
| 2989 | m_DEPENDENCIES += subuses[i]->get_package_name (); |
---|
| 2990 | } |
---|
| 2991 | } |
---|
| 2992 | |
---|
[599] | 2993 | if (!package_fragment.copy (m_output_file, 6, |
---|
| 2994 | &m_PACKAGE, &m_PACKAGEPREFIX, |
---|
| 2995 | &m_DEPENDENCIES, |
---|
[595] | 2996 | &m_PACKAGEMGRPATH, &m_PACKAGEFULLNAME, |
---|
| 2997 | &m_ISLOCAL)) return; |
---|
[588] | 2998 | } |
---|
| 2999 | |
---|
| 3000 | if (Symbol* s = Symbol::find ("CMTINSTALLAREA")) |
---|
| 3001 | { |
---|
| 3002 | cmt_string o = s->build_macro_value (); |
---|
| 3003 | Symbol::expand (o); |
---|
| 3004 | if (o != "") |
---|
| 3005 | { |
---|
| 3006 | temp = "CMTINSTALLAREA="; |
---|
| 3007 | temp += o; |
---|
| 3008 | #ifdef WIN32 |
---|
| 3009 | temp += " "; |
---|
| 3010 | #endif |
---|
| 3011 | fprintf (m_output_file, "%s\n", temp.c_str()); |
---|
| 3012 | } |
---|
| 3013 | } |
---|
| 3014 | |
---|
[595] | 3015 | if (!packages_trailer_fragment.copy (m_output_file, 0)) return; |
---|
[588] | 3016 | |
---|
| 3017 | CmtSystem::close_ostream (m_output_file, new_file_name); |
---|
| 3018 | // fclose (m_output_file); |
---|
| 3019 | |
---|
| 3020 | commit (new_file_name); |
---|
| 3021 | } |
---|
| 3022 | else |
---|
| 3023 | { |
---|
| 3024 | CmtError::set (CmtError::file_access_error, new_file_name); |
---|
| 3025 | } |
---|
| 3026 | } |
---|
| 3027 | |
---|
| 3028 | //-------------------------------------------------- |
---|
| 3029 | |
---|
[2] | 3030 | /** |
---|
| 3031 | With this Awk filter, we analyze an existing dependency file. |
---|
| 3032 | We get the source name in each line |
---|
| 3033 | The list of sources is maintained in m_sources |
---|
| 3034 | A source is stored in the form <name>_<suffix> (instead of <name>.<suffix>) |
---|
| 3035 | */ |
---|
| 3036 | class DependencyFilter : public Awk |
---|
| 3037 | { |
---|
| 3038 | public: |
---|
| 3039 | DependencyFilter () |
---|
[400] | 3040 | { |
---|
| 3041 | } |
---|
[2] | 3042 | |
---|
| 3043 | void begin () |
---|
[400] | 3044 | { |
---|
| 3045 | m_sources = ""; |
---|
| 3046 | } |
---|
[2] | 3047 | |
---|
| 3048 | void filter (const cmt_string& line) |
---|
[400] | 3049 | { |
---|
| 3050 | int pos = line.find ("_dependencies = "); |
---|
| 3051 | if (pos == cmt_string::npos) return; |
---|
[2] | 3052 | |
---|
[400] | 3053 | cmt_string s = line; |
---|
| 3054 | s.erase (pos); |
---|
[2] | 3055 | |
---|
[400] | 3056 | m_sources += " "; |
---|
| 3057 | m_sources += s; |
---|
| 3058 | m_sources += " "; |
---|
[2] | 3059 | |
---|
[400] | 3060 | //pos = s.find_last_of ("_"); |
---|
| 3061 | //if (pos != cmt_string::npos) s[pos] = "." |
---|
| 3062 | } |
---|
[2] | 3063 | |
---|
| 3064 | void add_source (const cmt_string& file_name) |
---|
[400] | 3065 | { |
---|
| 3066 | static cmt_string suffix; |
---|
| 3067 | static cmt_string name; |
---|
[2] | 3068 | |
---|
[400] | 3069 | CmtSystem::get_dot_suffix (file_name, suffix); |
---|
| 3070 | CmtSystem::basename (file_name, suffix, name); |
---|
| 3071 | CmtSystem::get_suffix (file_name, suffix); |
---|
[2] | 3072 | |
---|
[400] | 3073 | cmt_string s = " "; |
---|
| 3074 | s += name; |
---|
| 3075 | s += "_"; |
---|
| 3076 | s += suffix; |
---|
| 3077 | s += " "; |
---|
[2] | 3078 | |
---|
[400] | 3079 | if (m_sources.find (s) == cmt_string::npos) |
---|
| 3080 | { |
---|
| 3081 | m_sources += s; |
---|
| 3082 | } |
---|
| 3083 | } |
---|
[2] | 3084 | |
---|
| 3085 | bool has_source (const cmt_string& file_name) const |
---|
[400] | 3086 | { |
---|
| 3087 | static cmt_string suffix; |
---|
| 3088 | static cmt_string name; |
---|
[2] | 3089 | |
---|
[400] | 3090 | CmtSystem::get_dot_suffix (file_name, suffix); |
---|
| 3091 | CmtSystem::basename (file_name, suffix, name); |
---|
| 3092 | CmtSystem::get_suffix (file_name, suffix); |
---|
[2] | 3093 | |
---|
[400] | 3094 | cmt_string s = " "; |
---|
| 3095 | s += name; |
---|
| 3096 | s += "_"; |
---|
| 3097 | s += suffix; |
---|
| 3098 | s += " "; |
---|
[2] | 3099 | |
---|
[400] | 3100 | if (m_sources.find (s) == cmt_string::npos) |
---|
| 3101 | { |
---|
| 3102 | return (false); |
---|
[2] | 3103 | } |
---|
[400] | 3104 | else |
---|
[2] | 3105 | { |
---|
[400] | 3106 | return (true); |
---|
[2] | 3107 | } |
---|
[400] | 3108 | } |
---|
[2] | 3109 | |
---|
[400] | 3110 | cmt_string& get_sources () |
---|
| 3111 | { |
---|
| 3112 | return (m_sources); |
---|
| 3113 | } |
---|
| 3114 | |
---|
[2] | 3115 | private: |
---|
| 3116 | cmt_string m_sources; |
---|
| 3117 | }; |
---|
| 3118 | |
---|
[588] | 3119 | //-------------------------------------------------- |
---|
| 3120 | void DependencyGenerator::reset () |
---|
[2] | 3121 | { |
---|
[588] | 3122 | CmtGenerator::reset (); |
---|
| 3123 | m_deps_builder.clear (); |
---|
| 3124 | m_stamps = true; |
---|
[591] | 3125 | m_name = "cmt_unnamed"; |
---|
[588] | 3126 | } |
---|
[2] | 3127 | |
---|
[588] | 3128 | //-------------------------------------------------- |
---|
| 3129 | void DependencyGenerator::prepare_includes () |
---|
| 3130 | { |
---|
| 3131 | cmt_string path; |
---|
| 3132 | cmt_string substitution; |
---|
[427] | 3133 | |
---|
[588] | 3134 | Use* use = &Use::current (); |
---|
[2] | 3135 | |
---|
[588] | 3136 | // m_deps_builder.clear (); |
---|
| 3137 | |
---|
| 3138 | if (use->include_path != "none") |
---|
[2] | 3139 | { |
---|
[588] | 3140 | if (use->include_path == "") |
---|
| 3141 | { |
---|
| 3142 | m_deps_builder.add (incdir, "$(src)"); |
---|
| 3143 | } |
---|
| 3144 | else |
---|
| 3145 | { |
---|
| 3146 | substitution = use->include_path; |
---|
| 3147 | |
---|
| 3148 | path = substitution; |
---|
| 3149 | Symbol::expand (path); |
---|
| 3150 | |
---|
| 3151 | CmtSystem::reduce_file_separators (path); |
---|
| 3152 | |
---|
| 3153 | m_deps_builder.add (path, substitution); |
---|
| 3154 | } |
---|
[2] | 3155 | } |
---|
| 3156 | |
---|
[588] | 3157 | m_deps_builder.add_includes (*use); |
---|
[2] | 3158 | |
---|
[588] | 3159 | Use::UsePtrVector& uses = Use::get_ordered_uses (); |
---|
[2] | 3160 | |
---|
[588] | 3161 | if (uses.size () > 0) |
---|
| 3162 | { |
---|
| 3163 | int number; |
---|
[2] | 3164 | |
---|
[588] | 3165 | for (number = 0; number < uses.size (); number++) |
---|
| 3166 | { |
---|
| 3167 | use = uses[number]; |
---|
| 3168 | if (use->discarded) continue; |
---|
[2] | 3169 | |
---|
[588] | 3170 | if (use->real_path != "") |
---|
| 3171 | { |
---|
| 3172 | if (use->include_path != "none") |
---|
| 3173 | { |
---|
| 3174 | if (use->include_path == "") |
---|
| 3175 | { |
---|
| 3176 | use->get_full_path (path); |
---|
| 3177 | path += CmtSystem::file_separator (); |
---|
| 3178 | path += "src"; |
---|
[2] | 3179 | |
---|
[588] | 3180 | substitution = "$("; |
---|
| 3181 | substitution += use->prefix; |
---|
| 3182 | substitution += "ROOT)"; |
---|
| 3183 | substitution += CmtSystem::file_separator (); |
---|
| 3184 | substitution += "src"; |
---|
| 3185 | substitution += CmtSystem::file_separator (); |
---|
| 3186 | } |
---|
| 3187 | else |
---|
| 3188 | { |
---|
| 3189 | substitution = use->include_path; |
---|
[2] | 3190 | |
---|
[588] | 3191 | path = substitution; |
---|
| 3192 | Symbol::expand (path); |
---|
[2] | 3193 | |
---|
[588] | 3194 | CmtSystem::reduce_file_separators (path); |
---|
| 3195 | } |
---|
[2] | 3196 | |
---|
[588] | 3197 | m_deps_builder.add (path, substitution); |
---|
| 3198 | } |
---|
| 3199 | |
---|
| 3200 | m_deps_builder.add_includes (*use); |
---|
| 3201 | } |
---|
| 3202 | } |
---|
| 3203 | } |
---|
| 3204 | } |
---|
| 3205 | |
---|
| 3206 | //-------------------------------------------------- |
---|
| 3207 | void DependencyGenerator::prepare_header_file_filters () |
---|
| 3208 | { |
---|
| 3209 | const Use* current_use = &Use::current (); |
---|
| 3210 | Use::UsePtrVector uses (Use::get_ordered_uses ()); |
---|
| 3211 | uses.push_back (&Use::current ()); |
---|
| 3212 | bool current_only (true); |
---|
| 3213 | for (int i = uses.size () - 1; i >= 0; i--) |
---|
[2] | 3214 | { |
---|
[588] | 3215 | const Use* use = uses[i]; |
---|
| 3216 | //cerr << "prepare_header_file_filters(0)> " << use->get_package_name () << "[" << use->get_index () << "]\n"; |
---|
| 3217 | if (use->discarded) continue; |
---|
| 3218 | if (use->m_hidden) continue; |
---|
| 3219 | if (!use->located ()) continue; |
---|
[2] | 3220 | |
---|
[588] | 3221 | if (current_only && use != current_use) |
---|
| 3222 | current_only = false; |
---|
[2] | 3223 | |
---|
[588] | 3224 | cmt_string package_name = use->get_package_name (); |
---|
| 3225 | if (package_name == "CMT") continue; |
---|
| 3226 | |
---|
| 3227 | const Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter"); |
---|
| 3228 | if (filter_macro == 0) continue; |
---|
[591] | 3229 | const cmt_string filter_expr (filter_macro->resolve_macro_value ()); |
---|
| 3230 | if (filter_expr.size () == 0) continue; |
---|
[588] | 3231 | |
---|
| 3232 | const Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp"); |
---|
| 3233 | cmt_string stamp; |
---|
| 3234 | if (stamp_macro != 0) |
---|
[469] | 3235 | { |
---|
[588] | 3236 | stamp = stamp_macro->resolve_macro_value (); |
---|
| 3237 | } |
---|
| 3238 | else |
---|
| 3239 | { |
---|
| 3240 | use->get_full_path (stamp); |
---|
| 3241 | switch (use->style) |
---|
| 3242 | { |
---|
| 3243 | case cmt_style: |
---|
| 3244 | stamp += CmtSystem::file_separator (); |
---|
| 3245 | stamp += "cmt"; |
---|
| 3246 | break; |
---|
| 3247 | case mgr_style: |
---|
| 3248 | stamp += CmtSystem::file_separator (); |
---|
| 3249 | stamp += "mgr"; |
---|
| 3250 | break; |
---|
| 3251 | } |
---|
| 3252 | stamp += CmtSystem::file_separator (); |
---|
| 3253 | stamp += "cmt_header_file.stamp"; |
---|
| 3254 | //stamp += "cmt_all_headers.stamp"; |
---|
| 3255 | //<package>/cmt/cmt_all_headers.stamp |
---|
| 3256 | } |
---|
| 3257 | if (!CmtSystem::test_file (stamp)) continue; |
---|
| 3258 | |
---|
| 3259 | //cerr << "0: adding filter: " << use->get_package_name () << "[" << use->get_index () << "]\n"; |
---|
[591] | 3260 | cmt_regexp* filter = new cmt_regexp (filter_expr); |
---|
| 3261 | //cmt_regexp* filter = new cmt_regexp (filter_macro->resolve_macro_value ()); |
---|
[588] | 3262 | assert (filter != 0); |
---|
| 3263 | |
---|
| 3264 | m_deps_builder.add_header_filter (use, filter, stamp); |
---|
| 3265 | } |
---|
| 3266 | |
---|
| 3267 | if (current_only) |
---|
| 3268 | { // we are most likely reading dependencies[_CONSTITUENT].in without CMT |
---|
| 3269 | for (int number = 0; number < Symbol::symbol_number (); number++) |
---|
| 3270 | { |
---|
| 3271 | const Symbol& symbol = Symbol::symbol (number); |
---|
| 3272 | if (symbol.type != Symbol::SymbolMacro) continue; |
---|
| 3273 | int r = symbol.name.find_last_of ("_header_file_filter"); |
---|
| 3274 | if (r == cmt_string::npos || |
---|
| 3275 | (r + 19) != symbol.name.size () || |
---|
| 3276 | r == 0) continue; |
---|
[591] | 3277 | const cmt_string filter_expr (symbol.resolve_macro_value ()); |
---|
| 3278 | if (filter_expr.size () == 0) continue; |
---|
[588] | 3279 | |
---|
| 3280 | cmt_string package_name = symbol.name.substr(0, r); |
---|
| 3281 | const Use* use = Use::find (package_name); |
---|
| 3282 | if (use == current_use) continue; |
---|
| 3283 | if (0 != use && use->discarded) continue; |
---|
| 3284 | if (0 != use && use->m_hidden) continue; |
---|
| 3285 | if (0 != use && !use->located ()) continue; |
---|
| 3286 | |
---|
| 3287 | //Symbol* filter_macro = Symbol::find (package_name + "_header_file_filter"); |
---|
| 3288 | //if (filter_macro == 0) continue; |
---|
| 3289 | |
---|
| 3290 | const Symbol* stamp_macro = Symbol::find (package_name + "_header_file_stamp"); |
---|
| 3291 | cmt_string stamp; |
---|
| 3292 | if (stamp_macro != 0) |
---|
| 3293 | { |
---|
| 3294 | stamp = stamp_macro->resolve_macro_value (); |
---|
| 3295 | } |
---|
| 3296 | else if (0 != use) |
---|
| 3297 | { |
---|
| 3298 | use->get_full_path (stamp); |
---|
| 3299 | switch (use->style) |
---|
| 3300 | { |
---|
| 3301 | case cmt_style: |
---|
| 3302 | stamp += CmtSystem::file_separator (); |
---|
| 3303 | stamp += "cmt"; |
---|
| 3304 | break; |
---|
| 3305 | case mgr_style: |
---|
| 3306 | stamp += CmtSystem::file_separator (); |
---|
| 3307 | stamp += "mgr"; |
---|
| 3308 | break; |
---|
| 3309 | } |
---|
| 3310 | stamp += CmtSystem::file_separator (); |
---|
| 3311 | stamp += "cmt_header_file.stamp"; |
---|
| 3312 | } |
---|
| 3313 | if (!CmtSystem::test_file (stamp)) continue; |
---|
| 3314 | |
---|
| 3315 | //cerr << "1: adding filter: " << package_name << "\n"; |
---|
[591] | 3316 | cmt_regexp* filter = new cmt_regexp (filter_expr); |
---|
| 3317 | //cmt_regexp* filter = new cmt_regexp (symbol.resolve_macro_value ()); |
---|
[588] | 3318 | assert (filter != 0); |
---|
| 3319 | |
---|
| 3320 | m_deps_builder.add_header_filter (use, filter, stamp); |
---|
| 3321 | } |
---|
| 3322 | } |
---|
| 3323 | } |
---|
| 3324 | |
---|
| 3325 | //-------------------------------------------------- |
---|
| 3326 | void DependencyGenerator::build (const CmtSystem::cmt_string_vector& arguments) |
---|
| 3327 | { |
---|
| 3328 | reset (); |
---|
| 3329 | |
---|
| 3330 | // |
---|
| 3331 | // Parse arguments first |
---|
| 3332 | // |
---|
| 3333 | CmtSystem::cmt_string_vector cli_input, all; |
---|
| 3334 | bool all_sources = false; |
---|
| 3335 | bool config_files (false); |
---|
| 3336 | bool start_all (false); |
---|
| 3337 | |
---|
| 3338 | for (int i = 0; i < arguments.size (); i++) |
---|
| 3339 | { |
---|
| 3340 | cmt_string file_name = arguments[i]; |
---|
| 3341 | |
---|
| 3342 | //cerr << "i: " << i << " file_name=" << file_name << endl; |
---|
| 3343 | |
---|
| 3344 | if (file_name.substr (0, 5) == "-out=" || |
---|
| 3345 | file_name.substr (0, 5) == "-out:" || |
---|
| 3346 | file_name.substr (0, 5) == "/out:" || |
---|
| 3347 | file_name.substr (0, 5) == "/out=") |
---|
| 3348 | { |
---|
[469] | 3349 | file_name.erase (0, 5); |
---|
| 3350 | m_output_file_name = file_name; |
---|
| 3351 | } |
---|
[590] | 3352 | else if (file_name.substr (0, 6) == "-name=" || |
---|
| 3353 | file_name.substr (0, 6) == "-name:" || |
---|
| 3354 | file_name.substr (0, 6) == "/name:" || |
---|
| 3355 | file_name.substr (0, 6) == "/name=") |
---|
| 3356 | { |
---|
| 3357 | file_name.erase (0, 6); |
---|
| 3358 | m_name = file_name; |
---|
| 3359 | } |
---|
[474] | 3360 | else if (file_name == "-all_sources" || |
---|
| 3361 | file_name == "/all_sources") |
---|
[2] | 3362 | { |
---|
| 3363 | all_sources = true; |
---|
| 3364 | } |
---|
[474] | 3365 | else if (file_name == "-no_stamps" || |
---|
| 3366 | file_name == "/no_stamps") |
---|
[2] | 3367 | { |
---|
| 3368 | m_stamps = false; |
---|
| 3369 | } |
---|
[588] | 3370 | else if (file_name.substr (0, 2) == "-I" || |
---|
| 3371 | file_name.substr (0, 2) == "/I") |
---|
| 3372 | { |
---|
| 3373 | file_name.erase (0, 2); |
---|
| 3374 | //cerr << "include: " << file_name << endl; |
---|
| 3375 | m_deps_builder.add (file_name, file_name); |
---|
| 3376 | } |
---|
| 3377 | else if (file_name == "-start_all" || |
---|
| 3378 | file_name == "/start_all") |
---|
| 3379 | { |
---|
| 3380 | if (start_all) |
---|
| 3381 | { |
---|
| 3382 | CmtError::set(CmtError::syntax_error, |
---|
| 3383 | "Unexpected option " + file_name); |
---|
| 3384 | return; |
---|
| 3385 | } |
---|
| 3386 | start_all = true; |
---|
| 3387 | } |
---|
| 3388 | else if (file_name == "-end_all" || |
---|
| 3389 | file_name == "/end_all") |
---|
| 3390 | { |
---|
| 3391 | if (!start_all) |
---|
| 3392 | { |
---|
| 3393 | CmtMessage::warning |
---|
| 3394 | (CmtError::get_error_name (CmtError::syntax_error) |
---|
| 3395 | + ": Unexpected option " + file_name); |
---|
| 3396 | } |
---|
| 3397 | start_all = false; |
---|
| 3398 | } |
---|
| 3399 | else if (file_name.substr (0, 1) == "-" |
---|
| 3400 | #ifdef WIN32 |
---|
| 3401 | || file_name.substr (0, 1) == "/" |
---|
| 3402 | #endif |
---|
| 3403 | ) |
---|
| 3404 | { |
---|
| 3405 | if (CmtMessage::active (Verbose)) |
---|
| 3406 | CmtMessage::warning |
---|
| 3407 | (CmtError::get_error_name (CmtError::warning) |
---|
| 3408 | + ": Unknown option " + file_name); |
---|
| 3409 | } |
---|
| 3410 | else if (file_name.substr (file_name.size () - 12) == "requirements" || |
---|
| 3411 | file_name.substr (file_name.size () - 5) == ".make" || |
---|
| 3412 | file_name.substr (file_name.size () - 3) == ".mk" || |
---|
| 3413 | file_name.substr (file_name.size () - 6) == ".nmake" || |
---|
| 3414 | file_name.substr (file_name.size () - 3) == ".in" || |
---|
| 3415 | file_name.substr (file_name.size () - 6) == ".stamp") |
---|
| 3416 | { |
---|
| 3417 | // Configuration changed, |
---|
| 3418 | // want to rebuild dependencies from scratch |
---|
| 3419 | if (!config_files) config_files = true; |
---|
| 3420 | if (!all_sources) all_sources = true; |
---|
| 3421 | } |
---|
| 3422 | else if (start_all) |
---|
| 3423 | { |
---|
| 3424 | all.push_back (file_name); |
---|
| 3425 | } |
---|
[590] | 3426 | else |
---|
[588] | 3427 | { |
---|
| 3428 | cli_input.push_back (file_name); |
---|
| 3429 | } |
---|
[2] | 3430 | } |
---|
[588] | 3431 | |
---|
| 3432 | if (start_all) |
---|
| 3433 | CmtMessage::warning |
---|
| 3434 | (CmtError::get_error_name (CmtError::syntax_error) |
---|
| 3435 | + ": Missing option -end_all"); |
---|
[2] | 3436 | |
---|
[588] | 3437 | //cerr << "m_name: " << m_name << endl; |
---|
[590] | 3438 | /* |
---|
[588] | 3439 | if (m_name.size () == 0) |
---|
| 3440 | { |
---|
| 3441 | CmtError::set(CmtError::syntax_error, |
---|
| 3442 | "Name missing as first argument"); |
---|
| 3443 | return; |
---|
| 3444 | } |
---|
[590] | 3445 | */ |
---|
[588] | 3446 | //cerr << "config_files: " << config_files << endl; |
---|
| 3447 | |
---|
[590] | 3448 | if (0 != m_name.size ()) |
---|
| 3449 | m_constituent = Constituent::find (m_name); |
---|
[588] | 3450 | |
---|
| 3451 | if (!config_files && 0 == cli_input.size () && |
---|
| 3452 | 0 == all.size () && 0 == m_constituent) |
---|
| 3453 | { |
---|
| 3454 | CmtError::set(CmtError::syntax_error, |
---|
| 3455 | m_name + ": Files arguments missing"); |
---|
| 3456 | return; |
---|
| 3457 | } |
---|
| 3458 | /* |
---|
| 3459 | cerr << "cli_input:"; |
---|
| 3460 | for (int i = 0; i < cli_input.size (); i++) |
---|
| 3461 | cerr << " " << cli_input[i]; |
---|
| 3462 | cerr << "\n"; |
---|
| 3463 | |
---|
| 3464 | cerr << "all:"; |
---|
| 3465 | for (int i = 0; i < all.size (); i++) |
---|
| 3466 | cerr << " " << all[i]; |
---|
| 3467 | cerr << "\n"; |
---|
| 3468 | */ |
---|
| 3469 | prepare_includes (); |
---|
| 3470 | prepare_header_file_filters (); |
---|
| 3471 | |
---|
[469] | 3472 | // |
---|
| 3473 | // Now prepare the output file names |
---|
| 3474 | // |
---|
| 3475 | cmt_string branch = CmtSystem::current_branch (); |
---|
[2] | 3476 | |
---|
[469] | 3477 | if ((branch == "mgr") || (branch == "cmt")) |
---|
| 3478 | { |
---|
| 3479 | Use& current_use = Use::current (); |
---|
| 3480 | |
---|
| 3481 | Package* p = current_use.get_package (); |
---|
| 3482 | |
---|
| 3483 | if (p->is_cmt ()) |
---|
| 3484 | { |
---|
| 3485 | // m_bin = "../"; |
---|
| 3486 | m_bin = ".."; |
---|
| 3487 | m_bin += CmtSystem::file_separator (); |
---|
| 3488 | m_bin += CmtSystem::getenv ("CMTBIN"); |
---|
| 3489 | m_bin += CmtSystem::file_separator (); |
---|
| 3490 | } |
---|
| 3491 | else if (m_output_file_name != "") |
---|
| 3492 | { |
---|
| 3493 | CmtSystem::dirname (m_output_file_name, m_bin); |
---|
| 3494 | if (m_bin == "") |
---|
| 3495 | { |
---|
| 3496 | m_bin = "."; |
---|
| 3497 | } |
---|
| 3498 | m_bin += CmtSystem::file_separator (); |
---|
| 3499 | } |
---|
| 3500 | else |
---|
| 3501 | { |
---|
| 3502 | m_bin = "${bin}"; |
---|
| 3503 | } |
---|
| 3504 | |
---|
| 3505 | Symbol::expand (m_bin); |
---|
| 3506 | |
---|
| 3507 | //cerr << "m_output_file_name=" << m_output_file_name << endl; |
---|
| 3508 | //cerr << "current_tag=" << Cmt::current_tag << endl; |
---|
| 3509 | } |
---|
| 3510 | else |
---|
| 3511 | { |
---|
| 3512 | m_bin = "."; |
---|
| 3513 | m_bin += CmtSystem::file_separator (); |
---|
| 3514 | } |
---|
| 3515 | |
---|
| 3516 | if (m_output_file_name == "") |
---|
| 3517 | { |
---|
| 3518 | m_output_file_name = m_bin; |
---|
[588] | 3519 | m_output_file_name += m_name; |
---|
[469] | 3520 | m_output_file_name += "_"; |
---|
| 3521 | m_output_file_name += "dependencies."; |
---|
| 3522 | if (Cmt::build_nmake ()) |
---|
| 3523 | { |
---|
| 3524 | m_output_file_name += "nmake"; |
---|
| 3525 | } |
---|
| 3526 | else |
---|
| 3527 | { |
---|
| 3528 | m_output_file_name += "make"; |
---|
| 3529 | } |
---|
| 3530 | } |
---|
| 3531 | |
---|
[588] | 3532 | //------------------------------------------------------------------------------- |
---|
| 3533 | // |
---|
| 3534 | // For Makefile, we need to select, from cli_input, source files only, |
---|
| 3535 | // there may be dependencies of source files (typically, header files) as well |
---|
| 3536 | // |
---|
| 3537 | cmt_string dependencies; |
---|
| 3538 | if (!all_sources) |
---|
[2] | 3539 | { |
---|
[588] | 3540 | // want to validate cli_input against |
---|
| 3541 | // either |
---|
| 3542 | // o all cli sources |
---|
| 3543 | // or |
---|
| 3544 | // o m_constituent sources |
---|
[590] | 3545 | if (int n = set_source_files (all)) |
---|
[588] | 3546 | { |
---|
[590] | 3547 | if (0 == validate (cli_input)) |
---|
[588] | 3548 | { |
---|
[590] | 3549 | // cli_input contains source files ONLY |
---|
| 3550 | // calculate dependencies for them ONLY |
---|
| 3551 | if (CmtSystem::test_file (m_output_file_name)) |
---|
[588] | 3552 | { |
---|
[590] | 3553 | if (!dependencies.read (m_output_file_name)) |
---|
| 3554 | { |
---|
| 3555 | CmtError::set (CmtError::file_access_error, m_output_file_name); |
---|
| 3556 | return; |
---|
| 3557 | } |
---|
[588] | 3558 | } |
---|
[590] | 3559 | fill_dependencies (dependencies, cli_input); |
---|
[588] | 3560 | } |
---|
[590] | 3561 | else |
---|
| 3562 | { |
---|
| 3563 | all_sources = true; |
---|
| 3564 | // calculate dependencies for |
---|
| 3565 | // all cli sources |
---|
| 3566 | // or |
---|
| 3567 | // m_constituent sources |
---|
| 3568 | fill_dependencies (dependencies); |
---|
| 3569 | } |
---|
[588] | 3570 | } |
---|
| 3571 | else |
---|
| 3572 | { |
---|
[590] | 3573 | // calculate dependencies for all we have |
---|
| 3574 | fill_dependencies (dependencies, cli_input); |
---|
[588] | 3575 | } |
---|
| 3576 | /* |
---|
| 3577 | if (0 != all.size ()) |
---|
| 3578 | { |
---|
| 3579 | // o all cli sources |
---|
| 3580 | int n_invalid = 0; |
---|
| 3581 | for (int i = 0; i < cli_input.size (); i++) |
---|
| 3582 | { |
---|
| 3583 | bool valid = false; |
---|
| 3584 | for (int j = 0; j < all.size (); j++) |
---|
| 3585 | if (cli_input[i] == all[j]) |
---|
| 3586 | { |
---|
| 3587 | valid = true; |
---|
| 3588 | break; |
---|
| 3589 | } |
---|
| 3590 | if (!valid) |
---|
| 3591 | { |
---|
| 3592 | n_invalid += 1; |
---|
| 3593 | break; |
---|
| 3594 | } |
---|
| 3595 | } |
---|
| 3596 | if (0 == n_invalid) |
---|
| 3597 | { |
---|
| 3598 | // cli_input contains source files ONLY |
---|
| 3599 | // calculate dependencies for them ONLY |
---|
| 3600 | if (CmtSystem::test_file (m_output_file_name)) |
---|
| 3601 | { |
---|
| 3602 | if (!dependencies.read (m_output_file_name)) |
---|
| 3603 | { |
---|
| 3604 | CmtError::set (CmtError::file_access_error, m_output_file_name); |
---|
| 3605 | return; |
---|
| 3606 | } |
---|
| 3607 | } |
---|
| 3608 | fill_dependencies (dependencies, cli_input); |
---|
| 3609 | } |
---|
| 3610 | else |
---|
| 3611 | { |
---|
| 3612 | all_sources = true; |
---|
| 3613 | // calculate dependencies for all (all cli sources) |
---|
| 3614 | fill_dependencies (dependencies, all); |
---|
| 3615 | } |
---|
| 3616 | } |
---|
| 3617 | else // 0 == all.size () |
---|
| 3618 | { |
---|
| 3619 | // set_source_files (); |
---|
| 3620 | if (int n = set_source_files ()) |
---|
| 3621 | // if (0 != m_source_files.size ()) |
---|
| 3622 | { |
---|
| 3623 | // o m_constituent sources |
---|
| 3624 | int n_invalid = 0; |
---|
| 3625 | for (int i = 0; i < cli_input.size (); i++) |
---|
| 3626 | { |
---|
| 3627 | bool valid = false; |
---|
| 3628 | for (int j = 0; j < n; j++) |
---|
| 3629 | if (cli_input[i] == m_source_files[j].name ()) |
---|
| 3630 | { |
---|
| 3631 | valid = true; |
---|
| 3632 | break; |
---|
| 3633 | } |
---|
| 3634 | if (!valid) |
---|
| 3635 | { |
---|
| 3636 | n_invalid += 1; |
---|
| 3637 | break; |
---|
| 3638 | } |
---|
| 3639 | } |
---|
| 3640 | if (0 == n_invalid) |
---|
| 3641 | { |
---|
| 3642 | // cli_input contains source files ONLY |
---|
| 3643 | // calculate dependencies for them ONLY |
---|
| 3644 | if (CmtSystem::test_file (m_output_file_name)) |
---|
| 3645 | { |
---|
| 3646 | if (!dependencies.read (m_output_file_name)) |
---|
| 3647 | { |
---|
| 3648 | CmtError::set (CmtError::file_access_error, m_output_file_name); |
---|
| 3649 | return; |
---|
| 3650 | } |
---|
| 3651 | } |
---|
| 3652 | fill_dependencies (dependencies, cli_input); |
---|
| 3653 | } |
---|
| 3654 | else |
---|
| 3655 | { |
---|
| 3656 | all_sources = true; |
---|
| 3657 | // calculate dependencies for m_source_files |
---|
| 3658 | // (m_constituent sources) |
---|
| 3659 | fill_dependencies (dependencies); |
---|
| 3660 | } |
---|
| 3661 | } |
---|
| 3662 | else // 0 == m_source_files.size ()) |
---|
| 3663 | { |
---|
| 3664 | // no source files to validate against |
---|
| 3665 | fill_dependencies (dependencies, cli_input); |
---|
| 3666 | } |
---|
| 3667 | } |
---|
| 3668 | */ |
---|
[2] | 3669 | } |
---|
[588] | 3670 | else // all_sources = true |
---|
[2] | 3671 | { |
---|
[588] | 3672 | if (int n = set_source_files (all)) |
---|
| 3673 | { |
---|
| 3674 | // calculate dependencies for m_source_files |
---|
| 3675 | // either |
---|
| 3676 | // o all cli sources |
---|
| 3677 | // or |
---|
| 3678 | // o m_constituent sources |
---|
| 3679 | // if any existing |
---|
| 3680 | fill_dependencies (dependencies); |
---|
| 3681 | } |
---|
| 3682 | else |
---|
| 3683 | { |
---|
| 3684 | // calculate dependencies for all we have |
---|
| 3685 | fill_dependencies (dependencies, cli_input); |
---|
| 3686 | } |
---|
| 3687 | /* |
---|
| 3688 | if (0 != all.size ()) |
---|
| 3689 | { |
---|
| 3690 | // calculate dependencies for all (all cli sources) |
---|
| 3691 | fill_dependencies (dependencies, all); |
---|
| 3692 | } |
---|
| 3693 | else |
---|
| 3694 | { |
---|
| 3695 | if (int n = set_source_files ()) |
---|
| 3696 | { |
---|
| 3697 | // calculate dependencies for m_source_files (m_constituent sources) |
---|
| 3698 | fill_dependencies (dependencies); |
---|
| 3699 | } |
---|
| 3700 | else |
---|
| 3701 | { |
---|
| 3702 | // calculate dependencies for all we have |
---|
| 3703 | fill_dependencies (dependencies, cli_input); |
---|
| 3704 | } |
---|
| 3705 | } |
---|
| 3706 | */ |
---|
| 3707 | } |
---|
[2] | 3708 | |
---|
[588] | 3709 | if (CmtError::has_pending_error ()) |
---|
| 3710 | { |
---|
| 3711 | if (CmtError::get_last_error_code () == CmtError::path_not_found || |
---|
| 3712 | CmtError::get_last_error_code () == CmtError::file_access_error || |
---|
| 3713 | CmtError::get_last_error_code () == CmtError::execution_failed) |
---|
| 3714 | return; |
---|
[2] | 3715 | } |
---|
[588] | 3716 | //------------------------------------------------------------------------------- |
---|
[2] | 3717 | |
---|
| 3718 | FILE* f = fopen (m_output_file_name.c_str (), "wb"); |
---|
| 3719 | |
---|
[527] | 3720 | if (f != 0) |
---|
[2] | 3721 | { |
---|
[527] | 3722 | dependencies.write (f); |
---|
| 3723 | CmtSystem::close_ostream (f, m_output_file_name); |
---|
[2] | 3724 | } |
---|
| 3725 | else |
---|
| 3726 | { |
---|
[527] | 3727 | CmtError::set (CmtError::file_access_error, m_output_file_name); |
---|
[2] | 3728 | } |
---|
[427] | 3729 | |
---|
| 3730 | // m_deps_builder.clear (); |
---|
[2] | 3731 | } |
---|
| 3732 | |
---|
| 3733 | //-------------------------------------------------- |
---|
| 3734 | // o text contains lines with a pattern like : |
---|
[588] | 3735 | // key = value |
---|
[2] | 3736 | // o line follows the same pattern |
---|
| 3737 | // |
---|
[588] | 3738 | // This function |
---|
| 3739 | // o if the key found in <line> is found in <text>, removes the first line in <text> with the key, if any |
---|
| 3740 | // o appends <line> to <text> |
---|
[2] | 3741 | //-------------------------------------------------- |
---|
[588] | 3742 | void DependencyGenerator::add_line_to_text (const cmt_string& line, cmt_string& text) const |
---|
[2] | 3743 | { |
---|
| 3744 | static const cmt_string empty; |
---|
| 3745 | |
---|
| 3746 | int pos = line.find (" = "); |
---|
| 3747 | if (pos != cmt_string::npos) |
---|
| 3748 | { |
---|
| 3749 | static cmt_string key; |
---|
| 3750 | line.substr (0, pos + 3, key); |
---|
| 3751 | pos = text.find (key); |
---|
| 3752 | if (pos != cmt_string::npos) |
---|
| 3753 | { |
---|
| 3754 | // The key in line exists in text. |
---|
| 3755 | // Now check if the key is exactly the same. |
---|
| 3756 | |
---|
| 3757 | if ((pos == 0) || (text[pos -1] == '\n')) |
---|
| 3758 | { |
---|
| 3759 | // The key is either in the first line or |
---|
| 3760 | // exactly matches '^key = ...' |
---|
| 3761 | |
---|
| 3762 | int nl = text.find (pos, "\n"); |
---|
| 3763 | if (nl != cmt_string::npos) |
---|
| 3764 | { |
---|
| 3765 | static cmt_string old; |
---|
| 3766 | text.substr (pos, nl - pos + 1, old); |
---|
| 3767 | text.replace (old, empty); |
---|
| 3768 | } |
---|
| 3769 | else |
---|
| 3770 | { |
---|
| 3771 | text.erase (pos); |
---|
| 3772 | } |
---|
| 3773 | } |
---|
| 3774 | } |
---|
| 3775 | } |
---|
| 3776 | if (line != "") |
---|
| 3777 | { |
---|
| 3778 | text += line; |
---|
| 3779 | text += "\n"; |
---|
| 3780 | } |
---|
| 3781 | } |
---|
| 3782 | |
---|
[588] | 3783 | //-------------------------------------------------- |
---|
[2] | 3784 | cmt_string DependencyGenerator::build (const cmt_string& file_name) |
---|
| 3785 | { |
---|
| 3786 | Log; |
---|
| 3787 | |
---|
[588] | 3788 | // const Constituent& constituent = *m_constituent; |
---|
[2] | 3789 | |
---|
| 3790 | static cmt_string full_name; |
---|
| 3791 | static cmt_string suffix; |
---|
| 3792 | static cmt_string name; |
---|
| 3793 | static cmt_string line; |
---|
| 3794 | |
---|
| 3795 | full_name = ""; |
---|
| 3796 | line = ""; |
---|
| 3797 | |
---|
[588] | 3798 | /* |
---|
[2] | 3799 | if (!CmtSystem::absolute_path (file_name)) |
---|
| 3800 | { |
---|
| 3801 | full_name = srcdir; |
---|
| 3802 | } |
---|
[588] | 3803 | */ |
---|
[2] | 3804 | |
---|
| 3805 | full_name += file_name; |
---|
| 3806 | |
---|
| 3807 | CmtSystem::get_dot_suffix (full_name, suffix); |
---|
| 3808 | CmtSystem::basename (full_name, suffix, name); |
---|
| 3809 | CmtSystem::get_suffix (full_name, suffix); |
---|
| 3810 | |
---|
[588] | 3811 | // if (name == "requirements") return (line); |
---|
[2] | 3812 | |
---|
[588] | 3813 | const CmtSystem::cmt_string_vector& deps = m_deps_builder.run (full_name, m_name); |
---|
| 3814 | if (CmtError::has_pending_error ()) |
---|
| 3815 | { |
---|
| 3816 | return line; |
---|
| 3817 | } |
---|
| 3818 | // CmtError::set (CmtError::execution_failed, preprocessor, status); |
---|
| 3819 | // CmtError::set (CmtError::file_access_error, header_file_path); |
---|
| 3820 | // CmtError::set (CmtError::path_not_found, name); |
---|
[2] | 3821 | |
---|
| 3822 | line = name; |
---|
| 3823 | line += "_"; |
---|
| 3824 | line += suffix; |
---|
| 3825 | line += "_dependencies = "; |
---|
| 3826 | |
---|
| 3827 | filter_path (full_name); |
---|
| 3828 | |
---|
| 3829 | #ifdef WIN32 |
---|
| 3830 | static const char quote = '\"'; |
---|
| 3831 | #else |
---|
| 3832 | static const char quote = ' '; |
---|
| 3833 | #endif |
---|
| 3834 | |
---|
| 3835 | line += quote; |
---|
| 3836 | line += full_name; |
---|
| 3837 | line += quote; |
---|
| 3838 | |
---|
| 3839 | for (int j = 0; j < deps.size (); j++) |
---|
| 3840 | { |
---|
| 3841 | cmt_string d = deps[j]; |
---|
| 3842 | |
---|
| 3843 | log << "dep line = " << d << log_endl; |
---|
| 3844 | |
---|
| 3845 | filter_path (d); |
---|
| 3846 | |
---|
| 3847 | log << "filtered dep line = " << d << log_endl; |
---|
| 3848 | |
---|
| 3849 | line += " "; |
---|
| 3850 | line += quote; |
---|
| 3851 | line += d; |
---|
| 3852 | line += quote; |
---|
| 3853 | } |
---|
| 3854 | |
---|
| 3855 | Symbol::expand (line); |
---|
| 3856 | |
---|
| 3857 | if (m_stamps) |
---|
| 3858 | { |
---|
[588] | 3859 | cmt_string stamp_output_base = m_name; |
---|
| 3860 | // cmt_string stamp_output_base = constituent.name; |
---|
[2] | 3861 | stamp_output_base += "_deps"; |
---|
| 3862 | |
---|
| 3863 | cmt_string stamp_output = m_bin; |
---|
| 3864 | stamp_output += stamp_output_base; |
---|
| 3865 | |
---|
| 3866 | if (!CmtSystem::mkdir (stamp_output)) |
---|
| 3867 | { |
---|
[588] | 3868 | CmtError::set (CmtError::file_access_error, |
---|
| 3869 | + "Cannot create directory " + stamp_output |
---|
| 3870 | + " for " + m_name); |
---|
| 3871 | return line; |
---|
[2] | 3872 | } |
---|
| 3873 | |
---|
| 3874 | stamp_output_base += CmtSystem::file_separator (); |
---|
| 3875 | stamp_output_base += name; |
---|
| 3876 | stamp_output_base += "_"; |
---|
| 3877 | stamp_output_base += suffix; |
---|
| 3878 | stamp_output_base += ".stamp"; |
---|
| 3879 | |
---|
| 3880 | stamp_output = m_bin; |
---|
| 3881 | stamp_output += stamp_output_base; |
---|
| 3882 | |
---|
| 3883 | line += " $(bin)"; |
---|
| 3884 | line += stamp_output_base; |
---|
| 3885 | |
---|
| 3886 | cmt_string old_stamp; |
---|
| 3887 | |
---|
| 3888 | if (CmtSystem::test_file (stamp_output)) |
---|
| 3889 | { |
---|
[588] | 3890 | if (!old_stamp.read (stamp_output)) |
---|
| 3891 | { |
---|
| 3892 | CmtError::set (CmtError::file_access_error, stamp_output); |
---|
| 3893 | return line; |
---|
| 3894 | } |
---|
| 3895 | // old_stamp.read (stamp_output); |
---|
[2] | 3896 | } |
---|
| 3897 | |
---|
[588] | 3898 | if (line != old_stamp.substr(0, old_stamp.size () - 1)) |
---|
[2] | 3899 | { |
---|
[588] | 3900 | if (!(line + "\n").write (stamp_output)) |
---|
| 3901 | { |
---|
| 3902 | CmtError::set (CmtError::file_access_error, stamp_output); |
---|
| 3903 | return line; |
---|
| 3904 | } |
---|
| 3905 | // (line + "\n").write (stamp_output); |
---|
[2] | 3906 | } |
---|
| 3907 | } |
---|
| 3908 | |
---|
| 3909 | return (line); |
---|
| 3910 | } |
---|
| 3911 | |
---|
[427] | 3912 | //-------------------------------------------------- |
---|
[588] | 3913 | int DependencyGenerator::fill_dependencies (cmt_string& dependencies) |
---|
[427] | 3914 | { |
---|
[588] | 3915 | CmtSystem::cmt_string_vector sources; |
---|
| 3916 | for (int i = 0; i < m_source_files.size (); i++) |
---|
[427] | 3917 | { |
---|
[588] | 3918 | const SourceFile& file = m_source_files[i]; |
---|
| 3919 | sources.push_back (file.name ()); |
---|
| 3920 | } |
---|
| 3921 | return fill_dependencies (dependencies, sources); |
---|
| 3922 | } |
---|
[427] | 3923 | |
---|
[588] | 3924 | //-------------------------------------------------- |
---|
| 3925 | int DependencyGenerator::fill_dependencies (cmt_string& dependencies, |
---|
| 3926 | const CmtSystem::cmt_string_vector& sources) |
---|
| 3927 | { |
---|
| 3928 | int retval (0); |
---|
| 3929 | cmt_string file_name; |
---|
| 3930 | cmt_string compressed_name; |
---|
[427] | 3931 | |
---|
[588] | 3932 | for (int i = 0; i < sources.size (); i++) |
---|
| 3933 | { |
---|
| 3934 | file_name = sources[i]; |
---|
| 3935 | //set_full_name (full_name, file_name); |
---|
| 3936 | CmtSystem::reduce_file_separators (file_name); |
---|
| 3937 | if (file_name == "") continue; |
---|
| 3938 | CmtSystem::compress_path (file_name, compressed_name); |
---|
| 3939 | file_name = compressed_name; |
---|
| 3940 | //cerr << "file_name: " << file_name << endl; |
---|
| 3941 | if (file_name == "") continue; |
---|
[427] | 3942 | |
---|
[588] | 3943 | const cmt_string& line = build (file_name); |
---|
| 3944 | if (CmtError::has_pending_error ()) |
---|
| 3945 | { |
---|
| 3946 | // if (CmtError::get_last_error_code () == CmtError::file_access_error) |
---|
| 3947 | return -1; |
---|
| 3948 | } |
---|
| 3949 | |
---|
| 3950 | //cerr << "line: " << line << endl; |
---|
| 3951 | add_line_to_text (line, dependencies); |
---|
| 3952 | //cerr << "dependencies: " << dependencies << endl; |
---|
| 3953 | } |
---|
[427] | 3954 | |
---|
[588] | 3955 | return retval; |
---|
| 3956 | } |
---|
[427] | 3957 | |
---|
[588] | 3958 | //-------------------------------------------------- |
---|
| 3959 | int DependencyGenerator::set_source_files (const CmtSystem::cmt_string_vector& files) |
---|
| 3960 | { |
---|
| 3961 | m_source_files.clear (); |
---|
| 3962 | |
---|
| 3963 | for (int j = 0; j < files.size (); j++) |
---|
| 3964 | { |
---|
| 3965 | const cmt_string& name = files[j]; |
---|
| 3966 | if (name == "") continue; |
---|
| 3967 | |
---|
| 3968 | bool included = false; |
---|
| 3969 | for (int k = m_source_files.size () - 1; k >= 0; k--) |
---|
| 3970 | if (m_source_files[k].name () == name) |
---|
| 3971 | { |
---|
| 3972 | included = true; |
---|
| 3973 | break; |
---|
| 3974 | } |
---|
| 3975 | if (included) continue; |
---|
| 3976 | |
---|
| 3977 | SourceFile& source = m_source_files.add (); |
---|
| 3978 | source.set (name, Language::null (), ""); |
---|
[427] | 3979 | } |
---|
[588] | 3980 | |
---|
| 3981 | if (m_source_files.size ()) return m_source_files.size (); |
---|
| 3982 | else return set_source_files (); |
---|
[427] | 3983 | } |
---|
[588] | 3984 | |
---|
| 3985 | //-------------------------------------------------- |
---|
| 3986 | int DependencyGenerator::set_source_files () |
---|
| 3987 | { |
---|
| 3988 | if (0 == m_constituent && 0 != m_name.size ()) |
---|
| 3989 | m_constituent = Constituent::find (m_name); |
---|
| 3990 | if (0 == m_constituent) return 0; |
---|
| 3991 | |
---|
| 3992 | m_source_files.clear (); |
---|
| 3993 | |
---|
| 3994 | const CmtSystem::cmt_string_vector& sources = m_constituent->modules; |
---|
| 3995 | const cmt_vector<cmt_regexp>& excludes = m_constituent->exclude_exprs; |
---|
| 3996 | const cmt_vector<cmt_regexp>& selects = m_constituent->select_exprs; |
---|
| 3997 | |
---|
| 3998 | cmt_string file_name, full_name; |
---|
| 3999 | cmt_string compressed_name; |
---|
| 4000 | cmt_string visited, token; |
---|
| 4001 | |
---|
| 4002 | for (int i = 0; i < sources.size (); i++) |
---|
| 4003 | { |
---|
| 4004 | file_name = sources[i]; |
---|
| 4005 | set_full_name (full_name, file_name); |
---|
| 4006 | if (full_name == "") continue; |
---|
| 4007 | |
---|
| 4008 | CmtSystem::compress_path (full_name, compressed_name); |
---|
| 4009 | full_name = compressed_name; |
---|
| 4010 | |
---|
| 4011 | static CmtSystem::cmt_string_vector files; |
---|
| 4012 | |
---|
| 4013 | get_all_files (full_name, excludes, selects, files); |
---|
| 4014 | |
---|
| 4015 | for (int j = 0; j < files.size (); j++) |
---|
| 4016 | { |
---|
| 4017 | const cmt_string& name = files[j]; |
---|
| 4018 | |
---|
| 4019 | if (name == "") continue; |
---|
| 4020 | |
---|
| 4021 | cmt_string suffix; |
---|
| 4022 | CmtSystem::get_suffix (name, suffix); |
---|
| 4023 | Language& language = Language::find_with_suffix (suffix); |
---|
| 4024 | |
---|
| 4025 | if ((m_constituent->type == Application || m_constituent->type == Library) |
---|
| 4026 | && language != Language::null () && language.native_dependencies ()) |
---|
| 4027 | continue; |
---|
| 4028 | |
---|
| 4029 | bool included = false; |
---|
| 4030 | for (int k = m_source_files.size () - 1; k >= 0; k--) |
---|
| 4031 | if (m_source_files[k].name () == name) |
---|
| 4032 | { |
---|
| 4033 | included = true; |
---|
| 4034 | break; |
---|
| 4035 | } |
---|
| 4036 | if (included) continue; |
---|
| 4037 | |
---|
| 4038 | SourceFile& source = m_source_files.add (); |
---|
| 4039 | source.set (name, language, ""); |
---|
| 4040 | } |
---|
| 4041 | } |
---|
| 4042 | return m_source_files.size (); |
---|
| 4043 | } |
---|
| 4044 | |
---|
| 4045 | //-------------------------------------------------- |
---|
| 4046 | /** |
---|
[590] | 4047 | * Returns 0, if each file in @files is found in m_source_files, |
---|
[588] | 4048 | * otherwise returns 1 |
---|
| 4049 | */ |
---|
| 4050 | //-------------------------------------------------- |
---|
| 4051 | int DependencyGenerator::validate (const CmtSystem::cmt_string_vector& files) const |
---|
| 4052 | { |
---|
| 4053 | int n_invalid = 0; |
---|
| 4054 | for (int i = 0; i < files.size (); i++) |
---|
| 4055 | { |
---|
| 4056 | bool valid = false; |
---|
| 4057 | for (int j = 0; j < m_source_files.size (); j++) |
---|
| 4058 | if (files[i] == m_source_files[j].name ()) |
---|
| 4059 | { |
---|
| 4060 | valid = true; |
---|
| 4061 | break; |
---|
| 4062 | } |
---|
| 4063 | if (!valid) |
---|
| 4064 | { |
---|
| 4065 | n_invalid += 1; |
---|
| 4066 | break; |
---|
| 4067 | } |
---|
| 4068 | } |
---|
| 4069 | |
---|
| 4070 | return n_invalid; |
---|
| 4071 | } |
---|