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