2002-06-04 05:25:37 +00:00
|
|
|
/*
|
|
|
|
options.c
|
|
|
|
|
|
|
|
command line options handlnig
|
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Copyright (C) 2001 Jeff Teunissen <deek@d2dc.net>
|
2002-06-04 05:25:37 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Author: Jeff Teunissen <deek@d2dc.net>
|
|
|
|
Date: 2002/06/04
|
2002-06-04 05:25:37 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-01-15 15:31:36 +00:00
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2002-06-04 05:25:37 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "QF/pr_comp.h"
|
2002-06-04 05:25:37 +00:00
|
|
|
#include "QF/va.h"
|
|
|
|
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "cpp.h"
|
2002-11-01 18:05:12 +00:00
|
|
|
#include "linker.h"
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "options.h"
|
2002-08-20 21:13:18 +00:00
|
|
|
#include "qfcc.h"
|
2002-06-04 05:25:37 +00:00
|
|
|
|
|
|
|
const char *this_program;
|
2002-06-25 21:36:10 +00:00
|
|
|
const char **source_files;
|
|
|
|
static int num_files;
|
|
|
|
static int files_size;
|
2002-06-04 05:25:37 +00:00
|
|
|
|
|
|
|
static struct option const long_options[] = {
|
2002-06-24 22:53:21 +00:00
|
|
|
{"output-file", required_argument, 0, 'o'},
|
2002-06-04 05:25:37 +00:00
|
|
|
{"source", required_argument, 0, 's'},
|
|
|
|
{"progs-src", required_argument, 0, 'P'},
|
|
|
|
{"save-temps", no_argument, 0, 'S'},
|
|
|
|
{"quiet", no_argument, 0, 'q'},
|
|
|
|
{"verbose", no_argument, 0, 'v'},
|
|
|
|
{"code", required_argument, 0, 'C'},
|
|
|
|
{"warn", required_argument, 0, 'W'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
{"files", no_argument, 0, 'F'},
|
|
|
|
{"traditional", no_argument, 0, 't'},
|
|
|
|
{"strip-path", required_argument, 0, 'p'},
|
|
|
|
{"define", required_argument, 0, 'D'},
|
|
|
|
{"include", required_argument, 0, 'I'},
|
|
|
|
{"undefine", required_argument, 0, 'U'},
|
|
|
|
{"cpp", required_argument, 0, 256},
|
2002-06-20 19:29:06 +00:00
|
|
|
{"notice", required_argument, 0, 'N'},
|
2002-06-04 05:25:37 +00:00
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *short_options =
|
2002-06-25 21:36:10 +00:00
|
|
|
"-" // magic option parsing mode doohicky (must come first)
|
|
|
|
"l:" // lib file
|
2002-11-01 18:05:12 +00:00
|
|
|
"L:" // lib path
|
2002-06-24 22:53:21 +00:00
|
|
|
"o:" // output file
|
2002-06-21 20:46:56 +00:00
|
|
|
"c" // separate compilation
|
2002-07-12 04:50:31 +00:00
|
|
|
"r" // partial linking
|
2002-06-21 20:46:56 +00:00
|
|
|
"s:" // source dir
|
|
|
|
"P:" // progs.src name
|
2002-10-29 15:24:17 +00:00
|
|
|
"t" // traditional
|
2002-06-21 20:46:56 +00:00
|
|
|
"F" // generate files.dat
|
|
|
|
"q" // quiet
|
|
|
|
"v" // verbose
|
|
|
|
"g" // debug
|
|
|
|
"C:" // code options
|
|
|
|
"W:" // warning options
|
|
|
|
"h" // help
|
|
|
|
"V" // version
|
|
|
|
"p:" // strip path
|
|
|
|
"S" // save temps
|
|
|
|
"D:" // define
|
|
|
|
"I:" // set includes
|
|
|
|
"U:" // undefine
|
|
|
|
"N:" // notice options
|
2002-07-20 05:20:40 +00:00
|
|
|
"M::"
|
2003-02-23 23:43:43 +00:00
|
|
|
"z" // compress qfo files
|
2002-06-21 20:46:56 +00:00
|
|
|
;
|
2002-06-04 05:25:37 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage (int status)
|
|
|
|
{
|
|
|
|
printf ("%s - QuakeForge Code Compiler\n", this_program);
|
|
|
|
printf ("Usage: %s [options]\n", this_program);
|
|
|
|
printf (
|
|
|
|
"Options:\n"
|
|
|
|
" -s, --source DIR Look for progs.src in DIR instead of \".\"\n"
|
|
|
|
" -q, --quiet Inhibit usual output\n"
|
|
|
|
" -v, --verbose Display more output than usual\n"
|
|
|
|
" -g, Generate debuggin info\n"
|
|
|
|
" -C, --code OPTION,... Set code generation options\n"
|
|
|
|
" -W, --warn OPTION,... Set warning options\n"
|
2002-06-20 19:29:06 +00:00
|
|
|
" -N, --notice OPTION,... Set notice options\n"
|
2002-06-04 05:25:37 +00:00
|
|
|
" -h, --help Display this help and exit\n"
|
|
|
|
" -V, --version Output version information and exit\n\n"
|
|
|
|
" -S, --save-temps Do not delete temporary files\n"
|
|
|
|
" -D, --define SYMBOL[=VAL],... Define symbols for the preprocessor\n"
|
|
|
|
" -I, --include DIR,... Set directories for the preprocessor \n"
|
|
|
|
" to search for #includes\n"
|
|
|
|
" -U, --undefine SYMBOL,... Undefine preprocessor symbols\n\n"
|
|
|
|
"For help on options for --code and --warn, see the qfcc(1) manual page\n"
|
|
|
|
);
|
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
2002-06-25 21:36:10 +00:00
|
|
|
static void
|
|
|
|
add_file (const char *file)
|
|
|
|
{
|
|
|
|
if (num_files >= files_size - 1) {
|
|
|
|
files_size += 16;
|
|
|
|
source_files = realloc (source_files, files_size * sizeof (char *));
|
|
|
|
}
|
2002-11-01 18:05:12 +00:00
|
|
|
source_files[num_files++] = save_string (file);
|
2002-06-25 21:36:10 +00:00
|
|
|
source_files[num_files] = 0;
|
|
|
|
}
|
|
|
|
|
2002-06-04 05:25:37 +00:00
|
|
|
int
|
|
|
|
DecodeArgs (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
add_cpp_def ("-D__QFCC__=1");
|
|
|
|
add_cpp_def ("-D__QUAKEC__=1");
|
|
|
|
add_cpp_def ("-D__RUAMOKO__=1");
|
|
|
|
add_cpp_def ("-D__RAUMOKO__=1");
|
|
|
|
|
|
|
|
options.code.progsversion = PROG_VERSION;
|
|
|
|
options.warnings.uninited_variable = true;
|
|
|
|
|
|
|
|
options.save_temps = false;
|
|
|
|
options.verbosity = 0;
|
|
|
|
options.strip_path = 0;
|
|
|
|
|
|
|
|
sourcedir = "";
|
|
|
|
progs_src = "progs.src";
|
|
|
|
|
|
|
|
while ((c = getopt_long (argc, argv, short_options, long_options, 0))
|
|
|
|
!= EOF) {
|
|
|
|
switch (c) {
|
2002-06-25 21:36:10 +00:00
|
|
|
case 1: // ordinary file
|
2003-02-24 21:51:08 +00:00
|
|
|
add_file (NORMALIZE (optarg));
|
2002-06-25 21:36:10 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (options.output_file) {
|
|
|
|
fprintf (stderr, "%s: -o must not be used more than once\n",
|
|
|
|
this_program);
|
|
|
|
exit (1);
|
|
|
|
} else {
|
2003-02-24 21:51:08 +00:00
|
|
|
options.output_file = save_string (NORMALIZE (optarg));
|
2002-06-25 21:36:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l': // lib file
|
2003-02-24 21:51:08 +00:00
|
|
|
add_file (va ("-l%s", NORMALIZE (optarg)));
|
2002-06-25 21:36:10 +00:00
|
|
|
break;
|
2002-11-01 18:05:12 +00:00
|
|
|
case 'L':
|
2003-02-24 21:51:08 +00:00
|
|
|
linker_add_path (NORMALIZE (optarg));
|
2002-11-01 18:05:12 +00:00
|
|
|
break;
|
2002-06-04 05:25:37 +00:00
|
|
|
case 'h': // help
|
|
|
|
usage (0);
|
|
|
|
break;
|
|
|
|
case 'V': // version
|
|
|
|
printf ("%s version %s\n", PACKAGE, VERSION);
|
|
|
|
exit (0);
|
|
|
|
break;
|
|
|
|
case 's': // src dir
|
2003-02-24 21:51:08 +00:00
|
|
|
sourcedir = save_string (NORMALIZE (optarg));
|
2002-06-04 05:25:37 +00:00
|
|
|
break;
|
|
|
|
case 'P': // progs-src
|
2003-02-24 21:51:08 +00:00
|
|
|
progs_src = save_string (NORMALIZE (optarg));
|
2002-06-04 05:25:37 +00:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
options.strip_path = atoi (optarg);
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
options.files_dat = true;
|
|
|
|
break;
|
|
|
|
case 'q': // quiet
|
|
|
|
options.verbosity -= 1;
|
|
|
|
break;
|
|
|
|
case 'v': // verbose
|
|
|
|
options.verbosity += 1;
|
|
|
|
break;
|
|
|
|
case 'g': // debug
|
|
|
|
options.code.debug = true;
|
|
|
|
break;
|
|
|
|
case 't': // traditional
|
|
|
|
options.traditional = true;
|
|
|
|
options.code.progsversion = PROG_ID_VERSION;
|
|
|
|
break;
|
2003-02-21 22:30:49 +00:00
|
|
|
case 'c':
|
2002-06-21 20:46:56 +00:00
|
|
|
options.compile = true;
|
|
|
|
break;
|
2003-02-21 22:30:49 +00:00
|
|
|
case 'r':
|
2002-07-12 04:50:31 +00:00
|
|
|
options.partial_link = true;
|
|
|
|
break;
|
2003-02-23 23:43:43 +00:00
|
|
|
case 'z':
|
|
|
|
options.gzip = true;
|
|
|
|
break;
|
2002-06-04 05:25:37 +00:00
|
|
|
case 'C':{ // code options
|
|
|
|
char *opts = strdup (optarg);
|
|
|
|
char *temp = strtok (opts, ",");
|
|
|
|
|
|
|
|
while (temp) {
|
|
|
|
if (!(strcasecmp (temp, "cow"))) {
|
|
|
|
options.code.cow = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-cow"))) {
|
|
|
|
options.code.cow = false;
|
|
|
|
} else if (!(strcasecmp (temp, "no-cpp"))) {
|
|
|
|
cpp_name = 0;
|
|
|
|
} else if (!(strcasecmp (temp, "debug"))) {
|
|
|
|
options.code.debug = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-debug"))) {
|
|
|
|
options.code.debug = false;
|
|
|
|
} else if (!(strcasecmp (temp, "v6only"))) {
|
|
|
|
options.code.progsversion = PROG_ID_VERSION;
|
|
|
|
add_cpp_def ("-D__VERSION6__=1");
|
|
|
|
} else if (!(strcasecmp (temp, "no-v6only"))) {
|
|
|
|
options.code.progsversion = PROG_VERSION;
|
|
|
|
}
|
|
|
|
temp = strtok (NULL, ",");
|
|
|
|
}
|
|
|
|
free (opts);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'W':{ // warning options
|
|
|
|
char *opts = strdup (optarg);
|
|
|
|
char *temp = strtok (opts, ",");
|
|
|
|
|
|
|
|
while (temp) {
|
|
|
|
if (!(strcasecmp (temp, "all"))) {
|
|
|
|
options.warnings.cow = true;
|
|
|
|
options.warnings.undefined_function = true;
|
|
|
|
options.warnings.uninited_variable = true;
|
|
|
|
options.warnings.vararg_integer = true;
|
|
|
|
options.warnings.integer_divide = true;
|
|
|
|
} else if (!(strcasecmp (temp, "none"))) {
|
|
|
|
options.warnings.cow = false;
|
|
|
|
options.warnings.undefined_function = false;
|
|
|
|
options.warnings.uninited_variable = false;
|
|
|
|
options.warnings.vararg_integer = false;
|
|
|
|
options.warnings.integer_divide = false;
|
|
|
|
} else if (!(strcasecmp (temp, "cow"))) {
|
|
|
|
options.warnings.cow = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-cow"))) {
|
|
|
|
options.warnings.cow = false;
|
|
|
|
} else if (!(strcasecmp (temp, "error"))) {
|
|
|
|
options.warnings.promote = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-error"))) {
|
|
|
|
options.warnings.promote = false;
|
|
|
|
} else if (!(strcasecmp (temp, "undef-function"))) {
|
|
|
|
options.warnings.undefined_function = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-undef-function"))) {
|
|
|
|
options.warnings.undefined_function = false;
|
|
|
|
} else if (!(strcasecmp (temp, "uninited-var"))) {
|
|
|
|
options.warnings.uninited_variable = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-uninited-var"))) {
|
|
|
|
options.warnings.uninited_variable = false;
|
|
|
|
} else if (!(strcasecmp (temp, "vararg-integer"))) {
|
|
|
|
options.warnings.vararg_integer = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-vararg-integer"))) {
|
|
|
|
options.warnings.vararg_integer = false;
|
|
|
|
} else if (!(strcasecmp (temp, "integer-divide"))) {
|
|
|
|
options.warnings.integer_divide = true;
|
|
|
|
} else if (!(strcasecmp (temp, "no-integer-divide"))) {
|
|
|
|
options.warnings.integer_divide = false;
|
|
|
|
}
|
|
|
|
temp = strtok (NULL, ",");
|
2002-06-20 19:29:06 +00:00
|
|
|
}
|
|
|
|
free (opts);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'N':{ // notice options
|
|
|
|
char *opts = strdup (optarg);
|
|
|
|
char *temp = strtok (opts, ",");
|
|
|
|
|
|
|
|
while (temp) {
|
|
|
|
if (!(strcasecmp (temp, "none"))) {
|
|
|
|
options.notices.silent = true;
|
|
|
|
} else if (!(strcasecmp (temp, "warn"))) {
|
|
|
|
options.notices.promote = true;
|
|
|
|
}
|
|
|
|
temp = strtok (NULL, ",");
|
2002-06-04 05:25:37 +00:00
|
|
|
}
|
|
|
|
free (opts);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 256: // --cpp=
|
2002-11-01 18:05:12 +00:00
|
|
|
cpp_name = save_string (optarg);
|
2002-06-04 05:25:37 +00:00
|
|
|
break;
|
|
|
|
case 'S': // save temps
|
|
|
|
options.save_temps = true;
|
|
|
|
break;
|
|
|
|
case 'D':{ // defines for cpp
|
|
|
|
char *opts = strdup (optarg);
|
|
|
|
char *temp = strtok (opts, ",");
|
|
|
|
|
|
|
|
while (temp) {
|
2002-06-13 16:39:33 +00:00
|
|
|
add_cpp_def (nva ("%s%s", "-D", temp));
|
2002-06-04 05:25:37 +00:00
|
|
|
temp = strtok (NULL, ",");
|
|
|
|
}
|
|
|
|
free (opts);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'I':{ // includes
|
|
|
|
char *opts = strdup (optarg);
|
|
|
|
char *temp = strtok (opts, ",");
|
|
|
|
|
|
|
|
while (temp) {
|
2002-06-13 16:39:33 +00:00
|
|
|
add_cpp_def (nva ("%s%s", "-I", temp));
|
2002-06-04 05:25:37 +00:00
|
|
|
temp = strtok (NULL, ",");
|
|
|
|
}
|
|
|
|
free (opts);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'U':{ // undefines
|
|
|
|
char *opts = strdup (optarg);
|
|
|
|
char *temp = strtok (opts, ",");
|
|
|
|
|
|
|
|
while (temp) {
|
2002-06-13 16:39:33 +00:00
|
|
|
add_cpp_def (nva ("%s%s", "-U", temp));
|
2002-06-04 05:25:37 +00:00
|
|
|
temp = strtok (NULL, ",");
|
|
|
|
}
|
|
|
|
free (opts);
|
|
|
|
}
|
|
|
|
break;
|
2002-07-20 05:20:40 +00:00
|
|
|
case 'M':
|
2002-08-13 22:02:07 +00:00
|
|
|
if (optarg) {
|
|
|
|
add_cpp_def (nva ("-M%s", optarg));
|
|
|
|
if (!strchr (optarg, 'D'))
|
|
|
|
options.preprocess_only = 1;
|
|
|
|
if (strchr ("FQT", optarg[0]))
|
|
|
|
add_cpp_def (argv[optind++]);
|
|
|
|
} else {
|
|
|
|
options.preprocess_only = 1;
|
|
|
|
add_cpp_def (nva ("-M"));
|
|
|
|
}
|
2002-07-20 05:20:40 +00:00
|
|
|
break;
|
2002-06-04 05:25:37 +00:00
|
|
|
default:
|
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
}
|
2002-11-01 18:05:12 +00:00
|
|
|
|
|
|
|
// add the default paths
|
|
|
|
add_cpp_def (nva ("-I%s", QFCC_INCLUDE_PATH));
|
|
|
|
linker_add_path (QFCC_LIB_PATH);
|
|
|
|
|
2002-08-20 21:13:18 +00:00
|
|
|
if (options.verbosity >= 3)
|
|
|
|
yydebug = 1;
|
2002-06-04 05:25:37 +00:00
|
|
|
return optind;
|
|
|
|
}
|