]> git.sur5r.net Git - cc65/blobdiff - src/cl65/main.c
Move the version numbers from the interface of the version module into a new
[cc65] / src / cl65 / main.c
index aa12d191f70f725f2601f4f7e7b761841f475b51..bd3a3064bb7275d184ce544f0a1c996fd8605d38 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                          */
 /*                                                                          */
 /*                                                                          */
-/* (C) 1999-2004 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1999-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                          */
 /*                                                                          */
 /* This software is provided 'as-is', without any expressed or implied      */
@@ -118,8 +118,7 @@ static int Module = 0;
 /* Extension used for a module */
 #define MODULE_EXT      ".o65"
 
-/* Name of the crt0 object file and the runtime library */
-static char* TargetCRT0 = 0;
+/* Name of the target specific runtime library */
 static char* TargetLib = 0;
 
 
@@ -148,24 +147,32 @@ static char* TargetLib    = 0;
 
 
 
+static void CmdExpand (CmdDesc* Cmd)
+/* Expand the argument vector */
+{
+    unsigned NewMax  = Cmd->ArgMax + 10;
+    char**      NewArgs = xmalloc (NewMax * sizeof (char*));
+    memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
+    xfree (Cmd->Args);
+    Cmd->Args   = NewArgs;
+    Cmd->ArgMax = NewMax;
+}
+
+
+
 static void CmdAddArg (CmdDesc* Cmd, const char* Arg)
 /* Add a new argument to the command */
 {
     /* Expand the argument vector if needed */
-    if (Cmd->ArgCount == Cmd->ArgMax) {
-       unsigned NewMax  = Cmd->ArgMax + 10;
-       char**   NewArgs = xmalloc (NewMax * sizeof (char*));
-       memcpy (NewArgs, Cmd->Args, Cmd->ArgMax * sizeof (char*));
-       xfree (Cmd->Args);
-       Cmd->Args   = NewArgs;
-       Cmd->ArgMax = NewMax;
+    if (Cmd->ArgCount >= Cmd->ArgMax) {
+        CmdExpand (Cmd);
     }
 
     /* Add a copy of the new argument, allow a NULL pointer */
     if (Arg) {
-       Cmd->Args [Cmd->ArgCount++] = xstrdup (Arg);
+       Cmd->Args[Cmd->ArgCount++] = xstrdup (Arg);
     } else {
-       Cmd->Args [Cmd->ArgCount++] = 0;
+       Cmd->Args[Cmd->ArgCount++] = 0;
     }
 }
 
@@ -180,6 +187,47 @@ static void CmdAddArg2 (CmdDesc* Cmd, const char* Arg1, const char* Arg2)
 
 
 
+static void CmdAddArgList (CmdDesc* Cmd, const char* ArgList)
+/* Add a list of arguments separated by commas */
+{
+    const char* Arg = ArgList;
+    const char* P   = Arg;
+
+    while (1) {
+        if (*P == '\0' || *P == ',') {
+
+            /* End of argument, add it */
+            unsigned Len = P - Arg;
+
+            /* Expand the argument vector if needed */
+            if (Cmd->ArgCount >= Cmd->ArgMax) {
+                CmdExpand (Cmd);
+            }
+
+            /* Add the new argument */
+            Cmd->Args[Cmd->ArgCount] = memcpy (xmalloc (Len + 1), Arg, Len);
+            Cmd->Args[Cmd->ArgCount][Len] = '\0';
+            ++Cmd->ArgCount;
+
+            /* If the argument was terminated by a comma, skip it, otherwise
+             * we're done.
+             */
+            if (*P == ',') {
+                /* Start over at next char */
+                Arg = ++P;
+            } else {
+                break;
+            }
+        } else {
+            /* Skip other chars */
+            ++P;
+        }
+    }
+
+}
+
+
+
 static void CmdDelArgs (CmdDesc* Cmd, unsigned LastValid)
 /* Remove all arguments with an index greater than LastValid */
 {
@@ -279,18 +327,13 @@ static void CmdPrint (CmdDesc* Cmd, FILE* F)
 static void SetTargetFiles (void)
 /* Set the target system files */
 {
-    /* Determine the names of the default startup and library file */
+    /* Determine the names of the target specific library file */
     if (Target != TGT_NONE) {
 
        /* Get a pointer to the system name and its length */
        const char* TargetName = TargetNames [Target];
        unsigned    TargetNameLen = strlen (TargetName);
 
-       /* Set the startup file */
-       TargetCRT0 = xmalloc (TargetNameLen + 2 + 1);
-               memcpy (TargetCRT0, TargetName, TargetNameLen);
-               strcpy (TargetCRT0 + TargetNameLen, ".o");
-
        /* Set the library file */
        TargetLib = xmalloc (TargetNameLen + 4 + 1);
        memcpy (TargetLib, TargetName, TargetNameLen);
@@ -373,13 +416,6 @@ static void Link (void)
 
     }
 
-    /* If we have a startup file and if we are not linking a module, add its
-     * name as a parameter
-     */
-    if (TargetCRT0 && !Module) {
-       CmdAddArg (&LD65, TargetCRT0);
-    }
-
     /* Add all object files as parameters */
     for (I = 0; I < LD65.FileCount; ++I) {
        CmdAddArg (&LD65, LD65.Files [I]);
@@ -588,83 +624,88 @@ static void ConvertO65 (const char* File)
 static void Usage (void)
 /* Print usage information and exit */
 {
-    fprintf (stderr,
-            "Usage: %s [options] file [...]\n"
-                    "Short options:\n"
-                    "  -c\t\t\tCompile and assemble but don't link\n"
-                    "  -d\t\t\tDebug mode\n"
-                    "  -g\t\t\tAdd debug info\n"
-                    "  -h\t\t\tHelp (this text)\n"
-                    "  -l\t\t\tCreate an assembler listing\n"
-                    "  -m name\t\tCreate a map file\n"
-             "  -mm model\t\tSet the memory model\n"
-                    "  -o name\t\tName the output file\n"
-             "  -r\t\t\tEnable register variables\n"
-                    "  -t sys\t\tSet the target system\n"
-                    "  -v\t\t\tVerbose mode\n"
-                    "  -vm\t\t\tVerbose map file\n"
-                    "  -A\t\t\tStrict ANSI mode\n"
-                    "  -C name\t\tUse linker config file\n"
-                    "  -Cl\t\t\tMake local variables static\n"
-                    "  -D sym[=defn]\t\tDefine a preprocessor symbol\n"
-                    "  -I dir\t\tSet a compiler include directory path\n"
-             "  -L path\t\tSpecify a library search path\n"
-                    "  -Ln name\t\tCreate a VICE label file\n"
-                    "  -O\t\t\tOptimize code\n"
-                    "  -Oi\t\t\tOptimize code, inline functions\n"
-                    "  -Or\t\t\tOptimize code, honour the register keyword\n"
-                    "  -Os\t\t\tOptimize code, inline known C funtions\n"
-                    "  -S\t\t\tCompile but don't assemble and link\n"
-                    "  -T\t\t\tInclude source as comment\n"
-                    "  -V\t\t\tPrint the version number\n"
-                    "  -W\t\t\tSuppress warnings\n"
-            "\n"
-            "Long options:\n"
-                    "  --add-source\t\tInclude source as comment\n"
-                    "  --ansi\t\tStrict ANSI mode\n"
-                    "  --asm-define sym[=v]\tDefine an assembler symbol\n"
-            "  --asm-include-dir dir\tSet an assembler include directory\n"
-             "  --bss-label name\tDefine and export a BSS segment label\n"
-            "  --bss-name seg\tSet the name of the BSS segment\n"
-             "  --cfg-path path\tSpecify a config file search path\n"
-                    "  --check-stack\t\tGenerate stack overflow checks\n"
-             "  --code-label name\tDefine and export a CODE segment label\n"
-                    "  --code-name seg\tSet the name of the CODE segment\n"
-            "  --codesize x\t\tAccept larger code by factor x\n"
-                    "  --config name\t\tUse linker config file\n"
-                    "  --cpu type\t\tSet cpu type\n"
-            "  --create-dep\t\tCreate a make dependency file\n"
-             "  --data-label name\tDefine and export a DATA segment label\n"
-                    "  --data-name seg\tSet the name of the DATA segment\n"
-                    "  --debug\t\tDebug mode\n"
-                    "  --debug-info\t\tAdd debug info\n"
-            "  --feature name\tSet an emulation feature\n"
-                    "  --forget-inc-paths\tForget include search paths (compiler)\n"
-                    "  --help\t\tHelp (this text)\n"
-                    "  --include-dir dir\tSet a compiler include directory path\n"
-             "  --lib file\t\tLink this library\n"
-             "  --lib-path path\tSpecify a library search path\n"
-            "  --list-targets\tList all available targets\n"
-                    "  --listing\t\tCreate an assembler listing\n"
-            "  --mapfile name\tCreate a map file\n"
-             "  --memory-model model\tSet the memory model\n"
-             "  --module\t\tLink as a module\n"
-             "  --module-id id\tSpecify a module id for the linker\n"
-             "  --o65-model model\tOverride the o65 model\n"
-             "  --obj file\t\tLink this object file\n"
-             "  --obj-path path\tSpecify an object file search path\n"
-             "  --register-space b\tSet space available for register variables\n"
-             "  --register-vars\tEnable register variables\n"
-                    "  --rodata-name seg\tSet the name of the RODATA segment\n"
-                    "  --signed-chars\tDefault characters are signed\n"
-                    "  --start-addr addr\tSet the default start address\n"
-                    "  --static-locals\tMake local variables static\n"
-                    "  --target sys\t\tSet the target system\n"
-                    "  --version\t\tPrint the version number\n"
-                    "  --verbose\t\tVerbose mode\n"
-             "  --zeropage-label name\tDefine and export a ZEROPAGE segment label\n"
-                    "  --zeropage-name seg\tSet the name of the ZEROPAGE segment\n",
-            ProgName);
+    printf ("Usage: %s [options] file [...]\n"
+            "Short options:\n"
+            "  -c\t\t\tCompile and assemble but don't link\n"
+            "  -d\t\t\tDebug mode\n"
+            "  -g\t\t\tAdd debug info\n"
+            "  -h\t\t\tHelp (this text)\n"
+            "  -l\t\t\tCreate an assembler listing\n"
+            "  -m name\t\tCreate a map file\n"
+            "  -mm model\t\tSet the memory model\n"
+            "  -o name\t\tName the output file\n"
+            "  -r\t\t\tEnable register variables\n"
+            "  -t sys\t\tSet the target system\n"
+            "  -u sym\t\tForce an import of symbol `sym'\n"
+            "  -v\t\t\tVerbose mode\n"
+            "  -vm\t\t\tVerbose map file\n"
+            "  -C name\t\tUse linker config file\n"
+            "  -Cl\t\t\tMake local variables static\n"
+            "  -D sym[=defn]\t\tDefine a preprocessor symbol\n"
+            "  -I dir\t\tSet a compiler include directory path\n"
+            "  -L path\t\tSpecify a library search path\n"
+            "  -Ln name\t\tCreate a VICE label file\n"
+            "  -O\t\t\tOptimize code\n"
+            "  -Oi\t\t\tOptimize code, inline functions\n"
+            "  -Or\t\t\tOptimize code, honour the register keyword\n"
+            "  -Os\t\t\tOptimize code, inline known C funtions\n"
+            "  -S\t\t\tCompile but don't assemble and link\n"
+            "  -T\t\t\tInclude source as comment\n"
+            "  -V\t\t\tPrint the version number\n"
+            "  -W\t\t\tSuppress warnings\n"
+            "  -Wa options\t\tPass options to the assembler\n"
+            "  -Wl options\t\tPass options to the linker\n"
+            "\n"
+            "Long options:\n"
+            "  --add-source\t\tInclude source as comment\n"
+            "  --asm-args options\tPass options to the assembler\n"
+            "  --asm-define sym[=v]\tDefine an assembler symbol\n"
+            "  --asm-include-dir dir\tSet an assembler include directory\n"
+            "  --bss-label name\tDefine and export a BSS segment label\n"
+            "  --bss-name seg\tSet the name of the BSS segment\n"
+            "  --cfg-path path\tSpecify a config file search path\n"
+            "  --check-stack\t\tGenerate stack overflow checks\n"
+            "  --code-label name\tDefine and export a CODE segment label\n"
+            "  --code-name seg\tSet the name of the CODE segment\n"
+            "  --codesize x\t\tAccept larger code by factor x\n"
+            "  --config name\t\tUse linker config file\n"
+            "  --cpu type\t\tSet cpu type\n"
+            "  --create-dep\t\tCreate a make dependency file\n"
+            "  --data-label name\tDefine and export a DATA segment label\n"
+            "  --data-name seg\tSet the name of the DATA segment\n"
+            "  --debug\t\tDebug mode\n"
+            "  --debug-info\t\tAdd debug info\n"
+            "  --feature name\tSet an emulation feature\n"
+            "  --force-import sym\tForce an import of symbol `sym'\n"
+            "  --forget-inc-paths\tForget include search paths (compiler)\n"
+            "  --help\t\tHelp (this text)\n"
+            "  --include-dir dir\tSet a compiler include directory path\n"
+            "  --ld-args options\tPass options to the linker\n"
+            "  --lib file\t\tLink this library\n"
+            "  --lib-path path\tSpecify a library search path\n"
+            "  --list-targets\tList all available targets\n"
+            "  --listing\t\tCreate an assembler listing\n"
+            "  --list-bytes n\tNumber of bytes per assembler listing line\n"
+            "  --mapfile name\tCreate a map file\n"
+            "  --memory-model model\tSet the memory model\n"
+            "  --module\t\tLink as a module\n"
+            "  --module-id id\tSpecify a module id for the linker\n"
+            "  --o65-model model\tOverride the o65 model\n"
+            "  --obj file\t\tLink this object file\n"
+            "  --obj-path path\tSpecify an object file search path\n"
+            "  --register-space b\tSet space available for register variables\n"
+            "  --register-vars\tEnable register variables\n"
+            "  --rodata-name seg\tSet the name of the RODATA segment\n"
+            "  --signed-chars\tDefault characters are signed\n"
+            "  --standard std\tLanguage standard (c89, c99, cc65)\n"
+            "  --start-addr addr\tSet the default start address\n"
+            "  --static-locals\tMake local variables static\n"
+            "  --target sys\t\tSet the target system\n"
+            "  --version\t\tPrint the version number\n"
+            "  --verbose\t\tVerbose mode\n"
+            "  --zeropage-label name\tDefine and export a ZEROPAGE segment label\n"
+            "  --zeropage-name seg\tSet the name of the ZEROPAGE segment\n",
+            ProgName);
 }
 
 
@@ -678,11 +719,10 @@ static void OptAddSource (const char* Opt attribute ((unused)),
 
 
 
-static void OptAnsi (const char* Opt attribute ((unused)),
-                    const char* Arg attribute ((unused)))
-/* Strict ANSI mode (compiler) */
+static void OptAsmArgs (const char* Opt attribute ((unused)), const char* Arg)
+/* Pass arguments to the assembler */
 {
-    CmdAddArg (&CC65, "-A");
+    CmdAddArgList (&CA65, Arg);
 }
 
 
@@ -839,10 +879,19 @@ static void OptFeature (const char* Opt attribute ((unused)), const char* Arg)
 
 
 
-static void OptForgetIncPaths (const char* Opt attribute ((unused)), const char* Arg)
+static void OptForceImport (const char* Opt attribute ((unused)), const char* Arg)
+/* Emulation features for the assembler */
+{
+    CmdAddArg2 (&LD65, "-u", Arg);
+}
+
+
+
+static void OptForgetIncPaths (const char* Opt attribute ((unused)),
+                               const char* Arg attribute ((unused)))
 /* Forget all currently defined include paths */
 {
-    CmdAddArg2 (&CC65, "--forget-inc-paths", Arg);
+    CmdAddArg (&CC65, "--forget-inc-paths");
 }
 
 
@@ -865,6 +914,14 @@ static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg
 
 
 
+static void OptLdArgs (const char* Opt attribute ((unused)), const char* Arg)
+/* Pass arguments to the linker */
+{
+    CmdAddArgList (&LD65, Arg);
+}
+
+
+
 static void OptLib (const char* Opt attribute ((unused)), const char* Arg)
 /* Library file follows (linker) */
 {
@@ -881,6 +938,14 @@ static void OptLibPath (const char* Opt attribute ((unused)), const char* Arg)
 
 
 
+static void OptListBytes (const char* Opt attribute ((unused)), const char* Arg)
+/* Set the maximum number of bytes per asm listing line */
+{
+    CmdAddArg2 (&CA65, "--list-bytes", Arg);
+}
+
+
+
 static void OptListing (const char* Opt attribute ((unused)),
                        const char* Arg attribute ((unused)))
 /* Create an assembler listing */
@@ -1008,6 +1073,14 @@ static void OptSignedChars (const char* Opt attribute ((unused)),
 
 
 
+static void OptStandard (const char* Opt attribute ((unused)), const char* Arg)
+/* Set the language standard */
+{
+    CmdAddArg2 (&CC65, "--standard", Arg);
+}
+
+
+
 static void OptStartAddr (const char* Opt attribute ((unused)), const char* Arg)
 /* Set the default start address */
 {
@@ -1055,8 +1128,8 @@ static void OptVersion (const char* Opt attribute ((unused)),
 /* Print version number */
 {
     fprintf (stderr,
-            "cl65 V%u.%u.%u - (C) Copyright 1998-2003 Ullrich von Bassewitz\n",
-            VER_MAJOR, VER_MINOR, VER_PATCH);
+            "cl65 V%s - (C) Copyright 1998-2009 Ullrich von Bassewitz\n",
+            GetVersionAsString ());
 }
 
 
@@ -1083,7 +1156,7 @@ int main (int argc, char* argv [])
     /* Program long options */
     static const LongOpt OptTab[] = {
        { "--add-source",       0,      OptAddSource            },
-       { "--ansi",             0,      OptAnsi                 },
+        { "--asm-args",         1,      OptAsmArgs              },
                { "--asm-define",       1,      OptAsmDefine            },
        { "--asm-include-dir",  1,      OptAsmIncludeDir        },
                { "--bss-label",        1,      OptBssLabel             },
@@ -1101,13 +1174,16 @@ int main (int argc, char* argv [])
        { "--debug",            0,      OptDebug                },
        { "--debug-info",       0,      OptDebugInfo            },
        { "--feature",          1,      OptFeature              },
+        { "--force-import",     1,      OptForceImport          },
                { "--forget-inc-paths", 0,      OptForgetIncPaths       },
        { "--help",             0,      OptHelp                 },
        { "--include-dir",      1,      OptIncludeDir           },
+        { "--ld-args",          1,      OptLdArgs               },
                { "--lib",              1,      OptLib                  },
                { "--lib-path",         1,      OptLibPath              },
        { "--list-targets",     0,      OptListTargets          },
        { "--listing",          0,      OptListing              },
+        { "--list-bytes",       1,      OptListBytes            },
        { "--mapfile",          1,      OptMapFile              },
         { "--memory-model",     1,      OptMemoryModel          },
         { "--module",           0,      OptModule               },
@@ -1119,6 +1195,7 @@ int main (int argc, char* argv [])
         { "--register-vars",    0,      OptRegisterVars         },
        { "--rodata-name",      1,      OptRodataName           },
        { "--signed-chars",     0,      OptSignedChars          },
+        { "--standard",         1,      OptStandard             },
        { "--start-addr",       1,      OptStartAddr            },
                { "--static-locals",    0,      OptStaticLocals         },
        { "--target",           1,      OptTarget               },
@@ -1159,11 +1236,6 @@ int main (int argc, char* argv [])
                    LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
                    break;
 
-               case 'A':
-                   /* Strict ANSI mode (compiler) */
-                   OptAnsi (Arg, 0);
-                   break;
-
                case 'C':
                    if (Arg[2] == 'l' && Arg[3] == '\0') {
                        /* Make local variables static */
@@ -1215,10 +1287,27 @@ int main (int argc, char* argv [])
                    break;
 
                case 'W':
-                   /* Suppress warnings - compiler and assembler */
-                   CmdAddArg (&CC65, "-W");
-                   CmdAddArg2 (&CA65, "-W", "0");
-                   break;
+                    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 'c':
                    /* Don't link the resulting files */
@@ -1271,6 +1360,11 @@ int main (int argc, char* argv [])
                    OptTarget (Arg, GetArg (&I, 2));
                    break;
 
+               case 'u':
+                   /* Force an import (linker) */
+                   OptForceImport (Arg, GetArg (&I, 2));
+                   break;
+
                case 'v':
                    if (Arg [2] == 'm') {
                        /* Verbose map file (linker) */