static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 };
/* Variables controlling the steps we're doing */
-static int DontLink = 0;
-static int DontAssemble = 0;
+static int DoLink = 1;
+static int DoAssemble = 1;
/* The name of the output file, NULL if none given */
static const char* OutputName = 0;
/* Set the target system */
CmdSetTarget (&CA65, Target);
- /* If we won't link, this is the final step. In this case, set the
- * output name.
- */
- if (DontLink && OutputName) {
- CmdSetOutput (&CA65, OutputName);
- } else {
- /* The object file name will be the name of the source file
- * with .s replaced by ".o". Add this file to the list of
- * linker files.
- */
+ /* Check if this is the last processing step */
+ if (DoLink) {
+ /* We're linking later. Add the output file of the assembly
+ * the the file list of the linker. The name of the output
+ * file is that of the input file with ".s" replaced by ".o".
+ */
char* ObjName = MakeFilename (File, ".o");
CmdAddFile (&LD65, ObjName);
xfree (ObjName);
+ } else {
+ /* This is the final step. If an output name is given, set it */
+ if (OutputName) {
+ CmdSetOutput (&CA65, OutputName);
+ }
}
/* Add the file as argument for the assembler */
-static void AssembleIntermediate (const char* File)
-/* Assemble an intermediate file. The -dep options won't be added and
- * the file is removed after assembly.
+static void AssembleIntermediate (const char* SourceFile)
+/* Assemble an intermediate file which was generated by a previous processing
+ * step with SourceFile as input. The -dep options won't be added and
+ * the intermediate assembler file is removed after assembly.
*/
{
- /* Use common routine */
- AssembleFile (File, CA65.ArgCount);
+ /* Generate the name of the assembler output file from the source file
+ * name. It's the same name with the extension replaced by ".s"
+ */
+ char* AsmName = MakeFilename (SourceFile, ".s");
+
+ /* Assemble the intermediate assembler file */
+ AssembleFile (AsmName, CA65.ArgCount);
- /* Remove the generated file */
- if (remove (File) < 0) {
+ /* Remove the input file */
+ if (remove (AsmName) < 0) {
Warning ("Cannot remove temporary file `%s': %s",
- File, strerror (errno));
+ AsmName, strerror (errno));
}
+
+ /* Free the assembler file name which was allocated from the heap */
+ xfree (AsmName);
}
static void Compile (const char* File)
/* Compile the given file */
{
- char* AsmName = 0;
-
/* Remember the current compiler argument count */
unsigned ArgCount = CC65.ArgCount;
/* If we won't assemble, this is the final step. In this case, set the
* output name.
*/
- if (DontAssemble && OutputName) {
+ if (!DoAssemble && OutputName) {
CmdSetOutput (&CC65, OutputName);
- } else {
- /* The assembler file name will be the name of the source file
- * with .c replaced by ".s".
- */
- AsmName = MakeFilename (File, ".s");
}
/* Add the file as argument for the compiler */
/* If this is not the final step, assemble the generated file, then
* remove it
*/
- if (!DontAssemble) {
- AssembleIntermediate (AsmName);
+ if (DoAssemble) {
+ /* Assemble the intermediate file and remove it */
+ AssembleIntermediate (File);
}
-
- /* Free the assembler file name which was allocated from the heap */
- xfree (AsmName);
}
static void CompileRes (const char* File)
/* Compile the given geos resource file */
{
- char* AsmName = 0;
-
/* Remember the current assembler argument count */
unsigned ArgCount = GRC.ArgCount;
- /* The assembler file name will be the name of the source file
- * with .grc replaced by ".s".
- */
- AsmName = MakeFilename (File, ".s");
-
/* Add the file as argument for the resource compiler */
CmdAddArg (&GRC, File);
/* If this is not the final step, assemble the generated file, then
* remove it
*/
- if (!DontAssemble) {
- AssembleIntermediate (AsmName);
+ if (DoAssemble) {
+ /* Assemble the intermediate file and remove it */
+ AssembleIntermediate (File);
}
-
- /* Free the assembler file name which was allocated from the heap */
- xfree (AsmName);
}
static void ConvertO65 (const char* File)
/* Convert an o65 object file into an assembler file */
{
- char* AsmName = 0;
-
/* Remember the current converter argument count */
unsigned ArgCount = CO65.ArgCount;
/* If we won't assemble, this is the final step. In this case, set the
* output name.
*/
- if (DontAssemble && OutputName) {
- CmdSetOutput (&CO65, OutputName);
- } else {
- /* The assembler file name will be the name of the source file
- * with .c replaced by ".s".
- */
- AsmName = MakeFilename (File, ".s");
+ if (!DoAssemble && OutputName) {
+ CmdSetOutput (&CO65, OutputName);
}
/* Add the file as argument for the object file converter */
/* If this is not the final step, assemble the generated file, then
* remove it
*/
- if (!DontAssemble) {
- AssembleIntermediate (AsmName);
+ if (DoAssemble) {
+ /* Assemble the intermediate file and remove it */
+ AssembleIntermediate (File);
}
-
- /* Free the assembler file name which was allocated from the heap */
- xfree (AsmName);
}
case 'S':
/* Dont assemble and link the created files */
- DontLink = DontAssemble = 1;
+ DoAssemble = 0;
+ DoLink = 0;
break;
case 'T':
case 'c':
/* Don't link the resulting files */
- DontLink = 1;
+ DoLink = 0;
break;
case 'd':
case FILETYPE_ASM:
/* Assemble the file */
- if (!DontAssemble) {
+ if (DoAssemble) {
Assemble (Arg);
}
break;
}
/* Link the given files if requested and if we have any */
- if (DontLink == 0 && LD65.FileCount > 0) {
+ if (DoLink && LD65.FileCount > 0) {
Link ();
}