]> git.sur5r.net Git - cc65/blobdiff - src/cl65/main.c
Rather stay with OFF_YEAR as it is an "officially" name.
[cc65] / src / cl65 / main.c
index 3fed4f7af2d61469f4f942034496ea60119dc3c5..d20f1a2becb51f75038bec95a9da0f274571f565 100644 (file)
@@ -2,11 +2,11 @@
 /*                                                                          */
 /*                                 main.c                                   */
 /*                                                                          */
-/*            Main module for the cl65 compile and link utility             */
+/*            Main module for the cl65 compile-and-link utility             */
 /*                                                                          */
 /*                                                                          */
 /*                                                                          */
-/* (C) 1999-2010, Ullrich von Bassewitz                                      */
+/* (C) 1999-2012, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -306,7 +306,7 @@ static void CmdSetOutput (CmdDesc* Cmd, const char* File)
 static void CmdSetTarget (CmdDesc* Cmd, target_t Target)
 /* Set the output file in a command desc */
 {
-    CmdAddArg2 (Cmd, "-t", TargetNames[Target]);
+    CmdAddArg2 (Cmd, "-t", GetTargetName (Target));
 }
 
 
@@ -335,7 +335,7 @@ static void SetTargetFiles (void)
     if (Target != TGT_NONE) {
 
        /* Get a pointer to the system name and its length */
-       const char* TargetName = TargetNames [Target];
+       const char* TargetName = GetTargetName (Target);
        unsigned    TargetNameLen = strlen (TargetName);
 
        /* Set the library file */
@@ -386,23 +386,6 @@ static void Link (void)
 {
     unsigned I;
 
-    /* If we have a linker config file given, add it to the command line.
-     * Otherwise pass the target to the linker if we have one.
-     */
-    if (LinkerConfig) {
-        if (Module) {
-            Error ("Cannot use -C and --module together");
-        }
-               CmdAddArg2 (&LD65, "-C", LinkerConfig);
-    } else if (Module) {
-        CmdSetTarget (&LD65, TGT_MODULE);
-    } else {
-       CmdSetTarget (&LD65, Target);
-    }
-
-    /* Determine which target libraries are needed */
-    SetTargetFiles ();
-
     /* Since linking is always the final step, if we have an output file name
      * given, set it here. If we don't have an explicit output name given,
      * try to build one from the name of the first input file.
@@ -420,6 +403,23 @@ static void Link (void)
 
     }
 
+    /* If we have a linker config file given, add it to the command line.
+     * Otherwise pass the target to the linker if we have one.
+     */
+    if (LinkerConfig) {
+        if (Module) {
+            Error ("Cannot use -C and --module together");
+        }
+               CmdAddArg2 (&LD65, "-C", LinkerConfig);
+    } else if (Module) {
+        CmdSetTarget (&LD65, TGT_MODULE);
+    } else {
+       CmdSetTarget (&LD65, Target);
+    }
+
+    /* Determine which target libraries are needed */
+    SetTargetFiles ();
+
     /* Add all object files as parameters */
     for (I = 0; I < LD65.FileCount; ++I) {
        CmdAddArg (&LD65, LD65.Files [I]);
@@ -594,6 +594,11 @@ static void CompileRes (const char* File)
     /* Remember the current assembler argument count */
     unsigned ArgCount = GRC.ArgCount;
 
+    /* Resource files need an geos-apple or geos-cbm target but this
+     * is checked within grc65.
+     */
+    CmdSetTarget (&GRC, Target);
+
     /* Add the file as argument for the resource compiler */
     CmdAddArg (&GRC, File);
 
@@ -664,11 +669,11 @@ static void Usage (void)
 {
     printf ("Usage: %s [options] file [...]\n"
             "Short options:\n"
-            "  -c\t\t\t\tCompile and assemble but don't link\n"
+            "  -c\t\t\t\tCompile and assemble, but don't link\n"
             "  -d\t\t\t\tDebug mode\n"
             "  -g\t\t\t\tAdd debug info\n"
             "  -h\t\t\t\tHelp (this text)\n"
-            "  -l\t\t\t\tCreate an assembler listing\n"
+            "  -l name\t\t\tCreate an assembler listing file\n"
             "  -m name\t\t\tCreate a map file\n"
             "  -mm model\t\t\tSet the memory model\n"
             "  -o name\t\t\tName the output file\n"
@@ -684,14 +689,15 @@ static void Usage (void)
             "  -L path\t\t\tSpecify a library search path\n"
             "  -Ln name\t\t\tCreate a VICE label file\n"
             "  -O\t\t\t\tOptimize code\n"
-            "  -Oi\t\t\t\tOptimize code, inline functions\n"
+            "  -Oi\t\t\t\tOptimize code, inline runtime functions\n"
             "  -Or\t\t\t\tOptimize code, honour the register keyword\n"
-            "  -Os\t\t\t\tOptimize code, inline known C funtions\n"
-            "  -S\t\t\t\tCompile but don't assemble and link\n"
+            "  -Os\t\t\t\tOptimize code, inline known C functions\n"
+            "  -S\t\t\t\tCompile, but don't assemble and link\n"
             "  -T\t\t\t\tInclude source as comment\n"
             "  -V\t\t\t\tPrint the version number\n"
-            "  -W\t\t\t\tSuppress warnings\n"
+            "  -W name[,...]\t\t\tSuppress compiler warnings\n"
             "  -Wa options\t\t\tPass options to the assembler\n"
+            "  -Wc options\t\t\tPass options to the compiler\n"
             "  -Wl options\t\t\tPass options to the linker\n"
             "\n"
             "Long options:\n"
@@ -699,15 +705,17 @@ static void Usage (void)
             "  --asm-args options\t\tPass options to the assembler\n"
             "  --asm-define sym[=v]\t\tDefine an assembler symbol\n"
             "  --asm-include-dir dir\t\tSet an assembler include directory\n"
+            "  --bin-include-dir dir\t\tSet an assembler binary include directory\n"
             "  --bss-label name\t\tDefine and export a BSS segment label\n"
             "  --bss-name seg\t\tSet the name of the BSS segment\n"
+            "  --cc-args options\t\tPass options to the compiler\n"
             "  --cfg-path path\t\tSpecify a config file search path\n"
             "  --check-stack\t\t\tGenerate stack overflow checks\n"
             "  --code-label name\t\tDefine and export a CODE segment label\n"
             "  --code-name seg\t\tSet the name of the CODE segment\n"
             "  --codesize x\t\t\tAccept larger code by factor x\n"
             "  --config name\t\t\tUse linker config file\n"
-            "  --cpu type\t\t\tSet cpu type\n"
+            "  --cpu type\t\t\tSet CPU type\n"
             "  --create-dep name\t\tCreate a make dependency file\n"
             "  --create-full-dep name\tCreate a full make dependency file\n"
             "  --data-label name\t\tDefine and export a DATA segment label\n"
@@ -723,12 +731,12 @@ static void Usage (void)
             "  --lib file\t\t\tLink this library\n"
             "  --lib-path path\t\tSpecify a library search path\n"
             "  --list-targets\t\tList all available targets\n"
-            "  --listing\t\t\tCreate an assembler listing\n"
+            "  --listing name\t\tCreate an assembler listing file\n"
             "  --list-bytes n\t\tNumber of bytes per assembler listing line\n"
             "  --mapfile name\t\tCreate a map file\n"
             "  --memory-model model\t\tSet the memory model\n"
             "  --module\t\t\tLink as a module\n"
-            "  --module-id id\t\tSpecify a module id for the linker\n"
+            "  --module-id id\t\tSpecify a module ID for the linker\n"
             "  --o65-model model\t\tOverride the o65 model\n"
             "  --obj file\t\t\tLink this object file\n"
             "  --obj-path path\t\tSpecify an object file search path\n"
@@ -782,6 +790,14 @@ static void OptAsmIncludeDir (const char* Opt attribute ((unused)), const char*
 
 
 
+static void OptBinIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
+/* Binary include directory (assembler) */
+{
+    CmdAddArg2 (&CA65, "--bin-include-dir", Arg);
+}
+
+
+
 static void OptBssLabel (const char* Opt attribute ((unused)), const char* Arg)
 /* Handle the --bss-label option */
 {
@@ -799,6 +815,14 @@ static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
 
 
 
+static void OptCCArgs (const char* Opt attribute ((unused)), const char* Arg)
+/* Pass arguments to the compiler */
+{
+    CmdAddArgList (&CC65, Arg);
+}
+
+
+
 static void OptCfgPath (const char* Opt attribute ((unused)), const char* Arg)
 /* Config file search path (linker) */
 {
@@ -1000,24 +1024,23 @@ static void OptListBytes (const char* Opt attribute ((unused)), const char* Arg)
 
 
 
-static void OptListing (const char* Opt attribute ((unused)),
-                       const char* Arg attribute ((unused)))
+static void OptListing (const char* Opt attribute ((unused)), const char* Arg)
 /* Create an assembler listing */
 {
-    CmdAddArg (&CA65, "-l");
+    CmdAddArg2 (&CA65, "-l", Arg);
 }
 
 
 
 static void OptListTargets (const char* Opt attribute ((unused)),
-                           const char* Arg attribute ((unused)))
+                           const char* Arg attribute ((unused)))
 /* List all targets */
 {
-    unsigned I;
+    target_t T;
 
     /* List the targets */
-    for (I = TGT_NONE; I < TGT_COUNT; ++I) {
-       printf ("%s\n", TargetNames[I]);
+    for (T = TGT_NONE; T < TGT_COUNT; ++T) {
+       printf ("%s\n", GetTargetName (T));
     }
 
     /* Terminate */
@@ -1182,7 +1205,7 @@ static void OptVersion (const char* Opt attribute ((unused)),
 /* Print version number */
 {
     fprintf (stderr,
-            "cl65 V%s - (C) Copyright 1998-2009 Ullrich von Bassewitz\n",
+            "cl65 V%s - (C) Copyright 1998-2011 Ullrich von Bassewitz\n",
             GetVersionAsString ());
 }
 
@@ -1213,8 +1236,10 @@ int main (int argc, char* argv [])
         { "--asm-args",         1,      OptAsmArgs              },
                { "--asm-define",       1,      OptAsmDefine            },
        { "--asm-include-dir",  1,      OptAsmIncludeDir        },
+        { "--bin-include-dir",  1,      OptBinIncludeDir        },
                { "--bss-label",        1,      OptBssLabel             },
        { "--bss-name",         1,      OptBssName              },
+        { "--cc-args",          1,      OptCCArgs               },
                { "--cfg-path",         1,      OptCfgPath              },
                { "--check-stack",      0,      OptCheckStack           },
                { "--code-label",       1,      OptCodeLabel            },
@@ -1237,7 +1262,7 @@ int main (int argc, char* argv [])
                { "--lib",              1,      OptLib                  },
                { "--lib-path",         1,      OptLibPath              },
        { "--list-targets",     0,      OptListTargets          },
-       { "--listing",          0,      OptListing              },
+       { "--listing",          1,      OptListing              },
         { "--list-bytes",       1,      OptListBytes            },
        { "--mapfile",          1,      OptMapFile              },
         { "--memory-model",     1,      OptMemoryModel          },
@@ -1270,7 +1295,7 @@ int main (int argc, char* argv [])
     CmdInit (&CA65, "ca65");
     CmdInit (&CO65, "co65");
     CmdInit (&LD65, "ld65");
-    CmdInit (&GRC,  "grc");
+    CmdInit (&GRC,  "grc65");
 
     /* Our default target is the C64 instead of "none" */
     Target = TGT_C64;
@@ -1342,28 +1367,21 @@ int main (int argc, char* argv [])
                    OptVersion (Arg, 0);
                    break;
 
-               case 'W':
-                    switch (Arg[2]) {
-
-                        case 'a':
-                            OptAsmArgs (Arg, GetArg (&I, 3));
-                            break;
-
-                        case 'l':
-                            OptLdArgs (Arg, GetArg (&I, 3));
-                            break;
-
-                        case '\0':
-                            /* Suppress warnings - compiler and assembler */
-                            CmdAddArg (&CC65, "-W");
-                            CmdAddArg2 (&CA65, "-W", "0");
-                            break;
-
-                        default:
-                            UnknownOption (Arg);
-                            break;
-                    }
-                    break;
+               case 'W':
+                   if (Arg[2] == 'a' && Arg[3] == '\0') {
+                       /* -Wa: Pass options to assembler */
+                       OptAsmArgs (Arg, GetArg (&I, 3));
+                   } else if (Arg[2] == 'c' && Arg[3] == '\0') {
+                       /* -Wc: Pass options to compiler */
+                       OptCCArgs (Arg, GetArg (&I, 3));
+                   } else if (Arg[2] == 'l' && Arg[3] == '\0') {
+                       /* -Wl: Pass options to linker */
+                       OptLdArgs (Arg, GetArg (&I, 3));
+                   } else {
+                       /* Anything else: Suppress warnings (compiler) */
+                       CmdAddArg2 (&CC65, "-W", GetArg (&I, 2));
+                   }
+                   break;
 
                case 'c':
                    /* Don't link the resulting files */
@@ -1393,7 +1411,7 @@ int main (int argc, char* argv [])
 
                case 'l':
                    /* Create an assembler listing */
-                   OptListing (Arg, 0);
+                   OptListing (Arg, GetArg (&I, 2));
                    break;
 
                case 'm':