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