]> git.sur5r.net Git - cc65/blob - src/cl65/main.c
Merge pull request #7 from greg-king5/config-buf
[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-2013, 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 /* Check out if we have a spawn() function on the system, or if we must use
37  * our own.
38  */
39 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__MINGW32__) || defined(__DJGPP__)
40 #  define HAVE_SPAWN    1
41 #else
42 #  define NEED_SPAWN   1
43 #endif
44 #if defined(_MSC_VER)
45 #  pragma warning(disable : 4996)
46 #endif
47
48
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <ctype.h>
53 #include <errno.h>
54 #ifdef HAVE_SPAWN
55 #  include <process.h>
56 #endif
57
58 /* common */
59 #include "attrib.h"
60 #include "cmdline.h"
61 #include "filetype.h"
62 #include "fname.h"
63 #include "mmodel.h"
64 #include "strbuf.h"
65 #include "target.h"
66 #include "version.h"
67 #include "xmalloc.h"
68
69 /* cl65 */
70 #include "global.h"
71 #include "error.h"
72
73
74
75 /*****************************************************************************/
76 /*                                   Data                                    */
77 /*****************************************************************************/
78
79
80
81 /* Struct that describes a command */
82 typedef struct CmdDesc CmdDesc;
83 struct CmdDesc {
84     char*       Name;           /* The command name */
85
86     unsigned    ArgCount;       /* Count of arguments */
87     unsigned    ArgMax;         /* Maximum count of arguments */
88     char**      Args;           /* The arguments */
89
90     unsigned    FileCount;      /* Count of files to translate */
91     unsigned    FileMax;        /* Maximum count of files */
92     char**      Files;          /* The files */
93 };
94
95 /* Command descriptors for the different programs */
96 static CmdDesc CC65 = { 0, 0, 0, 0, 0, 0, 0 };
97 static CmdDesc CA65 = { 0, 0, 0, 0, 0, 0, 0 };
98 static CmdDesc CO65 = { 0, 0, 0, 0, 0, 0, 0 };
99 static CmdDesc LD65 = { 0, 0, 0, 0, 0, 0, 0 };
100 static CmdDesc GRC  = { 0, 0, 0, 0, 0, 0, 0 };
101
102 /* Variables controlling the steps we're doing */
103 static int DoLink       = 1;
104 static int DoAssemble   = 1;
105
106 /* The name of the output file, NULL if none given */
107 static const char* OutputName = 0;
108
109 /* The name of the linker configuration file if given */
110 static const char* LinkerConfig = 0;
111
112 /* The name of the first input file. This will be used to construct the
113  * executable file name if no explicit name is given.
114  */
115 static const char* FirstInput = 0;
116
117 /* The names of the files for dependency generation */
118 static const char* DepName = 0;
119 static const char* FullDepName = 0;
120
121 /* Remember if we should link a module */
122 static int Module = 0;
123
124 /* Extension used for a module */
125 #define MODULE_EXT      ".o65"
126
127 /* Name of the target specific runtime library */
128 static char* TargetLib  = 0;
129
130
131
132 /*****************************************************************************/
133 /*                Include the system specific spawn function                 */
134 /*****************************************************************************/
135
136
137
138 #if defined(NEED_SPAWN)
139 #  if defined(SPAWN_AMIGA)
140 #    include "spawn-amiga.inc"
141 #  else
142 #    include "spawn-unix.inc"
143 #  endif
144 #endif
145
146
147
148 /*****************************************************************************/
149 /*                        Command structure handling                         */
150 /*****************************************************************************/
151
152
153
154 static void CmdExpand (CmdDesc* Cmd)
155 /* Expand the argument vector */
156 {
157     unsigned NewMax  = Cmd->ArgMax + 10;
158     char**       NewArgs = xmalloc (NewMax * sizeof (char*));
159     memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
160     xfree (Cmd->Args);
161     Cmd->Args   = NewArgs;
162     Cmd->ArgMax = NewMax;
163 }
164
165
166
167 static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
168 /* Add a new argument to the command */
169 {
170     /* Expand the argument vector if needed */
171     if (Cmd->ArgCount >= Cmd->ArgMax) {
172         CmdExpand (Cmd);
173     }
174
175     /* Add a copy of the new argument, allow a NULL pointer */
176     if (Arg) {
177         Cmd->Args[Cmd->ArgCount++] = xstrdup (Arg);
178     } else {
179         Cmd->Args[Cmd->ArgCount++] = 0;
180     }
181 }
182
183
184
185 static void CmdAddArg2 (CmdDesc* Cmd, const char* Arg1, const char* Arg2)
186 /* Add a new argument pair to the command */
187 {
188     CmdAddArg (Cmd, Arg1);
189     CmdAddArg (Cmd, Arg2);
190 }
191
192
193
194 static void CmdAddArgList (CmdDesc* Cmd, const char* ArgList)
195 /* Add a list of arguments separated by commas */
196 {
197     const char* Arg = ArgList;
198     const char* P   = Arg;
199
200     while (1) {
201         if (*P == '\0' || *P == ',') {
202
203             /* End of argument, add it */
204             unsigned Len = P - Arg;
205
206             /* Expand the argument vector if needed */
207             if (Cmd->ArgCount >= Cmd->ArgMax) {
208                 CmdExpand (Cmd);
209             }
210
211             /* Add the new argument */
212             Cmd->Args[Cmd->ArgCount] = memcpy (xmalloc (Len + 1), Arg, Len);
213             Cmd->Args[Cmd->ArgCount][Len] = '\0';
214             ++Cmd->ArgCount;
215
216             /* If the argument was terminated by a comma, skip it, otherwise
217              * we're done.
218              */
219             if (*P == ',') {
220                 /* Start over at next char */
221                 Arg = ++P;
222             } else {
223                 break;
224             }
225         } else {
226             /* Skip other chars */
227             ++P;
228         }
229     }
230
231 }
232
233
234
235 static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
236 /* Remove all arguments with an index greater than LastValid */
237 {
238     while (Cmd->ArgCount > LastValid) {
239         Cmd->ArgCount--;
240         xfree (Cmd->Args [Cmd->ArgCount]);
241         Cmd->Args [Cmd->ArgCount] = 0;
242     }
243 }
244
245
246
247 static void CmdAddFile (CmdDesc* Cmd, const char* File)
248 /* Add a new file to the command */
249 {
250     /* Expand the file vector if needed */
251     if (Cmd->FileCount == Cmd->FileMax) {
252         unsigned NewMax   = Cmd->FileMax + 10;
253         char**   NewFiles = xmalloc (NewMax * sizeof (char*));
254         memcpy (NewFiles, Cmd->Files, Cmd->FileMax * sizeof (char*));
255         xfree (Cmd->Files);
256         Cmd->Files   = NewFiles;
257         Cmd->FileMax = NewMax;
258     }
259
260     /* If the file name is not NULL (which is legal and is used to terminate
261      * the file list), check if the file name does already exist in the file
262      * list and print a warning if so. Regardless of the search result, add
263      * the file.
264      */
265     if (File) {
266         unsigned I;
267         for (I = 0; I < Cmd->FileCount; ++I) {
268             if (strcmp (Cmd->Files[I], File) == 0) {
269                 /* Duplicate file */
270                 Warning ("Duplicate file in argument list: `%s'", File);
271                 /* No need to search further */
272                 break;
273             }
274         }
275
276         /* Add the file */
277         Cmd->Files [Cmd->FileCount++] = xstrdup (File);
278     } else {
279         /* Add a NULL pointer */
280         Cmd->Files [Cmd->FileCount++] = 0;
281     }
282 }
283
284
285
286 static void CmdInit (CmdDesc* Cmd, const char* Path, const char* Name)
287 /* Initialize the command using the given path and name of the executable */
288 {
289     char* FullName;
290
291     FullName = (char*) xmalloc (strlen (Path) + strlen (Name) + 1);
292     strcpy (FullName, Path);
293     strcat (FullName, Name);
294
295     /* Remember the command */
296     Cmd->Name = xstrdup (FullName);
297
298     /* Use the command name as first argument */
299     CmdAddArg (Cmd, FullName);
300
301     xfree (FullName);
302 }
303
304
305
306 static void CmdSetOutput (CmdDesc* Cmd, const char* File)
307 /* Set the output file in a command desc */
308 {
309     CmdAddArg2 (Cmd, "-o", File);
310 }
311
312
313
314 static void CmdSetTarget (CmdDesc* Cmd, target_t Target)
315 /* Set the output file in a command desc */
316 {
317     CmdAddArg2 (Cmd, "-t", GetTargetName (Target));
318 }
319
320
321
322 static void CmdPrint (CmdDesc* Cmd, FILE* F)
323 /* Output the command line encoded in the command desc */
324 {
325     unsigned I;
326     for (I = 0; I < Cmd->ArgCount && Cmd->Args[I] != 0; ++I) {
327         fprintf (F, "%s ", Cmd->Args[I]);
328     }
329 }
330
331
332
333 /*****************************************************************************/
334 /*                              Target handling                              */
335 /*****************************************************************************/
336
337
338
339 static void SetTargetFiles (void)
340 /* Set the target system files */
341 {
342     /* Determine the names of the target specific library file */
343     if (Target != TGT_NONE) {
344
345         /* Get a pointer to the system name and its length */
346         const char* TargetName = GetTargetName (Target);
347         unsigned    TargetNameLen = strlen (TargetName);
348
349         /* Set the library file */
350         TargetLib = xmalloc (TargetNameLen + 4 + 1);
351         memcpy (TargetLib, TargetName, TargetNameLen);
352         strcpy (TargetLib + TargetNameLen, ".lib");
353
354     }
355 }
356
357
358
359 /*****************************************************************************/
360 /*                               Subprocesses                                */
361 /*****************************************************************************/
362
363
364
365 static void ExecProgram (CmdDesc* Cmd)
366 /* Execute a subprocess with the given name/parameters. Exit on errors. */
367 {
368     int Status;
369
370     /* If in debug mode, output the command line we will execute */
371     if (Debug) {
372         printf ("Executing: ");
373         CmdPrint (Cmd, stdout);
374         printf ("\n");
375     }
376
377     /* Call the program */
378     Status = spawnvp (P_WAIT, Cmd->Name, Cmd->Args);
379
380     /* Check the result code */
381     if (Status < 0) {
382         /* Error executing the program */
383         Error ("Cannot execute `%s': %s", Cmd->Name, strerror (errno));
384     } else if (Status != 0) {
385         /* Called program had an error */
386         exit (Status);
387     }
388 }
389
390
391
392 static void Link (void)
393 /* Link the resulting executable */
394 {
395     unsigned I;
396
397     /* Since linking is always the final step, if we have an output file name
398      * given, set it here. If we don't have an explicit output name given,
399      * try to build one from the name of the first input file.
400      */
401     if (OutputName) {
402
403         CmdSetOutput (&LD65, OutputName);
404
405     } else if (FirstInput && FindExt (FirstInput)) {  /* Only if ext present! */
406
407         const char* Extension = Module? MODULE_EXT : "";
408         char* Output = MakeFilename (FirstInput, Extension);
409         CmdSetOutput (&LD65, Output);
410         xfree (Output);
411
412     }
413
414     /* If we have a linker config file given, add it to the command line.
415      * Otherwise pass the target to the linker if we have one.
416      */
417     if (LinkerConfig) {
418         if (Module) {
419             Error ("Cannot use -C and --module together");
420         }
421         CmdAddArg2 (&LD65, "-C", LinkerConfig);
422     } else if (Module) {
423         CmdSetTarget (&LD65, TGT_MODULE);
424     } else {
425         CmdSetTarget (&LD65, Target);
426     }
427
428     /* Determine which target libraries are needed */
429     SetTargetFiles ();
430
431     /* Add all object files as parameters */
432     for (I = 0; I < LD65.FileCount; ++I) {
433         CmdAddArg (&LD65, LD65.Files [I]);
434     }
435
436     /* Add the system runtime library */
437     if (TargetLib) {
438         CmdAddArg (&LD65, TargetLib);
439     }
440
441     /* Terminate the argument list with a NULL pointer */
442     CmdAddArg (&LD65, 0);
443
444     /* Call the linker */
445     ExecProgram (&LD65);
446 }
447
448
449
450 static void AssembleFile (const char* File, unsigned ArgCount)
451 /* Common routine to assemble a file. Will be called by Assemble() and
452  * AssembleIntermediate(). Adds options common for both routines and
453  * assembles the file. Will remove excess arguments after assembly.
454  */
455 {
456     /* Set the target system */
457     CmdSetTarget (&CA65, Target);
458
459     /* Check if this is the last processing step */
460     if (DoLink) {
461         /* We're linking later. Add the output file of the assembly
462          * the the file list of the linker. The name of the output
463          * file is that of the input file with ".s" replaced by ".o".
464          */
465         char* ObjName = MakeFilename (File, ".o");
466         CmdAddFile (&LD65, ObjName);
467         xfree (ObjName);
468     } else {
469         /* This is the final step. If an output name is given, set it */
470         if (OutputName) {
471             CmdSetOutput (&CA65, OutputName);
472         }
473     }
474
475     /* Add the file as argument for the assembler */
476     CmdAddArg (&CA65, File);
477
478     /* Add a NULL pointer to terminate the argument list */
479     CmdAddArg (&CA65, 0);
480
481     /* Run the assembler */
482     ExecProgram (&CA65);
483
484     /* Remove the excess arguments */
485     CmdDelArgs (&CA65, ArgCount);
486 }
487
488
489
490 static void AssembleIntermediate (const char* SourceFile)
491 /* Assemble an intermediate file which was generated by a previous processing
492  * step with SourceFile as input. The -dep options won't be added and
493  * the intermediate assembler file is removed after assembly.
494  */
495 {
496     /* Generate the name of the assembler output file from the source file
497      * name. It's the same name with the extension replaced by ".s"
498      */
499     char* AsmName = MakeFilename (SourceFile, ".s");
500
501     /* Assemble the intermediate assembler file */
502     AssembleFile (AsmName, CA65.ArgCount);
503
504     /* Remove the input file */
505     if (remove (AsmName) < 0) {
506         Warning ("Cannot remove temporary file `%s': %s",
507                  AsmName, strerror (errno));
508     }
509
510     /* Free the assembler file name which was allocated from the heap */
511     xfree (AsmName);
512 }
513
514
515
516 static void Assemble (const char* File)
517 /* Assemble the given file */
518 {
519     /* Remember the current assembler argument count */
520     unsigned ArgCount = CA65.ArgCount;
521
522     /* We aren't assembling an intermediate file, but one requested by the
523      * user. So add a few options here if they were given on the command
524      * line.
525      */
526     if (DepName && *DepName) {
527         CmdAddArg2 (&CA65, "--create-dep", DepName);
528     }
529     if (FullDepName && *FullDepName) {
530         CmdAddArg2 (&CA65, "--create-full-dep", FullDepName);
531     }
532
533     /* Use the common routine */
534     AssembleFile (File, ArgCount);
535 }
536
537
538
539 static void Compile (const char* File)
540 /* Compile the given file */
541 {
542     /* Remember the current compiler argument count */
543     unsigned ArgCount = CC65.ArgCount;
544
545     /* Set the target system */
546     CmdSetTarget (&CC65, Target);
547
548     /* Check if this is the final step */
549     if (DoAssemble) {
550         /* We will assemble this file later. If a dependency file is to be
551          * generated, set the dependency target to be the final object file,
552          * not the intermediate assembler file. But beware: There may be an
553          * output name specified for the assembler.
554          */
555         if (DepName || FullDepName) {
556             /* Was an output name for the assembler specified? */
557             if (!DoLink && OutputName) {
558                 /* Use this name as the dependency target */
559                 CmdAddArg2 (&CC65, "--dep-target", OutputName);
560             } else {
561                 /* Use the object file name as the dependency target */
562                 char* ObjName = MakeFilename (File, ".o");
563                 CmdAddArg2 (&CC65, "--dep-target", ObjName);
564                 xfree (ObjName);
565             }
566         }
567     } else {
568         /* If we won't assemble, this is the final step. In this case, set
569          * the output name if it was given.
570          */
571         if (OutputName) {
572             CmdSetOutput (&CC65, OutputName);
573         }
574     }
575
576     /* Add the file as argument for the compiler */
577     CmdAddArg (&CC65, File);
578
579     /* Add a NULL pointer to terminate the argument list */
580     CmdAddArg (&CC65, 0);
581
582     /* Run the compiler */
583     ExecProgram (&CC65);
584
585     /* Remove the excess arguments */
586     CmdDelArgs (&CC65, ArgCount);
587
588     /* If this is not the final step, assemble the generated file, then
589      * remove it
590      */
591     if (DoAssemble) {
592         /* Assemble the intermediate file and remove it */
593         AssembleIntermediate (File);
594     }
595 }
596
597
598
599 static void CompileRes (const char* File)
600 /* Compile the given geos resource file */
601 {
602     /* Remember the current assembler argument count */
603     unsigned ArgCount = GRC.ArgCount;
604
605     /* Resource files need an geos-apple or geos-cbm target but this
606      * is checked within grc65.
607      */
608     CmdSetTarget (&GRC, Target);
609
610     /* Add the file as argument for the resource compiler */
611     CmdAddArg (&GRC, File);
612
613     /* Add a NULL pointer to terminate the argument list */
614     CmdAddArg (&GRC, 0);
615
616     /* Run the compiler */
617     ExecProgram (&GRC);
618
619     /* Remove the excess arguments */
620     CmdDelArgs (&GRC, ArgCount);
621
622     /* If this is not the final step, assemble the generated file, then
623      * remove it
624      */
625     if (DoAssemble) {
626         /* Assemble the intermediate file and remove it */
627         AssembleIntermediate (File);
628     }
629 }
630
631
632
633 static void ConvertO65 (const char* File)
634 /* Convert an o65 object file into an assembler file */
635 {
636     /* Remember the current converter argument count */
637     unsigned ArgCount = CO65.ArgCount;
638
639     /* If we won't assemble, this is the final step. In this case, set the
640      * output name.
641      */
642     if (!DoAssemble && OutputName) {
643         CmdSetOutput (&CO65, OutputName);
644     }
645
646     /* Add the file as argument for the object file converter */
647     CmdAddArg (&CO65, File);
648
649     /* Add a NULL pointer to terminate the argument list */
650     CmdAddArg (&CO65, 0);
651
652     /* Run the converter */
653     ExecProgram (&CO65);
654
655     /* Remove the excess arguments */
656     CmdDelArgs (&CO65, ArgCount);
657
658     /* If this is not the final step, assemble the generated file, then
659      * remove it
660      */
661     if (DoAssemble) {
662         /* Assemble the intermediate file and remove it */
663         AssembleIntermediate (File);
664     }
665 }
666
667
668
669 /*****************************************************************************/
670 /*                                   Code                                    */
671 /*****************************************************************************/
672
673
674
675 static void Usage (void)
676 /* Print usage information and exit */
677 {
678     printf ("Usage: %s [options] file [...]\n"
679             "Short options:\n"
680             "  -c\t\t\t\tCompile and assemble, but don't link\n"
681             "  -d\t\t\t\tDebug mode\n"
682             "  -g\t\t\t\tAdd debug info\n"
683             "  -h\t\t\t\tHelp (this text)\n"
684             "  -l name\t\t\tCreate an assembler listing file\n"
685             "  -m name\t\t\tCreate a map file\n"
686             "  -mm model\t\t\tSet the memory model\n"
687             "  -o name\t\t\tName the output file\n"
688             "  -r\t\t\t\tEnable register variables\n"
689             "  -t sys\t\t\tSet the target system\n"
690             "  -u sym\t\t\tForce an import of symbol `sym'\n"
691             "  -v\t\t\t\tVerbose mode\n"
692             "  -vm\t\t\t\tVerbose map file\n"
693             "  -C name\t\t\tUse linker config file\n"
694             "  -Cl\t\t\t\tMake local variables static\n"
695             "  -D sym[=defn]\t\t\tDefine a preprocessor symbol\n"
696             "  -I dir\t\t\tSet a compiler include directory path\n"
697             "  -L path\t\t\tSpecify a library search path\n"
698             "  -Ln name\t\t\tCreate a VICE label file\n"
699             "  -O\t\t\t\tOptimize code\n"
700             "  -Oi\t\t\t\tOptimize code, inline runtime functions\n"
701             "  -Or\t\t\t\tOptimize code, honour the register keyword\n"
702             "  -Os\t\t\t\tOptimize code, inline known C functions\n"
703             "  -S\t\t\t\tCompile, but don't assemble and link\n"
704             "  -T\t\t\t\tInclude source as comment\n"
705             "  -V\t\t\t\tPrint the version number\n"
706             "  -W name[,...]\t\t\tSuppress compiler warnings\n"
707             "  -Wa options\t\t\tPass options to the assembler\n"
708             "  -Wc options\t\t\tPass options to the compiler\n"
709             "  -Wl options\t\t\tPass options to the linker\n"
710             "\n"
711             "Long options:\n"
712             "  --add-source\t\t\tInclude source as comment\n"
713             "  --asm-args options\t\tPass options to the assembler\n"
714             "  --asm-define sym[=v]\t\tDefine an assembler symbol\n"
715             "  --asm-include-dir dir\t\tSet an assembler include directory\n"
716             "  --bin-include-dir dir\t\tSet an assembler binary include directory\n"
717             "  --bss-label name\t\tDefine and export a BSS segment label\n"
718             "  --bss-name seg\t\tSet the name of the BSS segment\n"
719             "  --cc-args options\t\tPass options to the compiler\n"
720             "  --cfg-path path\t\tSpecify a config file search path\n"
721             "  --check-stack\t\t\tGenerate stack overflow checks\n"
722             "  --code-label name\t\tDefine and export a CODE segment label\n"
723             "  --code-name seg\t\tSet the name of the CODE segment\n"
724             "  --codesize x\t\t\tAccept larger code by factor x\n"
725             "  --config name\t\t\tUse linker config file\n"
726             "  --cpu type\t\t\tSet CPU type\n"
727             "  --create-dep name\t\tCreate a make dependency file\n"
728             "  --create-full-dep name\tCreate a full make dependency file\n"
729             "  --data-label name\t\tDefine and export a DATA segment label\n"
730             "  --data-name seg\t\tSet the name of the DATA segment\n"
731             "  --debug\t\t\tDebug mode\n"
732             "  --debug-info\t\t\tAdd debug info\n"
733             "  --feature name\t\tSet an emulation feature\n"
734             "  --force-import sym\t\tForce an import of symbol `sym'\n"
735             "  --help\t\t\tHelp (this text)\n"
736             "  --include-dir dir\t\tSet a compiler include directory path\n"
737             "  --ld-args options\t\tPass options to the linker\n"
738             "  --lib file\t\t\tLink this library\n"
739             "  --lib-path path\t\tSpecify a library search path\n"
740             "  --list-targets\t\tList all available targets\n"
741             "  --listing name\t\tCreate an assembler listing file\n"
742             "  --list-bytes n\t\tNumber of bytes per assembler listing line\n"
743             "  --mapfile name\t\tCreate a map file\n"
744             "  --memory-model model\t\tSet the memory model\n"
745             "  --module\t\t\tLink as a module\n"
746             "  --module-id id\t\tSpecify a module ID for the linker\n"
747             "  --o65-model model\t\tOverride the o65 model\n"
748             "  --obj file\t\t\tLink this object file\n"
749             "  --obj-path path\t\tSpecify an object file search path\n"
750             "  --register-space b\t\tSet space available for register variables\n"
751             "  --register-vars\t\tEnable register variables\n"
752             "  --rodata-name seg\t\tSet the name of the RODATA segment\n"
753             "  --signed-chars\t\tDefault characters are signed\n"
754             "  --standard std\t\tLanguage standard (c89, c99, cc65)\n"
755             "  --start-addr addr\t\tSet the default start address\n"
756             "  --static-locals\t\tMake local variables static\n"
757             "  --target sys\t\t\tSet the target system\n"
758             "  --version\t\t\tPrint the version number\n"
759             "  --verbose\t\t\tVerbose mode\n"
760             "  --zeropage-label name\t\tDefine and export a ZEROPAGE segment label\n"
761             "  --zeropage-name seg\t\tSet the name of the ZEROPAGE segment\n",
762             ProgName);
763 }
764
765
766
767 static void OptAddSource (const char* Opt attribute ((unused)),
768                           const char* Arg attribute ((unused)))
769 /* Strict source code as comments to the generated asm code */
770 {
771     CmdAddArg (&CC65, "-T");
772 }
773
774
775
776 static void OptAsmArgs (const char* Opt attribute ((unused)), const char* Arg)
777 /* Pass arguments to the assembler */
778 {
779     CmdAddArgList (&CA65, Arg);
780 }
781
782
783
784 static void OptAsmDefine (const char* Opt attribute ((unused)), const char* Arg)
785 /* Define an assembler symbol (assembler) */
786 {
787     CmdAddArg2 (&CA65, "-D", Arg);
788 }
789
790
791
792 static void OptAsmIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
793 /* Include directory (assembler) */
794 {
795     CmdAddArg2 (&CA65, "-I", Arg);
796 }
797
798
799
800 static void OptBinIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
801 /* Binary include directory (assembler) */
802 {
803     CmdAddArg2 (&CA65, "--bin-include-dir", Arg);
804 }
805
806
807
808 static void OptBssLabel (const char* Opt attribute ((unused)), const char* Arg)
809 /* Handle the --bss-label option */
810 {
811     CmdAddArg2 (&CO65, "--bss-label", Arg);
812 }
813
814
815
816 static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
817 /* Handle the --bss-name option */
818 {
819     CmdAddArg2 (&CC65, "--bss-name", Arg);
820     CmdAddArg2 (&CO65, "--bss-name", Arg);
821 }
822
823
824
825 static void OptCCArgs (const char* Opt attribute ((unused)), const char* Arg)
826 /* Pass arguments to the compiler */
827 {
828     CmdAddArgList (&CC65, Arg);
829 }
830
831
832
833 static void OptCfgPath (const char* Opt attribute ((unused)), const char* Arg)
834 /* Config file search path (linker) */
835 {
836     CmdAddArg2 (&LD65, "--cfg-path", Arg);
837 }
838
839
840
841 static void OptCheckStack (const char* Opt attribute ((unused)),
842                            const char* Arg attribute ((unused)))
843 /* Handle the --check-stack option */
844 {
845     CmdAddArg (&CC65, "--check-stack");
846 }
847
848
849
850 static void OptCodeLabel (const char* Opt attribute ((unused)), const char* Arg)
851 /* Handle the --code-label option */
852 {
853     CmdAddArg2 (&CO65, "--code-label", Arg);
854 }
855
856
857
858 static void OptCodeName (const char* Opt attribute ((unused)), const char* Arg)
859 /* Handle the --code-name option */
860 {
861     CmdAddArg2 (&CC65, "--code-name", Arg);
862     CmdAddArg2 (&CO65, "--code-name", Arg);
863 }
864
865
866
867 static void OptCodeSize (const char* Opt attribute ((unused)), const char* Arg)
868 /* Handle the --codesize option */
869 {
870     CmdAddArg2 (&CC65, "--codesize", Arg);
871 }
872
873
874
875 static void OptConfig (const char* Opt attribute ((unused)), const char* Arg)
876 /* Config file (linker) */
877 {
878     if (LinkerConfig) {
879         Error ("Cannot specify -C/--config twice");
880     }
881     LinkerConfig = Arg;
882 }
883
884
885
886 static void OptCPU (const char* Opt attribute ((unused)), const char* Arg)
887 /* Handle the --cpu option */
888 {
889     /* Add the cpu type to the assembler and compiler */
890     CmdAddArg2 (&CA65, "--cpu", Arg);
891     CmdAddArg2 (&CC65, "--cpu", Arg);
892 }
893
894
895
896 static void OptCreateDep (const char* Opt attribute ((unused)), const char* Arg)
897 /* Handle the --create-dep option */
898 {
899     /* Add the file name to the compiler */
900     CmdAddArg2 (&CC65, "--create-dep", Arg);
901
902     /* Remember the file name for the assembler */
903     DepName = Arg;
904 }
905
906
907
908 static void OptCreateFullDep (const char* Opt attribute ((unused)), const char* Arg)
909 /* Handle the --create-full-dep option */
910 {
911     /* Add the file name to the compiler */
912     CmdAddArg2 (&CC65, "--create-full-dep", Arg);
913
914     /* Remember the file name for the assembler */
915     FullDepName = Arg;
916 }
917
918
919
920 static void OptDataLabel (const char* Opt attribute ((unused)), const char* Arg)
921 /* Handle the --data-label option */
922 {
923     CmdAddArg2 (&CO65, "--data-label", Arg);
924 }
925
926
927
928 static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
929 /* Handle the --data-name option */
930 {
931     CmdAddArg2 (&CC65, "--data-name", Arg);
932     CmdAddArg2 (&CO65, "--data-name", Arg);
933 }
934
935
936
937 static void OptDebug (const char* Opt attribute ((unused)),
938                       const char* Arg attribute ((unused)))
939 /* Debug mode (compiler and cl65 utility) */
940 {
941     CmdAddArg (&CC65, "-d");
942     CmdAddArg (&CO65, "-d");
943     Debug = 1;
944 }
945
946
947
948 static void OptDebugInfo (const char* Opt attribute ((unused)),
949                           const char* Arg attribute ((unused)))
950 /* Debug Info - add to compiler and assembler */
951 {
952     CmdAddArg (&CC65, "-g");
953     CmdAddArg (&CA65, "-g");
954     CmdAddArg (&CO65, "-g");
955 }
956
957
958
959 static void OptFeature (const char* Opt attribute ((unused)), const char* Arg)
960 /* Emulation features for the assembler */
961 {
962     CmdAddArg2 (&CA65, "--feature", Arg);
963 }
964
965
966
967 static void OptForceImport (const char* Opt attribute ((unused)), const char* Arg)
968 /* Emulation features for the assembler */
969 {
970     CmdAddArg2 (&LD65, "-u", Arg);
971 }
972
973
974
975 static void OptHelp (const char* Opt attribute ((unused)),
976                      const char* Arg attribute ((unused)))
977 /* Print help - cl65 */
978 {
979     Usage ();
980     exit (EXIT_SUCCESS);
981 }
982
983
984
985 static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
986 /* Include directory (compiler) */
987 {
988     CmdAddArg2 (&CC65, "-I", Arg);
989 }
990
991
992
993 static void OptLdArgs (const char* Opt attribute ((unused)), const char* Arg)
994 /* Pass arguments to the linker */
995 {
996     CmdAddArgList (&LD65, Arg);
997 }
998
999
1000
1001 static void OptLib (const char* Opt attribute ((unused)), const char* Arg)
1002 /* Library file follows (linker) */
1003 {
1004     CmdAddArg2 (&LD65, "--lib", Arg);
1005 }
1006
1007
1008
1009 static void OptLibPath (const char* Opt attribute ((unused)), const char* Arg)
1010 /* Library search path (linker) */
1011 {
1012     CmdAddArg2 (&LD65, "--lib-path", Arg);
1013 }
1014
1015
1016
1017 static void OptListBytes (const char* Opt attribute ((unused)), const char* Arg)
1018 /* Set the maximum number of bytes per asm listing line */
1019 {
1020     CmdAddArg2 (&CA65, "--list-bytes", Arg);
1021 }
1022
1023
1024
1025 static void OptListing (const char* Opt attribute ((unused)), const char* Arg)
1026 /* Create an assembler listing */
1027 {
1028     CmdAddArg2 (&CA65, "-l", Arg);
1029 }
1030
1031
1032
1033 static void OptListTargets (const char* Opt attribute ((unused)),
1034                             const char* Arg attribute ((unused)))
1035 /* List all targets */
1036 {
1037     target_t T;
1038
1039     /* List the targets */
1040     for (T = TGT_NONE; T < TGT_COUNT; ++T) {
1041         printf ("%s\n", GetTargetName (T));
1042     }
1043
1044     /* Terminate */
1045     exit (EXIT_SUCCESS);
1046 }
1047
1048
1049
1050 static void OptMapFile (const char* Opt attribute ((unused)), const char* Arg)
1051 /* Create a map file */
1052 {
1053     /* Create a map file (linker) */
1054     CmdAddArg2 (&LD65, "-m", Arg);
1055 }
1056
1057
1058
1059 static void OptMemoryModel (const char* Opt attribute ((unused)), const char* Arg)
1060 /* Set the memory model */
1061 {
1062     mmodel_t MemoryModel = FindMemoryModel (Arg);
1063     if (MemoryModel == MMODEL_UNKNOWN) {
1064         Error ("Unknown memory model: %s", Arg);
1065     } else if (MemoryModel == MMODEL_HUGE) {
1066         Error ("Unsupported memory model: %s", Arg);
1067     } else {
1068         CmdAddArg2 (&CA65, "-mm", Arg);
1069         CmdAddArg2 (&CC65, "-mm", Arg);
1070     }
1071 }
1072
1073
1074
1075 static void OptModule (const char* Opt attribute ((unused)),
1076                        const char* Arg attribute ((unused)))
1077 /* Link as a module */
1078 {
1079     Module = 1;
1080 }
1081
1082
1083
1084 static void OptModuleId (const char* Opt attribute ((unused)), const char* Arg)
1085 /* Specify a module if for the linker */
1086 {
1087     /* Pass it straight to the linker */
1088     CmdAddArg2 (&LD65, "--module-id", Arg);
1089 }
1090
1091
1092
1093 static void OptO65Model (const char* Opt attribute ((unused)), const char* Arg)
1094 /* Handle the --o65-model option */
1095 {
1096     CmdAddArg2 (&CO65, "-m", Arg);
1097 }
1098
1099
1100
1101 static void OptObj (const char* Opt attribute ((unused)), const char* Arg)
1102 /* Object file follows (linker) */
1103 {
1104     CmdAddArg2 (&LD65, "--obj", Arg);
1105 }
1106
1107
1108
1109 static void OptObjPath (const char* Opt attribute ((unused)), const char* Arg)
1110 /* Object file search path (linker) */
1111 {
1112     CmdAddArg2 (&LD65, "--obj-path", Arg);
1113 }
1114
1115
1116
1117 static void OptRegisterSpace (const char* Opt attribute ((unused)), const char* Arg)
1118 /* Handle the --register-space option */
1119 {
1120     CmdAddArg2 (&CC65, "--register-space", Arg);
1121 }
1122
1123
1124
1125 static void OptRegisterVars (const char* Opt attribute ((unused)),
1126                              const char* Arg attribute ((unused)))
1127 /* Handle the --register-vars option */
1128 {
1129     CmdAddArg (&CC65, "-r");
1130 }
1131
1132
1133
1134 static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg)
1135 /* Handle the --rodata-name option */
1136 {
1137     CmdAddArg2 (&CC65, "--rodata-name", Arg);
1138 }
1139
1140
1141
1142 static void OptSignedChars (const char* Opt attribute ((unused)),
1143                             const char* Arg attribute ((unused)))
1144 /* Make default characters signed */
1145 {
1146     CmdAddArg (&CC65, "-j");
1147 }
1148
1149
1150
1151 static void OptStandard (const char* Opt attribute ((unused)), const char* Arg)
1152 /* Set the language standard */
1153 {
1154     CmdAddArg2 (&CC65, "--standard", Arg);
1155 }
1156
1157
1158
1159 static void OptStartAddr (const char* Opt attribute ((unused)), const char* Arg)
1160 /* Set the default start address */
1161 {
1162     CmdAddArg2 (&LD65, "-S", Arg);
1163 }
1164
1165
1166
1167 static void OptStaticLocals (const char* Opt attribute ((unused)),
1168                              const char* Arg attribute ((unused)))
1169 /* Place local variables in static storage */
1170 {
1171     CmdAddArg (&CC65, "-Cl");
1172 }
1173
1174
1175
1176 static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
1177 /* Set the target system */
1178 {
1179     Target = FindTarget (Arg);
1180     if (Target == TGT_UNKNOWN) {
1181         Error ("No such target system: `%s'", Arg);
1182     } else if (Target == TGT_MODULE) {
1183         Error ("Cannot use `module' as target, use --module instead");
1184     }
1185 }
1186
1187
1188
1189 static void OptVerbose (const char* Opt attribute ((unused)),
1190                         const char* Arg attribute ((unused)))
1191 /* Verbose mode (compiler, assembler, linker) */
1192 {
1193     CmdAddArg (&CC65, "-v");
1194     CmdAddArg (&CA65, "-v");
1195     CmdAddArg (&CO65, "-v");
1196     CmdAddArg (&LD65, "-v");
1197 }
1198
1199
1200
1201 static void OptVersion (const char* Opt attribute ((unused)),
1202                         const char* Arg attribute ((unused)))
1203 /* Print version number */
1204 {
1205     fprintf (stderr, "cl65 V%s\n", GetVersionAsString ());
1206 }
1207
1208
1209
1210 static void OptZeropageLabel (const char* Opt attribute ((unused)), const char* Arg)
1211 /* Handle the --zeropage-label option */
1212 {
1213     CmdAddArg2 (&CO65, "--zeropage-label", Arg);
1214 }
1215
1216
1217
1218 static void OptZeropageName (const char* Opt attribute ((unused)), const char* Arg)
1219 /* Handle the --zeropage-name option */
1220 {
1221     CmdAddArg2 (&CO65, "--zeropage-name", Arg);
1222 }
1223
1224
1225
1226 int main (int argc, char* argv [])
1227 /* Utility main program */
1228 {
1229     /* Program long options */
1230     static const LongOpt OptTab[] = {
1231         { "--add-source",       0,      OptAddSource            },
1232         { "--asm-args",         1,      OptAsmArgs              },
1233         { "--asm-define",       1,      OptAsmDefine            },
1234         { "--asm-include-dir",  1,      OptAsmIncludeDir        },
1235         { "--bin-include-dir",  1,      OptBinIncludeDir        },
1236         { "--bss-label",        1,      OptBssLabel             },
1237         { "--bss-name",         1,      OptBssName              },
1238         { "--cc-args",          1,      OptCCArgs               },
1239         { "--cfg-path",         1,      OptCfgPath              },
1240         { "--check-stack",      0,      OptCheckStack           },
1241         { "--code-label",       1,      OptCodeLabel            },
1242         { "--code-name",        1,      OptCodeName             },
1243         { "--codesize",         1,      OptCodeSize             },
1244         { "--config",           1,      OptConfig               },
1245         { "--cpu",              1,      OptCPU                  },
1246         { "--create-dep",       1,      OptCreateDep            },
1247         { "--create-full-dep",  1,      OptCreateFullDep        },
1248         { "--data-label",       1,      OptDataLabel            },
1249         { "--data-name",        1,      OptDataName             },
1250         { "--debug",            0,      OptDebug                },
1251         { "--debug-info",       0,      OptDebugInfo            },
1252         { "--feature",          1,      OptFeature              },
1253         { "--force-import",     1,      OptForceImport          },
1254         { "--help",             0,      OptHelp                 },
1255         { "--include-dir",      1,      OptIncludeDir           },
1256         { "--ld-args",          1,      OptLdArgs               },
1257         { "--lib",              1,      OptLib                  },
1258         { "--lib-path",         1,      OptLibPath              },
1259         { "--list-targets",     0,      OptListTargets          },
1260         { "--listing",          1,      OptListing              },
1261         { "--list-bytes",       1,      OptListBytes            },
1262         { "--mapfile",          1,      OptMapFile              },
1263         { "--memory-model",     1,      OptMemoryModel          },
1264         { "--module",           0,      OptModule               },
1265         { "--module-id",        1,      OptModuleId             },
1266         { "--o65-model",        1,      OptO65Model             },
1267         { "--obj",              1,      OptObj                  },
1268         { "--obj-path",         1,      OptObjPath              },
1269         { "--register-space",   1,      OptRegisterSpace        },
1270         { "--register-vars",    0,      OptRegisterVars         },
1271         { "--rodata-name",      1,      OptRodataName           },
1272         { "--signed-chars",     0,      OptSignedChars          },
1273         { "--standard",         1,      OptStandard             },
1274         { "--start-addr",       1,      OptStartAddr            },
1275         { "--static-locals",    0,      OptStaticLocals         },
1276         { "--target",           1,      OptTarget               },
1277         { "--verbose",          0,      OptVerbose              },
1278         { "--version",          0,      OptVersion              },
1279         { "--zeropage-label",   1,      OptZeropageLabel        },
1280         { "--zeropage-name",    1,      OptZeropageName         },
1281     };
1282
1283     char* CmdPath;
1284     unsigned I;
1285
1286     /* Initialize the cmdline module */
1287     InitCmdLine (&argc, &argv, "cl65");
1288
1289     /* Initialize the command descriptors */
1290     if (argc == 0) {
1291         CmdPath = xstrdup ("");
1292     } else {
1293         char* Ptr;
1294         CmdPath = xstrdup (argv[0]);
1295         Ptr = strrchr (CmdPath, '/');
1296         if (Ptr == 0) {
1297             Ptr = strrchr (CmdPath, '\\');
1298         }
1299         if (Ptr == 0) {
1300             *CmdPath = '\0';
1301         } else {
1302             *(Ptr + 1) = '\0';
1303         }
1304     }
1305     CmdInit (&CC65, CmdPath, "cc65");
1306     CmdInit (&CA65, CmdPath, "ca65");
1307     CmdInit (&CO65, CmdPath, "co65");
1308     CmdInit (&LD65, CmdPath, "ld65");
1309     CmdInit (&GRC,  CmdPath, "grc65");
1310     xfree (CmdPath);
1311
1312     /* Our default target is the C64 instead of "none" */
1313     Target = TGT_C64;
1314
1315     /* Check the parameters */
1316     I = 1;
1317     while (I < ArgCount) {
1318
1319         /* Get the argument */
1320         const char* Arg = ArgVec[I];
1321
1322         /* Check for an option */
1323         if (Arg [0] == '-') {
1324
1325             switch (Arg [1]) {
1326
1327                 case '-':
1328                     LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
1329                     break;
1330
1331                 case 'C':
1332                     if (Arg[2] == 'l' && Arg[3] == '\0') {
1333                         /* Make local variables static */
1334                         OptStaticLocals (Arg, 0);
1335                     } else {
1336                         /* Specify linker config file */
1337                         OptConfig (Arg, GetArg (&I, 2));
1338                     }
1339                     break;
1340
1341                 case 'D':
1342                     /* Define a preprocessor symbol (compiler) */
1343                     CmdAddArg2 (&CC65, "-D", GetArg (&I, 2));
1344                     break;
1345
1346                 case 'I':
1347                     /* Include directory (compiler) */
1348                     OptIncludeDir (Arg, GetArg (&I, 2));
1349                     break;
1350
1351                 case 'L':
1352                     if (Arg[2] == 'n' && Arg[3] == '\0') {
1353                         /* VICE label file (linker) */
1354                         CmdAddArg2 (&LD65, "-Ln", GetArg (&I, 3));
1355                     } else {
1356                         /* Library search path (linker) */
1357                         OptLibPath (Arg, GetArg (&I, 2));
1358                     }
1359                     break;
1360
1361                 case 'O':
1362                     /* Optimize code (compiler, also covers -Oi and others) */
1363                     CmdAddArg (&CC65, Arg);
1364                     break;
1365
1366                 case 'S':
1367                     /* Dont assemble and link the created files */
1368                     DoAssemble = 0;
1369                     DoLink     = 0;
1370                     break;
1371
1372                 case 'T':
1373                     /* Include source as comment (compiler) */
1374                     OptAddSource (Arg, 0);
1375                     break;
1376
1377                 case 'V':
1378                     /* Print version number */
1379                     OptVersion (Arg, 0);
1380                     break;
1381
1382                 case 'W':
1383                     if (Arg[2] == 'a' && Arg[3] == '\0') {
1384                         /* -Wa: Pass options to assembler */
1385                         OptAsmArgs (Arg, GetArg (&I, 3));
1386                     } else if (Arg[2] == 'c' && Arg[3] == '\0') {
1387                         /* -Wc: Pass options to compiler */
1388                         OptCCArgs (Arg, GetArg (&I, 3));
1389                     } else if (Arg[2] == 'l' && Arg[3] == '\0') {
1390                         /* -Wl: Pass options to linker */
1391                         OptLdArgs (Arg, GetArg (&I, 3));
1392                     } else {
1393                         /* Anything else: Suppress warnings (compiler) */
1394                         CmdAddArg2 (&CC65, "-W", GetArg (&I, 2));
1395                     }
1396                     break;
1397
1398                 case 'c':
1399                     /* Don't link the resulting files */
1400                     DoLink = 0;
1401                     break;
1402
1403                 case 'd':
1404                     /* Debug mode (compiler) */
1405                     OptDebug (Arg, 0);
1406                     break;
1407
1408                 case 'g':
1409                     /* Debugging - add to compiler and assembler */
1410                     OptDebugInfo (Arg, 0);
1411                     break;
1412
1413                 case 'h':
1414                 case '?':
1415                     /* Print help - cl65 */
1416                     OptHelp (Arg, 0);
1417                     break;
1418
1419                 case 'j':
1420                     /* Default characters are signed */
1421                     OptSignedChars (Arg, 0);
1422                     break;
1423
1424                 case 'l':
1425                     /* Create an assembler listing */
1426                     OptListing (Arg, GetArg (&I, 2));
1427                     break;
1428
1429                 case 'm':
1430                     /* Create a map file (linker) */
1431                     OptMapFile (Arg, GetArg (&I, 2));
1432                     break;
1433
1434                 case 'o':
1435                     /* Name the output file */
1436                     OutputName = GetArg (&I, 2);
1437                     break;
1438
1439                 case 'r':
1440                     /* Enable register variables */
1441                     OptRegisterVars (Arg, 0);
1442                     break;
1443
1444                 case 't':
1445                     /* Set target system - compiler, assembler and linker */
1446                     OptTarget (Arg, GetArg (&I, 2));
1447                     break;
1448
1449                 case 'u':
1450                     /* Force an import (linker) */
1451                     OptForceImport (Arg, GetArg (&I, 2));
1452                     break;
1453
1454                 case 'v':
1455                     if (Arg [2] == 'm') {
1456                         /* Verbose map file (linker) */
1457                         CmdAddArg (&LD65, "-vm");
1458                     } else {
1459                         /* Verbose mode (compiler, assembler, linker) */
1460                         OptVerbose (Arg, 0);
1461                     }
1462                     break;
1463
1464                 default:
1465                     UnknownOption (Arg);
1466             }
1467         } else {
1468
1469             /* Remember the first file name */
1470             if (FirstInput == 0) {
1471                 FirstInput = Arg;
1472             }
1473
1474             /* Determine the file type by the extension */
1475             switch (GetFileType (Arg)) {
1476
1477                 case FILETYPE_C:
1478                     /* Compile the file */
1479                     Compile (Arg);
1480                     break;
1481
1482                 case FILETYPE_ASM:
1483                     /* Assemble the file */
1484                     if (DoAssemble) {
1485                         Assemble (Arg);
1486                     }
1487                     break;
1488
1489                 case FILETYPE_OBJ:
1490                 case FILETYPE_LIB:
1491                     /* Add to the linker files */
1492                     CmdAddFile (&LD65, Arg);
1493                     break;
1494
1495                 case FILETYPE_GR:
1496                     /* Add to the resource compiler files */
1497                     CompileRes (Arg);
1498                     break;
1499
1500                 case FILETYPE_O65:
1501                     /* Add the the object file converter files */
1502                     ConvertO65 (Arg);
1503                     break;
1504
1505                 default:
1506                     Error ("Don't know what to do with `%s'", Arg);
1507
1508             }
1509
1510         }
1511
1512         /* Next argument */
1513         ++I;
1514     }
1515
1516     /* Check if we had any input files */
1517     if (FirstInput == 0) {
1518         Warning ("No input files");
1519     }
1520
1521     /* Link the given files if requested and if we have any */
1522     if (DoLink && LD65.FileCount > 0) {
1523         Link ();
1524     }
1525
1526     /* Return an apropriate exit code */
1527     return EXIT_SUCCESS;
1528 }
1529
1530
1531