]> git.sur5r.net Git - cc65/blob - src/cc65/main.c
Changed generation of makefile dependencies:
[cc65] / src / cc65 / main.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  main.c                                   */
4 /*                                                                           */
5 /*                             cc65 main program                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2010, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
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 <string.h>
38 #include <stdlib.h>
39 #include <errno.h>
40
41 /* common */
42 #include "abend.h"
43 #include "chartype.h"
44 #include "cmdline.h"
45 #include "cpu.h"
46 #include "debugflag.h"
47 #include "fname.h"
48 #include "mmodel.h"
49 #include "print.h"
50 #include "segnames.h"
51 #include "strbuf.h"
52 #include "target.h"
53 #include "tgttrans.h"
54 #include "version.h"
55 #include "xmalloc.h"
56
57 /* cc65 */
58 #include "asmcode.h"
59 #include "compile.h"
60 #include "codeopt.h"
61 #include "error.h"
62 #include "global.h"
63 #include "incpath.h"
64 #include "input.h"
65 #include "macrotab.h"
66 #include "output.h"
67 #include "scanner.h"
68 #include "segments.h"
69 #include "standard.h"
70 #include "svnversion.h"
71
72
73
74 /*****************************************************************************/
75 /*                                   Code                                    */
76 /*****************************************************************************/
77
78
79
80 static void Usage (void)
81 /* Print usage information to stderr */
82 {
83     printf ("Usage: %s [options] file\n"
84             "Short options:\n"
85             "  -Cl\t\t\t\tMake local variables static\n"
86             "  -Dsym[=defn]\t\t\tDefine a symbol\n"
87             "  -E\t\t\t\tStop after the preprocessing stage\n"
88             "  -I dir\t\t\tSet an include directory search path\n"
89             "  -O\t\t\t\tOptimize code\n"
90             "  -Oi\t\t\t\tOptimize code, inline more code\n"
91             "  -Or\t\t\t\tEnable register variables\n"
92             "  -Os\t\t\t\tInline some known functions\n"
93             "  -T\t\t\t\tInclude source as comment\n"
94             "  -V\t\t\t\tPrint the compiler version number\n"
95             "  -W\t\t\t\tSuppress warnings\n"
96             "  -d\t\t\t\tDebug mode\n"
97             "  -g\t\t\t\tAdd debug info to object file\n"
98             "  -h\t\t\t\tHelp (this text)\n"
99             "  -j\t\t\t\tDefault characters are signed\n"
100             "  -mm model\t\t\tSet the memory model\n"
101             "  -o name\t\t\tName the output file\n"
102             "  -r\t\t\t\tEnable register variables\n"
103             "  -t sys\t\t\tSet the target system\n"
104             "  -v\t\t\t\tIncrease verbosity\n"
105             "\n"
106             "Long options:\n"
107             "  --add-source\t\t\tInclude source as comment\n"
108             "  --bss-name seg\t\tSet the name of the BSS segment\n"
109             "  --check-stack\t\t\tGenerate stack overflow checks\n"
110             "  --code-name seg\t\tSet the name of the CODE segment\n"
111             "  --codesize x\t\t\tAccept larger code by factor x\n"
112             "  --cpu type\t\t\tSet cpu type (6502, 65c02)\n"
113             "  --create-dep name\t\tCreate a make dependency file\n"
114             "  --create-full-dep name\tCreate a full make dependency file\n"
115             "  --data-name seg\t\tSet the name of the DATA segment\n"
116             "  --debug\t\t\tDebug mode\n"
117             "  --debug-info\t\t\tAdd debug info to object file\n"
118             "  --debug-opt name\t\tDebug optimization steps\n"
119             "  --disable-opt name\t\tDisable an optimization step\n"
120             "  --enable-opt name\t\tEnable an optimization step\n"
121             "  --forget-inc-paths\t\tForget include search paths\n"
122             "  --help\t\t\tHelp (this text)\n"
123             "  --include-dir dir\t\tSet an include directory search path\n"
124             "  --list-opt-steps\t\tList all optimizer steps and exit\n"
125             "  --local-strings\t\tEmit string literals immediately\n"
126             "  --memory-model model\t\tSet the memory model\n"
127             "  --register-space b\t\tSet space available for register variables\n"
128             "  --register-vars\t\tEnable register variables\n"
129             "  --rodata-name seg\t\tSet the name of the RODATA segment\n"
130             "  --signed-chars\t\tDefault characters are signed\n"
131             "  --standard std\t\tLanguage standard (c89, c99, cc65)\n"
132             "  --static-locals\t\tMake local variables static\n"
133             "  --target sys\t\t\tSet the target system\n"
134             "  --verbose\t\t\tIncrease verbosity\n"
135             "  --version\t\t\tPrint the compiler version number\n"
136             "  --writable-strings\t\tMake string literals writable\n",
137             ProgName);
138 }
139
140
141
142 static void cbmsys (const char* sys)
143 /* Define a CBM system */
144 {
145     DefineNumericMacro ("__CBM__", 1);
146     DefineNumericMacro (sys, 1);
147 }
148
149
150
151 static void SetSys (const char* Sys)
152 /* Define a target system */
153 {
154     switch (Target = FindTarget (Sys)) {
155
156         case TGT_NONE:
157             break;
158
159         case TGT_MODULE:
160             AbEnd ("Cannot use `module' as a target for the compiler");
161             break;
162
163         case TGT_ATARI:
164             DefineNumericMacro ("__ATARI__", 1);
165             break;
166
167         case TGT_C16:
168             cbmsys ("__C16__");
169             break;
170
171         case TGT_C64:
172             cbmsys ("__C64__");
173             break;
174
175         case TGT_VIC20:
176             cbmsys ("__VIC20__");
177             break;
178
179         case TGT_C128:
180             cbmsys ("__C128__");
181             break;
182
183         case TGT_PLUS4:
184             cbmsys ("__PLUS4__");
185             break;
186
187         case TGT_CBM510:
188             cbmsys ("__CBM510__");
189             break;
190
191         case TGT_CBM610:
192             cbmsys ("__CBM610__");
193             break;
194
195         case TGT_PET:
196             cbmsys ("__PET__");
197             break;
198
199         case TGT_BBC:
200             DefineNumericMacro ("__BBC__", 1);
201             break;
202
203         case TGT_APPLE2:
204             DefineNumericMacro ("__APPLE2__", 1);
205             break;
206
207         case TGT_APPLE2ENH:
208             DefineNumericMacro ("__APPLE2ENH__", 1);
209             break;
210
211         case TGT_GEOS:
212             /* Do not handle as a CBM system */
213             DefineNumericMacro ("__GEOS__", 1);
214             break;
215
216         case TGT_LUNIX:
217             DefineNumericMacro ("__LUNIX__", 1);
218             break;
219
220         case TGT_ATMOS:
221             DefineNumericMacro ("__ATMOS__", 1);
222             break;
223
224         case TGT_NES:
225             DefineNumericMacro ("__NES__", 1);
226             break;
227
228         case TGT_SUPERVISION:
229             DefineNumericMacro ("__SUPERVISION__", 1);
230             break;
231
232         case TGT_LYNX:
233             DefineNumericMacro ("__LYNX__", 1);
234             break;
235
236         default:
237             AbEnd ("Unknown target system type %d", Target);
238     }
239
240     /* Initialize the translation tables for the target system */
241     TgtTranslateInit ();
242 }
243
244
245
246 static void FileNameOption (const char* Opt, const char* Arg, StrBuf* Name)
247 /* Handle an option that remembers a file name for later */
248 {
249     /* Cannot have the option twice */
250     if (SB_NotEmpty (Name)) {
251         AbEnd ("Cannot use option `%s' twice", Opt);
252     }
253     /* Remember the file name for later */
254     SB_CopyStr (Name, Arg);
255     SB_Terminate (Name);
256 }
257
258
259
260 static void DefineSym (const char* Def)
261 /* Define a symbol on the command line */
262 {
263     const char* P = Def;
264
265     /* The symbol must start with a character or underline */
266     if (Def [0] != '_' && !IsAlpha (Def [0])) {
267         InvDef (Def);
268     }
269
270     /* Check the symbol name */
271     while (IsAlNum (*P) || *P == '_') {
272         ++P;
273     }
274
275     /* Do we have a value given? */
276     if (*P != '=') {
277         if (*P != '\0') {
278             InvDef (Def);
279         }
280         /* No value given. Define the macro with the value 1 */
281         DefineNumericMacro (Def, 1);
282     } else {
283         /* We have a value, P points to the '=' character. Since the argument
284          * is const, create a copy and replace the '=' in the copy by a zero
285          * terminator.
286          */
287         char* Q;
288         unsigned Len = strlen (Def)+1;
289         char* S = (char*) xmalloc (Len);
290         memcpy (S, Def, Len);
291         Q = S + (P - Def);
292         *Q++ = '\0';
293
294         /* Define this as a macro */
295         DefineTextMacro (S, Q);
296
297         /* Release the allocated memory */
298         xfree (S);
299     }
300 }
301
302
303
304 static void CheckSegName (const char* Seg)
305 /* Abort if the given name is not a valid segment name */
306 {
307     /* Print an error and abort if the name is not ok */
308     if (!ValidSegName (Seg)) {
309         AbEnd ("Segment name `%s' is invalid", Seg);
310     }
311 }
312
313
314
315 static void OptAddSource (const char* Opt attribute ((unused)),
316                           const char* Arg attribute ((unused)))
317 /* Add source lines as comments in generated assembler file */
318 {
319     AddSource = 1;
320 }
321
322
323
324 static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
325 /* Handle the --bss-name option */
326 {
327     /* Check for a valid name */
328     CheckSegName (Arg);
329
330     /* Set the name */
331     SetSegName (SEG_BSS, Arg);
332 }
333
334
335
336 static void OptCheckStack (const char* Opt attribute ((unused)),
337                            const char* Arg attribute ((unused)))
338 /* Handle the --check-stack option */
339 {
340     IS_Set (&CheckStack, 1);
341 }
342
343
344
345 static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg)
346 /* Handle the --code-name option */
347 {
348     /* Check for a valid name */
349     CheckSegName (Arg);
350
351     /* Set the name */
352     SetSegName (SEG_CODE, Arg);
353 }
354
355
356
357 static void OptCodeSize (const char* Opt, const char* Arg)
358 /* Handle the --codesize option */
359 {
360     unsigned Factor;
361     char     BoundsCheck;
362
363     /* Numeric argument expected */
364     if (sscanf (Arg, "%u%c", &Factor, &BoundsCheck) != 1 ||
365         Factor < 10 || Factor > 1000) {
366         AbEnd ("Argument for %s is invalid", Opt);
367     }
368     IS_Set (&CodeSizeFactor, Factor);
369 }
370
371
372
373 static void OptCreateDep (const char* Opt, const char* Arg)
374 /* Handle the --create-dep option */
375 {
376     FileNameOption (Opt, Arg, &DepName);
377 }
378
379
380
381 static void OptCreateFullDep (const char* Opt attribute ((unused)),
382                               const char* Arg)
383 /* Handle the --create-full-dep option */
384 {
385     FileNameOption (Opt, Arg, &FullDepName);
386 }
387
388
389
390 static void OptCPU (const char* Opt, const char* Arg)
391 /* Handle the --cpu option */
392 {
393     /* Find the CPU from the given name */
394     CPU = FindCPU (Arg);
395     if (CPU != CPU_6502 && CPU != CPU_6502X && CPU != CPU_65SC02 &&
396         CPU != CPU_65C02 && CPU != CPU_65816 && CPU != CPU_HUC6280) {
397         AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
398     }
399 }
400
401
402
403 static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
404 /* Handle the --data-name option */
405 {
406     /* Check for a valid name */
407     CheckSegName (Arg);
408
409     /* Set the name */
410     SetSegName (SEG_DATA, Arg);
411 }
412
413
414
415 static void OptDebug (const char* Opt attribute ((unused)),
416                       const char* Arg attribute ((unused)))
417 /* Compiler debug mode */
418 {
419     ++Debug;
420 }
421
422
423
424 static void OptDebugInfo (const char* Opt attribute ((unused)),
425                           const char* Arg attribute ((unused)))
426 /* Add debug info to the object file */
427 {
428     DebugInfo = 1;
429 }
430
431
432
433 static void OptDebugOpt (const char* Opt attribute ((unused)), const char* Arg)
434 /* Debug optimization steps */
435 {
436     char Buf [128];
437     char* Line;
438
439     /* Open the file */
440     FILE* F = fopen (Arg, "r");
441     if (F == 0) {
442         AbEnd ("Cannot open `%s': %s", Arg, strerror (errno));
443     }
444
445     /* Read line by line, ignore empty lines and switch optimization
446      * steps on/off.
447      */
448     while (fgets (Buf, sizeof (Buf), F) != 0) {
449
450         /* Remove trailing control chars. This will also remove the
451          * trailing newline.
452          */
453         unsigned Len = strlen (Buf);
454         while (Len > 0 && IsControl (Buf[Len-1])) {
455             --Len;
456         }
457         Buf[Len] = '\0';
458
459         /* Get a pointer to the buffer and remove leading white space */
460         Line = Buf;
461         while (IsBlank (*Line)) {
462             ++Line;
463         }
464
465         /* Check the first character and enable/disable the step or
466          * ignore the line
467          */
468         switch (*Line) {
469
470             case '\0':
471             case '#':
472             case ';':
473                 /* Empty or comment line */
474                 continue;
475
476             case '-':
477                 DisableOpt (Line+1);
478                 break;
479
480             case '+':
481                 ++Line;
482                 /* FALLTHROUGH */
483
484             default:
485                 EnableOpt (Line);
486                 break;
487
488         }
489
490     }
491
492     /* Close the file, no error check here since we were just reading and
493      * this is only a debug function.
494      */
495     (void) fclose (F);
496 }
497
498
499
500 static void OptDisableOpt (const char* Opt attribute ((unused)), const char* Arg)
501 /* Disable an optimization step */
502 {
503     DisableOpt (Arg);
504 }
505
506
507
508 static void OptEnableOpt (const char* Opt attribute ((unused)), const char* Arg)
509 /* Enable an optimization step */
510 {
511     EnableOpt (Arg);
512 }
513
514
515
516 static void OptForgetIncPaths (const char* Opt attribute ((unused)),
517                                const char* Arg attribute ((unused)))
518 /* Forget all currently defined include paths */
519 {
520     ForgetAllIncludePaths ();
521 }
522
523
524
525 static void OptHelp (const char* Opt attribute ((unused)),
526                      const char* Arg attribute ((unused)))
527 /* Print usage information and exit */
528 {
529     Usage ();
530     exit (EXIT_SUCCESS);
531 }
532
533
534
535 static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
536 /* Add an include search path */
537 {
538     AddIncludePath (Arg, INC_SYS | INC_USER);
539 }
540
541
542
543 static void OptListOptSteps (const char* Opt attribute ((unused)),
544                              const char* Arg attribute ((unused)))
545 /* List all optimizer steps */
546 {
547     /* List the optimizer steps */
548     ListOptSteps (stdout);
549
550     /* Terminate */
551     exit (EXIT_SUCCESS);
552 }
553
554
555
556 static void OptLocalStrings (const char* Opt attribute ((unused)),
557                              const char* Arg attribute ((unused)))
558 /* Emit string literals immediately */
559 {
560     IS_Set (&LocalStrings, 1);
561 }
562
563
564
565 static void OptMemoryModel (const char* Opt, const char* Arg)
566 /* Set the memory model */
567 {
568     mmodel_t M;
569
570     /* Check the current memory model */
571     if (MemoryModel != MMODEL_UNKNOWN) {
572         AbEnd ("Cannot use option `%s' twice", Opt);
573     }
574
575     /* Translate the memory model name and check it */
576     M = FindMemoryModel (Arg);
577     if (M == MMODEL_UNKNOWN) {
578         AbEnd ("Unknown memory model: %s", Arg);
579     } else if (M == MMODEL_HUGE) {
580         AbEnd ("Unsupported memory model: %s", Arg);
581     }
582
583     /* Set the memory model */
584     SetMemoryModel (M);
585 }
586
587
588
589 static void OptRegisterSpace (const char* Opt, const char* Arg)
590 /* Handle the --register-space option */
591 {
592     /* Numeric argument expected */
593     if (sscanf (Arg, "%u", &RegisterSpace) != 1 || RegisterSpace > 256) {
594         AbEnd ("Argument for option %s is invalid", Opt);
595     }
596 }
597
598
599
600 static void OptRegisterVars (const char* Opt attribute ((unused)),
601                              const char* Arg attribute ((unused)))
602 /* Handle the --register-vars option */
603 {
604     IS_Set (&EnableRegVars, 1);
605 }
606
607
608
609 static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg)
610 /* Handle the --rodata-name option */
611 {
612     /* Check for a valid name */
613     CheckSegName (Arg);
614
615     /* Set the name */
616     SetSegName (SEG_RODATA, Arg);
617 }
618
619
620
621 static void OptSignedChars (const char* Opt attribute ((unused)),
622                             const char* Arg attribute ((unused)))
623 /* Make default characters signed */
624 {
625     IS_Set (&SignedChars, 1);
626 }
627
628
629
630 static void OptStandard (const char* Opt, const char* Arg)
631 /* Handle the --standard option */
632 {
633     /* Find the standard from the given name */
634     standard_t Std = FindStandard (Arg);
635     if (Std == STD_UNKNOWN) {
636         AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
637     } else if (IS_Get (&Standard) != STD_UNKNOWN) {
638         AbEnd ("Option %s given more than once", Opt);
639     } else {
640         IS_Set (&Standard, Std);
641     }
642 }
643
644
645
646 static void OptStaticLocals (const char* Opt attribute ((unused)),
647                              const char* Arg attribute ((unused)))
648 /* Place local variables in static storage */
649 {
650     IS_Set (&StaticLocals, 1);
651 }
652
653
654
655 static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
656 /* Set the target system */
657 {
658     SetSys (Arg);
659 }
660
661
662
663 static void OptVerbose (const char* Opt attribute ((unused)),
664                         const char* Arg attribute ((unused)))
665 /* Increase verbosity */
666 {
667     ++Verbosity;
668 }
669
670
671
672 static void OptVersion (const char* Opt attribute ((unused)),
673                         const char* Arg attribute ((unused)))
674 /* Print the compiler version */
675 {
676     fprintf (stderr,
677              "cc65 V%s\nSVN version: %s\n",
678              GetVersionAsString (), SVNVersion);
679     exit (EXIT_SUCCESS);
680 }
681
682
683
684 static void OptWarning (const char* Opt attribute ((unused)), const char* Arg)
685 /* Handle the -W option */
686 {
687     StrBuf W = AUTO_STRBUF_INITIALIZER;
688
689     /* Arg is a list of suboptions, separated by commas */
690     while (Arg) {
691
692         const char* Pos;
693         int         Enabled = 1;
694         IntStack*   S;
695
696         /* The suboption may be prefixed with '-' or '+' */
697         if (*Arg == '-') {
698             Enabled = 0;
699             ++Arg;
700         } else if (*Arg == '+') {
701             /* This is the default */
702             ++Arg;
703         }
704
705         /* Get the next suboption */
706         Pos = strchr (Arg, ',');
707         if (Pos) {
708             SB_CopyBuf (&W, Arg, Pos - Arg);
709             Arg = Pos + 1;
710         } else {
711             SB_CopyStr (&W, Arg);
712             Arg = 0;
713         }
714         SB_Terminate (&W);
715
716         /* Search for the warning */
717         S = FindWarning (SB_GetConstBuf (&W));
718         if (S == 0) {
719             InvArg (Opt, SB_GetConstBuf (&W));
720         }
721         IS_Set (S, Enabled);
722     }
723
724     /* Free allocated memory */
725     SB_Done (&W);
726 }
727
728
729
730 static void OptWritableStrings (const char* Opt attribute ((unused)),
731                                 const char* Arg attribute ((unused)))
732 /* Make string literals writable */
733 {
734     IS_Set (&WritableStrings, 1);
735 }
736
737
738
739 int main (int argc, char* argv[])
740 {
741     /* Program long options */
742     static const LongOpt OptTab[] = {
743         { "--add-source",       0,      OptAddSource            },
744         { "--bss-name",         1,      OptBssName              },
745         { "--check-stack",      0,      OptCheckStack           },
746         { "--code-name",        1,      OptCodeName             },
747         { "--codesize",         1,      OptCodeSize             },
748         { "--cpu",              1,      OptCPU                  },
749         { "--create-dep",       1,      OptCreateDep            },
750         { "--create-full-dep",  1,      OptCreateFullDep        },
751         { "--data-name",        1,      OptDataName             },
752         { "--debug",            0,      OptDebug                },
753         { "--debug-info",       0,      OptDebugInfo            },
754         { "--debug-opt",        1,      OptDebugOpt             },
755         { "--disable-opt",      1,      OptDisableOpt           },
756         { "--enable-opt",       1,      OptEnableOpt            },
757         { "--forget-inc-paths", 0,      OptForgetIncPaths       },
758         { "--help",             0,      OptHelp                 },
759         { "--include-dir",      1,      OptIncludeDir           },
760         { "--list-opt-steps",   0,      OptListOptSteps         },
761         { "--local-strings",    0,      OptLocalStrings         },
762         { "--memory-model",     1,      OptMemoryModel          },
763         { "--register-space",   1,      OptRegisterSpace        },
764         { "--register-vars",    0,      OptRegisterVars         },
765         { "--rodata-name",      1,      OptRodataName           },
766         { "--signed-chars",     0,      OptSignedChars          },
767         { "--standard",         1,      OptStandard             },
768         { "--static-locals",    0,      OptStaticLocals         },
769         { "--target",           1,      OptTarget               },
770         { "--verbose",          0,      OptVerbose              },
771         { "--version",          0,      OptVersion              },
772         { "--writable-strings", 0,      OptWritableStrings      },
773     };
774
775     unsigned I;
776
777     /* Initialize the input file name */
778     const char* InputFile  = 0;
779
780     /* Initialize the cmdline module */
781     InitCmdLine (&argc, &argv, "cc65");
782
783     /* Initialize the default segment names */
784     InitSegNames ();
785
786     /* Initialize the include search paths */
787     InitIncludePaths ();
788
789     /* Parse the command line */
790     I = 1;
791     while (I < ArgCount) {
792
793         const char* P;
794
795         /* Get the argument */
796         const char* Arg = ArgVec[I];
797
798         /* Check for an option */
799         if (Arg[0] == '-') {
800
801             switch (Arg[1]) {
802
803                 case '-':
804                     LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
805                     break;
806
807                 case 'd':
808                     OptDebug (Arg, 0);
809                     break;
810
811                 case 'h':
812                 case '?':
813                     OptHelp (Arg, 0);
814                     break;
815
816                 case 'g':
817                     OptDebugInfo (Arg, 0);
818                     break;
819
820                 case 'j':
821                     OptSignedChars (Arg, 0);
822                     break;
823
824                 case 'o':
825                     SetOutputName (GetArg (&I, 2));
826                     break;
827
828                 case 'r':
829                     OptRegisterVars (Arg, 0);
830                     break;
831
832                 case 't':
833                     OptTarget (Arg, GetArg (&I, 2));
834                     break;
835
836                 case 'u':
837                     OptCreateDep (Arg, 0);
838                     break;
839
840                 case 'v':
841                     OptVerbose (Arg, 0);
842                     break;
843
844                 case 'C':
845                     P = Arg + 2;
846                     while (*P) {
847                         switch (*P++) {
848                             case 'l':
849                                 OptStaticLocals (Arg, 0);
850                                 break;
851                             default:
852                                 UnknownOption (Arg);
853                                 break;
854                         }
855                     }
856                     break;
857
858                 case 'D':
859                     DefineSym (GetArg (&I, 2));
860                     break;
861
862                 case 'E':
863                     PreprocessOnly = 1;
864                     break;
865
866                 case 'I':
867                     OptIncludeDir (Arg, GetArg (&I, 2));
868                     break;
869
870                 case 'O':
871                     IS_Set (&Optimize, 1);
872                     P = Arg + 2;
873                     while (*P) {
874                         switch (*P++) {
875                             case 'i':
876                                 IS_Set (&CodeSizeFactor, 200);
877                                 break;
878                             case 'r':
879                                 IS_Set (&EnableRegVars, 1);
880                                 break;
881                             case 's':
882                                 IS_Set (&InlineStdFuncs, 1);
883                                 break;
884                         }
885                     }
886                     break;
887
888                 case 'T':
889                     OptAddSource (Arg, 0);
890                     break;
891
892                 case 'V':
893                     OptVersion (Arg, 0);
894                     break;
895
896                 case 'W':
897                     OptWarning (Arg, GetArg (&I, 2));
898                     break;
899
900                 default:
901                     UnknownOption (Arg);
902                     break;
903             }
904         } else {
905             if (InputFile) {
906                 fprintf (stderr, "additional file specs ignored\n");
907             } else {
908                 InputFile = Arg;
909             }
910         }
911
912         /* Next argument */
913         ++I;
914     }
915
916     /* Did we have a file spec on the command line? */
917     if (InputFile == 0) {
918         AbEnd ("No input files");
919     }
920
921     /* Create the output file name if it was not explicitly given */
922     MakeDefaultOutputName (InputFile);
923
924     /* If no CPU given, use the default CPU for the target */
925     if (CPU == CPU_UNKNOWN) {
926         if (Target != TGT_UNKNOWN) {
927             CPU = DefaultCPU[Target];
928         } else {
929             CPU = CPU_6502;
930         }
931     }
932
933     /* If no memory model was given, use the default */
934     if (MemoryModel == MMODEL_UNKNOWN) {
935         SetMemoryModel (MMODEL_NEAR);
936     }
937
938     /* If no language standard was given, use the default one */
939     if (IS_Get (&Standard) == STD_UNKNOWN) {
940         IS_Set (&Standard, STD_DEFAULT);
941     }
942
943     /* Go! */
944     Compile (InputFile);
945
946     /* Create the output file if we didn't had any errors */
947     if (PreprocessOnly == 0 && (ErrorCount == 0 || Debug)) {
948
949         /* Emit literals, externals, do cleanup and optimizations */
950         FinishCompile ();
951
952         /* Open the file */
953         OpenOutputFile ();
954
955         /* Write the output to the file */
956         WriteAsmOutput ();
957         Print (stdout, 1, "Wrote output to `%s'\n", OutputFilename);
958
959         /* Close the file, check for errors */
960         CloseOutputFile ();
961
962         /* Create dependencies if requested */
963         CreateDependencies ();
964     }
965
966     /* Return an apropriate exit code */
967     return (ErrorCount > 0)? EXIT_FAILURE : EXIT_SUCCESS;
968 }
969
970
971