/* */
/* */
/* */
-/* (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 */
/* 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;
+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;
}
}
+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 */
{
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);
}
- /* 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]);
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);
}
-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);
}
-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");
}
+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) */
{
+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 */
+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 */
{
/* 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 ());
}
/* 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 },
{ "--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 },
{ "--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 },
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 */
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 */
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) */