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 /*****************************************************************************/
41 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__)
42 # include <process.h> /* DOS, OS/2 and Windows */
44 # include "spawn.h" /* All others */
60 /*****************************************************************************/
62 /*****************************************************************************/
66 /* Struct that describes a command */
67 typedef struct CmdDesc CmdDesc;
69 char* Name; /* The command name */
71 unsigned ArgCount; /* Count of arguments */
72 unsigned ArgMax; /* Maximum count of arguments */
73 char** Args; /* The arguments */
75 unsigned FileCount; /* Count of files to translate */
76 unsigned FileMax; /* Maximum count of files */
77 char** Files; /* The files */
80 /* Command descriptors for the different programs */
81 static CmdDesc CC65 = { 0, 0, 0, 0, 0, 0, 0 };
82 static CmdDesc CA65 = { 0, 0, 0, 0, 0, 0, 0 };
83 static CmdDesc LD65 = { 0, 0, 0, 0, 0, 0, 0 };
84 static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 };
93 FILETYPE_GR /* GEOS resource file */
96 /* Default file type, used if type unknown */
97 static unsigned DefaultFileType = FILETYPE_UNKNOWN;
99 /* Variables controlling the steps we're doing */
100 static int DontLink = 0;
101 static int DontAssemble = 0;
103 /* The name of the output file, NULL if none given */
104 static const char* OutputName = 0;
106 /* The name of the linker configuration file if given */
107 static const char* LinkerConfig = 0;
109 /* The name of the first input file. This will be used to construct the
110 * executable file name if no explicit name is given.
112 static const char* FirstInput = 0;
114 /* Remember if we should link a module */
115 static int Module = 0;
117 /* Extension used for a module */
118 #define MODULE_EXT ".o65"
120 /* Name of the crt0 object file and the runtime library */
121 static char* TargetCRT0 = 0;
122 static char* TargetLib = 0;
126 /*****************************************************************************/
127 /* Determine a file type */
128 /*****************************************************************************/
132 static unsigned GetFileType (const char* File)
133 /* Determine the type of the given file */
135 /* Table mapping extensions to file types */
136 static const struct {
140 { ".c", FILETYPE_C },
141 { ".s", FILETYPE_ASM },
142 { ".asm", FILETYPE_ASM },
143 { ".a65", FILETYPE_ASM },
144 { ".o", FILETYPE_OBJ },
145 { ".obj", FILETYPE_OBJ },
146 { ".a", FILETYPE_LIB },
147 { ".lib", FILETYPE_LIB },
148 { ".grc", FILETYPE_GR },
153 /* Determine the file type by the extension */
154 const char* Ext = FindExt (File);
156 /* Do we have an extension? */
158 return DefaultFileType;
161 /* Check for known extensions */
162 for (I = 0; I < sizeof (FileTypes) / sizeof (FileTypes [0]); ++I) {
163 if (strcmp (FileTypes [I].Ext, Ext) == 0) {
165 return FileTypes [I].Type;
169 /* Not found, return the default */
170 return DefaultFileType;
175 /*****************************************************************************/
176 /* Command structure handling */
177 /*****************************************************************************/
181 static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
182 /* Add a new argument to the command */
184 /* Expand the argument vector if needed */
185 if (Cmd->ArgCount == Cmd->ArgMax) {
186 unsigned NewMax = Cmd->ArgMax + 10;
187 char** NewArgs = xmalloc (NewMax * sizeof (char*));
188 memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
191 Cmd->ArgMax = NewMax;
194 /* Add a copy of the new argument, allow a NULL pointer */
196 Cmd->Args [Cmd->ArgCount++] = xstrdup (Arg);
198 Cmd->Args [Cmd->ArgCount++] = 0;
204 static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
205 /* Remove all arguments with an index greater than LastValid */
207 while (Cmd->ArgCount > LastValid) {
209 xfree (Cmd->Args [Cmd->ArgCount]);
210 Cmd->Args [Cmd->ArgCount] = 0;
216 static void CmdAddFile (CmdDesc* Cmd, const char* File)
217 /* Add a new file to the command */
219 /* Expand the file vector if needed */
220 if (Cmd->FileCount == Cmd->FileMax) {
221 unsigned NewMax = Cmd->FileMax + 10;
222 char** NewFiles = xmalloc (NewMax * sizeof (char*));
223 memcpy (NewFiles, Cmd->Files, Cmd->FileMax * sizeof (char*));
225 Cmd->Files = NewFiles;
226 Cmd->FileMax = NewMax;
229 /* If the file name is not NULL (which is legal and is used to terminate
230 * the file list), check if the file name does already exist in the file
231 * list and print a warning if so. Regardless of the search result, add
236 for (I = 0; I < Cmd->FileCount; ++I) {
237 if (strcmp (Cmd->Files[I], File) == 0) {
239 Warning ("Duplicate file in argument list: `%s'", File);
240 /* No need to search further */
246 Cmd->Files [Cmd->FileCount++] = xstrdup (File);
248 /* Add a NULL pointer */
249 Cmd->Files [Cmd->FileCount++] = 0;
255 static void CmdInit (CmdDesc* Cmd, const char* Path)
256 /* Initialize the command using the given path to the executable */
258 /* Remember the command */
259 Cmd->Name = xstrdup (Path);
261 /* Use the command name as first argument */
262 CmdAddArg (Cmd, Path);
267 static void CmdSetOutput (CmdDesc* Cmd, const char* File)
268 /* Set the output file in a command desc */
270 CmdAddArg (Cmd, "-o");
271 CmdAddArg (Cmd, File);
276 static void CmdSetTarget (CmdDesc* Cmd, target_t Target)
277 /* Set the output file in a command desc */
279 CmdAddArg (Cmd, "-t");
280 CmdAddArg (Cmd, TargetNames[Target]);
285 static void CmdPrint (CmdDesc* Cmd, FILE* F)
286 /* Output the command line encoded in the command desc */
289 for (I = 0; I < Cmd->ArgCount && Cmd->Args[I] != 0; ++I) {
290 fprintf (F, "%s ", Cmd->Args[I]);
296 /*****************************************************************************/
297 /* Target handling */
298 /*****************************************************************************/
302 static void SetTargetFiles (void)
303 /* Set the target system files */
305 /* Determine the names of the default startup and library file */
306 if (Target != TGT_NONE) {
308 /* Get a pointer to the system name and its length */
309 const char* TargetName = TargetNames [Target];
310 unsigned TargetNameLen = strlen (TargetName);
312 /* Set the startup file */
313 TargetCRT0 = xmalloc (TargetNameLen + 2 + 1);
314 strcpy (TargetCRT0, TargetName);
315 strcat (TargetCRT0, ".o");
317 /* Set the library file */
318 TargetLib = xmalloc (TargetNameLen + 4 + 1);
319 strcpy (TargetLib, TargetName);
320 strcat (TargetLib, ".lib");
327 /*****************************************************************************/
329 /*****************************************************************************/
333 static void ExecProgram (CmdDesc* Cmd)
334 /* Execute a subprocess with the given name/parameters. Exit on errors. */
338 /* If in debug mode, output the command line we will execute */
340 printf ("Executing: ");
341 CmdPrint (Cmd, stdout);
345 /* Call the program */
346 Status = spawnvp (P_WAIT, Cmd->Name, Cmd->Args);
348 /* Check the result code */
350 /* Error executing the program */
351 Error ("Cannot execute `%s': %s", Cmd->Name, strerror (errno));
352 } else if (Status != 0) {
353 /* Called program had an error */
360 static void Link (void)
361 /* Link the resulting executable */
365 /* If we have a linker config file given, add it to the command line.
366 * Otherwise pass the target to the linker if we have one.
370 Error ("Cannot use -C and --module together");
372 CmdAddArg (&LD65, "-C");
373 CmdAddArg (&LD65, LinkerConfig);
375 CmdSetTarget (&LD65, TGT_MODULE);
376 } else if (Target != TGT_NONE) {
377 CmdSetTarget (&LD65, Target);
380 /* Determine which target libraries are needed */
383 /* Since linking is always the final step, if we have an output file name
384 * given, set it here. If we don't have an explicit output name given,
385 * try to build one from the name of the first input file.
389 CmdSetOutput (&LD65, OutputName);
391 } else if (FirstInput && FindExt (FirstInput)) { /* Only if ext present! */
393 const char* Extension = Module? MODULE_EXT : "";
394 char* Output = MakeFilename (FirstInput, Extension);
395 CmdSetOutput (&LD65, Output);
400 /* If we have a startup file and if we are not linking a module, add its
401 * name as a parameter
403 if (TargetCRT0 && !Module) {
404 CmdAddArg (&LD65, TargetCRT0);
407 /* Add all object files as parameters */
408 for (I = 0; I < LD65.FileCount; ++I) {
409 CmdAddArg (&LD65, LD65.Files [I]);
412 /* Add the system runtime library */
414 CmdAddArg (&LD65, TargetLib);
417 /* Terminate the argument list with a NULL pointer */
418 CmdAddArg (&LD65, 0);
420 /* Call the linker */
426 static void Assemble (const char* File)
427 /* Assemble the given file */
429 /* Remember the current assembler argument count */
430 unsigned ArgCount = CA65.ArgCount;
432 /* Set the target system */
433 CmdSetTarget (&CA65, Target);
435 /* If we won't link, this is the final step. In this case, set the
438 if (DontLink && OutputName) {
439 CmdSetOutput (&CA65, OutputName);
441 /* The object file name will be the name of the source file
442 * with .s replaced by ".o". Add this file to the list of
445 char* ObjName = MakeFilename (File, ".o");
446 CmdAddFile (&LD65, ObjName);
450 /* Add the file as argument for the assembler */
451 CmdAddArg (&CA65, File);
453 /* Add a NULL pointer to terminate the argument list */
454 CmdAddArg (&CA65, 0);
456 /* Run the assembler */
459 /* Remove the excess arguments */
460 CmdDelArgs (&CA65, ArgCount);
465 static void Compile (const char* File)
466 /* Compile the given file */
470 /* Remember the current assembler argument count */
471 unsigned ArgCount = CC65.ArgCount;
473 /* Set the target system */
474 CmdSetTarget (&CC65, Target);
476 /* If we won't link, this is the final step. In this case, set the
479 if (DontAssemble && OutputName) {
480 CmdSetOutput (&CC65, OutputName);
482 /* The assembler file name will be the name of the source file
483 * with .c replaced by ".s".
485 AsmName = MakeFilename (File, ".s");
488 /* Add the file as argument for the compiler */
489 CmdAddArg (&CC65, File);
491 /* Add a NULL pointer to terminate the argument list */
492 CmdAddArg (&CC65, 0);
494 /* Run the compiler */
497 /* Remove the excess arguments */
498 CmdDelArgs (&CC65, ArgCount);
500 /* If this is not the final step, assemble the generated file, then
505 if (remove (AsmName) < 0) {
506 Warning ("Cannot remove temporary file `%s': %s",
507 AsmName, strerror (errno));
515 static void CompileRes (const char* File)
516 /* Compile the given geos resource file */
520 /* Remember the current assembler argument count */
521 unsigned ArgCount = GRC.ArgCount;
523 /* The assembler file name will be the name of the source file
524 * with .grc replaced by ".s".
526 AsmName = MakeFilename (File, ".s");
528 /* Add the file as argument for the resource compiler */
529 CmdAddArg (&GRC, File);
531 /* Add a NULL pointer to terminate the argument list */
534 /* Run the compiler */
537 /* Remove the excess arguments */
538 CmdDelArgs (&GRC, ArgCount);
540 /* If this is not the final step, assemble the generated file, then
545 if (remove (AsmName) < 0) {
546 Warning ("Cannot remove temporary file `%s': %s",
547 AsmName, strerror (errno));
551 /* Free the assembler file name which was allocated from the heap */
557 /*****************************************************************************/
559 /*****************************************************************************/
563 static void Usage (void)
564 /* Print usage information and exit */
567 "Usage: %s [options] file [...]\n"
569 " -c\t\t\tCompile and assemble but don't link\n"
570 " -d\t\t\tDebug mode\n"
571 " -g\t\t\tAdd debug info\n"
572 " -h\t\t\tHelp (this text)\n"
573 " -l\t\t\tCreate an assembler listing\n"
574 " -m name\t\tCreate a map file\n"
575 " -o name\t\tName the output file\n"
576 " -t sys\t\tSet the target system\n"
577 " -v\t\t\tVerbose mode\n"
578 " -vm\t\t\tVerbose map file\n"
579 " -A\t\t\tStrict ANSI mode\n"
580 " -C name\t\tUse linker config file\n"
581 " -Cl\t\t\tMake local variables static\n"
582 " -D sym[=defn]\t\tDefine a preprocessor symbol\n"
583 " -I dir\t\tSet a compiler include directory path\n"
584 " -Ln name\t\tCreate a VICE label file\n"
585 " -O\t\t\tOptimize code\n"
586 " -Oi\t\t\tOptimize code, inline functions\n"
587 " -Or\t\t\tOptimize code, honour the register keyword\n"
588 " -Os\t\t\tOptimize code, inline known C funtions\n"
589 " -S\t\t\tCompile but don't assemble and link\n"
590 " -T\t\t\tInclude source as comment\n"
591 " -V\t\t\tPrint the version number\n"
592 " -W\t\t\tSuppress warnings\n"
595 " --add-source\t\tInclude source as comment\n"
596 " --ansi\t\tStrict ANSI mode\n"
597 " --asm-include-dir dir\tSet an assembler include directory\n"
598 " --bss-name seg\tSet the name of the BSS segment\n"
599 " --check-stack\t\tGenerate stack overflow checks\n"
600 " --code-name seg\tSet the name of the CODE segment\n"
601 " --codesize x\t\tAccept larger code by factor x\n"
602 " --cpu type\t\tSet cpu type\n"
603 " --create-dep\t\tCreate a make dependency file\n"
604 " --data-name seg\tSet the name of the DATA segment\n"
605 " --debug\t\tDebug mode\n"
606 " --debug-info\t\tAdd debug info\n"
607 " --feature name\tSet an emulation feature\n"
608 " --help\t\tHelp (this text)\n"
609 " --include-dir dir\tSet a compiler include directory path\n"
610 " --listing\t\tCreate an assembler listing\n"
611 " --mapfile name\tCreate a map file\n"
612 " --module\t\tLink as a module\n"
613 " --module-id id\tSpecify a module id for the linker\n"
614 " --rodata-name seg\tSet the name of the RODATA segment\n"
615 " --signed-chars\tDefault characters are signed\n"
616 " --start-addr addr\tSet the default start address\n"
617 " --static-locals\tMake local variables static\n"
618 " --target sys\t\tSet the target system\n"
619 " --version\t\tPrint the version number\n"
620 " --verbose\t\tVerbose mode\n",
626 static void OptAddSource (const char* Opt attribute ((unused)),
627 const char* Arg attribute ((unused)))
628 /* Strict source code as comments to the generated asm code */
630 CmdAddArg (&CC65, "-T");
635 static void OptAnsi (const char* Opt attribute ((unused)),
636 const char* Arg attribute ((unused)))
637 /* Strict ANSI mode (compiler) */
639 CmdAddArg (&CC65, "-A");
644 static void OptAsmIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
645 /* Include directory (assembler) */
647 CmdAddArg (&CA65, "-I");
648 CmdAddArg (&CA65, Arg);
653 static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
654 /* Handle the --bss-name option */
656 CmdAddArg (&CC65, "--bss-name");
657 CmdAddArg (&CC65, Arg);
662 static void OptCheckStack (const char* Opt attribute ((unused)),
663 const char* Arg attribute ((unused)))
664 /* Handle the --check-stack option */
666 CmdAddArg (&CC65, "--check-stack");
671 static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg)
672 /* Handle the --code-name option */
674 CmdAddArg (&CC65, "--code-name");
675 CmdAddArg (&CC65, Arg);
680 static void OptCodeSize (const char* Opt attribute ((unused)), const char* Arg)
681 /* Handle the --codesize option */
683 CmdAddArg (&CC65, "--codesize");
684 CmdAddArg (&CC65, Arg);
689 static void OptCPU (const char* Opt attribute ((unused)), const char* Arg)
690 /* Handle the --cpu option */
692 /* Add the cpu type to the assembler and compiler */
693 CmdAddArg (&CA65, "--cpu");
694 CmdAddArg (&CA65, Arg);
695 CmdAddArg (&CC65, "--cpu");
696 CmdAddArg (&CC65, Arg);
701 static void OptCreateDep (const char* Opt attribute ((unused)),
702 const char* Arg attribute ((unused)))
703 /* Handle the --create-dep option */
705 CmdAddArg (&CC65, "--create-dep");
710 static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
711 /* Handle the --data-name option */
713 CmdAddArg (&CC65, "--data-name");
714 CmdAddArg (&CC65, Arg);
719 static void OptDebug (const char* Opt attribute ((unused)),
720 const char* Arg attribute ((unused)))
721 /* Debug mode (compiler and cl65 utility) */
723 CmdAddArg (&CC65, "-d");
729 static void OptDebugInfo (const char* Opt attribute ((unused)),
730 const char* Arg attribute ((unused)))
731 /* Debug Info - add to compiler and assembler */
733 CmdAddArg (&CC65, "-g");
734 CmdAddArg (&CA65, "-g");
739 static void OptFeature (const char* Opt attribute ((unused)), const char* Arg)
740 /* Emulation features for the assembler */
742 CmdAddArg (&CA65, "--feature");
743 CmdAddArg (&CA65, Arg);
748 static void OptHelp (const char* Opt attribute ((unused)),
749 const char* Arg attribute ((unused)))
750 /* Print help - cl65 */
758 static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
759 /* Include directory (compiler) */
761 CmdAddArg (&CC65, "-I");
762 CmdAddArg (&CC65, Arg);
767 static void OptListing (const char* Opt attribute ((unused)),
768 const char* Arg attribute ((unused)))
769 /* Create an assembler listing */
771 CmdAddArg (&CA65, "-l");
776 static void OptMapFile (const char* Opt attribute ((unused)), const char* Arg)
777 /* Create a map file */
779 /* Create a map file (linker) */
780 CmdAddArg (&LD65, "-m");
781 CmdAddArg (&LD65, Arg);
786 static void OptModule (const char* Opt attribute ((unused)),
787 const char* Arg attribute ((unused)))
788 /* Link as a module */
795 static void OptModuleId (const char* Opt attribute ((unused)), const char* Arg)
796 /* Specify a module if for the linker */
798 /* Pass it straight to the linker */
799 CmdAddArg (&LD65, "--module-id");
800 CmdAddArg (&LD65, Arg);
805 static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg)
806 /* Handle the --rodata-name option */
808 CmdAddArg (&CC65, "--rodata-name");
809 CmdAddArg (&CC65, Arg);
814 static void OptSignedChars (const char* Opt attribute ((unused)),
815 const char* Arg attribute ((unused)))
816 /* Make default characters signed */
818 CmdAddArg (&CC65, "-j");
823 static void OptStartAddr (const char* Opt attribute ((unused)), const char* Arg)
824 /* Set the default start address */
826 CmdAddArg (&LD65, "-S");
827 CmdAddArg (&LD65, Arg);
832 static void OptStaticLocals (const char* Opt attribute ((unused)),
833 const char* Arg attribute ((unused)))
834 /* Place local variables in static storage */
836 CmdAddArg (&CC65, "-Cl");
841 static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
842 /* Set the target system */
844 Target = FindTarget (Arg);
845 if (Target == TGT_UNKNOWN) {
846 Error ("No such target system: `%s'", Arg);
847 } else if (Target == TGT_MODULE) {
848 Error ("Cannot use `module' as target, use --module instead");
854 static void OptVerbose (const char* Opt attribute ((unused)),
855 const char* Arg attribute ((unused)))
856 /* Verbose mode (compiler, assembler, linker) */
858 CmdAddArg (&CC65, "-v");
859 CmdAddArg (&CA65, "-v");
860 CmdAddArg (&LD65, "-v");
865 static void OptVersion (const char* Opt attribute ((unused)),
866 const char* Arg attribute ((unused)))
867 /* Print version number */
870 "cl65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n",
871 VER_MAJOR, VER_MINOR, VER_PATCH);
876 int main (int argc, char* argv [])
877 /* Utility main program */
879 /* Program long options */
880 static const LongOpt OptTab[] = {
881 { "--add-source", 0, OptAddSource },
882 { "--ansi", 0, OptAnsi },
883 { "--asm-include-dir", 1, OptAsmIncludeDir },
884 { "--bss-name", 1, OptBssName },
885 { "--check-stack", 0, OptCheckStack },
886 { "--code-name", 1, OptCodeName },
887 { "--codesize", 1, OptCodeSize },
888 { "--cpu", 1, OptCPU },
889 { "--create-dep", 0, OptCreateDep },
890 { "--data-name", 1, OptDataName },
891 { "--debug", 0, OptDebug },
892 { "--debug-info", 0, OptDebugInfo },
893 { "--feature", 1, OptFeature },
894 { "--help", 0, OptHelp },
895 { "--include-dir", 1, OptIncludeDir },
896 { "--listing", 0, OptListing },
897 { "--mapfile", 1, OptMapFile },
898 { "--module", 0, OptModule },
899 { "--module-id", 1, OptModuleId },
900 { "--rodata-name", 1, OptRodataName },
901 { "--signed-chars", 0, OptSignedChars },
902 { "--start-addr", 1, OptStartAddr },
903 { "--static-locals", 0, OptStaticLocals },
904 { "--target", 1, OptTarget },
905 { "--verbose", 0, OptVerbose },
906 { "--version", 0, OptVersion },
911 /* Initialize the cmdline module */
912 InitCmdLine (&argc, &argv, "cl65");
914 /* Initialize the command descriptors */
915 CmdInit (&CC65, "cc65");
916 CmdInit (&CA65, "ca65");
917 CmdInit (&LD65, "ld65");
918 CmdInit (&GRC, "grc");
920 /* Our default target is the C64 instead of "none" */
923 /* Check the parameters */
925 while (I < ArgCount) {
927 /* Get the argument */
928 const char* Arg = ArgVec[I];
930 /* Check for an option */
931 if (Arg [0] == '-') {
936 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
940 /* Strict ANSI mode (compiler) */
945 if (Arg[2] == 'l' && Arg[3] == '\0') {
946 /* Make local variables static */
947 OptStaticLocals (Arg, 0);
949 /* Specify linker config file */
950 LinkerConfig = GetArg (&I, 2);
955 /* Define a preprocessor symbol (compiler) */
956 CmdAddArg (&CC65, "-D");
957 CmdAddArg (&CC65, GetArg (&I, 2));
961 /* Include directory (compiler) */
962 OptIncludeDir (Arg, GetArg (&I, 2));
967 /* VICE label file (linker) */
968 CmdAddArg (&LD65, "-Ln");
969 CmdAddArg (&LD65, GetArg (&I, 3));
976 /* Optimize code (compiler, also covers -Oi and others) */
977 CmdAddArg (&CC65, Arg);
981 /* Dont assemble and link the created files */
982 DontLink = DontAssemble = 1;
986 /* Include source as comment (compiler) */
987 OptAddSource (Arg, 0);
991 /* Print version number */
996 /* Suppress warnings - compiler and assembler */
997 CmdAddArg (&CC65, "-W");
998 CmdAddArg (&CA65, "-W");
999 CmdAddArg (&CA65, "0");
1003 /* Don't link the resulting files */
1008 /* Debug mode (compiler) */
1013 /* Debugging - add to compiler and assembler */
1014 OptDebugInfo (Arg, 0);
1019 /* Print help - cl65 */
1024 /* Default characters are signed */
1025 OptSignedChars (Arg, 0);
1029 /* Create an assembler listing */
1030 OptListing (Arg, 0);
1034 /* Create a map file (linker) */
1035 OptMapFile (Arg, GetArg (&I, 2));
1039 /* Name the output file */
1040 OutputName = GetArg (&I, 2);
1044 /* Set target system - compiler, assembler and linker */
1045 OptTarget (Arg, GetArg (&I, 2));
1049 if (Arg [2] == 'm') {
1050 /* Verbose map file (linker) */
1051 CmdAddArg (&LD65, "-vm");
1053 /* Verbose mode (compiler, assembler, linker) */
1054 OptVerbose (Arg, 0);
1059 UnknownOption (Arg);
1063 /* Remember the first file name */
1064 if (FirstInput == 0) {
1068 /* Determine the file type by the extension */
1069 switch (GetFileType (Arg)) {
1072 /* Compile the file */
1077 /* Assemble the file */
1078 if (!DontAssemble) {
1085 /* Add to the linker files */
1086 CmdAddFile (&LD65, Arg);
1090 /* Add to the resource compiler files */
1095 Error ("Don't know what to do with `%s'", Arg);
1105 /* Check if we had any input files */
1106 if (FirstInput == 0) {
1107 Warning ("No input files");
1110 /* Link the given files if requested and if we have any */
1111 if (DontLink == 0 && LD65.FileCount > 0) {
1115 /* Return an apropriate exit code */
1116 return EXIT_SUCCESS;