/* common */
#include "attrib.h"
#include "cmdline.h"
+#include "filetype.h"
#include "fname.h"
+#include "mmodel.h"
#include "strbuf.h"
#include "target.h"
#include "version.h"
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
static CmdDesc LD65 = { 0, 0, 0, 0, 0, 0, 0 };
static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 };
-/* File types */
-enum {
- FILETYPE_UNKNOWN,
- FILETYPE_C,
- FILETYPE_ASM,
- FILETYPE_OBJ,
- FILETYPE_LIB,
- FILETYPE_GR, /* GEOS resource file */
- FILETYPE_O65 /* O65 object file */
-};
-
-/* Default file type, used if type unknown */
-static unsigned DefaultFileType = FILETYPE_UNKNOWN;
-
/* Variables controlling the steps we're doing */
static int DontLink = 0;
static int DontAssemble = 0;
-/*****************************************************************************/
-/* Determine a file type */
-/*****************************************************************************/
-
-
-
-static unsigned GetFileType (const char* File)
-/* Determine the type of the given file */
-{
- /* Table mapping extensions to file types */
- static const struct {
- const char* Ext;
- unsigned Type;
- } FileTypes [] = {
- { ".c", FILETYPE_C },
- { ".s", FILETYPE_ASM },
- { ".asm", FILETYPE_ASM },
- { ".a65", FILETYPE_ASM },
- { ".o", FILETYPE_OBJ },
- { ".obj", FILETYPE_OBJ },
- { ".a", FILETYPE_LIB },
- { ".lib", FILETYPE_LIB },
- { ".grc", FILETYPE_GR },
- { ".o65", FILETYPE_O65 },
- { ".emd", FILETYPE_O65 },
- { ".joy", FILETYPE_O65 },
- { ".tgi", FILETYPE_O65 },
- };
-
- unsigned I;
-
- /* Determine the file type by the extension */
- const char* Ext = FindExt (File);
-
- /* Do we have an extension? */
- if (Ext == 0) {
- return DefaultFileType;
- }
-
- /* Check for known extensions */
- for (I = 0; I < sizeof (FileTypes) / sizeof (FileTypes [0]); ++I) {
- if (strcmp (FileTypes [I].Ext, Ext) == 0) {
- /* Found */
- return FileTypes [I].Type;
- }
- }
-
- /* Not found, return the default */
- return DefaultFileType;
-}
-
-
-
/*****************************************************************************/
/* Command structure handling */
/*****************************************************************************/
/* Set the startup file */
TargetCRT0 = xmalloc (TargetNameLen + 2 + 1);
- strcpy (TargetCRT0, TargetName);
- strcat (TargetCRT0, ".o");
+ memcpy (TargetCRT0, TargetName, TargetNameLen);
+ strcpy (TargetCRT0 + TargetNameLen, ".o");
/* Set the library file */
TargetLib = xmalloc (TargetNameLen + 4 + 1);
- strcpy (TargetLib, TargetName);
- strcat (TargetLib, ".lib");
+ memcpy (TargetLib, TargetName, TargetNameLen);
+ strcpy (TargetLib + TargetNameLen, ".lib");
}
}
CmdAddArg2 (&LD65, "-C", LinkerConfig);
} else if (Module) {
CmdSetTarget (&LD65, TGT_MODULE);
- } else if (Target != TGT_NONE) {
+ } else {
CmdSetTarget (&LD65, Target);
}
" -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"
" -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"
"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"
" --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"
" --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"
+static void OptAsmDefine (const char* Opt attribute ((unused)), const char* Arg)
+/* Define an assembler symbol (assembler) */
+{
+ CmdAddArg2 (&CA65, "-D", Arg);
+}
+
+
+
static void OptAsmIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
/* Include directory (assembler) */
{
+static void OptCfgPath (const char* Opt attribute ((unused)), const char* Arg)
+/* Config file search path (linker) */
+{
+ CmdAddArg2 (&LD65, "--cfg-path", Arg);
+}
+
+
+
static void OptCheckStack (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Handle the --check-stack option */
+static void OptConfig (const char* Opt attribute ((unused)), const char* Arg)
+/* Config file (linker) */
+{
+ if (LinkerConfig) {
+ Error ("Cannot specify -C/--config twice");
+ }
+ LinkerConfig = Arg;
+}
+
+
+
static void OptCPU (const char* Opt attribute ((unused)), const char* Arg)
/* Handle the --cpu option */
{
+static void OptForgetIncPaths (const char* Opt attribute ((unused)), const char* Arg)
+/* Forget all currently defined include paths */
+{
+ CmdAddArg2 (&CC65, "--forget-inc-paths", Arg);
+}
+
+
+
static void OptHelp (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Print help - cl65 */
+static void OptLib (const char* Opt attribute ((unused)), const char* Arg)
+/* Library file follows (linker) */
+{
+ CmdAddArg2 (&LD65, "--lib", Arg);
+}
+
+
+
+static void OptLibPath (const char* Opt attribute ((unused)), const char* Arg)
+/* Library search path (linker) */
+{
+ CmdAddArg2 (&LD65, "--lib-path", Arg);
+}
+
+
+
static void OptListing (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Create an assembler listing */
+static void OptMemoryModel (const char* Opt attribute ((unused)), const char* Arg)
+/* Set the memory model */
+{
+ mmodel_t MemoryModel = FindMemoryModel (Arg);
+ if (MemoryModel == MMODEL_UNKNOWN) {
+ Error ("Unknown memory model: %s", Arg);
+ } else if (MemoryModel == MMODEL_HUGE) {
+ Error ("Unsupported memory model: %s", Arg);
+ } else {
+ CmdAddArg2 (&CA65, "-mm", Arg);
+ CmdAddArg2 (&CC65, "-mm", Arg);
+ }
+}
+
+
+
static void OptModule (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Link as a module */
+static void OptObj (const char* Opt attribute ((unused)), const char* Arg)
+/* Object file follows (linker) */
+{
+ CmdAddArg2 (&LD65, "--obj", Arg);
+}
+
+
+
+static void OptObjPath (const char* Opt attribute ((unused)), const char* Arg)
+/* Object file search path (linker) */
+{
+ CmdAddArg2 (&LD65, "--obj-path", Arg);
+}
+
+
+
static void OptRegisterSpace (const char* Opt attribute ((unused)), const char* Arg)
/* Handle the --register-space option */
{
static const LongOpt OptTab[] = {
{ "--add-source", 0, OptAddSource },
{ "--ansi", 0, OptAnsi },
+ { "--asm-define", 1, OptAsmDefine },
{ "--asm-include-dir", 1, OptAsmIncludeDir },
{ "--bss-label", 1, OptBssLabel },
{ "--bss-name", 1, OptBssName },
+ { "--cfg-path", 1, OptCfgPath },
{ "--check-stack", 0, OptCheckStack },
{ "--code-label", 1, OptCodeLabel },
{ "--code-name", 1, OptCodeName },
{ "--codesize", 1, OptCodeSize },
+ { "--config", 1, OptConfig },
{ "--cpu", 1, OptCPU },
{ "--create-dep", 0, OptCreateDep },
{ "--data-label", 1, OptDataLabel },
{ "--debug", 0, OptDebug },
{ "--debug-info", 0, OptDebugInfo },
{ "--feature", 1, OptFeature },
+ { "--forget-inc-paths", 0, OptForgetIncPaths },
{ "--help", 0, OptHelp },
{ "--include-dir", 1, OptIncludeDir },
+ { "--lib", 1, OptLib },
+ { "--lib-path", 1, OptLibPath },
{ "--listing", 0, OptListing },
{ "--mapfile", 1, OptMapFile },
+ { "--memory-model", 1, OptMemoryModel },
{ "--module", 0, OptModule },
{ "--module-id", 1, OptModuleId },
{ "--o65-model", 1, OptO65Model },
+ { "--obj", 1, OptObj },
+ { "--obj-path", 1, OptObjPath },
{ "--register-space", 1, OptRegisterSpace },
{ "--register-vars", 0, OptRegisterVars },
{ "--rodata-name", 1, OptRodataName },
OptStaticLocals (Arg, 0);
} else {
/* Specify linker config file */
- LinkerConfig = GetArg (&I, 2);
+ OptConfig (Arg, GetArg (&I, 2));
}
break;
break;
case 'L':
- if (Arg[2] == 'n') {
+ if (Arg[2] == 'n' && Arg[3] == '\0') {
/* VICE label file (linker) */
CmdAddArg2 (&LD65, "-Ln", GetArg (&I, 3));
} else {
- UnknownOption (Arg);
+ /* Library search path (linker) */
+ OptLibPath (Arg, GetArg (&I, 2));
}
break;