]> git.sur5r.net Git - cc65/blob - src/cl65/main.c
Fixed the help text
[cc65] / src / cl65 / main.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  main.c                                   */
4 /*                                                                           */
5 /*             Main module for the cl65 compile and link utility             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1999-2000 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <ctype.h>
40 #include <errno.h>
41 #if defined(__WATCOMC__) || defined(_MSC_VER)
42 #  include <process.h>          /* DOS, OS/2 and Windows */
43 #else
44 #  include "spawn.h"            /* All others */
45 #endif
46
47 /* common */
48 #include "cmdline.h"
49 #include "fname.h"
50 #include "target.h"
51 #include "version.h"
52 #include "xmalloc.h"
53
54 /* cl65 */
55 #include "global.h"
56 #include "error.h"
57
58
59
60 /*****************************************************************************/
61 /*                                   Data                                    */
62 /*****************************************************************************/
63
64
65
66 /* Struct that describes a command */
67 typedef struct CmdDesc_ CmdDesc;
68 struct CmdDesc_ {
69     char*       Name;           /* The command name */
70
71     unsigned    ArgCount;       /* Count of arguments */
72     unsigned    ArgMax;         /* Maximum count of arguments */
73     char**      Args;           /* The arguments */
74
75     unsigned    FileCount;      /* Count of files to translate */
76     unsigned    FileMax;        /* Maximum count of files */
77     char**      Files;          /* The files */
78 };
79
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 };
85
86 /* File types */
87 enum {
88     FILETYPE_UNKNOWN,
89     FILETYPE_C,
90     FILETYPE_ASM,
91     FILETYPE_OBJ,
92     FILETYPE_LIB,
93     FILETYPE_GR                 /* GEOS resource file */
94 };
95
96 /* Default file type, used if type unknown */
97 static unsigned DefaultFileType = FILETYPE_UNKNOWN;
98
99 /* Variables controlling the steps we're doing */
100 static int DontLink     = 0;
101 static int DontAssemble = 0;
102
103 /* The name of the output file, NULL if none given */
104 static const char* OutputName = 0;
105
106 /* The name of the linker configuration file if given */
107 static const char* LinkerConfig = 0;
108
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.
111  */
112 static const char* FirstInput = 0;
113
114 /* Name of the crt0 object file and the runtime library */
115 static char* TargetCRT0 = 0;
116 static char* TargetLib  = 0;
117
118
119
120 /*****************************************************************************/
121 /*                           Determine a file type                           */
122 /*****************************************************************************/
123
124
125
126 static unsigned GetFileType (const char* File)
127 /* Determine the type of the given file */
128 {
129     /* Table mapping extensions to file types */
130     static const struct {
131         const char*     Ext;
132         unsigned        Type;
133     } FileTypes [] = {
134         {   ".c",       FILETYPE_C      },
135         {   ".s",       FILETYPE_ASM    },
136         {   ".asm",     FILETYPE_ASM    },
137         {   ".a65",     FILETYPE_ASM    },
138         {   ".o",       FILETYPE_OBJ    },
139         {   ".obj",     FILETYPE_OBJ    },
140         {   ".a",       FILETYPE_LIB    },
141         {   ".lib",     FILETYPE_LIB    },
142         {   ".grc",     FILETYPE_GR     },
143     };
144
145     unsigned I;
146
147     /* Determine the file type by the extension */
148     const char* Ext = FindExt (File);
149
150     /* Do we have an extension? */
151     if (Ext == 0) {
152         return DefaultFileType;
153     }
154
155     /* Check for known extensions */
156     for (I = 0; I < sizeof (FileTypes) / sizeof (FileTypes [0]); ++I) {
157         if (strcmp (FileTypes [I].Ext, Ext) == 0) {
158             /* Found */
159             return FileTypes [I].Type;
160         }
161     }
162
163     /* Not found, return the default */
164     return DefaultFileType;
165 }
166
167
168
169 /*****************************************************************************/
170 /*                        Command structure handling                         */
171 /*****************************************************************************/
172
173
174
175 static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
176 /* Add a new argument to the command */
177 {
178     /* Expand the argument vector if needed */
179     if (Cmd->ArgCount == Cmd->ArgMax) {
180         unsigned NewMax  = Cmd->ArgMax + 10;
181         char**   NewArgs = xmalloc (NewMax * sizeof (char*));
182         memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
183         xfree (Cmd->Args);
184         Cmd->Args   = NewArgs;
185         Cmd->ArgMax = NewMax;
186     }
187
188     /* Add a copy of the new argument, allow a NULL pointer */
189     if (Arg) {
190         Cmd->Args [Cmd->ArgCount++] = xstrdup (Arg);
191     } else {
192         Cmd->Args [Cmd->ArgCount++] = 0;
193     }
194 }
195
196
197
198 static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
199 /* Remove all arguments with an index greater than LastValid */
200 {
201     while (Cmd->ArgCount > LastValid) {
202         Cmd->ArgCount--;
203         xfree (Cmd->Args [Cmd->ArgCount]);
204         Cmd->Args [Cmd->ArgCount] = 0;
205     }
206 }
207
208
209
210 static void CmdAddFile (CmdDesc* Cmd, const char* File)
211 /* Add a new file to the command */
212 {
213     /* Expand the file vector if needed */
214     if (Cmd->FileCount == Cmd->FileMax) {
215         unsigned NewMax   = Cmd->FileMax + 10;
216         char**   NewFiles = xmalloc (NewMax * sizeof (char*));
217         memcpy (NewFiles, Cmd->Files, Cmd->FileMax * sizeof (char*));
218         xfree (Cmd->Files);
219         Cmd->Files   = NewFiles;
220         Cmd->FileMax = NewMax;
221     }
222
223     /* If the file name is not NULL (which is legal and is used to terminate
224      * the file list), check if the file name does already exist in the file
225      * list and print a warning if so. Regardless of the search result, add
226      * the file.
227      */
228     if (File) {
229         unsigned I;
230         for (I = 0; I < Cmd->FileCount; ++I) {
231             if (strcmp (Cmd->Files[I], File) == 0) {
232                 /* Duplicate file */
233                 Warning ("Duplicate file in argument list: `%s'", File);
234                 /* No need to search further */
235                 break;
236             }
237         }
238
239         /* Add the file */
240         Cmd->Files [Cmd->FileCount++] = xstrdup (File);
241     } else {
242         /* Add a NULL pointer */
243         Cmd->Files [Cmd->FileCount++] = 0;
244     }
245 }
246
247
248
249 static void CmdInit (CmdDesc* Cmd, const char* Path)
250 /* Initialize the command using the given path to the executable */
251 {
252     /* Remember the command */
253     Cmd->Name = xstrdup (Path);
254
255     /* Use the command name as first argument */
256     CmdAddArg (Cmd, Path);
257 }
258
259
260
261 static void CmdSetOutput (CmdDesc* Cmd, const char* File)
262 /* Set the output file in a command desc */
263 {
264     CmdAddArg (Cmd, "-o");
265     CmdAddArg (Cmd, File);
266 }
267
268
269
270 static void CmdSetTarget (CmdDesc* Cmd, target_t Target)
271 /* Set the output file in a command desc */
272 {
273     CmdAddArg (Cmd, "-t");
274     CmdAddArg (Cmd, TargetNames[Target]);
275 }
276
277
278
279 /*****************************************************************************/
280 /*                              Target handling                              */
281 /*****************************************************************************/
282
283
284
285 static void SetTargetFiles (void)
286 /* Set the target system files */
287 {
288     /* Determine the names of the default startup and library file */
289     if (Target != TGT_NONE) {
290
291         /* Get a pointer to the system name and its length */
292         const char* TargetName = TargetNames [Target];
293         unsigned    TargetNameLen = strlen (TargetName);
294
295         /* Set the startup file */
296         TargetCRT0 = xmalloc (TargetNameLen + 2 + 1);
297         strcpy (TargetCRT0, TargetName);
298         strcat (TargetCRT0, ".o");
299
300         /* Set the library file */
301         TargetLib = xmalloc (TargetNameLen + 4 + 1);
302         strcpy (TargetLib, TargetName);
303         strcat (TargetLib, ".lib");
304
305     }
306 }
307
308
309
310 /*****************************************************************************/
311 /*                               Subprocesses                                */
312 /*****************************************************************************/
313
314
315
316 static void ExecProgram (CmdDesc* Cmd)
317 /* Execute a subprocess with the given name/parameters. Exit on errors. */
318 {
319     /* Call the program */
320     int Status = spawnvp (P_WAIT, Cmd->Name, Cmd->Args);
321
322     /* Check the result code */
323     if (Status < 0) {
324         /* Error executing the program */
325         Error ("Cannot execute `%s': %s", Cmd->Name, strerror (errno));
326     } else if (Status != 0) {
327         /* Called program had an error */
328         exit (Status);
329     }
330 }
331
332
333
334 static void Link (void)
335 /* Link the resulting executable */
336 {
337     unsigned I;
338
339     /* If we have a linker config file given, set the linker config file.
340      * Otherwise set the target system.
341      */
342     if (LinkerConfig) {
343         CmdAddArg (&LD65, "-C");
344         CmdAddArg (&LD65, LinkerConfig);
345     } else {
346         CmdSetTarget (&LD65, Target);
347         SetTargetFiles ();
348     }
349
350     /* Since linking is always the final step, if we have an output file name
351      * given, set it here. If we don't have an explicit output name given,
352      * try to build one from the name of the first input file.
353      */
354     if (OutputName) {
355
356         CmdAddArg (&LD65, "-o");
357         CmdAddArg (&LD65, OutputName);
358
359     } else if (FirstInput && FindExt (FirstInput)) {  /* Only if ext present! */
360
361         char* Output = MakeFilename (FirstInput, "");
362         CmdAddArg (&LD65, "-o");
363         CmdAddArg (&LD65, Output);
364         xfree (Output);
365
366     }
367
368     /* If we have a startup file, add its name as a parameter */
369     if (TargetCRT0) {
370         CmdAddArg (&LD65, TargetCRT0);
371     }
372
373     /* Add all object files as parameters */
374     for (I = 0; I < LD65.FileCount; ++I) {
375         CmdAddArg (&LD65, LD65.Files [I]);
376     }
377
378     /* Add the system runtime library */
379     if (TargetLib) {
380         CmdAddArg (&LD65, TargetLib);
381     }
382
383     /* Terminate the argument list with a NULL pointer */
384     CmdAddArg (&LD65, 0);
385
386     /* Call the linker */
387     ExecProgram (&LD65);
388 }
389
390
391
392 static void Assemble (const char* File)
393 /* Assemble the given file */
394 {
395     /* Remember the current assembler argument count */
396     unsigned ArgCount = CA65.ArgCount;
397
398     /* Set the target system */
399     CmdSetTarget (&CA65, Target);
400
401     /* If we won't link, this is the final step. In this case, set the
402      * output name.
403      */
404     if (DontLink && OutputName) {
405         CmdSetOutput (&CA65, OutputName);
406     } else {
407         /* The object file name will be the name of the source file
408          * with .s replaced by ".o". Add this file to the list of
409          * linker files.
410          */
411         char* ObjName = MakeFilename (File, ".o");
412         CmdAddFile (&LD65, ObjName);
413         xfree (ObjName);
414     }
415
416     /* Add the file as argument for the assembler */
417     CmdAddArg (&CA65, File);
418
419     /* Add a NULL pointer to terminate the argument list */
420     CmdAddArg (&CA65, 0);
421
422     /* Run the assembler */
423     ExecProgram (&CA65);
424
425     /* Remove the excess arguments */
426     CmdDelArgs (&CA65, ArgCount);
427 }
428
429
430
431 static void Compile (const char* File)
432 /* Compile the given file */
433 {
434     char* AsmName = 0;
435
436     /* Remember the current assembler argument count */
437     unsigned ArgCount = CC65.ArgCount;
438
439     /* Set the target system */
440     CmdSetTarget (&CC65, Target);
441
442     /* If we won't link, this is the final step. In this case, set the
443      * output name.
444      */
445     if (DontAssemble && OutputName) {
446         CmdSetOutput (&CC65, OutputName);
447     } else {
448         /* The assembler file name will be the name of the source file
449          * with .c replaced by ".s".
450          */
451         AsmName = MakeFilename (File, ".s");
452     }
453
454     /* Add the file as argument for the compiler */
455     CmdAddArg (&CC65, File);
456
457     /* Add a NULL pointer to terminate the argument list */
458     CmdAddArg (&CC65, 0);
459
460     /* Run the compiler */
461     ExecProgram (&CC65);
462
463     /* Remove the excess arguments */
464     CmdDelArgs (&CC65, ArgCount);
465
466     /* If this is not the final step, assemble the generated file, then
467      * remove it
468      */
469     if (!DontAssemble) {
470         Assemble (AsmName);
471         if (remove (AsmName) < 0) {
472             Warning ("Cannot remove temporary file `%s': %s",
473                      AsmName, strerror (errno));
474         }
475         xfree (AsmName);
476     }
477 }
478
479
480
481 static void CompileRes (const char* File)
482 /* Compile the given geos resource file */
483 {
484     char* AsmName = 0;
485
486     /* Remember the current assembler argument count */
487     unsigned ArgCount = GRC.ArgCount;
488
489     /* The assembler file name will be the name of the source file
490      * with .grc replaced by ".s".
491      */
492     AsmName = MakeFilename (File, ".s");
493
494     /* Add the file as argument for the resource compiler */
495     CmdAddArg (&GRC, File);
496
497     /* Add a NULL pointer to terminate the argument list */
498     CmdAddArg (&GRC, 0);
499
500     /* Run the compiler */
501     ExecProgram (&GRC);
502
503     /* Remove the excess arguments */
504     CmdDelArgs (&GRC, ArgCount);
505
506     /* If this is not the final step, assemble the generated file, then
507      * remove it
508      */
509     if (!DontAssemble) {
510         Assemble (AsmName);
511         if (remove (AsmName) < 0) {
512             Warning ("Cannot remove temporary file `%s': %s",
513                      AsmName, strerror (errno));
514         }
515     }
516
517     /* Free the assembler file name which was allocated from the heap */
518     xfree (AsmName);
519 }
520
521
522
523 /*****************************************************************************/
524 /*                                   Code                                    */
525 /*****************************************************************************/
526
527
528
529 static void Usage (void)
530 /* Print usage information and exit */
531 {
532     fprintf (stderr,
533              "Usage: %s [options] file\n"
534              "Short options:\n"
535              "  -A\t\t\tStrict ANSI mode\n"
536              "  -C name\t\tUse linker config file\n"
537              "  -Cl\t\t\tMake local variables static\n"
538              "  -D sym[=defn]\t\tDefine a preprocessor symbol\n"
539              "  -I dir\t\tSet a compiler include directory path\n"
540              "  -Ln name\t\tCreate a VICE label file\n"
541              "  -O\t\t\tOptimize code\n"
542              "  -Oi\t\t\tOptimize code, inline functions\n"
543              "  -Or\t\t\tOptimize code, honour the register keyword\n"
544              "  -Os\t\t\tOptimize code, inline known C funtions\n"
545              "  -S\t\t\tCompile but don't assemble and link\n"
546              "  -V\t\t\tPrint the version number\n"
547              "  -W\t\t\tSuppress warnings\n"
548              "  -c\t\t\tCompiler and assemble but don't link\n"
549              "  -d\t\t\tDebug mode\n"
550              "  -g\t\t\tAdd debug info\n"
551              "  -h\t\t\tHelp (this text)\n"
552              "  -l\t\t\tCreate an assembler listing\n"
553              "  -m name\t\tCreate a map file\n"
554              "  -o name\t\tName the output file\n"
555              "  -t sys\t\tSet the target system\n"
556              "  -v\t\t\tVerbose mode\n"
557              "  -vm\t\t\tVerbose map file\n"
558              "\n"
559              "Long options:\n"
560              "  --ansi\t\tStrict ANSI mode\n"
561              "  --asm-include-dir dir\tSet an assembler include directory\n"
562              "  --debug\t\tDebug mode\n"
563              "  --debug-info\t\tAdd debug info\n"
564              "  --feature name\tSet an emulation feature\n"
565              "  --help\t\tHelp (this text)\n"
566              "  --include-dir dir\tSet a compiler include directory path\n"
567              "  --listing\t\tCreate an assembler listing\n"
568              "  --mapfile name\tCreate a map file\n"
569              "  --start-addr addr\tSet the default start address\n"
570              "  --target sys\t\tSet the target system\n"
571              "  --version\t\tPrint the version number\n"
572              "  --verbose\t\tVerbose mode\n",
573              ProgName);
574 }
575
576
577
578 static void OptAnsi (const char* Opt, const char* Arg)
579 /* Strict ANSI mode (compiler) */
580 {
581     CmdAddArg (&CC65, "-A");
582 }
583
584
585
586 static void OptAsmIncludeDir (const char* Opt, const char* Arg)
587 /* Include directory (assembler) */
588 {
589     CmdAddArg (&CA65, "-I");
590     CmdAddArg (&CA65, Arg);
591 }
592
593
594
595 static void OptDebug (const char* Opt, const char* Arg)
596 /* Debug mode (compiler) */
597 {
598     CmdAddArg (&CC65, "-d");
599 }
600
601
602
603 static void OptDebugInfo (const char* Opt, const char* Arg)
604 /* Debug Info - add to compiler and assembler */
605 {
606     CmdAddArg (&CC65, "-g");
607     CmdAddArg (&CA65, "-g");
608 }
609
610
611
612 static void OptFeature (const char* Opt, const char* Arg)
613 /* Emulation features for the assembler */
614 {
615     CmdAddArg (&CA65, "--feature");
616     CmdAddArg (&CA65, Arg);
617 }
618
619
620
621 static void OptHelp (const char* Opt, const char* Arg)
622 /* Print help - cl65 */
623 {
624     Usage ();
625     exit (EXIT_SUCCESS);
626 }
627
628
629
630 static void OptIncludeDir (const char* Opt, const char* Arg)
631 /* Include directory (compiler) */
632 {
633     CmdAddArg (&CC65, "-I");
634     CmdAddArg (&CC65, Arg);
635 }
636
637
638
639 static void OptListing (const char* Opt, const char* Arg)
640 /* Create an assembler listing */
641 {
642     CmdAddArg (&CA65, "-l");
643 }
644
645
646
647 static void OptMapFile (const char* Opt, const char* Arg)
648 /* Create a map file */
649 {
650     /* Create a map file (linker) */
651     CmdAddArg (&LD65, "-m");
652     CmdAddArg (&LD65, Arg);
653 }
654
655
656
657 static void OptStartAddr (const char* Opt, const char* Arg)
658 /* Set the default start address */
659 {
660     CmdAddArg (&LD65, "-S");
661     CmdAddArg (&LD65, Arg);
662 }
663
664
665
666 static void OptTarget (const char* Opt, const char* Arg)
667 /* Set the target system */
668 {
669     Target = FindTarget (Arg);
670     if (Target == TGT_UNKNOWN) {
671         Error ("No such target system: `%s'", Arg);
672     }
673 }
674
675
676
677 static void OptVerbose (const char* Opt, const char* Arg)
678 /* Verbose mode (compiler, assembler, linker) */
679 {
680     CmdAddArg (&CC65, "-v");
681     CmdAddArg (&CA65, "-v");
682     CmdAddArg (&LD65, "-v");
683 }
684
685
686
687 static void OptVersion (const char* Opt, const char* Arg)
688 /* Print version number */
689 {
690     fprintf (stderr,
691              "cl65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n",
692              VER_MAJOR, VER_MINOR, VER_PATCH);
693 }
694
695
696
697 int main (int argc, char* argv [])
698 /* Utility main program */
699 {
700     /* Program long options */
701     static const LongOpt OptTab[] = {
702         { "--ansi",             0,      OptAnsi                 },
703         { "--asm-include-dir",  1,      OptAsmIncludeDir        },
704         { "--debug",            0,      OptDebug                },
705         { "--debug-info",       0,      OptDebugInfo            },
706         { "--feature",          1,      OptFeature              },
707         { "--help",             0,      OptHelp                 },
708         { "--include-dir",      1,      OptIncludeDir           },
709         { "--listing",          0,      OptListing              },
710         { "--mapfile",          1,      OptMapFile              },
711         { "--start-addr",       1,      OptStartAddr            },
712         { "--target",           1,      OptTarget               },
713         { "--verbose",          0,      OptVerbose              },
714         { "--version",          0,      OptVersion              },
715     };
716
717     int I;
718
719     /* Initialize the cmdline module */
720     InitCmdLine (argc, argv, "cl65");
721
722     /* Initialize the command descriptors */
723     CmdInit (&CC65, "cc65");
724     CmdInit (&CA65, "ca65");
725     CmdInit (&LD65, "ld65");
726     CmdInit (&GRC,  "grc");
727
728     /* Our default target is the C64 instead of "none" */
729     Target = TGT_C64;
730
731     /* Check the parameters */
732     I = 1;
733     while (I < argc) {
734
735         /* Get the argument */
736         const char* Arg = argv [I];
737
738         /* Check for an option */
739         if (Arg [0] == '-') {
740
741             switch (Arg [1]) {
742
743                 case '-':
744                     LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
745                     break;
746
747                 case 'A':
748                     /* Strict ANSI mode (compiler) */
749                     OptAnsi (Arg, 0);
750                     break;
751
752                 case 'C':
753                     if (Arg[2] == 'l' && Arg[3] == '\0') {
754                         /* Make local variables static */
755                         CmdAddArg (&CC65, "-Cl");
756                     } else {
757                         /* Specify linker config file */
758                         LinkerConfig = GetArg (&I, 2);
759                     }
760                     break;
761
762                 case 'D':
763                     /* Define a preprocessor symbol (compiler) */
764                     CmdAddArg (&CC65, "-D");
765                     CmdAddArg (&CC65, GetArg (&I, 2));
766                     break;
767
768                 case 'I':
769                     /* Include directory (compiler) */
770                     OptIncludeDir (Arg, GetArg (&I, 2));
771                     break;
772
773                 case 'L':
774                     if (Arg[2] == 'n') {
775                         /* VICE label file (linker) */
776                         CmdAddArg (&LD65, "-Ln");
777                         CmdAddArg (&LD65, GetArg (&I, 3));
778                     } else {
779                         UnknownOption (Arg);
780                     }
781                     break;
782
783                 case 'O':
784                     /* Optimize code (compiler, also covers -Oi and others) */
785                     CmdAddArg (&CC65, Arg);
786                     break;
787
788                 case 'S':
789                     /* Dont assemble and link the created files */
790                     DontLink = DontAssemble = 1;
791                     break;
792
793                 case 'T':
794                     /* Include source as comment (compiler) */
795                     CmdAddArg (&CC65, "-T");
796                     break;
797
798                 case 'V':
799                     /* Print version number */
800                     OptVersion (Arg, 0);
801                     break;
802
803                 case 'W':
804                     /* Suppress warnings - compiler and assembler */
805                     CmdAddArg (&CC65, "-W");
806                     CmdAddArg (&CA65, "-W");
807                     CmdAddArg (&CA65, "0");
808                     break;
809
810                 case 'c':
811                     /* Don't link the resulting files */
812                     DontLink = 1;
813                     break;
814
815                 case 'd':
816                     /* Debug mode (compiler) */
817                     OptDebug (Arg, 0);
818                     break;
819
820                 case 'g':
821                     /* Debugging - add to compiler and assembler */
822                     OptDebugInfo (Arg, 0);
823                     break;
824
825                 case 'h':
826                 case '?':
827                     /* Print help - cl65 */
828                     OptHelp (Arg, 0);
829                     break;
830
831                 case 'l':
832                     /* Create an assembler listing */
833                     OptListing (Arg, 0);
834                     break;
835
836                 case 'm':
837                     /* Create a map file (linker) */
838                     OptMapFile (Arg, GetArg (&I, 2));
839                     break;
840
841                 case 'o':
842                     /* Name the output file */
843                     OutputName = GetArg (&I, 2);
844                     break;
845
846                 case 't':
847                     /* Set target system - compiler, assembler and linker */
848                     OptTarget (Arg, GetArg (&I, 2));
849                     break;
850
851                 case 'v':
852                     if (Arg [2] == 'm') {
853                         /* Verbose map file (linker) */
854                         CmdAddArg (&LD65, "-vm");
855                     } else {
856                         /* Verbose mode (compiler, assembler, linker) */
857                         OptVerbose (Arg, 0);
858                     }
859                     break;
860
861                 default:
862                     UnknownOption (Arg);
863             }
864         } else {
865
866             /* Remember the first file name */
867             if (FirstInput == 0) {
868                 FirstInput = Arg;
869             }
870
871             /* Determine the file type by the extension */
872             switch (GetFileType (Arg)) {
873
874                 case FILETYPE_C:
875                     /* Compile the file */
876                     Compile (Arg);
877                     break;
878
879                 case FILETYPE_ASM:
880                     /* Assemble the file */
881                     if (!DontAssemble) {
882                         Assemble (Arg);
883                     }
884                     break;
885
886                 case FILETYPE_OBJ:
887                 case FILETYPE_LIB:
888                     /* Add to the linker files */
889                     CmdAddFile (&LD65, Arg);
890                     break;
891
892                 case FILETYPE_GR:
893                     /* Add to the resource compiler files */
894                     CompileRes (Arg);
895                     break;
896
897                 default:
898                     Error ("Don't know what to do with `%s'", Arg);
899
900             }
901
902         }
903
904         /* Next argument */
905         ++I;
906     }
907
908     /* Check if we had any input files */
909     if (FirstInput == 0) {
910         Warning ("No input files");
911     }
912
913     /* Link the given files if requested and if we have any */
914     if (DontLink == 0 && LD65.FileCount > 0) {
915         Link ();
916     }
917
918     /* Return an apropriate exit code */
919     return EXIT_SUCCESS;
920 }
921
922
923
924