Change target handling, use modules from the common directory.

New long options: --config and --mapfile.


git-svn-id: svn://svn.cc65.org/cc65/trunk@302 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2000-08-23 14:13:24 +00:00
parent e163b07d1b
commit c3105a4e5d
5 changed files with 134 additions and 203 deletions

View file

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998 Ullrich von Bassewitz */ /* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Wacholderweg 14 */
/* D-70597 Stuttgart */ /* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */ /* EMail: uz@musoftware.de */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -38,23 +38,27 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "../common/cmdline.h" /* common */
#include "../common/libdefs.h" #include "cmdline.h"
#include "../common/objdefs.h" #include "libdefs.h"
#include "../common/version.h" #include "objdefs.h"
#include "../common/xmalloc.h"
#include "global.h"
#include "error.h"
#include "target.h" #include "target.h"
#include "fileio.h" #include "version.h"
#include "scanner.h" #include "xmalloc.h"
/* ld65 */
#include "binfmt.h"
#include "config.h" #include "config.h"
#include "objfile.h" #include "error.h"
#include "library.h"
#include "exports.h" #include "exports.h"
#include "segments.h" #include "fileio.h"
#include "global.h"
#include "library.h"
#include "mapfile.h" #include "mapfile.h"
#include "objfile.h"
#include "scanner.h"
#include "segments.h"
#include "tgtcfg.h"
@ -86,7 +90,7 @@ static void Usage (void)
" -h\t\t\tHelp (this text)\n" " -h\t\t\tHelp (this text)\n"
" -m name\t\tCreate a map file\n" " -m name\t\tCreate a map file\n"
" -o name\t\tName the default output file\n" " -o name\t\tName the default output file\n"
" -t type\t\tType of target system\n" " -t sys\t\tSet the target system\n"
" -v\t\t\tVerbose mode\n" " -v\t\t\tVerbose mode\n"
" -vm\t\t\tVerbose map file\n" " -vm\t\t\tVerbose map file\n"
" -C name\t\tUse linker config file\n" " -C name\t\tUse linker config file\n"
@ -97,6 +101,8 @@ static void Usage (void)
"\n" "\n"
"Long options:\n" "Long options:\n"
" --help\t\tHelp (this text)\n" " --help\t\tHelp (this text)\n"
" --mapfile name\tCreate a map file\n"
" --target sys\t\tSet the target system\n"
" --version\t\tPrint the linker version\n", " --version\t\tPrint the linker version\n",
ProgName); ProgName);
} }
@ -207,6 +213,17 @@ static void LinkFile (const char* Name)
static void OptConfig (const char* Opt, const char* Arg)
/* Define the config file */
{
if (CfgAvail ()) {
Error ("Cannot use -C/-t twice");
}
CfgSetName (Arg);
}
static void OptHelp (const char* Opt, const char* Arg) static void OptHelp (const char* Opt, const char* Arg)
/* Print usage information and exit */ /* Print usage information and exit */
{ {
@ -216,6 +233,35 @@ static void OptHelp (const char* Opt, const char* Arg)
static void OptMapFile (const char* Opt, const char* Arg)
/* Give the name of the map file */
{
MapFileName = Arg;
}
static void OptTarget (const char* Opt, const char* Arg)
/* Set the target system */
{
const TargetDesc* D;
/* Map the target name to a target id */
Target = FindTarget (Arg);
if (Target == TGT_UNKNOWN) {
Error ("Invalid target name: `%s'", Arg);
}
/* Get the target description record */
D = &Targets[Target];
/* Set the target data */
DefaultBinFmt = D->BinFmt;
CfgSetBuf (D->Cfg);
}
static void OptVersion (const char* Opt, const char* Arg) static void OptVersion (const char* Opt, const char* Arg)
/* Print the assembler version */ /* Print the assembler version */
{ {
@ -231,8 +277,11 @@ int main (int argc, char* argv [])
{ {
/* Program long options */ /* Program long options */
static const LongOpt OptTab[] = { static const LongOpt OptTab[] = {
{ "--help", 0, OptHelp }, { "--config", 1, OptConfig },
{ "--version", 0, OptVersion }, { "--help", 0, OptHelp },
{ "--mapfile", 1, OptMapFile },
{ "--target", 1, OptTarget },
{ "--version", 0, OptVersion },
}; };
int I; int I;
@ -255,7 +304,7 @@ int main (int argc, char* argv [])
/* Check the parameters */ /* Check the parameters */
I = 1; I = 1;
while (I < argc) { while (I < argc) {
/* Get the argument */ /* Get the argument */
const char* Arg = argv [I]; const char* Arg = argv [I];
@ -266,37 +315,34 @@ int main (int argc, char* argv [])
switch (Arg [1]) { switch (Arg [1]) {
case '-': case '-':
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
break; break;
case 'm': case 'm':
MapFileName = GetArg (&I, 2); OptMapFile (Arg, GetArg (&I, 2));
break; break;
case 'o': case 'o':
OutputName = GetArg (&I, 2); OutputName = GetArg (&I, 2);
break; break;
case 't': case 't':
if (CfgAvail ()) { if (CfgAvail ()) {
Error ("Cannot use -C/-t twice"); Error ("Cannot use -C/-t twice");
} }
TgtSet (GetArg (&I, 2)); OptTarget (Arg, GetArg (&I, 2));
break; break;
case 'v': case 'v':
switch (Arg [2]) { switch (Arg [2]) {
case 'm': VerboseMap = 1; break; case 'm': VerboseMap = 1; break;
case '\0': ++Verbose; break; case '\0': ++Verbose; break;
default: UnknownOption (Arg); default: UnknownOption (Arg);
} }
break; break;
case 'C': case 'C':
if (CfgAvail ()) { OptConfig (Arg, GetArg (&I, 2));
Error ("Cannot use -C/-t twice");
}
CfgSetName (GetArg (&I, 2));
break; break;
case 'L': case 'L':
@ -315,9 +361,9 @@ int main (int argc, char* argv [])
OptVersion (Arg, 0); OptVersion (Arg, 0);
break; break;
default: default:
UnknownOption (Arg); UnknownOption (Arg);
break; break;
} }
} else { } else {
@ -333,14 +379,12 @@ int main (int argc, char* argv [])
/* Check if we had any object files */ /* Check if we had any object files */
if (ObjFiles == 0) { if (ObjFiles == 0) {
fprintf (stderr, "No object files to link\n"); Error ("No object files to link");
exit (EXIT_FAILURE);
} }
/* Check if we have a valid configuration */ /* Check if we have a valid configuration */
if (!CfgAvail ()) { if (!CfgAvail ()) {
fprintf (stderr, "Memory configuration missing\n"); Error ("Memory configuration missing");
exit (EXIT_FAILURE);
} }
/* Read the config file */ /* Read the config file */

View file

@ -29,7 +29,7 @@ OBJS = bin.o \
objfile.o \ objfile.o \
scanner.o \ scanner.o \
segments.o \ segments.o \
target.o tgtcfg.o
LIBS = $(COMMON)/common.a LIBS = $(COMMON)/common.a

View file

@ -85,7 +85,7 @@ OBJS = bin.obj \
objfile.obj \ objfile.obj \
scanner.obj \ scanner.obj \
segments.obj \ segments.obj \
target.obj tgtcfg.obj
LIBS = ..\common\common.lib LIBS = ..\common\common.lib
@ -93,16 +93,16 @@ LIBS = ..\common\common.lib
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Main targets # Main targets
all: ld65 all: ld65
ld65: ld65.exe ld65: ld65.exe
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Other targets # Other targets
ld65.exe: $(OBJS) $(LIBS) ld65.exe: $(OBJS) $(LIBS)
$(LD) system $(SYSTEM) @&&| $(LD) system $(SYSTEM) @&&|
DEBUG ALL DEBUG ALL
OPTION QUIET OPTION QUIET
@ -125,7 +125,7 @@ FILE objdata.obj
FILE objfile.obj FILE objfile.obj
FILE scanner.obj FILE scanner.obj
FILE segments.obj FILE segments.obj
FILE target.obj FILE tgtcfg.obj
LIBRARY ..\common\common.lib LIBRARY ..\common\common.lib
| |

View file

@ -1,8 +1,8 @@
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* target.c */ /* tgtcfg.c */
/* */ /* */
/* Target system support for the ld65 linker */ /* Target machine configurations the ld65 linker */
/* */ /* */
/* */ /* */
/* */ /* */
@ -32,18 +32,9 @@
/*****************************************************************************/ /*****************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "error.h"
#include "global.h"
#include "binfmt.h" #include "binfmt.h"
#include "scanner.h" #include "tgtcfg.h"
#include "config.h"
#include "target.h"
@ -221,131 +212,22 @@ static const char CfgGeos [] =
/* Supported systems */ /* Target configurations for all systems */
#define TGT_NONE 0 const TargetDesc Targets [TGT_COUNT] = {
#define TGT_ATARI 1 /* Atari 8 bit machines */ { BINFMT_BINARY, CfgNone },
#define TGT_C64 2 { BINFMT_BINARY, CfgAtari },
#define TGT_C128 3 { BINFMT_BINARY, CfgC64 },
#define TGT_ACE 4 { BINFMT_BINARY, CfgC128 },
#define TGT_PLUS4 5 { BINFMT_BINARY, CfgAce },
#define TGT_CBM610 6 /* CBM 600/700 family */ { BINFMT_BINARY, CfgPlus4 },
#define TGT_PET 7 /* CBM PET family */ { BINFMT_BINARY, CfgCBM610 },
#define TGT_NES 8 /* Nintendo Entertainment System */ { BINFMT_BINARY, CfgPET },
#define TGT_LUNIX 9 { BINFMT_BINARY, CfgNES },
#define TGT_OSA65 10 { BINFMT_O65, CfgLunix },
#define TGT_APPLE2 11 { BINFMT_O65, CfgOSA65 },
#define TGT_GEOS 12 { BINFMT_BINARY, CfgApple2 },
#define TGT_COUNT 13 /* Count of supported systems */ { BINFMT_BINARY, CfgGeos },
/* Structure describing a target */
typedef struct TargetCfg_ TargetCfg;
struct TargetCfg_ {
const char* Name; /* Name of the system */
unsigned char BinFmt; /* Default binary format for the target */
const char* Cfg; /* Pointer to configuration */
}; };
static const TargetCfg Targets [TGT_COUNT] = {
{ "none", BINFMT_BINARY, CfgNone },
{ "atari", BINFMT_BINARY, CfgAtari },
{ "c64", BINFMT_BINARY, CfgC64 },
{ "c128", BINFMT_BINARY, CfgC128 },
{ "ace", BINFMT_BINARY, CfgAce },
{ "plus4", BINFMT_BINARY, CfgPlus4 },
{ "cbm610", BINFMT_BINARY, CfgCBM610 },
{ "pet", BINFMT_BINARY, CfgPET },
{ "nes", BINFMT_BINARY, CfgNES },
{ "lunix", BINFMT_O65, CfgLunix },
{ "osa65", BINFMT_O65, CfgOSA65 },
{ "apple2", BINFMT_BINARY, CfgApple2 },
{ "geos", BINFMT_BINARY, CfgGeos },
};
/* Selected target system type */
static const TargetCfg* Target;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static int StrICmp (const char* S1, const char* S2)
/* Compare two strings case insensitive */
{
int Diff = 0;
while (1) {
Diff = tolower (*S1) - tolower (*S2);
if (Diff != 0 || *S1 == '\0') {
return Diff;
}
++S1;
++S2;
}
}
static int TgtMap (const char* Name)
/* Map a target name to a system code. Return -1 in case of an error */
{
unsigned I;
/* Check for a numeric target */
if (isdigit (*Name)) {
int Target = atoi (Name);
if (Target >= 0 && Target < TGT_COUNT) {
return Target;
}
}
/* Check for a target string */
for (I = 0; I < TGT_COUNT; ++I) {
if (StrICmp (Targets [I].Name, Name) == 0) {
return I;
}
}
/* Not found */
return -1;
}
void TgtSet (const char* T)
/* Set the target system, initialize internal stuff for this target */
{
/* Map the target to a number */
int TgtNum = TgtMap (T);
if (TgtNum == -1) {
Error ("Invalid target system: %s", T);
}
Target = &Targets [TgtNum];
/* Set the target data */
DefaultBinFmt = Target->BinFmt;
CfgSetBuf (Target->Cfg);
}
void TgtPrintList (FILE* F)
/* Print a list of the available target systems */
{
unsigned I;
/* Print a header */
fprintf (F, "Available targets:\n");
/* Print a list of the target systems */
for (I = 0; I < TGT_COUNT; ++I) {
fprintf (F, " %s\n", Targets [I].Name);
}
}

View file

@ -1,8 +1,8 @@
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* target.h */ /* tgtcfg.h */
/* */ /* */
/* Target system support for the ld65 linker */ /* Target machine configurations the ld65 linker */
/* */ /* */
/* */ /* */
/* */ /* */
@ -33,30 +33,35 @@
#ifndef TARGET_H #ifndef TGTCFG_H
#define TARGET_H #define TGTCFG_H
#include <stdio.h> /* common */
#include "target.h"
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Target configurations */
/*****************************************************************************/ /*****************************************************************************/
void TgtSet (const char* T); /* Structure describing a target */
/* Set the target system, initialize internal stuff for this target */ typedef struct TargetDesc TargetDesc;
struct TargetDesc {
unsigned char BinFmt; /* Default binary format for the target */
const char* Cfg; /* Pointer to configuration */
};
void TgtPrintList (FILE* F); /* Target configurations for all systems */
/* Print a list of the available target systems */ extern const TargetDesc Targets [TGT_COUNT];
/* End of target.h */ /* End of tgtcfg.h */
#endif #endif