| 1 | #ifdef RCSID |
| 2 | static char RCSid[] = |
| 3 | "$Header$"; |
| 4 | #endif |
| 5 | |
| 6 | /* |
| 7 | * Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved. |
| 8 | * |
| 9 | * Please see the accompanying license file, LICENSE.TXT, for information |
| 10 | * on using and copying this software. |
| 11 | */ |
| 12 | /* |
| 13 | Name |
| 14 | tcmakecl.cpp - TADS Compiler "Make" command line tool |
| 15 | Function |
| 16 | Command-line interface to "make" program build utility |
| 17 | Notes |
| 18 | |
| 19 | Modified |
| 20 | 07/11/99 MJRoberts - Creation |
| 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include "os.h" |
| 28 | #include "t3_os.h" |
| 29 | #include "t3std.h" |
| 30 | #include "tcmake.h" |
| 31 | #include "tchostsi.h" |
| 32 | #include "vmerr.h" |
| 33 | #include "tcvsn.h" |
| 34 | #include "resload.h" |
| 35 | #include "tcmain.h" |
| 36 | #include "tclibprs.h" |
| 37 | #include "t3test.h" |
| 38 | #include "tccmdutl.h" |
| 39 | #include "rcmain.h" |
| 40 | |
| 41 | /* |
| 42 | * Library parser. This is a specialized version of the library parser |
| 43 | * that we use to expand library arguments into their corresponding source |
| 44 | * file lists. |
| 45 | */ |
| 46 | class CTcLibParserCmdline: public CTcLibParser |
| 47 | { |
| 48 | public: |
| 49 | /* |
| 50 | * Process a command-line argument that refers to a library. We'll |
| 51 | * read the library and add each file mentioned in the library to the |
| 52 | * source module list. |
| 53 | * |
| 54 | * Returns zero on success, non-zero if any errors occur. Fills in |
| 55 | * '*nodef' on return to indicate whether or not a "nodef" flag |
| 56 | * appeared in the library. |
| 57 | */ |
| 58 | static int process_lib_arg(CTcHostIfc *hostifc, CTcMake *mk, |
| 59 | CRcResList *res_list, |
| 60 | const char *lib_name, const char *lib_url, |
| 61 | int *nodef) |
| 62 | { |
| 63 | char path[OSFNMAX]; |
| 64 | char full_name[OSFNMAX]; |
| 65 | |
| 66 | /* add a default "tl" extension to the library name */ |
| 67 | strcpy(full_name, lib_name); |
| 68 | os_defext(full_name, "tl"); |
| 69 | |
| 70 | /* extract the path name from the library's name */ |
| 71 | os_get_path_name(path, sizeof(path), lib_name); |
| 72 | |
| 73 | /* |
| 74 | * add the directory containing the library to the include path, |
| 75 | * if it's not already there |
| 76 | */ |
| 77 | mk->maybe_add_include_path(path); |
| 78 | |
| 79 | /* set up our library parser object */ |
| 80 | CTcLibParserCmdline parser(hostifc, mk, res_list, full_name, lib_url); |
| 81 | |
| 82 | /* scan the library and add its files to the command line */ |
| 83 | parser.parse_lib(); |
| 84 | |
| 85 | /* set the 'nodef' indication for the caller */ |
| 86 | *nodef = parser.nodef_; |
| 87 | |
| 88 | /* if there are any errors, return non-zero */ |
| 89 | return parser.get_err_cnt(); |
| 90 | } |
| 91 | |
| 92 | protected: |
| 93 | /* instantiate */ |
| 94 | CTcLibParserCmdline(CTcHostIfc *hostifc, CTcMake *mk, |
| 95 | CRcResList *res_list, |
| 96 | const char *lib_name, const char *lib_url) |
| 97 | : CTcLibParser(lib_name) |
| 98 | { |
| 99 | /* remember our host interface */ |
| 100 | hostifc_ = hostifc; |
| 101 | |
| 102 | /* remember our 'make' control object */ |
| 103 | mk_ = mk; |
| 104 | |
| 105 | /* remember our resource list container */ |
| 106 | res_list_ = res_list; |
| 107 | |
| 108 | /* remember the URL to the library */ |
| 109 | lib_name_ = lib_copy_str(lib_name); |
| 110 | lib_url_ = lib_copy_str(lib_url); |
| 111 | |
| 112 | /* no "nodef" flag yet */ |
| 113 | nodef_ = FALSE; |
| 114 | } |
| 115 | |
| 116 | ~CTcLibParserCmdline() |
| 117 | { |
| 118 | /* delete the library name and URL strings */ |
| 119 | lib_free_str(lib_name_); |
| 120 | lib_free_str(lib_url_); |
| 121 | } |
| 122 | |
| 123 | /* process a source file entry in the library */ |
| 124 | void scan_full_source(const char *val, const char *fname) |
| 125 | { |
| 126 | char url[OSFNMAX*2 + 20]; |
| 127 | CTcMakeModule *mod; |
| 128 | |
| 129 | /* add the source module to our module list */ |
| 130 | mod = mk_->add_module(fname, 0, 0); |
| 131 | |
| 132 | /* |
| 133 | * build the full URL for the module - this is the library URL |
| 134 | * prefix plus the "source:" value (not the full filename - simply |
| 135 | * the original unretouched value of the "source:" variable) |
| 136 | */ |
| 137 | sprintf(url, "%.*s%.*s", (int)OSFNMAX, lib_url_, (int)OSFNMAX, val); |
| 138 | |
| 139 | /* set the module's URL */ |
| 140 | mod->set_url(url); |
| 141 | |
| 142 | /* set the module's original name and library name */ |
| 143 | mod->set_orig_name(val); |
| 144 | mod->set_from_lib(lib_name_, lib_url_); |
| 145 | } |
| 146 | |
| 147 | /* process a sub-library entry in the library */ |
| 148 | void scan_full_library(const char *val, const char *fname) |
| 149 | { |
| 150 | char url[OSFNMAX*2 + 20]; |
| 151 | int nodef; |
| 152 | |
| 153 | /* |
| 154 | * build the library URL prefix - this is the parent library URL |
| 155 | * prefix, plus our "library:" value (not the full filename - |
| 156 | * simply the original unretouched "library:" variable value), |
| 157 | * plus a slash |
| 158 | */ |
| 159 | sprintf(url, "%.*s%.*s/", (int)OSFNMAX, lib_url_, (int)OSFNMAX, val); |
| 160 | |
| 161 | /* parse the sub-library */ |
| 162 | if (process_lib_arg(hostifc_, mk_, res_list_, fname, url, &nodef)) |
| 163 | { |
| 164 | /* |
| 165 | * error parsing the sub-library - count it in our own error |
| 166 | * count, so we know the parsing failed |
| 167 | */ |
| 168 | ++err_cnt_; |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * if the sub-library had a 'nodef' flag, count it as a 'nodef' |
| 173 | * flag in this library |
| 174 | */ |
| 175 | if (nodef) |
| 176 | nodef_ = TRUE; |
| 177 | } |
| 178 | |
| 179 | /* process a resource entry in the library */ |
| 180 | void scan_full_resource(const char *val, const char *fname) |
| 181 | { |
| 182 | /* add the resource to the list */ |
| 183 | res_list_->add_file(fname, val, TRUE); |
| 184 | } |
| 185 | |
| 186 | /* display an error */ |
| 187 | void err_msg(const char *msg, ...) |
| 188 | { |
| 189 | va_list args; |
| 190 | |
| 191 | /* display the error */ |
| 192 | va_start(args, msg); |
| 193 | hostifc_->v_print_err(msg, args); |
| 194 | hostifc_->print_err("\n"); |
| 195 | va_end(args); |
| 196 | } |
| 197 | |
| 198 | /* look up a preprocessor symbol */ |
| 199 | int get_pp_symbol(char *dst, size_t dst_len, |
| 200 | const char *sym_name, size_t sym_len) |
| 201 | { |
| 202 | const char *val; |
| 203 | size_t val_len; |
| 204 | |
| 205 | /* ask the 'make' control object for the expansion */ |
| 206 | val = mk_->look_up_pp_sym(sym_name, sym_len); |
| 207 | |
| 208 | /* if we didn't find a value, return undefined */ |
| 209 | if (val == 0) |
| 210 | return -1; |
| 211 | |
| 212 | /* if it fits in the caller's result buffer, copy it */ |
| 213 | val_len = strlen(val); |
| 214 | if (val_len <= dst_len) |
| 215 | memcpy(dst, val, val_len); |
| 216 | |
| 217 | /* return the value length */ |
| 218 | return val_len; |
| 219 | } |
| 220 | |
| 221 | /* scan a "nodef" flag */ |
| 222 | void scan_nodef() { nodef_ = TRUE; } |
| 223 | |
| 224 | /* our 'make' control object */ |
| 225 | CTcMake *mk_; |
| 226 | |
| 227 | /* our resource list container */ |
| 228 | CRcResList *res_list_; |
| 229 | |
| 230 | /* host system interface */ |
| 231 | CTcHostIfc *hostifc_; |
| 232 | |
| 233 | /* the library name */ |
| 234 | char *lib_name_; |
| 235 | |
| 236 | /* |
| 237 | * the library URL - this is the common prefix for the URL of every |
| 238 | * member of the library |
| 239 | */ |
| 240 | char *lib_url_; |
| 241 | |
| 242 | /* flag: we've seen a "nodef" flag */ |
| 243 | int nodef_; |
| 244 | }; |
| 245 | |
| 246 | |
| 247 | /* ------------------------------------------------------------------------ */ |
| 248 | /* |
| 249 | * Helper object for CTcCommandUtil::parse_opt_file |
| 250 | */ |
| 251 | class CMainOptHelper: public CTcOptFileHelper |
| 252 | { |
| 253 | public: |
| 254 | /* allocate an option string */ |
| 255 | char *alloc_opt_file_str(size_t len) { return lib_alloc_str(len); } |
| 256 | |
| 257 | /* free an option string previously allocated */ |
| 258 | void free_opt_file_str(char *str) { lib_free_str(str); } |
| 259 | |
| 260 | /* process a comment (we ignore comments) */ |
| 261 | void process_comment_line(const char *) { } |
| 262 | |
| 263 | /* process a non-comment line (ignore it) */ |
| 264 | void process_non_comment_line(const char *) { } |
| 265 | |
| 266 | /* process a configuration section line (ignore it) */ |
| 267 | void process_config_line(const char *, const char *, int) { } |
| 268 | }; |
| 269 | |
| 270 | /* ------------------------------------------------------------------------ */ |
| 271 | /* |
| 272 | * Make a file path relative to the option file path, if we indeed have an |
| 273 | * option file path. 'buf' is a buffer the caller provides where we can |
| 274 | * build the full path, if necessary. We'll return a pointer either to the |
| 275 | * buffer containing the combined path, or to the original filename if we |
| 276 | * decided not to use the relative path. |
| 277 | */ |
| 278 | static char *make_opt_file_relative(char *buf, size_t buflen, |
| 279 | int read_opt_file, |
| 280 | const char *opt_file_path, |
| 281 | char *fname) |
| 282 | { |
| 283 | /* |
| 284 | * if we haven't read an option file, we don't have an option file path |
| 285 | * to use as the relative root, so use the original filename unchanged |
| 286 | */ |
| 287 | if (!read_opt_file) |
| 288 | return fname; |
| 289 | |
| 290 | /* convert the name to local conventions */ |
| 291 | char lcl[OSFNMAX]; |
| 292 | os_cvt_url_dir(buf, buflen < sizeof(lcl) ? buflen : sizeof(lcl), fname); |
| 293 | |
| 294 | /* if the filename is absolute, use it as given */ |
| 295 | if (os_is_file_absolute(buf)) |
| 296 | return buf; |
| 297 | |
| 298 | /* |
| 299 | * we have a relative filename and an option file, so build the given |
| 300 | * name relative to the option file path, using the version that we |
| 301 | * converted to local conventions |
| 302 | */ |
| 303 | lib_strcpy(lcl, sizeof(lcl), buf); |
| 304 | os_build_full_path(buf, buflen, opt_file_path, lcl); |
| 305 | |
| 306 | /* return the caller's buffer where we built the full path */ |
| 307 | return buf; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | |
| 312 | /* ------------------------------------------------------------------------ */ |
| 313 | /* |
| 314 | * Program main entrypoint |
| 315 | */ |
| 316 | int main(int argc, char **argv) |
| 317 | { |
| 318 | CTcHostIfcStdio *hostifc = new CTcHostIfcStdio(); |
| 319 | int curarg; |
| 320 | char *p; |
| 321 | int force_build = FALSE; |
| 322 | int force_link = FALSE; |
| 323 | CTcMake *mk; |
| 324 | int err_cnt, warn_cnt; |
| 325 | int image_specified = FALSE; |
| 326 | char dirbuf[OSFNMAX + 4096]; |
| 327 | int show_banner; |
| 328 | const char *opt_file = 0; |
| 329 | char opt_file_path[OSFNMAX]; |
| 330 | int read_opt_file = FALSE; |
| 331 | int usage_err = FALSE; |
| 332 | int add_def_mod = TRUE; |
| 333 | int compile_only = FALSE; |
| 334 | int pp_only = FALSE; |
| 335 | osfildef *string_fp = 0; |
| 336 | osfildef *assembly_fp = 0; |
| 337 | int sym_dir_set = FALSE; |
| 338 | int obj_dir_set = FALSE; |
| 339 | int lib_err = FALSE; |
| 340 | CMainOptHelper opt_helper; |
| 341 | int opt_file_path_warning = FALSE; |
| 342 | int need_opt_file_path_warning; |
| 343 | const size_t SUPPRESS_LIST_MAX = 100; |
| 344 | int suppress_list[SUPPRESS_LIST_MAX]; |
| 345 | size_t suppress_cnt; |
| 346 | CTcMakePath *sys_inc_entry; |
| 347 | CTcMakePath *sys_lib_entry; |
| 348 | int verbose = FALSE; |
| 349 | int pedantic = FALSE; |
| 350 | int res_recurse = TRUE; |
| 351 | CRcResList *res_list; |
| 352 | int warnings_as_errors = FALSE; |
| 353 | |
| 354 | /* we don't have any warning codes to suppress yet */ |
| 355 | suppress_cnt = 0; |
| 356 | |
| 357 | /* no errors or warnings yet */ |
| 358 | err_cnt = warn_cnt = 0; |
| 359 | |
| 360 | /* create a resource list, in case we have resource options */ |
| 361 | res_list = new CRcResList(); |
| 362 | |
| 363 | /* initialize the error subsystem */ |
| 364 | { |
| 365 | CResLoader *res_loader; |
| 366 | char buf[OSFNMAX]; |
| 367 | |
| 368 | /* create a resource loader */ |
| 369 | os_get_special_path(buf, sizeof(buf), argv[0], OS_GSP_T3_RES); |
| 370 | res_loader = new CResLoader(buf); |
| 371 | |
| 372 | /* tell the resource loader the executable filename, if possible */ |
| 373 | if (os_get_exe_filename(buf, sizeof(buf), argv[0])) |
| 374 | res_loader->set_exe_filename(buf); |
| 375 | |
| 376 | /* initialize the error subsystem */ |
| 377 | CTcMain::tc_err_init(1024, res_loader); |
| 378 | |
| 379 | /* done with the resource loader */ |
| 380 | delete res_loader; |
| 381 | } |
| 382 | |
| 383 | /* create the 'make' object */ |
| 384 | mk = new CTcMake(); |
| 385 | |
| 386 | /* presume we'll show the banner and progress messages */ |
| 387 | show_banner = TRUE; |
| 388 | |
| 389 | /* |
| 390 | * Add the default system header directory to the system include path. |
| 391 | * System include paths always follow any user-specified paths in the |
| 392 | * search order. |
| 393 | */ |
| 394 | os_get_special_path(dirbuf, sizeof(dirbuf), argv[0], OS_GSP_T3_INC); |
| 395 | sys_inc_entry = mk->add_sys_include_path(dirbuf); |
| 396 | |
| 397 | /* |
| 398 | * Add the user library search path list to the source search path. |
| 399 | * This list comes from platform-specific global configuration data |
| 400 | * (such as a environment variable on Unix), so we want it to come |
| 401 | * after any search list specified in the command-line options; ensure |
| 402 | * that we search these locations last by making them "system" paths, |
| 403 | * since system paths follow all command-line paths. |
| 404 | */ |
| 405 | os_get_special_path(dirbuf, sizeof(dirbuf), argv[0], OS_GSP_T3_USER_LIBS); |
| 406 | for (p = dirbuf ; *p != '\0' ; ) |
| 407 | { |
| 408 | char *start; |
| 409 | char *nxt; |
| 410 | |
| 411 | /* remember where this list element starts */ |
| 412 | start = p; |
| 413 | |
| 414 | /* find the next path separator character */ |
| 415 | for ( ; *p != '\0' && *p != OSPATHSEP ; ++p) ; |
| 416 | |
| 417 | /* if there's another path element, note its start */ |
| 418 | nxt = p; |
| 419 | if (*nxt == OSPATHSEP) |
| 420 | ++nxt; |
| 421 | |
| 422 | /* null-terminate the path at the separator */ |
| 423 | *p = '\0'; |
| 424 | |
| 425 | /* add this path */ |
| 426 | mk->add_sys_source_path(start); |
| 427 | |
| 428 | /* continue scanning at the next list element */ |
| 429 | p = nxt; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * Add the default system library directory to the source path. |
| 434 | * System source paths always follow user-specified paths in the |
| 435 | * search order. |
| 436 | */ |
| 437 | os_get_special_path(dirbuf, sizeof(dirbuf), argv[0], OS_GSP_T3_LIB); |
| 438 | sys_lib_entry = mk->add_sys_source_path(dirbuf); |
| 439 | |
| 440 | parse_options: |
| 441 | /* read the options */ |
| 442 | for (curarg = 1 ; curarg < argc && argv[curarg][0] == '-' ; ++curarg) |
| 443 | { |
| 444 | char subopt; |
| 445 | char relbuf[OSFNMAX]; |
| 446 | |
| 447 | /* |
| 448 | * if we have a "-source" or "-lib" argument, we're done with |
| 449 | * options, and we're on to the module list |
| 450 | */ |
| 451 | if (strcmp(argv[curarg], "-source") == 0 |
| 452 | || strcmp(argv[curarg], "-lib") == 0 |
| 453 | || strcmp(argv[curarg], "-res") == 0) |
| 454 | break; |
| 455 | |
| 456 | /* |
| 457 | * figure out which option we have, starting with the first letter |
| 458 | * after the '-' |
| 459 | */ |
| 460 | switch(argv[curarg][1]) |
| 461 | { |
| 462 | case 'f': |
| 463 | /* read an options file - make sure we don't have one already */ |
| 464 | if (opt_file != 0) |
| 465 | { |
| 466 | /* can't read a file from a file */ |
| 467 | printf("error: only one option file (-f) is allowed\n"); |
| 468 | err_cnt = 1; |
| 469 | goto done; |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | * remember the options file name - we'll get around to the |
| 474 | * actual reading of the file after we finish with the |
| 475 | * command line options |
| 476 | */ |
| 477 | opt_file = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 1); |
| 478 | if (opt_file == 0) |
| 479 | goto missing_option_arg; |
| 480 | break; |
| 481 | |
| 482 | case 'd': |
| 483 | /* set debug mode */ |
| 484 | mk->set_debug(TRUE); |
| 485 | break; |
| 486 | |
| 487 | case 'D': |
| 488 | /* add preprocessor symbol definition */ |
| 489 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 1); |
| 490 | if (p != 0) |
| 491 | { |
| 492 | char *eq; |
| 493 | |
| 494 | /* see if there's an '=' in the string */ |
| 495 | for (eq = p ; *eq != '\0' && *eq != '=' ; ++eq) ; |
| 496 | |
| 497 | /* if the '=' is present, replace it with a null byte */ |
| 498 | if (*eq == '=') |
| 499 | { |
| 500 | /* replace it */ |
| 501 | *eq = '\0'; |
| 502 | |
| 503 | /* skip to the start of the replacement text */ |
| 504 | ++eq; |
| 505 | } |
| 506 | |
| 507 | /* add the symbol definition */ |
| 508 | mk->def_pp_sym(p, eq); |
| 509 | } |
| 510 | else |
| 511 | goto missing_option_arg; |
| 512 | break; |
| 513 | |
| 514 | case 'e': |
| 515 | /* check for longer option names */ |
| 516 | if (strlen(argv[curarg]) >= 7 |
| 517 | && memcmp(argv[curarg], "-errnum", 7) == 0) |
| 518 | { |
| 519 | /* check for "+" or "-" suffixes */ |
| 520 | if (strcmp(argv[curarg] + 7, "+") == 0 |
| 521 | || argv[curarg][7] == '\0') |
| 522 | { |
| 523 | /* turn on error number display */ |
| 524 | mk->set_show_err_numbers(TRUE); |
| 525 | } |
| 526 | else if (strcmp(argv[curarg] + 7, "-") == 0) |
| 527 | { |
| 528 | /* turn off error number display */ |
| 529 | mk->set_show_err_numbers(FALSE); |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | /* invalid option */ |
| 534 | goto bad_option; |
| 535 | } |
| 536 | } |
| 537 | else |
| 538 | { |
| 539 | /* invalid option */ |
| 540 | goto bad_option; |
| 541 | } |
| 542 | break; |
| 543 | |
| 544 | case 'U': |
| 545 | /* add preprocess symbol un-definition */ |
| 546 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 1); |
| 547 | if (p != 0) |
| 548 | mk->undef_pp_sym(p); |
| 549 | else |
| 550 | goto missing_option_arg; |
| 551 | break; |
| 552 | |
| 553 | case 'c': |
| 554 | /* see what follows */ |
| 555 | switch (argv[curarg][2]) |
| 556 | { |
| 557 | case 's': |
| 558 | /* it's a character set specification */ |
| 559 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 2); |
| 560 | if (p != 0) |
| 561 | mk->set_source_charset(p); |
| 562 | else |
| 563 | goto missing_option_arg; |
| 564 | break; |
| 565 | |
| 566 | case 'l': |
| 567 | /* check for "-clean" */ |
| 568 | if (strcmp(argv[curarg], "-clean") == 0) |
| 569 | { |
| 570 | /* set "clean" mode */ |
| 571 | mk->set_clean_mode(TRUE); |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | /* invalid option */ |
| 576 | goto bad_option; |
| 577 | } |
| 578 | break; |
| 579 | |
| 580 | case '\0': |
| 581 | /* set compile-only (no link) mode */ |
| 582 | mk->set_do_link(FALSE); |
| 583 | compile_only = TRUE; |
| 584 | break; |
| 585 | |
| 586 | default: |
| 587 | /* invalid option */ |
| 588 | goto bad_option; |
| 589 | } |
| 590 | break; |
| 591 | |
| 592 | case 'a': |
| 593 | /* see what follows */ |
| 594 | switch(argv[curarg][2]) |
| 595 | { |
| 596 | case 'l': |
| 597 | /* force only the link phase */ |
| 598 | force_link = TRUE; |
| 599 | break; |
| 600 | |
| 601 | case '\0': |
| 602 | force_build = TRUE; |
| 603 | break; |
| 604 | |
| 605 | default: |
| 606 | /* invalid option */ |
| 607 | goto bad_option; |
| 608 | } |
| 609 | break; |
| 610 | |
| 611 | case 'v': |
| 612 | /* set verbose mode */ |
| 613 | mk->set_verbose(TRUE); |
| 614 | verbose = TRUE; |
| 615 | break; |
| 616 | |
| 617 | case 'I': |
| 618 | /* add a #include path */ |
| 619 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 1); |
| 620 | if (p != 0) |
| 621 | { |
| 622 | /* make it relative to the option file path if appropriate */ |
| 623 | p = make_opt_file_relative(relbuf, sizeof(relbuf), |
| 624 | read_opt_file, opt_file_path, p); |
| 625 | |
| 626 | /* add the path */ |
| 627 | mk->add_include_path(p); |
| 628 | } |
| 629 | else |
| 630 | goto missing_option_arg; |
| 631 | break; |
| 632 | |
| 633 | case 'o': |
| 634 | /* set the image file name */ |
| 635 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 1); |
| 636 | if (p != 0) |
| 637 | { |
| 638 | /* make it relative to the option file path if appropriate */ |
| 639 | p = make_opt_file_relative(relbuf, sizeof(relbuf), |
| 640 | read_opt_file, opt_file_path, p); |
| 641 | |
| 642 | /* set the image file name */ |
| 643 | mk->set_image_file(p); |
| 644 | |
| 645 | /* note that we have an explicit image file name */ |
| 646 | image_specified = TRUE; |
| 647 | } |
| 648 | else |
| 649 | goto missing_option_arg; |
| 650 | break; |
| 651 | |
| 652 | case 'O': |
| 653 | switch(argv[curarg][2]) |
| 654 | { |
| 655 | case 's': |
| 656 | /* |
| 657 | * if we already have a string capture file, close the |
| 658 | * old one |
| 659 | */ |
| 660 | if (string_fp != 0) |
| 661 | { |
| 662 | osfcls(string_fp); |
| 663 | string_fp = 0; |
| 664 | } |
| 665 | |
| 666 | /* set the string file */ |
| 667 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 2); |
| 668 | if (p == 0) |
| 669 | goto missing_option_arg; |
| 670 | |
| 671 | /* make it relative to the option file path if appropriate */ |
| 672 | p = make_opt_file_relative(relbuf, sizeof(relbuf), |
| 673 | read_opt_file, opt_file_path, p); |
| 674 | |
| 675 | /* open the string file */ |
| 676 | string_fp = osfopwt(p, OSFTTEXT); |
| 677 | if (string_fp == 0) |
| 678 | { |
| 679 | printf("error: unable to create string capture file " |
| 680 | "\"%s\"\n", p); |
| 681 | goto done; |
| 682 | } |
| 683 | |
| 684 | /* set the string capture file in the build object */ |
| 685 | mk->set_string_capture(string_fp); |
| 686 | |
| 687 | /* done */ |
| 688 | break; |
| 689 | |
| 690 | default: |
| 691 | /* invalid suboption */ |
| 692 | goto bad_option; |
| 693 | } |
| 694 | break; |
| 695 | |
| 696 | case 'F': |
| 697 | /* presume we won't need an option file path warning */ |
| 698 | need_opt_file_path_warning = FALSE; |
| 699 | |
| 700 | /* note the sub-option letter */ |
| 701 | subopt = argv[curarg][2]; |
| 702 | |
| 703 | /* |
| 704 | * If applicable, get the filename/path argument. Most of the |
| 705 | * -F suboptions take an argument, but some don't, so check for |
| 706 | * the ones that don't. |
| 707 | */ |
| 708 | p = 0; |
| 709 | if (strchr("C", subopt) == 0) |
| 710 | { |
| 711 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 2); |
| 712 | if (p == 0) |
| 713 | goto missing_option_arg; |
| 714 | |
| 715 | /* make it relative to the option file path */ |
| 716 | p = make_opt_file_relative(relbuf, sizeof(relbuf), |
| 717 | read_opt_file, opt_file_path, p); |
| 718 | |
| 719 | /* |
| 720 | * if this is an absolute path, note it so we can warn |
| 721 | * about it if this is in an option file |
| 722 | */ |
| 723 | need_opt_file_path_warning = os_is_file_absolute(p); |
| 724 | } |
| 725 | |
| 726 | /* check the suboption */ |
| 727 | switch(subopt) |
| 728 | { |
| 729 | case 'L': |
| 730 | /* override the system library path */ |
| 731 | sys_lib_entry->set_path(p); |
| 732 | break; |
| 733 | |
| 734 | case 'I': |
| 735 | /* override the system include path */ |
| 736 | sys_inc_entry->set_path(p); |
| 737 | break; |
| 738 | |
| 739 | case 's': |
| 740 | /* add the source path */ |
| 741 | mk->add_source_path(p); |
| 742 | break; |
| 743 | |
| 744 | case 'y': |
| 745 | /* set the symbol path */ |
| 746 | mk->set_symbol_dir(p); |
| 747 | |
| 748 | /* remember that we have a symbol directory */ |
| 749 | sym_dir_set = TRUE; |
| 750 | break; |
| 751 | |
| 752 | case 'o': |
| 753 | /* set the object file directory */ |
| 754 | mk->set_object_dir(p); |
| 755 | |
| 756 | /* remember that we've set this path */ |
| 757 | obj_dir_set = TRUE; |
| 758 | break; |
| 759 | |
| 760 | case 'C': |
| 761 | /* set the "create output directories" flag */ |
| 762 | mk->set_create_dirs(TRUE); |
| 763 | break; |
| 764 | |
| 765 | case 'a': |
| 766 | /* |
| 767 | * Set the assembly listing file. Note that this is an |
| 768 | * undocumented option - at the moment, the assembly |
| 769 | * listing is a bit rough, and is meant for internal TADS 3 |
| 770 | * development use, to facilitate analysis of the |
| 771 | * compiler's code generation. |
| 772 | */ |
| 773 | |
| 774 | /* close any previous assembly listing file */ |
| 775 | if (assembly_fp != 0) |
| 776 | { |
| 777 | osfcls(assembly_fp); |
| 778 | assembly_fp = 0; |
| 779 | } |
| 780 | |
| 781 | /* open the listing file */ |
| 782 | assembly_fp = osfopwt(p, OSFTTEXT); |
| 783 | if (assembly_fp == 0) |
| 784 | { |
| 785 | printf("error: unable to create assembly listing file " |
| 786 | "\"%s\"\n", p); |
| 787 | goto done; |
| 788 | } |
| 789 | |
| 790 | /* set the listing file */ |
| 791 | mk->set_assembly_listing(assembly_fp); |
| 792 | |
| 793 | /* done */ |
| 794 | break; |
| 795 | |
| 796 | default: |
| 797 | /* invalid option */ |
| 798 | goto bad_option; |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * if we're reading from a command file, and we haven't already |
| 803 | * found reason to warn about absolute paths, note that we need |
| 804 | * to warn now |
| 805 | */ |
| 806 | if (read_opt_file |
| 807 | && need_opt_file_path_warning) |
| 808 | opt_file_path_warning = TRUE; |
| 809 | |
| 810 | /* done */ |
| 811 | break; |
| 812 | |
| 813 | case 'G': |
| 814 | /* code generation options */ |
| 815 | if (strcmp(argv[curarg], "-Gstg") == 0) |
| 816 | { |
| 817 | /* turn on sourceTextGroup mode */ |
| 818 | mk->set_source_text_group_mode(TRUE); |
| 819 | } |
| 820 | else |
| 821 | goto bad_option; |
| 822 | break; |
| 823 | |
| 824 | case 'n': |
| 825 | /* check what we have */ |
| 826 | if (strcmp(argv[curarg], "-nopre") == 0) |
| 827 | { |
| 828 | /* explicitly turn off preinit mode */ |
| 829 | mk->set_preinit(FALSE); |
| 830 | } |
| 831 | else if (strcmp(argv[curarg], "-nobanner") == 0) |
| 832 | { |
| 833 | /* turn off the banner */ |
| 834 | show_banner = FALSE; |
| 835 | } |
| 836 | else if (strcmp(argv[curarg], "-nodef") == 0) |
| 837 | { |
| 838 | /* don't add the default modules */ |
| 839 | add_def_mod = FALSE; |
| 840 | } |
| 841 | else |
| 842 | goto bad_option; |
| 843 | break; |
| 844 | |
| 845 | case 'p': |
| 846 | /* check what we have */ |
| 847 | if (strcmp(argv[curarg], "-pre") == 0) |
| 848 | { |
| 849 | /* explicitly turn on preinit mode */ |
| 850 | mk->set_preinit(TRUE); |
| 851 | } |
| 852 | else |
| 853 | goto bad_option; |
| 854 | break; |
| 855 | |
| 856 | case 'P': |
| 857 | /* |
| 858 | * A preprocess-only mode. The plain -P generates |
| 859 | * preprocessed source to standard output; -Pi generates only |
| 860 | * a list of names of #included files to standard output. |
| 861 | */ |
| 862 | if (strcmp(argv[curarg], "-P") == 0) |
| 863 | { |
| 864 | /* set preprocess-only mode */ |
| 865 | mk->set_pp_only(TRUE); |
| 866 | pp_only = TRUE; |
| 867 | } |
| 868 | else if (strcmp(argv[curarg], "-Pi") == 0) |
| 869 | { |
| 870 | /* set list-includes mode */ |
| 871 | mk->set_list_includes(TRUE); |
| 872 | pp_only = TRUE; |
| 873 | } |
| 874 | break; |
| 875 | |
| 876 | case 'q': |
| 877 | /* check the full option name */ |
| 878 | if (strcmp(argv[curarg], "-quotefname") == 0) |
| 879 | { |
| 880 | /* they want quoted filenames in error messages */ |
| 881 | mk->set_err_quoted_fnames(TRUE); |
| 882 | } |
| 883 | else if (strcmp(argv[curarg], "-q") == 0) |
| 884 | { |
| 885 | /* quiet mode - turn off banner and progress messages */ |
| 886 | show_banner = FALSE; |
| 887 | hostifc->set_show_progress(FALSE); |
| 888 | } |
| 889 | else |
| 890 | goto bad_option; |
| 891 | break; |
| 892 | |
| 893 | case 's': |
| 894 | /* check the full option name */ |
| 895 | if (strcmp(argv[curarg], "-statprefix") == 0) |
| 896 | { |
| 897 | /* get the argument */ |
| 898 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 10); |
| 899 | |
| 900 | /* set the status message prefix text */ |
| 901 | if (p != 0) |
| 902 | hostifc->set_status_prefix(p); |
| 903 | else |
| 904 | goto missing_option_arg; |
| 905 | } |
| 906 | else if (strcmp(argv[curarg], "-statpct") == 0) |
| 907 | { |
| 908 | /* note that we want status percentage updates */ |
| 909 | mk->set_status_pct_mode(TRUE); |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | /* unknown option - report usage error */ |
| 914 | goto bad_option; |
| 915 | } |
| 916 | break; |
| 917 | |
| 918 | case 't': |
| 919 | /* check the full option name */ |
| 920 | if (strcmp(argv[curarg], "-test") == 0) |
| 921 | { |
| 922 | /* |
| 923 | * it's the secret test-mode option - the test scripts use |
| 924 | * this to set the reporting mode so that we suppress path |
| 925 | * names in progress reports, so that the test logs can be |
| 926 | * insensitive to local path name conventions |
| 927 | */ |
| 928 | mk->set_test_report_mode(TRUE); |
| 929 | |
| 930 | /* perform any necessary test initialization */ |
| 931 | test_init(); |
| 932 | } |
| 933 | else |
| 934 | { |
| 935 | /* unknown option - report usage error */ |
| 936 | goto bad_option; |
| 937 | } |
| 938 | break; |
| 939 | |
| 940 | case 'w': |
| 941 | /* warning level/mode - see what level they're setting */ |
| 942 | switch(argv[curarg][2]) |
| 943 | { |
| 944 | int num; |
| 945 | int enable; |
| 946 | |
| 947 | case '0': |
| 948 | /* no warnings */ |
| 949 | mk->set_warnings(FALSE); |
| 950 | mk->set_pedantic(FALSE); |
| 951 | break; |
| 952 | |
| 953 | case '1': |
| 954 | /* normal warnings, but not pedantic warnings */ |
| 955 | mk->set_warnings(TRUE); |
| 956 | mk->set_pedantic(FALSE); |
| 957 | break; |
| 958 | |
| 959 | case '2': |
| 960 | /* show all warnings, even pedantic ones */ |
| 961 | mk->set_warnings(TRUE); |
| 962 | mk->set_pedantic(TRUE); |
| 963 | pedantic = TRUE; |
| 964 | break; |
| 965 | |
| 966 | case '+': |
| 967 | case '-': |
| 968 | /* |
| 969 | * Add/remove a warning to/from the list of warnings to |
| 970 | * suppress. First, note whether we're enabling or |
| 971 | * disabling the warning. |
| 972 | */ |
| 973 | enable = (argv[curarg][2] == '+'); |
| 974 | |
| 975 | /* get the warning number */ |
| 976 | p = CTcCommandUtil::get_opt_arg(argc, argv, &curarg, 2); |
| 977 | if (p == 0) |
| 978 | goto missing_option_arg; |
| 979 | |
| 980 | /* convert it to a number */ |
| 981 | num = atoi(p); |
| 982 | |
| 983 | /* |
| 984 | * add it to the list if we're disabling it, otherwise |
| 985 | * remove it from the list (since every warning is enabled |
| 986 | * by default) |
| 987 | */ |
| 988 | if (!enable) |
| 989 | { |
| 990 | /* if we don't have room, we can't add it */ |
| 991 | if (suppress_cnt >= SUPPRESS_LIST_MAX) |
| 992 | { |
| 993 | /* tell them what's wrong */ |
| 994 | printf("Too many -w-# options - maximum %d.\n", |
| 995 | (int)SUPPRESS_LIST_MAX); |
| 996 | |
| 997 | /* abort */ |
| 998 | goto done; |
| 999 | } |
| 1000 | |
| 1001 | /* add the new list entry */ |
| 1002 | suppress_list[suppress_cnt++] = num; |
| 1003 | } |
| 1004 | else |
| 1005 | { |
| 1006 | size_t rem; |
| 1007 | int *src; |
| 1008 | int *dst; |
| 1009 | |
| 1010 | /* |
| 1011 | * scan the list for an existing instance of this |
| 1012 | * number, and remove any we find |
| 1013 | */ |
| 1014 | for (rem = suppress_cnt, src = dst = suppress_list ; |
| 1015 | rem != 0 ; ++src, --rem) |
| 1016 | { |
| 1017 | /* if this one isn't to be suppressed, keep it */ |
| 1018 | if (*src != num) |
| 1019 | *dst++ = *src; |
| 1020 | } |
| 1021 | |
| 1022 | /* calculate the new count */ |
| 1023 | suppress_cnt = dst - suppress_list; |
| 1024 | } |
| 1025 | |
| 1026 | /* remember the updated list */ |
| 1027 | mk->set_suppress_list(suppress_list, suppress_cnt); |
| 1028 | |
| 1029 | /* done */ |
| 1030 | break; |
| 1031 | |
| 1032 | case 'e': |
| 1033 | /* turn "warnings as errors" mode on or off */ |
| 1034 | switch (argv[curarg][3]) |
| 1035 | { |
| 1036 | case '\0': |
| 1037 | case '+': |
| 1038 | warnings_as_errors = TRUE; |
| 1039 | mk->set_warnings_as_errors(TRUE); |
| 1040 | break; |
| 1041 | |
| 1042 | case '-': |
| 1043 | warnings_as_errors = FALSE; |
| 1044 | mk->set_warnings_as_errors(FALSE); |
| 1045 | break; |
| 1046 | |
| 1047 | default: |
| 1048 | goto bad_option; |
| 1049 | } |
| 1050 | break; |
| 1051 | |
| 1052 | default: |
| 1053 | /* invalid option */ |
| 1054 | goto bad_option; |
| 1055 | } |
| 1056 | break; |
| 1057 | |
| 1058 | case '?': |
| 1059 | /* take '?' as an explicit request to show the usage message */ |
| 1060 | goto show_usage; |
| 1061 | |
| 1062 | case 'h': |
| 1063 | /* check for "-help" */ |
| 1064 | if (strcmp(argv[curarg], "-help") == 0) |
| 1065 | goto show_usage; |
| 1066 | |
| 1067 | /* other '-h*' options are unrecognized */ |
| 1068 | goto bad_option; |
| 1069 | |
| 1070 | default: |
| 1071 | bad_option: |
| 1072 | /* invalid - describe the problem */ |
| 1073 | printf("Error: Invalid option: \"%s\"\n" |
| 1074 | "(Type \"t3make -help\" for a summary of the " |
| 1075 | "command syntax)\n", argv[curarg]); |
| 1076 | |
| 1077 | /* abort */ |
| 1078 | goto done; |
| 1079 | |
| 1080 | missing_option_arg: |
| 1081 | /* missing option argument */ |
| 1082 | printf("Error: Missing argument for option \"%s\"\n" |
| 1083 | "(Type \"t3make -help\" for a summary of the " |
| 1084 | "command syntax)\n", argv[curarg]); |
| 1085 | |
| 1086 | /* abort */ |
| 1087 | goto done; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | /* |
| 1092 | * if there are no module arguments, and no project file was |
| 1093 | * specified, look for a default project file |
| 1094 | */ |
| 1095 | if (curarg >= argc && !usage_err && opt_file == 0) |
| 1096 | { |
| 1097 | /* |
| 1098 | * if the default project file exists, try reading it; otherwise, |
| 1099 | * show a usage error |
| 1100 | */ |
| 1101 | if (!osfacc(T3_DEFAULT_PROJ_FILE)) |
| 1102 | opt_file = T3_DEFAULT_PROJ_FILE; |
| 1103 | else |
| 1104 | { |
| 1105 | /* |
| 1106 | * if there are no arguments at all, just show the usage |
| 1107 | * message; otherwise, explain that we need some source files |
| 1108 | */ |
| 1109 | if (argc == 1) |
| 1110 | { |
| 1111 | /* just fall through to the usage message */ |
| 1112 | usage_err = TRUE; |
| 1113 | } |
| 1114 | else |
| 1115 | { |
| 1116 | /* explain that we need source files */ |
| 1117 | printf("Error: No source file(s) specified.\n" |
| 1118 | "(Type \"t3make -help\" for help with the " |
| 1119 | "command syntax.\n"); |
| 1120 | goto done; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | /* |
| 1126 | * Show the banner, unless they explicitly asked us not to (and even |
| 1127 | * then, show it anyway if we're going to show the "usage" message). |
| 1128 | */ |
| 1129 | if ((show_banner || usage_err) && (opt_file == 0 || read_opt_file)) |
| 1130 | { |
| 1131 | char patch_id[10]; |
| 1132 | |
| 1133 | /* |
| 1134 | * Generate the patch number or development build iteration number, |
| 1135 | * if appropriate. If there's a patch number, give it precedence, |
| 1136 | * appending it as an extra dot-number suffix; if there's a build |
| 1137 | * number, show it as an alphabetic suffix. If neither is defined, |
| 1138 | * add nothing, so we'll just have a three-part dotted version |
| 1139 | * number. |
| 1140 | */ |
| 1141 | if (TC_VSN_PATCH != 0) |
| 1142 | sprintf(patch_id, ".%d", TC_VSN_PATCH); |
| 1143 | else if (TC_VSN_DEVBUILD != 0) |
| 1144 | sprintf(patch_id, "%c", TC_VSN_DEVBUILD + 'a' - 1); |
| 1145 | else |
| 1146 | patch_id[0] = '\0'; |
| 1147 | |
| 1148 | /* show the banner */ |
| 1149 | /* copyright-date-string */ |
| 1150 | printf("TADS Compiler %d.%d.%d%s " |
| 1151 | "Copyright 1999, 2012 Michael J. Roberts\n", |
| 1152 | TC_VSN_MAJOR, TC_VSN_MINOR, TC_VSN_REV, patch_id); |
| 1153 | } |
| 1154 | |
| 1155 | /* |
| 1156 | * warn about absolute paths in the options file, if necessary; do this |
| 1157 | * only in pedantic mode, though, since it's only a usage suggestion |
| 1158 | */ |
| 1159 | if (opt_file_path_warning && pedantic) |
| 1160 | { |
| 1161 | /* show the warning */ |
| 1162 | printf("Warning: absolute path found in -Fs/-Fo/-Fy option " |
| 1163 | "in options (-f) file.\n"); |
| 1164 | |
| 1165 | /* add more explanation if in verbose mode */ |
| 1166 | if (verbose) |
| 1167 | printf("It's better not to use absolute paths in the " |
| 1168 | "options file, because this\n" |
| 1169 | "ties the options file to the particular " |
| 1170 | "directory layout of your machine.\n" |
| 1171 | "If possible, refer only to subfolders of the " |
| 1172 | "folder containing the options\n" |
| 1173 | "file, and refer to the subfolders using " |
| 1174 | "relative path notation.\n"); |
| 1175 | } |
| 1176 | |
| 1177 | /* if a usage error occurred, display the usage message */ |
| 1178 | if (usage_err) |
| 1179 | { |
| 1180 | show_usage: |
| 1181 | printf("usage: t3make [options] module ... [-res resources]\n" |
| 1182 | "Options:\n" |
| 1183 | " -a - rebuild all files, " |
| 1184 | "even if up to date\n" |
| 1185 | " -al - relink, even if image file is up to date\n" |
| 1186 | " -c - compile only (do not create image file)\n" |
| 1187 | " -clean - delete all derived (symbol, object, image) " |
| 1188 | "files\n" |
| 1189 | " -cs xxx - source file character set is 'xxx'\n" |
| 1190 | " -d - compile for debugging (include symbols)\n" |
| 1191 | " -D x=y - define preprocessor symbol 'x' with value 'y'\n" |
| 1192 | " -errnum - show numeric error codes with error messages\n" |
| 1193 | " -f file - read command line options from 'file'\n" |
| 1194 | " -I dir - add 'dir' to #include search path\n" |
| 1195 | " -FC - create output directories (for -Fy, -Fo) if they " |
| 1196 | "don't exist\n" |
| 1197 | " -Fs dir - add 'dir' to source file search path\n" |
| 1198 | " -Fy dir - put symbol files in directory 'dir'\n" |
| 1199 | " -Fo dir - put object files in directory 'dir'\n" |
| 1200 | " -FI dir - override the standard system include path\n" |
| 1201 | " -FL dir - override the standard system library path\n" |
| 1202 | " -Gstg - generate sourceTextGroup properties\n" |
| 1203 | " -nobanner - suppress version/copyright banner\n" |
| 1204 | " -nodef - do not include default library modules in build\n" |
| 1205 | " -nopre - do not run pre-initialization, regardless of " |
| 1206 | "debug mode\n" |
| 1207 | " -o img - set image file name to 'img'\n" |
| 1208 | " -Os str - write all strings found in compiled files to " |
| 1209 | "text file 'str'\n" |
| 1210 | " -P - preprocess only; write preprocessed source " |
| 1211 | "to console\n" |
| 1212 | " -Pi - preprocess only; write only list of #include " |
| 1213 | "files to console\n" |
| 1214 | " -pre - run pre-initialization, regardless of " |
| 1215 | "debug mode\n" |
| 1216 | " -q - quiet mode: suppress banner and " |
| 1217 | "progress reports\n" |
| 1218 | " -quotefname - quote filenames in error messages\n" |
| 1219 | " -statprefix txt - set status-message prefix text\n" |
| 1220 | " -U x - un-define preprocessor symbol 'x'\n" |
| 1221 | " -v - display verbose error messages\n" |
| 1222 | " -w# - warning level: 0=none, 1=standard " |
| 1223 | "(default), 2=pedantic\n" |
| 1224 | " -w-# - suppress the given warning number\n" |
| 1225 | " -w+# - enable the given warning number\n" |
| 1226 | " -we - treat warnings as errors (-we- to disable)\n" |
| 1227 | "\n" |
| 1228 | "Modules: Each entry in the module list can have one " |
| 1229 | "of these forms:\n" |
| 1230 | "\n" |
| 1231 | " filename - specify the name of a source or " |
| 1232 | "library file; the\n" |
| 1233 | " file's type is inferred from its " |
| 1234 | "filename suffix\n" |
| 1235 | " -source filename - specify the name of a source file\n" |
| 1236 | " -lib filename - specify the name of a library\n" |
| 1237 | "\n" |
| 1238 | "The default filename suffix for a source file is \".t\", " |
| 1239 | "and the default for a\n" |
| 1240 | "library is \".tl\". You can omit the \"-source\" or " |
| 1241 | "\"-lib\" specifier for any\n" |
| 1242 | "file if its name includes the correct default suffix for " |
| 1243 | "its type, and its\n" |
| 1244 | "name doesn't begin with a \"-\".\n" |
| 1245 | "Immediately following each library, you can add one or more " |
| 1246 | "\"-x filename\"\n" |
| 1247 | "options to exclude library members. Each \"-x\" excludes " |
| 1248 | "one library member.\n" |
| 1249 | "The filename specified in a \"-x\" option must exactly " |
| 1250 | "match the filename as it\n" |
| 1251 | "appears in the library \"source:\" line.\n" |
| 1252 | "\n" |
| 1253 | "If no modules are specified, the compiler will attempt to " |
| 1254 | "find '" T3_DEFAULT_PROJ_FILE "'\n" |
| 1255 | "in the current directory, and will read it to obtain build " |
| 1256 | "instructions.\n" |
| 1257 | "\n" |
| 1258 | "Resources: Multi-media resources can be bundled into the " |
| 1259 | "image file using the\n" |
| 1260 | "-res option. After the -res option, specify any desired " |
| 1261 | "resource options:\n" |
| 1262 | "\n" |
| 1263 | " -recurse - recurse into subdirectories for subsequent " |
| 1264 | "items (default)\n" |
| 1265 | " -norecurse - do not recurse into subdirectories for " |
| 1266 | "subsequent items\n" |
| 1267 | " file - add 'file' as a multimedia resource\n" |
| 1268 | " file=alias - add 'file', using 'alias' as the resource " |
| 1269 | "name\n" |
| 1270 | " dir - add all files within directory 'dir' (and all " |
| 1271 | "files in all\n" |
| 1272 | " subdirectories of 'dir', if -recurse option " |
| 1273 | "is in effect)\n" |
| 1274 | "\n" |
| 1275 | "When a file is specified without an '=alias' name, the " |
| 1276 | "stored resource name is\n" |
| 1277 | "the original filename converted to URL-style notation. If " |
| 1278 | "an '=alias' name is\n" |
| 1279 | "specified, then the stored resource will be named with the " |
| 1280 | "alias name.\n" |
| 1281 | "\n" |
| 1282 | "Note that resource options are ignored when compiling " |
| 1283 | "for debugging.\n"); |
| 1284 | |
| 1285 | /* terminate */ |
| 1286 | goto done; |
| 1287 | } |
| 1288 | |
| 1289 | /* add the modules */ |
| 1290 | for ( ; curarg < argc ; ++curarg) |
| 1291 | { |
| 1292 | int is_source; |
| 1293 | int is_lib; |
| 1294 | char relbuf[OSFNMAX]; |
| 1295 | |
| 1296 | /* we don't know the file type yet */ |
| 1297 | is_source = FALSE; |
| 1298 | is_lib = FALSE; |
| 1299 | |
| 1300 | /* check to see if we have a module type option */ |
| 1301 | if (argv[curarg][0] == '-') |
| 1302 | { |
| 1303 | if (strcmp(argv[curarg], "-source") == 0) |
| 1304 | { |
| 1305 | /* note that we have a source file, and skip the option */ |
| 1306 | is_source = TRUE; |
| 1307 | ++curarg; |
| 1308 | } |
| 1309 | else if (strcmp(argv[curarg], "-lib") == 0) |
| 1310 | { |
| 1311 | /* note that we have a library, and skip the option */ |
| 1312 | is_lib = TRUE; |
| 1313 | ++curarg; |
| 1314 | } |
| 1315 | else if (strcmp(argv[curarg], "-res") == 0) |
| 1316 | { |
| 1317 | /* |
| 1318 | * Resource arguments follow - we're done with modules. |
| 1319 | * Skip the "-res" argument and exit the module loop. |
| 1320 | */ |
| 1321 | ++curarg; |
| 1322 | break; |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | /* invalid option in the module list */ |
| 1327 | goto bad_option; |
| 1328 | } |
| 1329 | |
| 1330 | /* |
| 1331 | * if we have no filename argument following the type |
| 1332 | * specifier, it's an error |
| 1333 | */ |
| 1334 | if (curarg == argc) |
| 1335 | { |
| 1336 | --curarg; |
| 1337 | goto missing_option_arg; |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | /* |
| 1342 | * if we didn't find an explicit type specifier, infer the type |
| 1343 | * from the filename suffix |
| 1344 | */ |
| 1345 | if (!is_source && !is_lib) |
| 1346 | { |
| 1347 | size_t len; |
| 1348 | |
| 1349 | /* |
| 1350 | * if we have a ".tl" suffix, assume it's a library file; |
| 1351 | * otherwise, assume it's a source file |
| 1352 | */ |
| 1353 | if ((len = strlen(argv[curarg])) > 3 |
| 1354 | && stricmp(argv[curarg] + len - 3, ".tl") == 0) |
| 1355 | { |
| 1356 | /* ".tl" - it's a library file */ |
| 1357 | is_lib = TRUE; |
| 1358 | } |
| 1359 | else |
| 1360 | { |
| 1361 | /* something else - assume it's a source file */ |
| 1362 | is_source = TRUE; |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | /* make the filename relative to the option file path */ |
| 1367 | p = make_opt_file_relative(relbuf, sizeof(relbuf), |
| 1368 | read_opt_file, opt_file_path, |
| 1369 | argv[curarg]); |
| 1370 | |
| 1371 | /* process the file according to its type */ |
| 1372 | if (is_source) |
| 1373 | { |
| 1374 | /* add this file to the module list */ |
| 1375 | CTcMakeModule *mod = mk->add_module(p, 0, 0); |
| 1376 | |
| 1377 | /* set the module's original name to the name as given */ |
| 1378 | mod->set_orig_name(argv[curarg]); |
| 1379 | |
| 1380 | /* |
| 1381 | * Also use the original name (with a default .t suffix) as the |
| 1382 | * search name, in case it's a file we're going to search for |
| 1383 | * using the source search path. When searching, we want to |
| 1384 | * search for the original name, not the project-relative name. |
| 1385 | */ |
| 1386 | char sbuf[OSFNMAX]; |
| 1387 | lib_strcpy(sbuf, sizeof(sbuf), argv[curarg]); |
| 1388 | os_defext(sbuf, "t"); |
| 1389 | mod->set_search_source_name(sbuf); |
| 1390 | |
| 1391 | /* |
| 1392 | * if no image has been specified yet already, use this |
| 1393 | * module's name as the image name, with the suffix ".t3" |
| 1394 | */ |
| 1395 | if (!image_specified) |
| 1396 | { |
| 1397 | char buf[OSFNMAX]; |
| 1398 | |
| 1399 | /* |
| 1400 | * build the default image filename by changing the |
| 1401 | * module's extension to "t3" (or adding the "t3" |
| 1402 | * extension if the module didn't have one to begin with) |
| 1403 | */ |
| 1404 | strcpy(buf, p); |
| 1405 | os_remext(buf); |
| 1406 | os_addext(buf, "t3"); |
| 1407 | |
| 1408 | /* set the filename */ |
| 1409 | mk->set_image_file(buf); |
| 1410 | |
| 1411 | /* note that we know the image file's name now */ |
| 1412 | image_specified = TRUE; |
| 1413 | } |
| 1414 | } |
| 1415 | else |
| 1416 | { |
| 1417 | CTcMakeModule lib_mod; |
| 1418 | CTcMakeModule *last_pre_lib_mod; |
| 1419 | char fname[OSFNMAX]; |
| 1420 | char orig_fname[OSFNMAX]; |
| 1421 | int nodef; |
| 1422 | |
| 1423 | /* add a default "tl" extension */ |
| 1424 | strcpy(fname, p); |
| 1425 | os_defext(fname, "tl"); |
| 1426 | |
| 1427 | /* likewise, add a default "tl" extension to the original name */ |
| 1428 | strcpy(orig_fname, argv[curarg]); |
| 1429 | os_defext(orig_fname, "tl"); |
| 1430 | |
| 1431 | /* |
| 1432 | * set up a module for the library, so we can easily search |
| 1433 | * the source path for the module |
| 1434 | */ |
| 1435 | lib_mod.set_module_name(fname); |
| 1436 | lib_mod.set_search_source_name(orig_fname); |
| 1437 | |
| 1438 | /* get the module name by searching the path if necessary */ |
| 1439 | mk->get_srcfile(fname, &lib_mod); |
| 1440 | |
| 1441 | /* remember the last module before this library's modules */ |
| 1442 | last_pre_lib_mod = mk->get_last_module(); |
| 1443 | |
| 1444 | /* |
| 1445 | * Process the library. Since this is a top-level library |
| 1446 | * (rather than a sub-library included from within another |
| 1447 | * library), there is no prefix to the URL's of the member |
| 1448 | * items. |
| 1449 | */ |
| 1450 | if (CTcLibParserCmdline::process_lib_arg( |
| 1451 | hostifc, mk, res_list, fname, "", &nodef)) |
| 1452 | lib_err = TRUE; |
| 1453 | |
| 1454 | /* if there was a 'nodef' flag, note it */ |
| 1455 | if (nodef) |
| 1456 | add_def_mod = FALSE; |
| 1457 | |
| 1458 | /* process any exclusion options */ |
| 1459 | while (curarg + 1 < argc && strcmp(argv[curarg+1], "-x") == 0) |
| 1460 | { |
| 1461 | |
| 1462 | /* skip to the "-x" */ |
| 1463 | ++curarg; |
| 1464 | |
| 1465 | /* if the filename is missing, report a usage error */ |
| 1466 | if (curarg + 1 >= argc) |
| 1467 | goto missing_option_arg; |
| 1468 | |
| 1469 | /* skip the -x and get its argument (the URL to exclude) */ |
| 1470 | const char *xurl = argv[++curarg]; |
| 1471 | |
| 1472 | /* |
| 1473 | * Start with the next module after the last module before |
| 1474 | * this library. If there was nothing before this library, |
| 1475 | * then this library's first module is the first module in |
| 1476 | * the entire program,. |
| 1477 | */ |
| 1478 | CTcMakeModule *mod = last_pre_lib_mod; |
| 1479 | if (mod != 0) |
| 1480 | mod = mod->get_next(); |
| 1481 | else |
| 1482 | mod = mk->get_first_module(); |
| 1483 | |
| 1484 | /* scan the list of library modules for a match */ |
| 1485 | for ( ; mod != 0 ; mod = mod->get_next()) |
| 1486 | { |
| 1487 | /* if this module has the excluded URL, exclude it */ |
| 1488 | if (stricmp(mod->get_url(), xurl) == 0) |
| 1489 | { |
| 1490 | /* mark this module as excluded */ |
| 1491 | mod->set_excluded(TRUE); |
| 1492 | |
| 1493 | /* |
| 1494 | * no need to look any further - assume each URL |
| 1495 | * is unique |
| 1496 | */ |
| 1497 | break; |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | /* if we have any more arguments, they're for resource files */ |
| 1505 | for ( ; curarg < argc ; ++curarg) |
| 1506 | { |
| 1507 | char relbuf[OSFNMAX]; |
| 1508 | |
| 1509 | /* check for a resource bundler option */ |
| 1510 | if (argv[curarg][0] == '-') |
| 1511 | { |
| 1512 | /* check the argument */ |
| 1513 | switch(argv[curarg][1]) |
| 1514 | { |
| 1515 | case 'n': |
| 1516 | /* check for '-norecurse' */ |
| 1517 | if (strcmp(argv[curarg], "-norecurse") == 0) |
| 1518 | res_recurse = FALSE; |
| 1519 | else |
| 1520 | goto bad_option; |
| 1521 | break; |
| 1522 | |
| 1523 | case 'r': |
| 1524 | /* check for '-recurse' */ |
| 1525 | if (strcmp(argv[curarg], "-recurse") == 0) |
| 1526 | res_recurse = TRUE; |
| 1527 | else |
| 1528 | goto bad_option; |
| 1529 | break; |
| 1530 | |
| 1531 | default: |
| 1532 | /* unknown option */ |
| 1533 | goto bad_option; |
| 1534 | } |
| 1535 | } |
| 1536 | else |
| 1537 | { |
| 1538 | char *p; |
| 1539 | char *fname; |
| 1540 | char *alias; |
| 1541 | |
| 1542 | /* |
| 1543 | * It's not an option, so it must be a file. Scan for an |
| 1544 | * alias, which is introduced with an '=' character. |
| 1545 | */ |
| 1546 | for (p = fname = argv[curarg] ; *p != '\0' && *p != '=' ; ++p) ; |
| 1547 | if (*p == '=') |
| 1548 | { |
| 1549 | /* |
| 1550 | * overwrite the '=' with a null byte, so that the filename |
| 1551 | * ends here |
| 1552 | */ |
| 1553 | *p = '\0'; |
| 1554 | |
| 1555 | /* the alias starts after the '=' */ |
| 1556 | alias = p + 1; |
| 1557 | } |
| 1558 | else |
| 1559 | { |
| 1560 | /* there's no alias */ |
| 1561 | alias = 0; |
| 1562 | } |
| 1563 | |
| 1564 | /* make the filename relative to the option file path */ |
| 1565 | fname = make_opt_file_relative(relbuf, sizeof(relbuf), |
| 1566 | read_opt_file, opt_file_path, |
| 1567 | fname); |
| 1568 | |
| 1569 | /* add this file to the resource list*/ |
| 1570 | res_list->add_file(fname, alias, res_recurse); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | /* |
| 1575 | * If an option file was specified or implied, and we haven't read |
| 1576 | * it yet, read it now. |
| 1577 | */ |
| 1578 | if (opt_file != 0 && !read_opt_file) |
| 1579 | { |
| 1580 | osfildef *fp; |
| 1581 | int new_argc; |
| 1582 | char **new_argv; |
| 1583 | char new_opt_file[OSFNMAX]; |
| 1584 | |
| 1585 | /* if the options file doesn't exist, try adding the suffix 't3m' */ |
| 1586 | if (osfacc(opt_file)) |
| 1587 | { |
| 1588 | strcpy(new_opt_file, opt_file); |
| 1589 | os_defext(new_opt_file, "t3m"); |
| 1590 | opt_file = new_opt_file; |
| 1591 | } |
| 1592 | |
| 1593 | /* open the options file */ |
| 1594 | fp = osfoprt(opt_file, OSFTTEXT); |
| 1595 | if (fp == 0) |
| 1596 | { |
| 1597 | printf("error: unable to read option file \"%s\"\n", opt_file); |
| 1598 | err_cnt = 1; |
| 1599 | goto done; |
| 1600 | } |
| 1601 | |
| 1602 | /* |
| 1603 | * First, parse the file simply to count the arguments. Add in one |
| 1604 | * extra argument to make room for making a copy of argv[0]. |
| 1605 | */ |
| 1606 | new_argc = CTcCommandUtil::parse_opt_file(fp, 0, &opt_helper) + 1; |
| 1607 | |
| 1608 | /* rewind the file to parse it again */ |
| 1609 | osfseek(fp, 0, OSFSK_SET); |
| 1610 | |
| 1611 | /* allocate a new argument list */ |
| 1612 | new_argv = (char **)t3malloc(new_argc * sizeof(new_argv[0])); |
| 1613 | |
| 1614 | /* copy the program name from argv[0] */ |
| 1615 | new_argv[0] = argv[0]; |
| 1616 | |
| 1617 | /* |
| 1618 | * Re-read the file, saving the arguments. Note that we want to |
| 1619 | * start saving the arguments from the file at index 1 in the new |
| 1620 | * argv array, because we reserve argv[0] to hold the original |
| 1621 | * program name argument. |
| 1622 | */ |
| 1623 | CTcCommandUtil::parse_opt_file(fp, new_argv + 1, &opt_helper); |
| 1624 | |
| 1625 | /* done with the file - close it */ |
| 1626 | osfcls(fp); |
| 1627 | |
| 1628 | /* start over with the new argument vector */ |
| 1629 | argv = new_argv; |
| 1630 | argc = new_argc; |
| 1631 | |
| 1632 | /* |
| 1633 | * note that we've read the options file - we can only do this |
| 1634 | * once per run |
| 1635 | */ |
| 1636 | read_opt_file = TRUE; |
| 1637 | |
| 1638 | /* |
| 1639 | * Note the option file's path prefix. We'll assume that any |
| 1640 | * relative filename paths mentioned in the option file are meant |
| 1641 | * to be relative to the folder containing the option file itself. |
| 1642 | */ |
| 1643 | os_get_path_name(opt_file_path, sizeof(opt_file_path), opt_file); |
| 1644 | |
| 1645 | /* go add the new command options */ |
| 1646 | goto parse_options; |
| 1647 | } |
| 1648 | |
| 1649 | /* |
| 1650 | * Add the default object modules, if appropriate. Don't add the |
| 1651 | * default modules unless we're linking. |
| 1652 | */ |
| 1653 | if (add_def_mod && !compile_only && !pp_only) |
| 1654 | { |
| 1655 | /* build the full path to the "_main" library module */ |
| 1656 | char srcname[OSFNMAX]; |
| 1657 | os_build_full_path(srcname, sizeof(srcname), |
| 1658 | sys_lib_entry->get_path(), "_main"); |
| 1659 | |
| 1660 | /* add this as the first module of our compilation */ |
| 1661 | CTcMakeModule *mod = mk->add_module_first(srcname, 0, 0); |
| 1662 | |
| 1663 | /* set its original name, and note it's from the system library */ |
| 1664 | mod->set_orig_name("_main"); |
| 1665 | mod->set_from_syslib(); |
| 1666 | } |
| 1667 | |
| 1668 | /* |
| 1669 | * If the symbol file and object file directory paths weren't |
| 1670 | * explicitly set, set these to the same path used by the image file. |
| 1671 | * This will put all of the output files in the same place, if they |
| 1672 | * didn't explicitly tell us where to put the different kinds of |
| 1673 | * generated files. |
| 1674 | */ |
| 1675 | os_get_path_name(dirbuf, sizeof(dirbuf), mk->get_image_file()); |
| 1676 | if (!sym_dir_set) |
| 1677 | mk->set_symbol_dir(dirbuf); |
| 1678 | if (!obj_dir_set) |
| 1679 | mk->set_object_dir(dirbuf); |
| 1680 | |
| 1681 | /* if we encountered any errors parsing a library, we can't proceed */ |
| 1682 | if (lib_err) |
| 1683 | goto done; |
| 1684 | |
| 1685 | /* build the program */ |
| 1686 | mk->build(hostifc, &err_cnt, &warn_cnt, |
| 1687 | force_build, force_link, res_list, argv[0]); |
| 1688 | |
| 1689 | done: |
| 1690 | /* terminate the error subsystem */ |
| 1691 | CTcMain::tc_err_term(); |
| 1692 | |
| 1693 | /* delete our 'make' object */ |
| 1694 | delete mk; |
| 1695 | |
| 1696 | /* show the error and warning counts if non-zero */ |
| 1697 | if (err_cnt != 0 || warn_cnt != 0) |
| 1698 | printf("Errors: %d\n" |
| 1699 | "Warnings: %d\n", err_cnt, warn_cnt); |
| 1700 | |
| 1701 | /* if we read an options file, delete the memory used for the options */ |
| 1702 | if (read_opt_file) |
| 1703 | { |
| 1704 | int i; |
| 1705 | |
| 1706 | /* |
| 1707 | * delete the argv strings (except for argv[0], which came from |
| 1708 | * the caller) |
| 1709 | */ |
| 1710 | for (i = 1 ; i < argc ; ++i) |
| 1711 | opt_helper.free_opt_file_str(argv[i]); |
| 1712 | |
| 1713 | /* delete the argv vector itself */ |
| 1714 | t3free(argv); |
| 1715 | } |
| 1716 | |
| 1717 | /* if we have a string capture file, close it */ |
| 1718 | if (string_fp != 0) |
| 1719 | osfcls(string_fp); |
| 1720 | |
| 1721 | /* if we have an aassembly listing file, close it */ |
| 1722 | if (assembly_fp != 0) |
| 1723 | osfcls(assembly_fp); |
| 1724 | |
| 1725 | /* delete the host interface */ |
| 1726 | delete hostifc; |
| 1727 | |
| 1728 | /* delete the resource list */ |
| 1729 | delete res_list; |
| 1730 | |
| 1731 | /* show any unfreed memory (if we're in a debug build) */ |
| 1732 | t3_list_memory_blocks(0); |
| 1733 | |
| 1734 | /* |
| 1735 | * exit with an appropriate exit code, depending on whether we had |
| 1736 | * any errors or not |
| 1737 | */ |
| 1738 | return (err_cnt != 0 || (warnings_as_errors && warn_cnt != 0) |
| 1739 | ? OSEXFAIL : OSEXSUCC); |
| 1740 | } |
| 1741 |