1 /*****************************************************************************/
5 /* Main module for the cl65 compile and link utility */
9 /* (C) 1999-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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 CO65 = { 0, 0, 0, 0, 0, 0, 0 };
95 static CmdDesc LD65 = { 0, 0, 0, 0, 0, 0, 0 };
96 static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 };
105 FILETYPE_GR, /* GEOS resource file */
106 FILETYPE_O65 /* O65 object file */
109 /* Default file type, used if type unknown */
110 static unsigned DefaultFileType = FILETYPE_UNKNOWN;
112 /* Variables controlling the steps we're doing */
113 static int DontLink = 0;
114 static int DontAssemble = 0;
116 /* The name of the output file, NULL if none given */
117 static const char* OutputName = 0;
119 /* The name of the linker configuration file if given */
120 static const char* LinkerConfig = 0;
122 /* The name of the first input file. This will be used to construct the
123 * executable file name if no explicit name is given.
125 static const char* FirstInput = 0;
127 /* Remember if we should link a module */
128 static int Module = 0;
130 /* Extension used for a module */
131 #define MODULE_EXT ".o65"
133 /* Name of the crt0 object file and the runtime library */
134 static char* TargetCRT0 = 0;
135 static char* TargetLib = 0;
139 /*****************************************************************************/
140 /* Include the system specific spawn function */
141 /*****************************************************************************/
145 #if defined(NEED_SPAWN)
146 # if defined(SPAWN_UNIX)
147 # include "spawn-unix.inc"
148 # elif defined(SPAWN_AMIGA)
149 # include "spawn-amiga.inc"
151 # error "Don't know which spawn module to include!"
157 /*****************************************************************************/
158 /* Determine a file type */
159 /*****************************************************************************/
163 static unsigned GetFileType (const char* File)
164 /* Determine the type of the given file */
166 /* Table mapping extensions to file types */
167 static const struct {
171 { ".c", FILETYPE_C },
172 { ".s", FILETYPE_ASM },
173 { ".asm", FILETYPE_ASM },
174 { ".a65", FILETYPE_ASM },
175 { ".o", FILETYPE_OBJ },
176 { ".obj", FILETYPE_OBJ },
177 { ".a", FILETYPE_LIB },
178 { ".lib", FILETYPE_LIB },
179 { ".grc", FILETYPE_GR },
180 { ".o65", FILETYPE_O65 },
181 { ".emd", FILETYPE_O65 },
182 { ".joy", FILETYPE_O65 },
183 { ".tgi", FILETYPE_O65 },
188 /* Determine the file type by the extension */
189 const char* Ext = FindExt (File);
191 /* Do we have an extension? */
193 return DefaultFileType;
196 /* Check for known extensions */
197 for (I = 0; I < sizeof (FileTypes) / sizeof (FileTypes [0]); ++I) {
198 if (strcmp (FileTypes [I].Ext, Ext) == 0) {
200 return FileTypes [I].Type;
204 /* Not found, return the default */
205 return DefaultFileType;
210 /*****************************************************************************/
211 /* Command structure handling */
212 /*****************************************************************************/
216 static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
217 /* Add a new argument to the command */
219 /* Expand the argument vector if needed */
220 if (Cmd->ArgCount == Cmd->ArgMax) {
221 unsigned NewMax = Cmd->ArgMax + 10;
222 char** NewArgs = xmalloc (NewMax * sizeof (char*));
223 memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
226 Cmd->ArgMax = NewMax;
229 /* Add a copy of the new argument, allow a NULL pointer */
231 Cmd->Args [Cmd->ArgCount++] = xstrdup (Arg);
233 Cmd->Args [Cmd->ArgCount++] = 0;
239 static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
240 /* Remove all arguments with an index greater than LastValid */
242 while (Cmd->ArgCount > LastValid) {
244 xfree (Cmd->Args [Cmd->ArgCount]);
245 Cmd->Args [Cmd->ArgCount] = 0;
251 static void CmdAddFile (CmdDesc* Cmd, const char* File)
252 /* Add a new file to the command */
254 /* Expand the file vector if needed */
255 if (Cmd->FileCount == Cmd->FileMax) {
256 unsigned NewMax = Cmd->FileMax + 10;
257 char** NewFiles = xmalloc (NewMax * sizeof (char*));
258 memcpy (NewFiles, Cmd->Files, Cmd->FileMax * sizeof (char*));
260 Cmd->Files = NewFiles;
261 Cmd->FileMax = NewMax;
264 /* If the file name is not NULL (which is legal and is used to terminate
265 * the file list), check if the file name does already exist in the file
266 * list and print a warning if so. Regardless of the search result, add
271 for (I = 0; I < Cmd->FileCount; ++I) {
272 if (strcmp (Cmd->Files[I], File) == 0) {
274 Warning ("Duplicate file in argument list: `%s'", File);
275 /* No need to search further */
281 Cmd->Files [Cmd->FileCount++] = xstrdup (File);
283 /* Add a NULL pointer */
284 Cmd->Files [Cmd->FileCount++] = 0;
290 static void CmdInit (CmdDesc* Cmd, const char* Path)
291 /* Initialize the command using the given path to the executable */
293 /* Remember the command */
294 Cmd->Name = xstrdup (Path);
296 /* Use the command name as first argument */
297 CmdAddArg (Cmd, Path);
302 static void CmdSetOutput (CmdDesc* Cmd, const char* File)
303 /* Set the output file in a command desc */
305 CmdAddArg (Cmd, "-o");
306 CmdAddArg (Cmd, File);
311 static void CmdSetTarget (CmdDesc* Cmd, target_t Target)
312 /* Set the output file in a command desc */
314 CmdAddArg (Cmd, "-t");
315 CmdAddArg (Cmd, TargetNames[Target]);
320 static void CmdPrint (CmdDesc* Cmd, FILE* F)
321 /* Output the command line encoded in the command desc */
324 for (I = 0; I < Cmd->ArgCount && Cmd->Args[I] != 0; ++I) {
325 fprintf (F, "%s ", Cmd->Args[I]);
331 /*****************************************************************************/
332 /* Target handling */
333 /*****************************************************************************/
337 static void SetTargetFiles (void)
338 /* Set the target system files */
340 /* Determine the names of the default startup and library file */
341 if (Target != TGT_NONE) {
343 /* Get a pointer to the system name and its length */
344 const char* TargetName = TargetNames [Target];
345 unsigned TargetNameLen = strlen (TargetName);
347 /* Set the startup file */
348 TargetCRT0 = xmalloc (TargetNameLen + 2 + 1);
349 strcpy (TargetCRT0, TargetName);
350 strcat (TargetCRT0, ".o");
352 /* Set the library file */
353 TargetLib = xmalloc (TargetNameLen + 4 + 1);
354 strcpy (TargetLib, TargetName);
355 strcat (TargetLib, ".lib");
362 /*****************************************************************************/
364 /*****************************************************************************/
368 static void ExecProgram (CmdDesc* Cmd)
369 /* Execute a subprocess with the given name/parameters. Exit on errors. */
373 /* If in debug mode, output the command line we will execute */
375 printf ("Executing: ");
376 CmdPrint (Cmd, stdout);
380 /* Call the program */
381 Status = spawnvp (P_WAIT, Cmd->Name, Cmd->Args);
383 /* Check the result code */
385 /* Error executing the program */
386 Error ("Cannot execute `%s': %s", Cmd->Name, strerror (errno));
387 } else if (Status != 0) {
388 /* Called program had an error */
395 static void Link (void)
396 /* Link the resulting executable */
400 /* If we have a linker config file given, add it to the command line.
401 * Otherwise pass the target to the linker if we have one.
405 Error ("Cannot use -C and --module together");
407 CmdAddArg (&LD65, "-C");
408 CmdAddArg (&LD65, LinkerConfig);
410 CmdSetTarget (&LD65, TGT_MODULE);
411 } else if (Target != TGT_NONE) {
412 CmdSetTarget (&LD65, Target);
415 /* Determine which target libraries are needed */
418 /* Since linking is always the final step, if we have an output file name
419 * given, set it here. If we don't have an explicit output name given,
420 * try to build one from the name of the first input file.
424 CmdSetOutput (&LD65, OutputName);
426 } else if (FirstInput && FindExt (FirstInput)) { /* Only if ext present! */
428 const char* Extension = Module? MODULE_EXT : "";
429 char* Output = MakeFilename (FirstInput, Extension);
430 CmdSetOutput (&LD65, Output);
435 /* If we have a startup file and if we are not linking a module, add its
436 * name as a parameter
438 if (TargetCRT0 && !Module) {
439 CmdAddArg (&LD65, TargetCRT0);
442 /* Add all object files as parameters */
443 for (I = 0; I < LD65.FileCount; ++I) {
444 CmdAddArg (&LD65, LD65.Files [I]);
447 /* Add the system runtime library */
449 CmdAddArg (&LD65, TargetLib);
452 /* Terminate the argument list with a NULL pointer */
453 CmdAddArg (&LD65, 0);
455 /* Call the linker */
461 static void Assemble (const char* File)
462 /* Assemble the given file */
464 /* Remember the current assembler argument count */
465 unsigned ArgCount = CA65.ArgCount;
467 /* Set the target system */
468 CmdSetTarget (&CA65, Target);
470 /* If we won't link, this is the final step. In this case, set the
473 if (DontLink && OutputName) {
474 CmdSetOutput (&CA65, OutputName);
476 /* The object file name will be the name of the source file
477 * with .s replaced by ".o". Add this file to the list of
480 char* ObjName = MakeFilename (File, ".o");
481 CmdAddFile (&LD65, ObjName);
485 /* Add the file as argument for the assembler */
486 CmdAddArg (&CA65, File);
488 /* Add a NULL pointer to terminate the argument list */
489 CmdAddArg (&CA65, 0);
491 /* Run the assembler */
494 /* Remove the excess arguments */
495 CmdDelArgs (&CA65, ArgCount);
500 static void Compile (const char* File)
501 /* Compile the given file */
505 /* Remember the current compiler argument count */
506 unsigned ArgCount = CC65.ArgCount;
508 /* Set the target system */
509 CmdSetTarget (&CC65, Target);
511 /* If we won't link, this is the final step. In this case, set the
514 if (DontAssemble && OutputName) {
515 CmdSetOutput (&CC65, OutputName);
517 /* The assembler file name will be the name of the source file
518 * with .c replaced by ".s".
520 AsmName = MakeFilename (File, ".s");
523 /* Add the file as argument for the compiler */
524 CmdAddArg (&CC65, File);
526 /* Add a NULL pointer to terminate the argument list */
527 CmdAddArg (&CC65, 0);
529 /* Run the compiler */
532 /* Remove the excess arguments */
533 CmdDelArgs (&CC65, ArgCount);
535 /* If this is not the final step, assemble the generated file, then
540 if (remove (AsmName) < 0) {
541 Warning ("Cannot remove temporary file `%s': %s",
542 AsmName, strerror (errno));
550 static void CompileRes (const char* File)
551 /* Compile the given geos resource file */
555 /* Remember the current assembler argument count */
556 unsigned ArgCount = GRC.ArgCount;
558 /* The assembler file name will be the name of the source file
559 * with .grc replaced by ".s".
561 AsmName = MakeFilename (File, ".s");
563 /* Add the file as argument for the resource compiler */
564 CmdAddArg (&GRC, File);
566 /* Add a NULL pointer to terminate the argument list */
569 /* Run the compiler */
572 /* Remove the excess arguments */
573 CmdDelArgs (&GRC, ArgCount);
575 /* If this is not the final step, assemble the generated file, then
580 if (remove (AsmName) < 0) {
581 Warning ("Cannot remove temporary file `%s': %s",
582 AsmName, strerror (errno));
586 /* Free the assembler file name which was allocated from the heap */
592 static void ConvertO65 (const char* File)
593 /* Convert an o65 object file into an assembler file */
597 /* Remember the current converter argument count */
598 unsigned ArgCount = CO65.ArgCount;
600 /* If we won't link, this is the final step. In this case, set the
603 if (DontAssemble && OutputName) {
604 CmdSetOutput (&CO65, OutputName);
606 /* The assembler file name will be the name of the source file
607 * with .c replaced by ".s".
609 AsmName = MakeFilename (File, ".s");
612 /* Add the file as argument for the object file converter */
613 CmdAddArg (&CO65, File);
615 /* Add a NULL pointer to terminate the argument list */
616 CmdAddArg (&CO65, 0);
618 /* Run the converter */
621 /* Remove the excess arguments */
622 CmdDelArgs (&CO65, ArgCount);
624 /* If this is not the final step, assemble the generated file, then
629 if (remove (AsmName) < 0) {
630 Warning ("Cannot remove temporary file `%s': %s",
631 AsmName, strerror (errno));
635 /* Free the assembler file name which was allocated from the heap */
641 /*****************************************************************************/
643 /*****************************************************************************/
647 static void Usage (void)
648 /* Print usage information and exit */
651 "Usage: %s [options] file [...]\n"
653 " -c\t\t\tCompile and assemble but don't link\n"
654 " -d\t\t\tDebug mode\n"
655 " -g\t\t\tAdd debug info\n"
656 " -h\t\t\tHelp (this text)\n"
657 " -l\t\t\tCreate an assembler listing\n"
658 " -m name\t\tCreate a map file\n"
659 " -o name\t\tName the output file\n"
660 " -r\t\t\tEnable register variables\n"
661 " -t sys\t\tSet the target system\n"
662 " -v\t\t\tVerbose mode\n"
663 " -vm\t\t\tVerbose map file\n"
664 " -A\t\t\tStrict ANSI mode\n"
665 " -C name\t\tUse linker config file\n"
666 " -Cl\t\t\tMake local variables static\n"
667 " -D sym[=defn]\t\tDefine a preprocessor symbol\n"
668 " -I dir\t\tSet a compiler include directory path\n"
669 " -Ln name\t\tCreate a VICE label file\n"
670 " -O\t\t\tOptimize code\n"
671 " -Oi\t\t\tOptimize code, inline functions\n"
672 " -Or\t\t\tOptimize code, honour the register keyword\n"
673 " -Os\t\t\tOptimize code, inline known C funtions\n"
674 " -S\t\t\tCompile but don't assemble and link\n"
675 " -T\t\t\tInclude source as comment\n"
676 " -V\t\t\tPrint the version number\n"
677 " -W\t\t\tSuppress warnings\n"
680 " --add-source\t\tInclude source as comment\n"
681 " --ansi\t\tStrict ANSI mode\n"
682 " --asm-include-dir dir\tSet an assembler include directory\n"
683 " --bss-name seg\tSet the name of the BSS segment\n"
684 " --check-stack\t\tGenerate stack overflow checks\n"
685 " --code-name seg\tSet the name of the CODE segment\n"
686 " --codesize x\t\tAccept larger code by factor x\n"
687 " --cpu type\t\tSet cpu type\n"
688 " --create-dep\t\tCreate a make dependency file\n"
689 " --data-name seg\tSet the name of the DATA segment\n"
690 " --debug\t\tDebug mode\n"
691 " --debug-info\t\tAdd debug info\n"
692 " --feature name\tSet an emulation feature\n"
693 " --help\t\tHelp (this text)\n"
694 " --include-dir dir\tSet a compiler include directory path\n"
695 " --listing\t\tCreate an assembler listing\n"
696 " --mapfile name\tCreate a map file\n"
697 " --module\t\tLink as a module\n"
698 " --module-id id\tSpecify a module id for the linker\n"
699 " --register-space b\tSet space available for register variables\n"
700 " --register-vars\tEnable register variables\n"
701 " --rodata-name seg\tSet the name of the RODATA segment\n"
702 " --signed-chars\tDefault characters are signed\n"
703 " --start-addr addr\tSet the default start address\n"
704 " --static-locals\tMake local variables static\n"
705 " --target sys\t\tSet the target system\n"
706 " --version\t\tPrint the version number\n"
707 " --verbose\t\tVerbose mode\n",
713 static void OptAddSource (const char* Opt attribute ((unused)),
714 const char* Arg attribute ((unused)))
715 /* Strict source code as comments to the generated asm code */
717 CmdAddArg (&CC65, "-T");
722 static void OptAnsi (const char* Opt attribute ((unused)),
723 const char* Arg attribute ((unused)))
724 /* Strict ANSI mode (compiler) */
726 CmdAddArg (&CC65, "-A");
731 static void OptAsmIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
732 /* Include directory (assembler) */
734 CmdAddArg (&CA65, "-I");
735 CmdAddArg (&CA65, Arg);
740 static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
741 /* Handle the --bss-name option */
743 CmdAddArg (&CC65, "--bss-name");
744 CmdAddArg (&CC65, Arg);
749 static void OptCheckStack (const char* Opt attribute ((unused)),
750 const char* Arg attribute ((unused)))
751 /* Handle the --check-stack option */
753 CmdAddArg (&CC65, "--check-stack");
758 static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg)
759 /* Handle the --code-name option */
761 CmdAddArg (&CC65, "--code-name");
762 CmdAddArg (&CC65, Arg);
767 static void OptCodeSize (const char* Opt attribute ((unused)), const char* Arg)
768 /* Handle the --codesize option */
770 CmdAddArg (&CC65, "--codesize");
771 CmdAddArg (&CC65, Arg);
776 static void OptCPU (const char* Opt attribute ((unused)), const char* Arg)
777 /* Handle the --cpu option */
779 /* Add the cpu type to the assembler and compiler */
780 CmdAddArg (&CA65, "--cpu");
781 CmdAddArg (&CA65, Arg);
782 CmdAddArg (&CC65, "--cpu");
783 CmdAddArg (&CC65, Arg);
788 static void OptCreateDep (const char* Opt attribute ((unused)),
789 const char* Arg attribute ((unused)))
790 /* Handle the --create-dep option */
792 CmdAddArg (&CC65, "--create-dep");
797 static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
798 /* Handle the --data-name option */
800 CmdAddArg (&CC65, "--data-name");
801 CmdAddArg (&CC65, Arg);
806 static void OptDebug (const char* Opt attribute ((unused)),
807 const char* Arg attribute ((unused)))
808 /* Debug mode (compiler and cl65 utility) */
810 CmdAddArg (&CC65, "-d");
816 static void OptDebugInfo (const char* Opt attribute ((unused)),
817 const char* Arg attribute ((unused)))
818 /* Debug Info - add to compiler and assembler */
820 CmdAddArg (&CC65, "-g");
821 CmdAddArg (&CA65, "-g");
826 static void OptFeature (const char* Opt attribute ((unused)), const char* Arg)
827 /* Emulation features for the assembler */
829 CmdAddArg (&CA65, "--feature");
830 CmdAddArg (&CA65, Arg);
835 static void OptHelp (const char* Opt attribute ((unused)),
836 const char* Arg attribute ((unused)))
837 /* Print help - cl65 */
845 static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
846 /* Include directory (compiler) */
848 CmdAddArg (&CC65, "-I");
849 CmdAddArg (&CC65, Arg);
854 static void OptListing (const char* Opt attribute ((unused)),
855 const char* Arg attribute ((unused)))
856 /* Create an assembler listing */
858 CmdAddArg (&CA65, "-l");
863 static void OptMapFile (const char* Opt attribute ((unused)), const char* Arg)
864 /* Create a map file */
866 /* Create a map file (linker) */
867 CmdAddArg (&LD65, "-m");
868 CmdAddArg (&LD65, Arg);
873 static void OptModule (const char* Opt attribute ((unused)),
874 const char* Arg attribute ((unused)))
875 /* Link as a module */
882 static void OptModuleId (const char* Opt attribute ((unused)), const char* Arg)
883 /* Specify a module if for the linker */
885 /* Pass it straight to the linker */
886 CmdAddArg (&LD65, "--module-id");
887 CmdAddArg (&LD65, Arg);
892 static void OptRegisterSpace (const char* Opt attribute ((unused)), const char* Arg)
893 /* Handle the --register-space option */
895 CmdAddArg (&CC65, "--register-space");
896 CmdAddArg (&CC65, Arg);
901 static void OptRegisterVars (const char* Opt attribute ((unused)),
902 const char* Arg attribute ((unused)))
903 /* Handle the --register-vars option */
905 CmdAddArg (&CC65, "-r");
910 static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg)
911 /* Handle the --rodata-name option */
913 CmdAddArg (&CC65, "--rodata-name");
914 CmdAddArg (&CC65, Arg);
919 static void OptSignedChars (const char* Opt attribute ((unused)),
920 const char* Arg attribute ((unused)))
921 /* Make default characters signed */
923 CmdAddArg (&CC65, "-j");
928 static void OptStartAddr (const char* Opt attribute ((unused)), const char* Arg)
929 /* Set the default start address */
931 CmdAddArg (&LD65, "-S");
932 CmdAddArg (&LD65, Arg);
937 static void OptStaticLocals (const char* Opt attribute ((unused)),
938 const char* Arg attribute ((unused)))
939 /* Place local variables in static storage */
941 CmdAddArg (&CC65, "-Cl");
946 static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
947 /* Set the target system */
949 Target = FindTarget (Arg);
950 if (Target == TGT_UNKNOWN) {
951 Error ("No such target system: `%s'", Arg);
952 } else if (Target == TGT_MODULE) {
953 Error ("Cannot use `module' as target, use --module instead");
959 static void OptVerbose (const char* Opt attribute ((unused)),
960 const char* Arg attribute ((unused)))
961 /* Verbose mode (compiler, assembler, linker) */
963 CmdAddArg (&CC65, "-v");
964 CmdAddArg (&CA65, "-v");
965 CmdAddArg (&LD65, "-v");
970 static void OptVersion (const char* Opt attribute ((unused)),
971 const char* Arg attribute ((unused)))
972 /* Print version number */
975 "cl65 V%u.%u.%u - (C) Copyright 1998-2003 Ullrich von Bassewitz\n",
976 VER_MAJOR, VER_MINOR, VER_PATCH);
981 int main (int argc, char* argv [])
982 /* Utility main program */
984 /* Program long options */
985 static const LongOpt OptTab[] = {
986 { "--add-source", 0, OptAddSource },
987 { "--ansi", 0, OptAnsi },
988 { "--asm-include-dir", 1, OptAsmIncludeDir },
989 { "--bss-name", 1, OptBssName },
990 { "--check-stack", 0, OptCheckStack },
991 { "--code-name", 1, OptCodeName },
992 { "--codesize", 1, OptCodeSize },
993 { "--cpu", 1, OptCPU },
994 { "--create-dep", 0, OptCreateDep },
995 { "--data-name", 1, OptDataName },
996 { "--debug", 0, OptDebug },
997 { "--debug-info", 0, OptDebugInfo },
998 { "--feature", 1, OptFeature },
999 { "--help", 0, OptHelp },
1000 { "--include-dir", 1, OptIncludeDir },
1001 { "--listing", 0, OptListing },
1002 { "--mapfile", 1, OptMapFile },
1003 { "--module", 0, OptModule },
1004 { "--module-id", 1, OptModuleId },
1005 { "--register-space", 1, OptRegisterSpace },
1006 { "--register-vars", 0, OptRegisterVars },
1007 { "--rodata-name", 1, OptRodataName },
1008 { "--signed-chars", 0, OptSignedChars },
1009 { "--start-addr", 1, OptStartAddr },
1010 { "--static-locals", 0, OptStaticLocals },
1011 { "--target", 1, OptTarget },
1012 { "--verbose", 0, OptVerbose },
1013 { "--version", 0, OptVersion },
1018 /* Initialize the cmdline module */
1019 InitCmdLine (&argc, &argv, "cl65");
1021 /* Initialize the command descriptors */
1022 CmdInit (&CC65, "cc65");
1023 CmdInit (&CA65, "ca65");
1024 CmdInit (&CO65, "co65");
1025 CmdInit (&LD65, "ld65");
1026 CmdInit (&GRC, "grc");
1028 /* Our default target is the C64 instead of "none" */
1031 /* Check the parameters */
1033 while (I < ArgCount) {
1035 /* Get the argument */
1036 const char* Arg = ArgVec[I];
1038 /* Check for an option */
1039 if (Arg [0] == '-') {
1044 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
1048 /* Strict ANSI mode (compiler) */
1053 if (Arg[2] == 'l' && Arg[3] == '\0') {
1054 /* Make local variables static */
1055 OptStaticLocals (Arg, 0);
1057 /* Specify linker config file */
1058 LinkerConfig = GetArg (&I, 2);
1063 /* Define a preprocessor symbol (compiler) */
1064 CmdAddArg (&CC65, "-D");
1065 CmdAddArg (&CC65, GetArg (&I, 2));
1069 /* Include directory (compiler) */
1070 OptIncludeDir (Arg, GetArg (&I, 2));
1074 if (Arg[2] == 'n') {
1075 /* VICE label file (linker) */
1076 CmdAddArg (&LD65, "-Ln");
1077 CmdAddArg (&LD65, GetArg (&I, 3));
1079 UnknownOption (Arg);
1084 /* Optimize code (compiler, also covers -Oi and others) */
1085 CmdAddArg (&CC65, Arg);
1089 /* Dont assemble and link the created files */
1090 DontLink = DontAssemble = 1;
1094 /* Include source as comment (compiler) */
1095 OptAddSource (Arg, 0);
1099 /* Print version number */
1100 OptVersion (Arg, 0);
1104 /* Suppress warnings - compiler and assembler */
1105 CmdAddArg (&CC65, "-W");
1106 CmdAddArg (&CA65, "-W");
1107 CmdAddArg (&CA65, "0");
1111 /* Don't link the resulting files */
1116 /* Debug mode (compiler) */
1121 /* Debugging - add to compiler and assembler */
1122 OptDebugInfo (Arg, 0);
1127 /* Print help - cl65 */
1132 /* Default characters are signed */
1133 OptSignedChars (Arg, 0);
1137 /* Create an assembler listing */
1138 OptListing (Arg, 0);
1142 /* Create a map file (linker) */
1143 OptMapFile (Arg, GetArg (&I, 2));
1147 /* Name the output file */
1148 OutputName = GetArg (&I, 2);
1152 /* Enable register variables */
1153 OptRegisterVars (Arg, 0);
1157 /* Set target system - compiler, assembler and linker */
1158 OptTarget (Arg, GetArg (&I, 2));
1162 if (Arg [2] == 'm') {
1163 /* Verbose map file (linker) */
1164 CmdAddArg (&LD65, "-vm");
1166 /* Verbose mode (compiler, assembler, linker) */
1167 OptVerbose (Arg, 0);
1172 UnknownOption (Arg);
1176 /* Remember the first file name */
1177 if (FirstInput == 0) {
1181 /* Determine the file type by the extension */
1182 switch (GetFileType (Arg)) {
1185 /* Compile the file */
1190 /* Assemble the file */
1191 if (!DontAssemble) {
1198 /* Add to the linker files */
1199 CmdAddFile (&LD65, Arg);
1203 /* Add to the resource compiler files */
1208 /* Add the the object file converter files */
1213 Error ("Don't know what to do with `%s'", Arg);
1223 /* Check if we had any input files */
1224 if (FirstInput == 0) {
1225 Warning ("No input files");
1228 /* Link the given files if requested and if we have any */
1229 if (DontLink == 0 && LD65.FileCount > 0) {
1233 /* Return an apropriate exit code */
1234 return EXIT_SUCCESS;