1 /*****************************************************************************/
5 /* Main module for the cl65 compile and link utility */
9 /* (C) 1999-2002 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
36 /* Check out if we have a spawn() function on the system, or if we must use
39 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) || defined(__DJGPP__)
71 /*****************************************************************************/
73 /*****************************************************************************/
77 /* Struct that describes a command */
78 typedef struct CmdDesc CmdDesc;
80 char* Name; /* The command name */
82 unsigned ArgCount; /* Count of arguments */
83 unsigned ArgMax; /* Maximum count of arguments */
84 char** Args; /* The arguments */
86 unsigned FileCount; /* Count of files to translate */
87 unsigned FileMax; /* Maximum count of files */
88 char** Files; /* The files */
91 /* Command descriptors for the different programs */
92 static CmdDesc CC65 = { 0, 0, 0, 0, 0, 0, 0 };
93 static CmdDesc CA65 = { 0, 0, 0, 0, 0, 0, 0 };
94 static CmdDesc LD65 = { 0, 0, 0, 0, 0, 0, 0 };
95 static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 };
104 FILETYPE_GR /* GEOS resource file */
107 /* Default file type, used if type unknown */
108 static unsigned DefaultFileType = FILETYPE_UNKNOWN;
110 /* Variables controlling the steps we're doing */
111 static int DontLink = 0;
112 static int DontAssemble = 0;
114 /* The name of the output file, NULL if none given */
115 static const char* OutputName = 0;
117 /* The name of the linker configuration file if given */
118 static const char* LinkerConfig = 0;
120 /* The name of the first input file. This will be used to construct the
121 * executable file name if no explicit name is given.
123 static const char* FirstInput = 0;
125 /* Remember if we should link a module */
126 static int Module = 0;
128 /* Extension used for a module */
129 #define MODULE_EXT ".o65"
131 /* Name of the crt0 object file and the runtime library */
132 static char* TargetCRT0 = 0;
133 static char* TargetLib = 0;
137 /*****************************************************************************/
138 /* Include the system specific spawn function */
139 /*****************************************************************************/
143 #if defined(NEED_SPAWN)
144 # if defined(SPAWN_UNIX)
145 # include "spawn-unix.inc"
146 # elif defined(SPAWN_AMIGA)
147 # include "spawn-amiga.inc"
149 # error "Don't know which spawn module to include!"
155 /*****************************************************************************/
156 /* Determine a file type */
157 /*****************************************************************************/
161 static unsigned GetFileType (const char* File)
162 /* Determine the type of the given file */
164 /* Table mapping extensions to file types */
165 static const struct {
169 { ".c", FILETYPE_C },
170 { ".s", FILETYPE_ASM },
171 { ".asm", FILETYPE_ASM },
172 { ".a65", FILETYPE_ASM },
173 { ".o", FILETYPE_OBJ },
174 { ".obj", FILETYPE_OBJ },
175 { ".a", FILETYPE_LIB },
176 { ".lib", FILETYPE_LIB },
177 { ".grc", FILETYPE_GR },
182 /* Determine the file type by the extension */
183 const char* Ext = FindExt (File);
185 /* Do we have an extension? */
187 return DefaultFileType;
190 /* Check for known extensions */
191 for (I = 0; I < sizeof (FileTypes) / sizeof (FileTypes [0]); ++I) {
192 if (strcmp (FileTypes [I].Ext, Ext) == 0) {
194 return FileTypes [I].Type;
198 /* Not found, return the default */
199 return DefaultFileType;
204 /*****************************************************************************/
205 /* Command structure handling */
206 /*****************************************************************************/
210 static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
211 /* Add a new argument to the command */
213 /* Expand the argument vector if needed */
214 if (Cmd->ArgCount == Cmd->ArgMax) {
215 unsigned NewMax = Cmd->ArgMax + 10;
216 char** NewArgs = xmalloc (NewMax * sizeof (char*));
217 memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
220 Cmd->ArgMax = NewMax;
223 /* Add a copy of the new argument, allow a NULL pointer */
225 Cmd->Args [Cmd->ArgCount++] = xstrdup (Arg);
227 Cmd->Args [Cmd->ArgCount++] = 0;
233 static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
234 /* Remove all arguments with an index greater than LastValid */
236 while (Cmd->ArgCount > LastValid) {
238 xfree (Cmd->Args [Cmd->ArgCount]);
239 Cmd->Args [Cmd->ArgCount] = 0;
245 static void CmdAddFile (CmdDesc* Cmd, const char* File)
246 /* Add a new file to the command */
248 /* Expand the file vector if needed */
249 if (Cmd->FileCount == Cmd->FileMax) {
250 unsigned NewMax = Cmd->FileMax + 10;
251 char** NewFiles = xmalloc (NewMax * sizeof (char*));
252 memcpy (NewFiles, Cmd->Files, Cmd->FileMax * sizeof (char*));
254 Cmd->Files = NewFiles;
255 Cmd->FileMax = NewMax;
258 /* If the file name is not NULL (which is legal and is used to terminate
259 * the file list), check if the file name does already exist in the file
260 * list and print a warning if so. Regardless of the search result, add
265 for (I = 0; I < Cmd->FileCount; ++I) {
266 if (strcmp (Cmd->Files[I], File) == 0) {
268 Warning ("Duplicate file in argument list: `%s'", File);
269 /* No need to search further */
275 Cmd->Files [Cmd->FileCount++] = xstrdup (File);
277 /* Add a NULL pointer */
278 Cmd->Files [Cmd->FileCount++] = 0;
284 static void CmdInit (CmdDesc* Cmd, const char* Path)
285 /* Initialize the command using the given path to the executable */
287 /* Remember the command */
288 Cmd->Name = xstrdup (Path);
290 /* Use the command name as first argument */
291 CmdAddArg (Cmd, Path);
296 static void CmdSetOutput (CmdDesc* Cmd, const char* File)
297 /* Set the output file in a command desc */
299 CmdAddArg (Cmd, "-o");
300 CmdAddArg (Cmd, File);
305 static void CmdSetTarget (CmdDesc* Cmd, target_t Target)
306 /* Set the output file in a command desc */
308 CmdAddArg (Cmd, "-t");
309 CmdAddArg (Cmd, TargetNames[Target]);
314 static void CmdPrint (CmdDesc* Cmd, FILE* F)
315 /* Output the command line encoded in the command desc */
318 for (I = 0; I < Cmd->ArgCount && Cmd->Args[I] != 0; ++I) {
319 fprintf (F, "%s ", Cmd->Args[I]);
325 /*****************************************************************************/
326 /* Target handling */
327 /*****************************************************************************/
331 static void SetTargetFiles (void)
332 /* Set the target system files */
334 /* Determine the names of the default startup and library file */
335 if (Target != TGT_NONE) {
337 /* Get a pointer to the system name and its length */
338 const char* TargetName = TargetNames [Target];
339 unsigned TargetNameLen = strlen (TargetName);
341 /* Set the startup file */
342 TargetCRT0 = xmalloc (TargetNameLen + 2 + 1);
343 strcpy (TargetCRT0, TargetName);
344 strcat (TargetCRT0, ".o");
346 /* Set the library file */
347 TargetLib = xmalloc (TargetNameLen + 4 + 1);
348 strcpy (TargetLib, TargetName);
349 strcat (TargetLib, ".lib");
356 /*****************************************************************************/
358 /*****************************************************************************/
362 static void ExecProgram (CmdDesc* Cmd)
363 /* Execute a subprocess with the given name/parameters. Exit on errors. */
367 /* If in debug mode, output the command line we will execute */
369 printf ("Executing: ");
370 CmdPrint (Cmd, stdout);
374 /* Call the program */
375 Status = spawnvp (P_WAIT, Cmd->Name, Cmd->Args);
377 /* Check the result code */
379 /* Error executing the program */
380 Error ("Cannot execute `%s': %s", Cmd->Name, strerror (errno));
381 } else if (Status != 0) {
382 /* Called program had an error */
389 static void Link (void)
390 /* Link the resulting executable */
394 /* If we have a linker config file given, add it to the command line.
395 * Otherwise pass the target to the linker if we have one.
399 Error ("Cannot use -C and --module together");
401 CmdAddArg (&LD65, "-C");
402 CmdAddArg (&LD65, LinkerConfig);
404 CmdSetTarget (&LD65, TGT_MODULE);
405 } else if (Target != TGT_NONE) {
406 CmdSetTarget (&LD65, Target);
409 /* Determine which target libraries are needed */
412 /* Since linking is always the final step, if we have an output file name
413 * given, set it here. If we don't have an explicit output name given,
414 * try to build one from the name of the first input file.
418 CmdSetOutput (&LD65, OutputName);
420 } else if (FirstInput && FindExt (FirstInput)) { /* Only if ext present! */
422 const char* Extension = Module? MODULE_EXT : "";
423 char* Output = MakeFilename (FirstInput, Extension);
424 CmdSetOutput (&LD65, Output);
429 /* If we have a startup file and if we are not linking a module, add its
430 * name as a parameter
432 if (TargetCRT0 && !Module) {
433 CmdAddArg (&LD65, TargetCRT0);
436 /* Add all object files as parameters */
437 for (I = 0; I < LD65.FileCount; ++I) {
438 CmdAddArg (&LD65, LD65.Files [I]);
441 /* Add the system runtime library */
443 CmdAddArg (&LD65, TargetLib);
446 /* Terminate the argument list with a NULL pointer */
447 CmdAddArg (&LD65, 0);
449 /* Call the linker */
455 static void Assemble (const char* File)
456 /* Assemble the given file */
458 /* Remember the current assembler argument count */
459 unsigned ArgCount = CA65.ArgCount;
461 /* Set the target system */
462 CmdSetTarget (&CA65, Target);
464 /* If we won't link, this is the final step. In this case, set the
467 if (DontLink && OutputName) {
468 CmdSetOutput (&CA65, OutputName);
470 /* The object file name will be the name of the source file
471 * with .s replaced by ".o". Add this file to the list of
474 char* ObjName = MakeFilename (File, ".o");
475 CmdAddFile (&LD65, ObjName);
479 /* Add the file as argument for the assembler */
480 CmdAddArg (&CA65, File);
482 /* Add a NULL pointer to terminate the argument list */
483 CmdAddArg (&CA65, 0);
485 /* Run the assembler */
488 /* Remove the excess arguments */
489 CmdDelArgs (&CA65, ArgCount);
494 static void Compile (const char* File)
495 /* Compile the given file */
499 /* Remember the current assembler argument count */
500 unsigned ArgCount = CC65.ArgCount;
502 /* Set the target system */
503 CmdSetTarget (&CC65, Target);
505 /* If we won't link, this is the final step. In this case, set the
508 if (DontAssemble && OutputName) {
509 CmdSetOutput (&CC65, OutputName);
511 /* The assembler file name will be the name of the source file
512 * with .c replaced by ".s".
514 AsmName = MakeFilename (File, ".s");
517 /* Add the file as argument for the compiler */
518 CmdAddArg (&CC65, File);
520 /* Add a NULL pointer to terminate the argument list */
521 CmdAddArg (&CC65, 0);
523 /* Run the compiler */
526 /* Remove the excess arguments */
527 CmdDelArgs (&CC65, ArgCount);
529 /* If this is not the final step, assemble the generated file, then
534 if (remove (AsmName) < 0) {
535 Warning ("Cannot remove temporary file `%s': %s",
536 AsmName, strerror (errno));
544 static void CompileRes (const char* File)
545 /* Compile the given geos resource file */
549 /* Remember the current assembler argument count */
550 unsigned ArgCount = GRC.ArgCount;
552 /* The assembler file name will be the name of the source file
553 * with .grc replaced by ".s".
555 AsmName = MakeFilename (File, ".s");
557 /* Add the file as argument for the resource compiler */
558 CmdAddArg (&GRC, File);
560 /* Add a NULL pointer to terminate the argument list */
563 /* Run the compiler */
566 /* Remove the excess arguments */
567 CmdDelArgs (&GRC, ArgCount);
569 /* If this is not the final step, assemble the generated file, then
574 if (remove (AsmName) < 0) {
575 Warning ("Cannot remove temporary file `%s': %s",
576 AsmName, strerror (errno));
580 /* Free the assembler file name which was allocated from the heap */
586 /*****************************************************************************/
588 /*****************************************************************************/
592 static void Usage (void)
593 /* Print usage information and exit */
596 "Usage: %s [options] file [...]\n"
598 " -c\t\t\tCompile and assemble but don't link\n"
599 " -d\t\t\tDebug mode\n"
600 " -g\t\t\tAdd debug info\n"
601 " -h\t\t\tHelp (this text)\n"
602 " -l\t\t\tCreate an assembler listing\n"
603 " -m name\t\tCreate a map file\n"
604 " -o name\t\tName the output file\n"
605 " -r\t\t\tEnable register variables\n"
606 " -t sys\t\tSet the target system\n"
607 " -v\t\t\tVerbose mode\n"
608 " -vm\t\t\tVerbose map file\n"
609 " -A\t\t\tStrict ANSI mode\n"
610 " -C name\t\tUse linker config file\n"
611 " -Cl\t\t\tMake local variables static\n"
612 " -D sym[=defn]\t\tDefine a preprocessor symbol\n"
613 " -I dir\t\tSet a compiler include directory path\n"
614 " -Ln name\t\tCreate a VICE label file\n"
615 " -O\t\t\tOptimize code\n"
616 " -Oi\t\t\tOptimize code, inline functions\n"
617 " -Or\t\t\tOptimize code, honour the register keyword\n"
618 " -Os\t\t\tOptimize code, inline known C funtions\n"
619 " -S\t\t\tCompile but don't assemble and link\n"
620 " -T\t\t\tInclude source as comment\n"
621 " -V\t\t\tPrint the version number\n"
622 " -W\t\t\tSuppress warnings\n"
625 " --add-source\t\tInclude source as comment\n"
626 " --ansi\t\tStrict ANSI mode\n"
627 " --asm-include-dir dir\tSet an assembler include directory\n"
628 " --bss-name seg\tSet the name of the BSS segment\n"
629 " --check-stack\t\tGenerate stack overflow checks\n"
630 " --code-name seg\tSet the name of the CODE segment\n"
631 " --codesize x\t\tAccept larger code by factor x\n"
632 " --cpu type\t\tSet cpu type\n"
633 " --create-dep\t\tCreate a make dependency file\n"
634 " --data-name seg\tSet the name of the DATA segment\n"
635 " --debug\t\tDebug mode\n"
636 " --debug-info\t\tAdd debug info\n"
637 " --feature name\tSet an emulation feature\n"
638 " --help\t\tHelp (this text)\n"
639 " --include-dir dir\tSet a compiler include directory path\n"
640 " --listing\t\tCreate an assembler listing\n"
641 " --mapfile name\tCreate a map file\n"
642 " --module\t\tLink as a module\n"
643 " --module-id id\tSpecify a module id for the linker\n"
644 " --register-space b\tSet space available for register variables\n"
645 " --register-vars\tEnable register variables\n"
646 " --rodata-name seg\tSet the name of the RODATA segment\n"
647 " --signed-chars\tDefault characters are signed\n"
648 " --start-addr addr\tSet the default start address\n"
649 " --static-locals\tMake local variables static\n"
650 " --target sys\t\tSet the target system\n"
651 " --version\t\tPrint the version number\n"
652 " --verbose\t\tVerbose mode\n",
658 static void OptAddSource (const char* Opt attribute ((unused)),
659 const char* Arg attribute ((unused)))
660 /* Strict source code as comments to the generated asm code */
662 CmdAddArg (&CC65, "-T");
667 static void OptAnsi (const char* Opt attribute ((unused)),
668 const char* Arg attribute ((unused)))
669 /* Strict ANSI mode (compiler) */
671 CmdAddArg (&CC65, "-A");
676 static void OptAsmIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
677 /* Include directory (assembler) */
679 CmdAddArg (&CA65, "-I");
680 CmdAddArg (&CA65, Arg);
685 static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
686 /* Handle the --bss-name option */
688 CmdAddArg (&CC65, "--bss-name");
689 CmdAddArg (&CC65, Arg);
694 static void OptCheckStack (const char* Opt attribute ((unused)),
695 const char* Arg attribute ((unused)))
696 /* Handle the --check-stack option */
698 CmdAddArg (&CC65, "--check-stack");
703 static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg)
704 /* Handle the --code-name option */
706 CmdAddArg (&CC65, "--code-name");
707 CmdAddArg (&CC65, Arg);
712 static void OptCodeSize (const char* Opt attribute ((unused)), const char* Arg)
713 /* Handle the --codesize option */
715 CmdAddArg (&CC65, "--codesize");
716 CmdAddArg (&CC65, Arg);
721 static void OptCPU (const char* Opt attribute ((unused)), const char* Arg)
722 /* Handle the --cpu option */
724 /* Add the cpu type to the assembler and compiler */
725 CmdAddArg (&CA65, "--cpu");
726 CmdAddArg (&CA65, Arg);
727 CmdAddArg (&CC65, "--cpu");
728 CmdAddArg (&CC65, Arg);
733 static void OptCreateDep (const char* Opt attribute ((unused)),
734 const char* Arg attribute ((unused)))
735 /* Handle the --create-dep option */
737 CmdAddArg (&CC65, "--create-dep");
742 static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
743 /* Handle the --data-name option */
745 CmdAddArg (&CC65, "--data-name");
746 CmdAddArg (&CC65, Arg);
751 static void OptDebug (const char* Opt attribute ((unused)),
752 const char* Arg attribute ((unused)))
753 /* Debug mode (compiler and cl65 utility) */
755 CmdAddArg (&CC65, "-d");
761 static void OptDebugInfo (const char* Opt attribute ((unused)),
762 const char* Arg attribute ((unused)))
763 /* Debug Info - add to compiler and assembler */
765 CmdAddArg (&CC65, "-g");
766 CmdAddArg (&CA65, "-g");
771 static void OptFeature (const char* Opt attribute ((unused)), const char* Arg)
772 /* Emulation features for the assembler */
774 CmdAddArg (&CA65, "--feature");
775 CmdAddArg (&CA65, Arg);
780 static void OptHelp (const char* Opt attribute ((unused)),
781 const char* Arg attribute ((unused)))
782 /* Print help - cl65 */
790 static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
791 /* Include directory (compiler) */
793 CmdAddArg (&CC65, "-I");
794 CmdAddArg (&CC65, Arg);
799 static void OptListing (const char* Opt attribute ((unused)),
800 const char* Arg attribute ((unused)))
801 /* Create an assembler listing */
803 CmdAddArg (&CA65, "-l");
808 static void OptMapFile (const char* Opt attribute ((unused)), const char* Arg)
809 /* Create a map file */
811 /* Create a map file (linker) */
812 CmdAddArg (&LD65, "-m");
813 CmdAddArg (&LD65, Arg);
818 static void OptModule (const char* Opt attribute ((unused)),
819 const char* Arg attribute ((unused)))
820 /* Link as a module */
827 static void OptModuleId (const char* Opt attribute ((unused)), const char* Arg)
828 /* Specify a module if for the linker */
830 /* Pass it straight to the linker */
831 CmdAddArg (&LD65, "--module-id");
832 CmdAddArg (&LD65, Arg);
837 static void OptRegisterSpace (const char* Opt attribute ((unused)), const char* Arg)
838 /* Handle the --register-space option */
840 CmdAddArg (&CC65, "--register-space");
841 CmdAddArg (&CC65, Arg);
846 static void OptRegisterVars (const char* Opt attribute ((unused)),
847 const char* Arg attribute ((unused)))
848 /* Handle the --register-vars option */
850 CmdAddArg (&CC65, "-r");
855 static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg)
856 /* Handle the --rodata-name option */
858 CmdAddArg (&CC65, "--rodata-name");
859 CmdAddArg (&CC65, Arg);
864 static void OptSignedChars (const char* Opt attribute ((unused)),
865 const char* Arg attribute ((unused)))
866 /* Make default characters signed */
868 CmdAddArg (&CC65, "-j");
873 static void OptStartAddr (const char* Opt attribute ((unused)), const char* Arg)
874 /* Set the default start address */
876 CmdAddArg (&LD65, "-S");
877 CmdAddArg (&LD65, Arg);
882 static void OptStaticLocals (const char* Opt attribute ((unused)),
883 const char* Arg attribute ((unused)))
884 /* Place local variables in static storage */
886 CmdAddArg (&CC65, "-Cl");
891 static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
892 /* Set the target system */
894 Target = FindTarget (Arg);
895 if (Target == TGT_UNKNOWN) {
896 Error ("No such target system: `%s'", Arg);
897 } else if (Target == TGT_MODULE) {
898 Error ("Cannot use `module' as target, use --module instead");
904 static void OptVerbose (const char* Opt attribute ((unused)),
905 const char* Arg attribute ((unused)))
906 /* Verbose mode (compiler, assembler, linker) */
908 CmdAddArg (&CC65, "-v");
909 CmdAddArg (&CA65, "-v");
910 CmdAddArg (&LD65, "-v");
915 static void OptVersion (const char* Opt attribute ((unused)),
916 const char* Arg attribute ((unused)))
917 /* Print version number */
920 "cl65 V%u.%u.%u - (C) Copyright 1998-2002 Ullrich von Bassewitz\n",
921 VER_MAJOR, VER_MINOR, VER_PATCH);
926 int main (int argc, char* argv [])
927 /* Utility main program */
929 /* Program long options */
930 static const LongOpt OptTab[] = {
931 { "--add-source", 0, OptAddSource },
932 { "--ansi", 0, OptAnsi },
933 { "--asm-include-dir", 1, OptAsmIncludeDir },
934 { "--bss-name", 1, OptBssName },
935 { "--check-stack", 0, OptCheckStack },
936 { "--code-name", 1, OptCodeName },
937 { "--codesize", 1, OptCodeSize },
938 { "--cpu", 1, OptCPU },
939 { "--create-dep", 0, OptCreateDep },
940 { "--data-name", 1, OptDataName },
941 { "--debug", 0, OptDebug },
942 { "--debug-info", 0, OptDebugInfo },
943 { "--feature", 1, OptFeature },
944 { "--help", 0, OptHelp },
945 { "--include-dir", 1, OptIncludeDir },
946 { "--listing", 0, OptListing },
947 { "--mapfile", 1, OptMapFile },
948 { "--module", 0, OptModule },
949 { "--module-id", 1, OptModuleId },
950 { "--register-space", 1, OptRegisterSpace },
951 { "--register-vars", 0, OptRegisterVars },
952 { "--rodata-name", 1, OptRodataName },
953 { "--signed-chars", 0, OptSignedChars },
954 { "--start-addr", 1, OptStartAddr },
955 { "--static-locals", 0, OptStaticLocals },
956 { "--target", 1, OptTarget },
957 { "--verbose", 0, OptVerbose },
958 { "--version", 0, OptVersion },
963 /* Initialize the cmdline module */
964 InitCmdLine (&argc, &argv, "cl65");
966 /* Initialize the command descriptors */
967 CmdInit (&CC65, "cc65");
968 CmdInit (&CA65, "ca65");
969 CmdInit (&LD65, "ld65");
970 CmdInit (&GRC, "grc");
972 /* Our default target is the C64 instead of "none" */
975 /* Check the parameters */
977 while (I < ArgCount) {
979 /* Get the argument */
980 const char* Arg = ArgVec[I];
982 /* Check for an option */
983 if (Arg [0] == '-') {
988 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
992 /* Strict ANSI mode (compiler) */
997 if (Arg[2] == 'l' && Arg[3] == '\0') {
998 /* Make local variables static */
999 OptStaticLocals (Arg, 0);
1001 /* Specify linker config file */
1002 LinkerConfig = GetArg (&I, 2);
1007 /* Define a preprocessor symbol (compiler) */
1008 CmdAddArg (&CC65, "-D");
1009 CmdAddArg (&CC65, GetArg (&I, 2));
1013 /* Include directory (compiler) */
1014 OptIncludeDir (Arg, GetArg (&I, 2));
1018 if (Arg[2] == 'n') {
1019 /* VICE label file (linker) */
1020 CmdAddArg (&LD65, "-Ln");
1021 CmdAddArg (&LD65, GetArg (&I, 3));
1023 UnknownOption (Arg);
1028 /* Optimize code (compiler, also covers -Oi and others) */
1029 CmdAddArg (&CC65, Arg);
1033 /* Dont assemble and link the created files */
1034 DontLink = DontAssemble = 1;
1038 /* Include source as comment (compiler) */
1039 OptAddSource (Arg, 0);
1043 /* Print version number */
1044 OptVersion (Arg, 0);
1048 /* Suppress warnings - compiler and assembler */
1049 CmdAddArg (&CC65, "-W");
1050 CmdAddArg (&CA65, "-W");
1051 CmdAddArg (&CA65, "0");
1055 /* Don't link the resulting files */
1060 /* Debug mode (compiler) */
1065 /* Debugging - add to compiler and assembler */
1066 OptDebugInfo (Arg, 0);
1071 /* Print help - cl65 */
1076 /* Default characters are signed */
1077 OptSignedChars (Arg, 0);
1081 /* Create an assembler listing */
1082 OptListing (Arg, 0);
1086 /* Create a map file (linker) */
1087 OptMapFile (Arg, GetArg (&I, 2));
1091 /* Name the output file */
1092 OutputName = GetArg (&I, 2);
1096 /* Enable register variables */
1097 OptRegisterVars (Arg, 0);
1101 /* Set target system - compiler, assembler and linker */
1102 OptTarget (Arg, GetArg (&I, 2));
1106 if (Arg [2] == 'm') {
1107 /* Verbose map file (linker) */
1108 CmdAddArg (&LD65, "-vm");
1110 /* Verbose mode (compiler, assembler, linker) */
1111 OptVerbose (Arg, 0);
1116 UnknownOption (Arg);
1120 /* Remember the first file name */
1121 if (FirstInput == 0) {
1125 /* Determine the file type by the extension */
1126 switch (GetFileType (Arg)) {
1129 /* Compile the file */
1134 /* Assemble the file */
1135 if (!DontAssemble) {
1142 /* Add to the linker files */
1143 CmdAddFile (&LD65, Arg);
1147 /* Add to the resource compiler files */
1152 Error ("Don't know what to do with `%s'", Arg);
1162 /* Check if we had any input files */
1163 if (FirstInput == 0) {
1164 Warning ("No input files");
1167 /* Link the given files if requested and if we have any */
1168 if (DontLink == 0 && LD65.FileCount > 0) {
1172 /* Return an apropriate exit code */
1173 return EXIT_SUCCESS;