| 1 |
#include "pconf.h" |
| 2 |
|
| 3 |
|
| 4 |
void PConfSetColor(pconf_core_struct *core_ptr, FILE *stream, int color_code); |
| 5 |
static platform_struct *PConfMatchPlatformByName( |
| 6 |
platform_struct **platform, int total_platforms, |
| 7 |
const char *name, int *n |
| 8 |
); |
| 9 |
feature_struct *PConfMatchFeatureByName( |
| 10 |
platform_struct *platform_ptr, |
| 11 |
const char *name, int *n |
| 12 |
); |
| 13 |
static void PConfFreeCore(pconf_core_struct *core_ptr); |
| 14 |
void PConfPrintHR(pconf_core_struct *core_ptr); |
| 15 |
static void PConfPrintHelp(const char *prog_name); |
| 16 |
static void PConfPrintPlatform( |
| 17 |
pconf_core_struct *core_ptr, |
| 18 |
platform_struct *platform_ptr, int print_level, |
| 19 |
int print_for_review |
| 20 |
); |
| 21 |
static void PConfPrintPlatforms( |
| 22 |
pconf_core_struct *core_ptr, |
| 23 |
platform_struct **platform, int total_platforms, |
| 24 |
const char *specific_platform, |
| 25 |
int print_level, |
| 26 |
int print_for_review |
| 27 |
); |
| 28 |
static int PConfPrereqCheck( |
| 29 |
char *platforms_ini, int argc, char **argv |
| 30 |
); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
void PConfSetColor(pconf_core_struct *core_ptr, FILE *stream, int color_code) |
| 39 |
{ |
| 40 |
if(stream == NULL) |
| 41 |
return; |
| 42 |
|
| 43 |
if(core_ptr != NULL) |
| 44 |
{ |
| 45 |
if(!core_ptr->colors) |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
if(color_code == PCONF_COLOR_DEFAULT) |
| 50 |
fprintf(stream, "\033[0;39m"); |
| 51 |
else if(color_code == PCONF_COLOR_SELECTABLE) |
| 52 |
fprintf(stream, "\033[4;34m"); |
| 53 |
else if(color_code == PCONF_COLOR_HEADING) |
| 54 |
fprintf(stream, "\033[1;m"); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
else |
| 59 |
fprintf(stream, "\033[1;%im", color_code); |
| 60 |
|
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static platform_struct *PConfMatchPlatformByName( |
| 69 |
platform_struct **platform, int total_platforms, |
| 70 |
const char *name, int *n |
| 71 |
) |
| 72 |
{ |
| 73 |
int i; |
| 74 |
platform_struct *platform_ptr; |
| 75 |
|
| 76 |
if(n != NULL) |
| 77 |
(*n) = -1; |
| 78 |
|
| 79 |
if((platform == NULL) || (total_platforms < 1) || (name == NULL)) |
| 80 |
return(NULL); |
| 81 |
|
| 82 |
for(i = 0; i < total_platforms; i++) |
| 83 |
{ |
| 84 |
platform_ptr = platform[i]; |
| 85 |
if(platform_ptr == NULL) |
| 86 |
continue; |
| 87 |
|
| 88 |
if(platform_ptr->name == NULL) |
| 89 |
continue; |
| 90 |
|
| 91 |
if(!STRCASECMP(platform_ptr->name, name)) |
| 92 |
{ |
| 93 |
if(n != NULL) |
| 94 |
(*n) = i; |
| 95 |
return(platform_ptr); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
return(NULL); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
feature_struct *PConfMatchFeatureByName( |
| 107 |
platform_struct *platform_ptr, |
| 108 |
const char *name, int *n |
| 109 |
) |
| 110 |
{ |
| 111 |
int i; |
| 112 |
feature_struct *feature_ptr; |
| 113 |
|
| 114 |
if(n != NULL) |
| 115 |
(*n) = -1; |
| 116 |
|
| 117 |
if((platform_ptr == NULL) || (name == NULL)) |
| 118 |
return(NULL); |
| 119 |
|
| 120 |
for(i = 0; i < platform_ptr->total_features; i++) |
| 121 |
{ |
| 122 |
feature_ptr = platform_ptr->feature[i]; |
| 123 |
if(feature_ptr == NULL) |
| 124 |
continue; |
| 125 |
|
| 126 |
if(feature_ptr->name == NULL) |
| 127 |
continue; |
| 128 |
|
| 129 |
if(!STRCASECMP(feature_ptr->name, name)) |
| 130 |
{ |
| 131 |
if(n != NULL) |
| 132 |
(*n) = i; |
| 133 |
return(feature_ptr); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
return(NULL); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
static void PConfFreeCore(pconf_core_struct *core_ptr) |
| 144 |
{ |
| 145 |
char **s; |
| 146 |
|
| 147 |
#define DO_FREE_STRING \ |
| 148 |
{ \ |
| 149 |
if((*s) != NULL) \ |
| 150 |
{ \ |
| 151 |
FREE(*s); \ |
| 152 |
(*s) = NULL; \ |
| 153 |
} \ |
| 154 |
} |
| 155 |
|
| 156 |
if(core_ptr == NULL) |
| 157 |
return; |
| 158 |
|
| 159 |
PConfFreePlatforms( |
| 160 |
&core_ptr->platform, |
| 161 |
&core_ptr->total_platforms |
| 162 |
); |
| 163 |
|
| 164 |
PConfFreePlatform(core_ptr->selected_platform); |
| 165 |
core_ptr->selected_platform = NULL; |
| 166 |
|
| 167 |
s = &core_ptr->makefile_output; |
| 168 |
DO_FREE_STRING |
| 169 |
s = &core_ptr->makefile_input_prepend; |
| 170 |
DO_FREE_STRING |
| 171 |
s = &core_ptr->makefile_input_append; |
| 172 |
DO_FREE_STRING |
| 173 |
|
| 174 |
s = &core_ptr->message_configure_startup; |
| 175 |
DO_FREE_STRING |
| 176 |
s = &core_ptr->message_platform_unsupported; |
| 177 |
DO_FREE_STRING |
| 178 |
s = &core_ptr->message_depend_failed; |
| 179 |
DO_FREE_STRING |
| 180 |
s = &core_ptr->message_success; |
| 181 |
DO_FREE_STRING |
| 182 |
|
| 183 |
s = &core_ptr->os_name; |
| 184 |
DO_FREE_STRING |
| 185 |
s = &core_ptr->machine_name; |
| 186 |
DO_FREE_STRING |
| 187 |
|
| 188 |
FREE(core_ptr); |
| 189 |
core_ptr = NULL; |
| 190 |
|
| 191 |
#undef DO_FREE_STRING |
| 192 |
|
| 193 |
return; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
void PConfPrintHR(pconf_core_struct *core_ptr) |
| 201 |
{ |
| 202 |
int i, len = 80; |
| 203 |
|
| 204 |
if(core_ptr->screen_width > 0) |
| 205 |
len = core_ptr->screen_width; |
| 206 |
|
| 207 |
for(i = 0; i < len; i++) |
| 208 |
FPUTC('-', stdout); |
| 209 |
FPUTC('\n', stdout); |
| 210 |
|
| 211 |
return; |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
static void PConfPrintHelp(const char *prog_name) |
| 223 |
{ |
| 224 |
if(prog_name == NULL) |
| 225 |
prog_name = "pconf"; |
| 226 |
|
| 227 |
printf( |
| 228 |
"Usage: ./configure [platform] [modifiers] [options]\n" |
| 229 |
); |
| 230 |
printf( |
| 231 |
" ./configure [options]\n" |
| 232 |
); |
| 233 |
printf( |
| 234 |
"\n\ |
| 235 |
Where [platform] specifies the name of the platform to configure for (use\n\ |
| 236 |
the --listall argument to see a complete list of supported platforms).\n\ |
| 237 |
\n\ |
| 238 |
Where [modifiers] can be any of the following modifications of features\n\ |
| 239 |
or parameters (use the --listall argument to see a list of features\n\ |
| 240 |
and parameters of each platform):\n\ |
| 241 |
\n\ |
| 242 |
--enable=<feature> Enables the specified <feature>.\n\ |
| 243 |
--disable=<feature> Disables the specified <feature>.\n\ |
| 244 |
--<parameter>=<value> Override <parameter> with new <value>,\n\ |
| 245 |
example: --prefix=/usr/local/\n\ |
| 246 |
\n\ |
| 247 |
Where [options] can be any of the following:\n\ |
| 248 |
\n\ |
| 249 |
--list[=<platform>] Show descriptions and features of each\n\ |
| 250 |
platform (or just a specific platform if\n\ |
| 251 |
<platform> is specified).\n\ |
| 252 |
--listall[=<platform>] Show descriptions, features, dependancies,\n\ |
| 253 |
and all other details of each platform\n\ |
| 254 |
(or just a specific platform if <platform>\n\ |
| 255 |
is specified).\n\ |
| 256 |
--v Prints extra verbose messages (also displays\n\ |
| 257 |
post configuration report).\n\ |
| 258 |
--interactive Use interactive mode when needed.\n\ |
| 259 |
--no-warnings Do not print warning messages.\n\ |
| 260 |
--no-colors Disable ANSI color.\n\ |
| 261 |
--force Ignore errors when possible.\n\ |
| 262 |
--ignore-environments Do not use any environment variable values.\n\ |
| 263 |
--help Prints (this) help screen and exits.\n\ |
| 264 |
--version Prints version information and exits.\n\ |
| 265 |
\n\ |
| 266 |
Examples:\n\ |
| 267 |
\n\ |
| 268 |
./configure --listall\n\ |
| 269 |
\n\ |
| 270 |
./configure Linux --prefix=/usr/local/\n\ |
| 271 |
\n\ |
| 272 |
./configure UNIX -v --prefix=/usr --CFLAGS=\"-O2 -g -Wall\"\n\ |
| 273 |
\n" |
| 274 |
); |
| 275 |
|
| 276 |
return; |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
static void PConfPrintPlatform( |
| 294 |
pconf_core_struct *core_ptr, |
| 295 |
platform_struct *platform_ptr, int print_level, |
| 296 |
int print_for_review |
| 297 |
) |
| 298 |
{ |
| 299 |
int n, j; |
| 300 |
feature_struct *feature_ptr; |
| 301 |
depend_struct *depend_ptr; |
| 302 |
|
| 303 |
|
| 304 |
if(platform_ptr == NULL) |
| 305 |
return; |
| 306 |
|
| 307 |
#define PLATFORMS_INDENT " " |
| 308 |
|
| 309 |
|
| 310 |
if(print_level >= 0) |
| 311 |
{ |
| 312 |
if(print_level >= 1) |
| 313 |
{ |
| 314 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_HEADING); |
| 315 |
printf("Platform"); |
| 316 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 317 |
printf(": "); |
| 318 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_SELECTABLE); |
| 319 |
printf("%s\n", platform_ptr->name); |
| 320 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 321 |
} |
| 322 |
else |
| 323 |
{ |
| 324 |
printf("%s\n", |
| 325 |
platform_ptr->name |
| 326 |
); |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
if((platform_ptr->description != NULL) && |
| 331 |
(print_level >= 1) |
| 332 |
) |
| 333 |
{ |
| 334 |
printf( |
| 335 |
PLATFORMS_INDENT "Description: %s\n", |
| 336 |
platform_ptr->description |
| 337 |
); |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
if((platform_ptr->prefix != NULL) && |
| 342 |
(print_level >= 3) |
| 343 |
) |
| 344 |
{ |
| 345 |
printf( |
| 346 |
PLATFORMS_INDENT "PREFIX: %s\n", |
| 347 |
platform_ptr->prefix |
| 348 |
); |
| 349 |
} |
| 350 |
|
| 351 |
if((platform_ptr->cflags != NULL) && |
| 352 |
(print_level >= 3) |
| 353 |
) |
| 354 |
{ |
| 355 |
printf( |
| 356 |
PLATFORMS_INDENT "CFLAGS: %s\n", |
| 357 |
platform_ptr->cflags |
| 358 |
); |
| 359 |
} |
| 360 |
|
| 361 |
if((platform_ptr->inc_dirs != NULL) && |
| 362 |
(print_level >= 3) |
| 363 |
) |
| 364 |
{ |
| 365 |
printf( |
| 366 |
PLATFORMS_INDENT "INC_DIRS: %s\n", |
| 367 |
platform_ptr->inc_dirs |
| 368 |
); |
| 369 |
} |
| 370 |
|
| 371 |
if((platform_ptr->libs != NULL) && |
| 372 |
(print_level >= 3) |
| 373 |
) |
| 374 |
{ |
| 375 |
printf( |
| 376 |
PLATFORMS_INDENT "LIBS: %s\n", |
| 377 |
platform_ptr->libs |
| 378 |
); |
| 379 |
} |
| 380 |
|
| 381 |
if((platform_ptr->lib_dirs != NULL) && |
| 382 |
(print_level >= 3) |
| 383 |
) |
| 384 |
{ |
| 385 |
printf( |
| 386 |
PLATFORMS_INDENT "LIB_DIRS: %s\n", |
| 387 |
platform_ptr->lib_dirs |
| 388 |
); |
| 389 |
} |
| 390 |
|
| 391 |
if((platform_ptr->cc != NULL) && |
| 392 |
(print_level >= 3) |
| 393 |
) |
| 394 |
{ |
| 395 |
printf( |
| 396 |
PLATFORMS_INDENT "CC: %s\n", |
| 397 |
platform_ptr->cc |
| 398 |
); |
| 399 |
} |
| 400 |
|
| 401 |
if((platform_ptr->cpp != NULL) && |
| 402 |
(print_level >= 3) |
| 403 |
) |
| 404 |
{ |
| 405 |
printf( |
| 406 |
PLATFORMS_INDENT "CPP: %s\n", |
| 407 |
platform_ptr->cpp |
| 408 |
); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
if(print_level >= 1) |
| 414 |
{ |
| 415 |
#define FEATURES_INDENT " " |
| 416 |
|
| 417 |
for(n = 0; n < platform_ptr->total_features; n++) |
| 418 |
{ |
| 419 |
feature_ptr = platform_ptr->feature[n]; |
| 420 |
if(feature_ptr == NULL) |
| 421 |
continue; |
| 422 |
|
| 423 |
if(feature_ptr->name != NULL) |
| 424 |
{ |
| 425 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_HEADING); |
| 426 |
printf(PLATFORMS_INDENT "Feature"); |
| 427 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 428 |
printf(": "); |
| 429 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_SELECTABLE); |
| 430 |
printf("%s", feature_ptr->name); |
| 431 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
if(print_for_review) |
| 439 |
{ |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
printf(" ("); |
| 445 |
switch(feature_ptr->must_exist) |
| 446 |
{ |
| 447 |
case PCONF_MUST_EXIST_NO: |
| 448 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_WARNING); |
| 449 |
printf("Disabled"); |
| 450 |
break; |
| 451 |
|
| 452 |
case PCONF_MUST_EXIST_YES: |
| 453 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_SUCCESS); |
| 454 |
printf("Enabled"); |
| 455 |
break; |
| 456 |
|
| 457 |
default: |
| 458 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_FAILURE); |
| 459 |
printf("Undefined"); |
| 460 |
break; |
| 461 |
} |
| 462 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 463 |
printf(")\n"); |
| 464 |
} |
| 465 |
else |
| 466 |
{ |
| 467 |
printf(" ("); |
| 468 |
switch(feature_ptr->must_exist) |
| 469 |
{ |
| 470 |
case PCONF_MUST_EXIST_NO: |
| 471 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_FAILURE); |
| 472 |
printf("Not Checked"); |
| 473 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 474 |
printf(") To Enable: --enable=\"%s\"\n", |
| 475 |
feature_ptr->name |
| 476 |
); |
| 477 |
break; |
| 478 |
|
| 479 |
case PCONF_MUST_EXIST_PREFERRED: |
| 480 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_WARNING); |
| 481 |
printf("Preferred"); |
| 482 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 483 |
printf(") To Disable: --disable=\"%s\"\n", |
| 484 |
feature_ptr->name |
| 485 |
); |
| 486 |
break; |
| 487 |
|
| 488 |
case PCONF_MUST_EXIST_YES: |
| 489 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_SUCCESS); |
| 490 |
printf("Required"); |
| 491 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 492 |
printf(")\n"); |
| 493 |
break; |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
if((print_level >= 2) && (feature_ptr->description != NULL)) |
| 499 |
{ |
| 500 |
printf( |
| 501 |
FEATURES_INDENT "Description: %s\n", |
| 502 |
feature_ptr->description |
| 503 |
); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
if((print_level >= 3) && (feature_ptr->url_homepage != NULL)) |
| 508 |
{ |
| 509 |
printf( |
| 510 |
FEATURES_INDENT "URL Home Page: %s\n", |
| 511 |
feature_ptr->url_homepage |
| 512 |
); |
| 513 |
} |
| 514 |
|
| 515 |
if((print_level >= 3) && (feature_ptr->url_download != NULL)) |
| 516 |
{ |
| 517 |
printf( |
| 518 |
FEATURES_INDENT "URL Download: %s\n", |
| 519 |
feature_ptr->url_download |
| 520 |
); |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
if(print_level >= 2) |
| 526 |
{ |
| 527 |
#define DEPEND_INDENT " " |
| 528 |
if(feature_ptr->total_depends > 0) |
| 529 |
printf( |
| 530 |
FEATURES_INDENT "Depends On:\n" |
| 531 |
); |
| 532 |
|
| 533 |
for(j = 0; j < feature_ptr->total_depends; j++) |
| 534 |
{ |
| 535 |
depend_ptr = feature_ptr->depend[j]; |
| 536 |
if(depend_ptr == NULL) |
| 537 |
continue; |
| 538 |
|
| 539 |
if(depend_ptr->name != NULL) |
| 540 |
printf( |
| 541 |
DEPEND_INDENT "%s\n", |
| 542 |
depend_ptr->name |
| 543 |
); |
| 544 |
} |
| 545 |
#undef DEPEND_INDENT |
| 546 |
} |
| 547 |
} |
| 548 |
#undef FEATURES_INDENT |
| 549 |
} |
| 550 |
|
| 551 |
return; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
static void PConfPrintPlatforms( |
| 571 |
pconf_core_struct *core_ptr, |
| 572 |
platform_struct **platform, int total_platforms, |
| 573 |
const char *specific_platform, |
| 574 |
int print_level, |
| 575 |
int print_for_review |
| 576 |
) |
| 577 |
{ |
| 578 |
int i; |
| 579 |
platform_struct *platform_ptr; |
| 580 |
int platforms_printed = 0; |
| 581 |
|
| 582 |
|
| 583 |
if((platform == NULL) || (total_platforms < 1)) |
| 584 |
{ |
| 585 |
printf( |
| 586 |
"No platforms defined.\n" |
| 587 |
); |
| 588 |
return; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
if((specific_platform == NULL) && (total_platforms > 0)) |
| 593 |
printf("Available platforms:\n\n"); |
| 594 |
|
| 595 |
|
| 596 |
for(i = 0; i < total_platforms; i++) |
| 597 |
{ |
| 598 |
platform_ptr = platform[i]; |
| 599 |
if(platform_ptr == NULL) |
| 600 |
continue; |
| 601 |
|
| 602 |
|
| 603 |
if(platform_ptr->name == NULL) |
| 604 |
continue; |
| 605 |
|
| 606 |
|
| 607 |
if(specific_platform != NULL) |
| 608 |
{ |
| 609 |
|
| 610 |
if(STRCASECMP(specific_platform, platform_ptr->name)) |
| 611 |
continue; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
PConfPrintPlatform( |
| 616 |
core_ptr, platform_ptr, print_level, |
| 617 |
print_for_review |
| 618 |
); |
| 619 |
|
| 620 |
|
| 621 |
if(print_level > 0) |
| 622 |
printf("\n"); |
| 623 |
|
| 624 |
|
| 625 |
platforms_printed++; |
| 626 |
|
| 627 |
#undef PLATFORMS_INDENT |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
if(platforms_printed == 0) |
| 632 |
{ |
| 633 |
if(specific_platform != NULL) |
| 634 |
printf("No such platform \"%s\"\n", specific_platform); |
| 635 |
} |
| 636 |
|
| 637 |
return; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
static int PConfPrereqCheck( |
| 652 |
char *platforms_ini, int argc, char **argv |
| 653 |
) |
| 654 |
{ |
| 655 |
FILE *fp; |
| 656 |
|
| 657 |
|
| 658 |
if(platforms_ini == NULL) |
| 659 |
{ |
| 660 |
|
| 661 |
if(argc < 2) |
| 662 |
return(-2); |
| 663 |
else |
| 664 |
platforms_ini = argv[1]; |
| 665 |
} |
| 666 |
else |
| 667 |
{ |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
if(argc > 1) |
| 672 |
platforms_ini = argv[1]; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
fp = FOPEN(platforms_ini, "rb"); |
| 677 |
if(fp == NULL) |
| 678 |
{ |
| 679 |
return(-1); |
| 680 |
} |
| 681 |
else |
| 682 |
{ |
| 683 |
FCLOSE(fp); |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
if(argc < 3) |
| 688 |
return(-3); |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
return(0); |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
int main(int argc, char *argv[]) |
| 706 |
{ |
| 707 |
int i, status; |
| 708 |
const char *arg_ptr; |
| 709 |
int verbose = 0; |
| 710 |
int warnings = 1; |
| 711 |
int colors = 1; |
| 712 |
int interactive = 0; |
| 713 |
int force = 0; |
| 714 |
int ignore_environments = 0; |
| 715 |
char *platforms_ini = NULL; |
| 716 |
char *platform_name = NULL; |
| 717 |
char *specific_platform = NULL; |
| 718 |
int print_platforms_level = -1; |
| 719 |
pconf_core_struct *core_ptr; |
| 720 |
int selected_platform_num; |
| 721 |
platform_struct *selected_platform; |
| 722 |
|
| 723 |
|
| 724 |
#define DO_FREE_LOCALS \ |
| 725 |
{ \ |
| 726 |
FREE(platforms_ini); \ |
| 727 |
platforms_ini = NULL; \ |
| 728 |
\ |
| 729 |
FREE(platform_name); \ |
| 730 |
platform_name = NULL; \ |
| 731 |
\ |
| 732 |
FREE(specific_platform); \ |
| 733 |
specific_platform = NULL; \ |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
for(i = 1; i < argc; i++) |
| 738 |
{ |
| 739 |
arg_ptr = (const char *)argv[i]; |
| 740 |
if(arg_ptr == NULL) |
| 741 |
continue; |
| 742 |
|
| 743 |
|
| 744 |
if(STRCASEPFX(arg_ptr, "--h") || |
| 745 |
STRCASEPFX(arg_ptr, "-h") || |
| 746 |
!STRCASECMP(arg_ptr, "-?") || |
| 747 |
!STRCASECMP(arg_ptr, "/?") |
| 748 |
) |
| 749 |
{ |
| 750 |
PConfPrintHelp((argc > 0) ? argv[0] : NULL); |
| 751 |
DO_FREE_LOCALS |
| 752 |
return(4); |
| 753 |
} |
| 754 |
|
| 755 |
else if(STRCASEPFX(arg_ptr, "--ver") || |
| 756 |
STRCASEPFX(arg_ptr, "-ver") |
| 757 |
) |
| 758 |
{ |
| 759 |
printf( |
| 760 |
"%s Version %s\n", |
| 761 |
PROG_NAME, PROG_VERSION |
| 762 |
); |
| 763 |
DO_FREE_LOCALS |
| 764 |
return(4); |
| 765 |
} |
| 766 |
|
| 767 |
else if(!STRCASECMP(arg_ptr, "-v")) |
| 768 |
{ |
| 769 |
verbose = 1; |
| 770 |
} |
| 771 |
|
| 772 |
else if(!STRCASECMP(arg_ptr, "--no_warnings") || |
| 773 |
!STRCASECMP(arg_ptr, "--no_warn") || |
| 774 |
!STRCASECMP(arg_ptr, "--no-warnings") || |
| 775 |
!STRCASECMP(arg_ptr, "--no-warn") || |
| 776 |
!STRCASECMP(arg_ptr, "-no_warnings") || |
| 777 |
!STRCASECMP(arg_ptr, "-no_warn") || |
| 778 |
!STRCASECMP(arg_ptr, "-no-warnings") || |
| 779 |
!STRCASECMP(arg_ptr, "-no-warn") || |
| 780 |
!STRCASECMP(arg_ptr, "--nowarnings") || |
| 781 |
!STRCASECMP(arg_ptr, "-nowarn") |
| 782 |
) |
| 783 |
{ |
| 784 |
warnings = 0; |
| 785 |
} |
| 786 |
|
| 787 |
else if(!STRCASECMP(arg_ptr, "--interactive") || |
| 788 |
!STRCASECMP(arg_ptr, "-interactive") || |
| 789 |
!STRCASECMP(arg_ptr, "--i") || |
| 790 |
!STRCASECMP(arg_ptr, "-i") |
| 791 |
) |
| 792 |
{ |
| 793 |
interactive = 1; |
| 794 |
} |
| 795 |
|
| 796 |
else if(!STRCASECMP(arg_ptr, "--force") || |
| 797 |
!STRCASECMP(arg_ptr, "-force") |
| 798 |
) |
| 799 |
{ |
| 800 |
force = 1; |
| 801 |
} |
| 802 |
|
| 803 |
else if(!STRCASECMP(arg_ptr, "--no-colors") || |
| 804 |
!STRCASECMP(arg_ptr, "--no-colours") || |
| 805 |
!STRCASECMP(arg_ptr, "--no_colors") || |
| 806 |
!STRCASECMP(arg_ptr, "--no_colours") || |
| 807 |
!STRCASECMP(arg_ptr, "--no-color") || |
| 808 |
!STRCASECMP(arg_ptr, "--no-colour") || |
| 809 |
!STRCASECMP(arg_ptr, "--no_color") || |
| 810 |
!STRCASECMP(arg_ptr, "--no_colour") || |
| 811 |
!STRCASECMP(arg_ptr, "-no-colors") || |
| 812 |
!STRCASECMP(arg_ptr, "-no-colours") || |
| 813 |
!STRCASECMP(arg_ptr, "-no_colors") || |
| 814 |
!STRCASECMP(arg_ptr, "-no_colours") || |
| 815 |
!STRCASECMP(arg_ptr, "-no-color") || |
| 816 |
!STRCASECMP(arg_ptr, "-no-colour") || |
| 817 |
!STRCASECMP(arg_ptr, "-no_color") || |
| 818 |
!STRCASECMP(arg_ptr, "-no_colour") || |
| 819 |
!STRCASECMP(arg_ptr, "--nocolors") || |
| 820 |
!STRCASECMP(arg_ptr, "--nocolours") || |
| 821 |
!STRCASECMP(arg_ptr, "--nocolor") || |
| 822 |
!STRCASECMP(arg_ptr, "--nocolour") || |
| 823 |
!STRCASECMP(arg_ptr, "-nocolors") || |
| 824 |
!STRCASECMP(arg_ptr, "-nocolours") || |
| 825 |
!STRCASECMP(arg_ptr, "-nocolor") || |
| 826 |
!STRCASECMP(arg_ptr, "-nocolour") |
| 827 |
) |
| 828 |
{ |
| 829 |
colors = 0; |
| 830 |
} |
| 831 |
|
| 832 |
else if(!STRCASECMP(arg_ptr, "--ignore_environments") || |
| 833 |
!STRCASECMP(arg_ptr, "-ignore_environments") || |
| 834 |
!STRCASECMP(arg_ptr, "--ignore-environments") || |
| 835 |
!STRCASECMP(arg_ptr, "-ignore-environments") || |
| 836 |
!STRCASECMP(arg_ptr, "--ignoreenvironments") || |
| 837 |
!STRCASECMP(arg_ptr, "-ignoreenvironments") |
| 838 |
) |
| 839 |
{ |
| 840 |
ignore_environments = 1; |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
status = PConfPrereqCheck( |
| 847 |
platforms_ini, |
| 848 |
argc, argv |
| 849 |
); |
| 850 |
switch(status) |
| 851 |
{ |
| 852 |
case -1: |
| 853 |
fprintf( |
| 854 |
stderr, |
| 855 |
"%s: Cannot open platforms configuration file.\n", |
| 856 |
(argc > 1) ? argv[1] : platforms_ini |
| 857 |
); |
| 858 |
fprintf( |
| 859 |
stderr, |
| 860 |
"This file is used to configure generation of the output Makefile\n\ |
| 861 |
used in compiling the program source, it should be specified as the\n\ |
| 862 |
first argument. If you cannot locate the platforms configuration file,\n\ |
| 863 |
notify the vendor that this file is missing.\n" |
| 864 |
); |
| 865 |
DO_FREE_LOCALS |
| 866 |
return(1); |
| 867 |
break; |
| 868 |
|
| 869 |
case -2: |
| 870 |
|
| 871 |
PConfPrintHelp((argc > 0) ? argv[0] : NULL); |
| 872 |
DO_FREE_LOCALS |
| 873 |
return(4); |
| 874 |
break; |
| 875 |
|
| 876 |
case -3: |
| 877 |
|
| 878 |
printf("You must specify a supported platform to configure for.\n"); |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
print_platforms_level = 0; |
| 883 |
break; |
| 884 |
|
| 885 |
default: |
| 886 |
break; |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
if(argc > 1) |
| 894 |
{ |
| 895 |
FREE(platforms_ini); |
| 896 |
platforms_ini = STRDUP(argv[1]); |
| 897 |
} |
| 898 |
|
| 899 |
if(argc > 2) |
| 900 |
{ |
| 901 |
FREE(platform_name); |
| 902 |
platform_name = STRDUP(argv[2]); |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
for(i = 2; i < argc; i++) |
| 907 |
{ |
| 908 |
arg_ptr = (const char *)argv[i]; |
| 909 |
if(arg_ptr == NULL) |
| 910 |
continue; |
| 911 |
|
| 912 |
|
| 913 |
if(STRCASEPFX(arg_ptr, "--list_a") || |
| 914 |
STRCASEPFX(arg_ptr, "-list_a") || |
| 915 |
STRCASEPFX(arg_ptr, "--lista") || |
| 916 |
STRCASEPFX(arg_ptr, "-lista") |
| 917 |
) |
| 918 |
{ |
| 919 |
const char *cstrptr; |
| 920 |
|
| 921 |
print_platforms_level = 3; |
| 922 |
|
| 923 |
|
| 924 |
cstrptr = STRCHR(arg_ptr, '='); |
| 925 |
if(cstrptr != NULL) |
| 926 |
{ |
| 927 |
cstrptr++; |
| 928 |
while(ISBLANK(*cstrptr)) |
| 929 |
cstrptr++; |
| 930 |
|
| 931 |
FREE(specific_platform); |
| 932 |
specific_platform = STRDUP(cstrptr); |
| 933 |
} |
| 934 |
} |
| 935 |
|
| 936 |
else if(STRCASEPFX(arg_ptr, "--list") || |
| 937 |
STRCASEPFX(arg_ptr, "-list") |
| 938 |
) |
| 939 |
{ |
| 940 |
const char *cstrptr; |
| 941 |
|
| 942 |
print_platforms_level = 1; |
| 943 |
|
| 944 |
|
| 945 |
cstrptr = STRCHR(arg_ptr, '='); |
| 946 |
if(cstrptr != NULL) |
| 947 |
{ |
| 948 |
cstrptr++; |
| 949 |
while(ISBLANK(*cstrptr)) |
| 950 |
cstrptr++; |
| 951 |
|
| 952 |
FREE(specific_platform); |
| 953 |
specific_platform = STRDUP(cstrptr); |
| 954 |
} |
| 955 |
} |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
else if(i == 2) |
| 960 |
{ |
| 961 |
FREE(specific_platform); |
| 962 |
specific_platform = STRDUP(arg_ptr); |
| 963 |
} |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
core_ptr = (pconf_core_struct *)calloc( |
| 969 |
1, sizeof(pconf_core_struct) |
| 970 |
); |
| 971 |
if(core_ptr == NULL) |
| 972 |
{ |
| 973 |
|
| 974 |
DO_FREE_LOCALS |
| 975 |
return(3); |
| 976 |
} |
| 977 |
else |
| 978 |
{ |
| 979 |
const char *cstrptr; |
| 980 |
|
| 981 |
|
| 982 |
cstrptr = (const char *)GETENV("COLUMNS"); |
| 983 |
if(cstrptr == NULL) |
| 984 |
cstrptr = (const char *)GETENV("SCREEN_WIDTH"); |
| 985 |
if(cstrptr == NULL) |
| 986 |
cstrptr = (const char *)GETENV("SCREENWIDTH"); |
| 987 |
if(cstrptr != NULL) |
| 988 |
core_ptr->screen_width = atoi(cstrptr); |
| 989 |
|
| 990 |
core_ptr->verbose = verbose; |
| 991 |
core_ptr->warnings = warnings; |
| 992 |
core_ptr->colors = colors; |
| 993 |
core_ptr->interactive = interactive; |
| 994 |
core_ptr->force = force; |
| 995 |
core_ptr->ignore_environments = ignore_environments; |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
status = PConfLoadPlatformsFromFile(core_ptr, platforms_ini); |
| 1000 |
if(status) |
| 1001 |
{ |
| 1002 |
|
| 1003 |
PConfFreeCore(core_ptr); |
| 1004 |
core_ptr = NULL; |
| 1005 |
DO_FREE_LOCALS |
| 1006 |
return(1); |
| 1007 |
} |
| 1008 |
|
| 1009 |
if(print_platforms_level >= 0) |
| 1010 |
{ |
| 1011 |
PConfPrintPlatforms( |
| 1012 |
core_ptr, |
| 1013 |
core_ptr->platform, core_ptr->total_platforms, |
| 1014 |
specific_platform, |
| 1015 |
print_platforms_level, |
| 1016 |
0 |
| 1017 |
); |
| 1018 |
if(print_platforms_level == 0) |
| 1019 |
{ |
| 1020 |
printf( |
| 1021 |
"\n\ |
| 1022 |
For more details and features available on each platform, specify the\n\ |
| 1023 |
--listall argument. To configure for a particular platform, just specify\n\ |
| 1024 |
that platform's name.\n" |
| 1025 |
); |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
PConfFreeCore(core_ptr); |
| 1030 |
core_ptr = NULL; |
| 1031 |
DO_FREE_LOCALS |
| 1032 |
return(4); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
selected_platform = PConfMatchPlatformByName( |
| 1037 |
core_ptr->platform, core_ptr->total_platforms, |
| 1038 |
specific_platform, &selected_platform_num |
| 1039 |
); |
| 1040 |
if(selected_platform == NULL) |
| 1041 |
{ |
| 1042 |
|
| 1043 |
fprintf( |
| 1044 |
stderr, |
| 1045 |
"%s: ", |
| 1046 |
specific_platform |
| 1047 |
); |
| 1048 |
PConfSetColor(core_ptr, stderr, PCONF_COLOR_FAILURE); |
| 1049 |
fprintf( |
| 1050 |
stderr, |
| 1051 |
"No such platform.\n" |
| 1052 |
); |
| 1053 |
PConfSetColor(core_ptr, stderr, PCONF_COLOR_DEFAULT); |
| 1054 |
if(core_ptr->message_platform_unsupported == NULL) |
| 1055 |
{ |
| 1056 |
fprintf( |
| 1057 |
stderr, |
| 1058 |
"Use argument --listall to list available platforms.\n" |
| 1059 |
); |
| 1060 |
} |
| 1061 |
else |
| 1062 |
{ |
| 1063 |
fprintf( |
| 1064 |
stderr, |
| 1065 |
"%s\n", |
| 1066 |
core_ptr->message_platform_unsupported |
| 1067 |
); |
| 1068 |
} |
| 1069 |
|
| 1070 |
|
| 1071 |
PConfFreeCore(core_ptr); |
| 1072 |
core_ptr = NULL; |
| 1073 |
DO_FREE_LOCALS |
| 1074 |
return(2); |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
core_ptr->selected_platform = selected_platform; |
| 1081 |
|
| 1082 |
|
| 1083 |
if((selected_platform_num >= 0) && |
| 1084 |
(selected_platform_num < core_ptr->total_platforms) |
| 1085 |
) |
| 1086 |
core_ptr->platform[selected_platform_num] = NULL; |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
PConfFreePlatforms( |
| 1093 |
&core_ptr->platform, &core_ptr->total_platforms |
| 1094 |
); |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
if(selected_platform->name != NULL) |
| 1101 |
printf("Configuring for platform `%s'...\n", |
| 1102 |
selected_platform->name |
| 1103 |
); |
| 1104 |
if(core_ptr->message_configure_startup != NULL) |
| 1105 |
printf("%s\n", |
| 1106 |
core_ptr->message_configure_startup |
| 1107 |
); |
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
PConfApplyArgsToPlatform( |
| 1114 |
core_ptr, selected_platform, |
| 1115 |
argc, argv |
| 1116 |
); |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
status = PConfCheckDepends( |
| 1123 |
core_ptr, selected_platform |
| 1124 |
); |
| 1125 |
|
| 1126 |
if(status > 0) |
| 1127 |
{ |
| 1128 |
if(core_ptr->warnings) |
| 1129 |
{ |
| 1130 |
if(core_ptr->force) |
| 1131 |
{ |
| 1132 |
fprintf(stderr, "*** "); |
| 1133 |
PConfSetColor(core_ptr, stderr, PCONF_COLOR_FAILURE); |
| 1134 |
fprintf( |
| 1135 |
stderr, |
| 1136 |
"%i failed %s ignored (because --force used)!", |
| 1137 |
status, (status > 1) ? "dependencies" : "dependency" |
| 1138 |
); |
| 1139 |
PConfSetColor(core_ptr, stderr, PCONF_COLOR_DEFAULT); |
| 1140 |
fprintf(stderr, " ***\n"); |
| 1141 |
} |
| 1142 |
else |
| 1143 |
{ |
| 1144 |
fprintf(stderr, "*** "); |
| 1145 |
PConfSetColor(core_ptr, stderr, PCONF_COLOR_FAILURE); |
| 1146 |
fprintf( |
| 1147 |
stderr, |
| 1148 |
"%i failed %s!", |
| 1149 |
status, (status > 1) ? "dependencies" : "dependency" |
| 1150 |
); |
| 1151 |
PConfSetColor(core_ptr, stderr, PCONF_COLOR_DEFAULT); |
| 1152 |
fprintf(stderr, " ***\n"); |
| 1153 |
} |
| 1154 |
} |
| 1155 |
|
| 1156 |
|
| 1157 |
if(!core_ptr->force) |
| 1158 |
{ |
| 1159 |
if(core_ptr->message_depend_failed != NULL) |
| 1160 |
{ |
| 1161 |
fprintf( |
| 1162 |
stderr, |
| 1163 |
"%s\n", |
| 1164 |
core_ptr->message_depend_failed |
| 1165 |
); |
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
PConfFreeCore(core_ptr); |
| 1170 |
core_ptr = NULL; |
| 1171 |
DO_FREE_LOCALS |
| 1172 |
return(1); |
| 1173 |
} |
| 1174 |
} |
| 1175 |
else |
| 1176 |
{ |
| 1177 |
if(core_ptr->verbose) |
| 1178 |
{ |
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
} |
| 1187 |
} |
| 1188 |
|
| 1189 |
|
| 1190 |
if(core_ptr->verbose) |
| 1191 |
{ |
| 1192 |
PConfPrintHR(core_ptr); |
| 1193 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_HEADING); |
| 1194 |
printf("Configuration Review:\n\n"); |
| 1195 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 1196 |
PConfPrintPlatform(core_ptr, selected_platform, 3, 1); |
| 1197 |
printf("\n"); |
| 1198 |
PConfPrintHR(core_ptr); |
| 1199 |
|
| 1200 |
if(core_ptr->interactive) |
| 1201 |
{ |
| 1202 |
|
| 1203 |
} |
| 1204 |
} |
| 1205 |
|
| 1206 |
|
| 1207 |
PConfGenerateOutputMakefile( |
| 1208 |
core_ptr, selected_platform |
| 1209 |
); |
| 1210 |
|
| 1211 |
|
| 1212 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_HEADING); |
| 1213 |
printf("\nPlatform configuration completed!\n"); |
| 1214 |
PConfSetColor(core_ptr, stdout, PCONF_COLOR_DEFAULT); |
| 1215 |
|
| 1216 |
if(core_ptr->message_success != NULL) |
| 1217 |
{ |
| 1218 |
PConfPrintHR(core_ptr); |
| 1219 |
printf("%s\n", |
| 1220 |
core_ptr->message_success |
| 1221 |
); |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
PConfFreeCore(core_ptr); |
| 1230 |
core_ptr = NULL; |
| 1231 |
|
| 1232 |
|
| 1233 |
DO_FREE_LOCALS |
| 1234 |
|
| 1235 |
#undef DO_FREE_LOCALS |
| 1236 |
|
| 1237 |
return(0); |
| 1238 |
} |