1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-09 06:29:38 +00:00

Changed generation of makefile dependencies:

* There are now two options, --create-dep and --create-full-dep. One
    will add system includes, the other not.
  * Both options require a file name. This is an incompatible change(!)
    but has the advantage that the user is in control of extension and
    path of the generated file.
  * Output will always include a phony target for the input files. This
    may not work with all make programs.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4652 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2010-05-01 09:42:12 +00:00
parent 54740da820
commit 96cf7f6271
7 changed files with 263 additions and 179 deletions

View File

@ -49,52 +49,60 @@ The compiler may be called as follows:
<tscreen><verb>
---------------------------------------------------------------------------
Usage: cc65 [options] file
Short options:
-Cl Make local variables static
-Dsym[=defn] Define a symbol
-I dir Set an include directory search path
-O Optimize code
-Oi Optimize code, inline more code
-Or Enable register variables
-Os Inline some known functions
-T Include source as comment
-V Print the compiler version number
-W name[,name] Enable or disable warnings
-d Debug mode
-g Add debug info to object file
-h Help (this text)
-j Default characters are signed
-o name Name the output file
-r Enable register variables
-t sys Set the target system
-v Increase verbosity
Usage: cc65 [options] file
Short options:
-Cl Make local variables static
-Dsym[=defn] Define a symbol
-E Stop after the preprocessing stage
-I dir Set an include directory search path
-O Optimize code
-Oi Optimize code, inline more code
-Or Enable register variables
-Os Inline some known functions
-T Include source as comment
-V Print the compiler version number
-W Suppress warnings
-d Debug mode
-g Add debug info to object file
-h Help (this text)
-j Default characters are signed
-mm model Set the memory model
-o name Name the output file
-r Enable register variables
-t sys Set the target system
-v Increase verbosity
Long options:
--add-source Include source as comment
--bss-name seg Set the name of the BSS segment
--check-stack Generate stack overflow checks
--code-name seg Set the name of the CODE segment
--codesize x Accept larger code by factor x
--cpu type Set cpu type
--create-dep Create a make dependency file
--data-name seg Set the name of the DATA segment
--debug Debug mode
--debug-info Add debug info to object file
--forget-inc-paths Forget include search paths
--help Help (this text)
--include-dir dir Set an include directory search path
--local-strings Emit string literals immediately
--register-space b Set space available for register variables
--register-vars Enable register variables
--rodata-name seg Set the name of the RODATA segment
--signed-chars Default characters are signed
--standard std Language standard (c89, c99, cc65)
--static-locals Make local variables static
--target sys Set the target system
--verbose Increase verbosity
--version Print the compiler version number
--writable-strings Make string literals writable
--add-source Include source as comment
--bss-name seg Set the name of the BSS segment
--check-stack Generate stack overflow checks
--code-name seg Set the name of the CODE segment
--codesize x Accept larger code by factor x
--cpu type Set cpu type (6502, 65c02)
--create-dep name Create a make dependency file
--create-full-dep name Create a full make dependency file
--data-name seg Set the name of the DATA segment
--debug Debug mode
--debug-info Add debug info to object file
--debug-opt name Debug optimization steps
--disable-opt name Disable an optimization step
--enable-opt name Enable an optimization step
--forget-inc-paths Forget include search paths
--help Help (this text)
--include-dir dir Set an include directory search path
--list-opt-steps List all optimizer steps and exit
--local-strings Emit string literals immediately
--memory-model model Set the memory model
--register-space b Set space available for register variables
--register-vars Enable register variables
--rodata-name seg Set the name of the RODATA segment
--signed-chars Default characters are signed
--standard std Language standard (c89, c99, cc65)
--static-locals Make local variables static
--target sys Set the target system
--verbose Increase verbosity
--version Print the compiler version number
--writable-strings Make string literals writable
---------------------------------------------------------------------------
</verb></tscreen>
@ -139,20 +147,29 @@ Here is a description of all the command line options:
<label id="option-cpu">
<tag><tt>--cpu CPU</tt></tag>
A new, still experimental option. You may specify "6502" or "65C02" as
the CPU. 6502 is the default, so this will not change anything.
Specifying 65C02 will use a few 65C02 instructions when generating code.
Don't expect too much from this option: It is still new (and may have
bugs), and the additional instructions for the 65C02 are not that
overwhelming.
A new, still experimental option. You may specify "6502" or "65C02" as the
CPU. 6502 is the default, so this will not change anything. Specifying 65C02
will use a few 65C02 instructions when generating code. Don't expect too
much from this option: It is still new (and may have bugs), and the
additional instructions for the 65C02 are not that overwhelming.
<label id="option-create-dep">
<tag><tt>--create-dep</tt></tag>
<tag><tt>--create-dep name</tt></tag>
Tells the compiler to generate a file containing the dependency list for
the compiled module in makefile syntax. The file is named as the C input
file with the extension replaced by <tt/.u/.
Tells the compiler to generate a file containing the dependency list for the
compiled module in makefile syntax. The output is written to a file with the
given name. The output does not include system include files (in angle
brackets).
<label id="option-create-full-dep">
<tag><tt>--create-full-dep name</tt></tag>
Tells the compiler to generate a file containing the dependency list for the
compiled module in makefile syntax. The output is written to a file with the
given name. The output does include system include files (in angle
brackets).
<label id="option-data-name">

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2009, Ullrich von Bassewitz */
/* (C) 1998-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -45,7 +45,6 @@
unsigned char AddSource = 0; /* Add source lines as comments */
unsigned char DebugInfo = 0; /* Add debug info to the obj */
unsigned char CreateDep = 0; /* Create a dependency file */
unsigned char PreprocessOnly = 0; /* Just preprocess the input */
unsigned RegisterSpace = 6; /* Space available for register vars */
@ -62,4 +61,9 @@ IntStack CheckStack = INTSTACK(0); /* Generate stack overflow checks */
IntStack Optimize = INTSTACK(0); /* Optimize flag */
IntStack CodeSizeFactor = INTSTACK(100);/* Size factor for generated code */
/* File names */
StrBuf DepName = STATIC_STRBUF_INITIALIZER; /* Name of dependencies file */
StrBuf FullDepName = STATIC_STRBUF_INITIALIZER; /* Name of full dependencies file */

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2009, Ullrich von Bassewitz */
/* (C) 1998-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -40,6 +40,7 @@
/* common */
#include "intstack.h"
#include "strbuf.h"
@ -52,7 +53,6 @@
/* Options */
extern unsigned char AddSource; /* Add source lines as comments */
extern unsigned char DebugInfo; /* Add debug info to the obj */
extern unsigned char CreateDep; /* Create a dependency file */
extern unsigned char PreprocessOnly; /* Just preprocess the input */
extern unsigned RegisterSpace; /* Space available for register vars */
@ -69,6 +69,10 @@ extern IntStack CheckStack; /* Generate stack overflow checks */
extern IntStack Optimize; /* Optimize flag */
extern IntStack CodeSizeFactor; /* Size factor for generated code */
/* File names */
extern StrBuf DepName; /* Name of dependencies file */
extern StrBuf FullDepName; /* Name of full dependencies file */
/* End of global.h */

View File

@ -43,14 +43,17 @@
#include "check.h"
#include "coll.h"
#include "print.h"
#include "strbuf.h"
#include "xmalloc.h"
/* cc65 */
#include "codegen.h"
#include "error.h"
#include "global.h"
#include "incpath.h"
#include "lineinfo.h"
#include "input.h"
#include "lineinfo.h"
#include "output.h"
@ -60,6 +63,15 @@
/* An enum that describes different types of input files. The members are
* choosen so that it is possible to combine them to bitsets
*/
typedef enum {
IT_MAIN = 0x01, /* Main input file */
IT_SYSINC = 0x02, /* System include file (using <>) */
IT_USERINC = 0x04, /* User include file (using "") */
} InputType;
/* The current input line */
StrBuf* Line;
@ -70,6 +82,17 @@ char NextC = '\0';
/* Maximum count of nested includes */
#define MAX_INC_NESTING 16
/* Struct that describes an input file */
typedef struct IFile IFile;
struct IFile {
unsigned Index; /* File index */
unsigned Usage; /* Usage counter */
unsigned long Size; /* File size */
unsigned long MTime; /* Time of last modification */
InputType Type; /* Type of input file */
char Name[1]; /* Name of file (dynamically allocated) */
};
/* Struct that describes an active input file */
typedef struct AFile AFile;
struct AFile {
@ -490,6 +513,14 @@ int NextLine (void)
const char* GetInputFile (const struct IFile* IF)
/* Return a filename from an IFile struct */
{
return IF->Name;
}
const char* GetCurrentFile (void)
/* Return the name of the current input file */
{
@ -526,30 +557,77 @@ unsigned GetCurrentLine (void)
void WriteDependencies (FILE* F, const char* OutputFile)
/* Write a makefile dependency list to the given file */
static void WriteDep (FILE* F, InputType Types)
/* Helper function. Writes all file names that match Types to the output */
{
unsigned I;
/* Get the number of input files */
unsigned IFileCount = CollCount (&IFiles);
/* Print the output file followed by a tab char */
fprintf (F, "%s:\t", OutputFile);
/* Loop over all files */
for (I = 0; I < IFileCount; ++I) {
/* Get the next input file */
const IFile* IF = (const IFile*) CollAt (&IFiles, I);
/* If this is not the first file, add a space */
const char* Format = (I == 0)? "%s" : " %s";
/* Print the dependency */
fprintf (F, Format, IF->Name);
}
unsigned FileCount = CollCount (&IFiles);
for (I = 0; I < FileCount; ++I) {
/* End the line */
fprintf (F, "\n\n");
/* Get the next input file */
const IFile* IF = (const IFile*) CollAt (&IFiles, I);
/* Ignore it if it is not of the correct type */
if ((IF->Type & Types) == 0) {
continue;
}
/* If this is not the first file, add a space */
if (I > 0) {
fputc (' ', F);
}
/* Print the dependency */
fputs (IF->Name, F);
}
}
static void CreateDepFile (const char* Name, InputType Types)
/* Create a dependency file with the given name and place dependencies for
* all files with the given types there.
*/
{
/* Open the file */
FILE* F = fopen (Name, "w");
if (F == 0) {
Fatal ("Cannot open dependency file `%s': %s", Name, strerror (errno));
}
/* Print the output file followed by a tab char */
fprintf (F, "%s:\t", OutputFilename);
/* Write out the dependencies for the output file */
WriteDep (F, Types);
fputs ("\n\n", F);
/* Write out a phony dependency for the included files */
WriteDep (F, Types);
fputs (":\n\n", F);
/* Close the file, check for errors */
if (fclose (F) != 0) {
remove (Name);
Fatal ("Cannot write to dependeny file (disk full?)");
}
}
void CreateDependencies (void)
/* Create dependency files requested by the user */
{
if (SB_NotEmpty (&DepName)) {
CreateDepFile (SB_GetConstBuf (&DepName),
IT_MAIN | IT_USERINC);
}
if (SB_NotEmpty (&FullDepName)) {
CreateDepFile (SB_GetConstBuf (&FullDepName),
IT_MAIN | IT_SYSINC | IT_USERINC);
}
}

View File

@ -51,12 +51,8 @@
/* An enum that describes different types of input files */
typedef enum {
IT_MAIN, /* Main input file */
IT_SYSINC, /* System include file (using <>) */
IT_USERINC, /* User include file (using "") */
} InputType;
/* Forward for an IFile structure */
struct IFile;
/* The current input line */
extern StrBuf* Line;
@ -65,17 +61,6 @@ extern StrBuf* Line;
extern char CurC;
extern char NextC;
/* Struct that describes an input file */
typedef struct IFile IFile;
struct IFile {
unsigned Index; /* File index */
unsigned Usage; /* Usage counter */
unsigned long Size; /* File size */
unsigned long MTime; /* Time of last modification */
InputType Type; /* Type of input file */
char Name[1]; /* Name of file (dynamically allocated) */
};
/*****************************************************************************/
@ -107,14 +92,17 @@ StrBuf* InitLine (StrBuf* Buf);
int NextLine (void);
/* Get a line from the current input. Returns 0 on end of file. */
const char* GetInputFile (const struct IFile* IF);
/* Return a filename from an IFile struct */
const char* GetCurrentFile (void);
/* Return the name of the current input file */
unsigned GetCurrentLine (void);
/* Return the line number in the current input file */
void WriteDependencies (FILE* F, const char* OutputFile);
/* Write a makefile dependency list to the given file */
void CreateDependencies (void);
/* Create dependency files requested by the user */

View File

@ -181,7 +181,7 @@ const char* GetInputName (const LineInfo* LI)
/* Return the file name from a line info */
{
PRECONDITION (LI != 0);
return LI->InputFile->Name;
return GetInputFile (LI->InputFile);
}

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2000-2009, Ullrich von Bassewitz */
/* (C) 2000-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -82,57 +82,58 @@ static void Usage (void)
{
printf ("Usage: %s [options] file\n"
"Short options:\n"
" -Cl\t\t\tMake local variables static\n"
" -Dsym[=defn]\t\tDefine a symbol\n"
" -E\t\t\tStop after the preprocessing stage\n"
" -I dir\t\tSet an include directory search path\n"
" -O\t\t\tOptimize code\n"
" -Oi\t\t\tOptimize code, inline more code\n"
" -Or\t\t\tEnable register variables\n"
" -Os\t\t\tInline some known functions\n"
" -T\t\t\tInclude source as comment\n"
" -V\t\t\tPrint the compiler version number\n"
" -W\t\t\tSuppress warnings\n"
" -d\t\t\tDebug mode\n"
" -g\t\t\tAdd debug info to object file\n"
" -h\t\t\tHelp (this text)\n"
" -j\t\t\tDefault characters are signed\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\tIncrease verbosity\n"
" -Cl\t\t\t\tMake local variables static\n"
" -Dsym[=defn]\t\t\tDefine a symbol\n"
" -E\t\t\t\tStop after the preprocessing stage\n"
" -I dir\t\t\tSet an include directory search path\n"
" -O\t\t\t\tOptimize code\n"
" -Oi\t\t\t\tOptimize code, inline more code\n"
" -Or\t\t\t\tEnable register variables\n"
" -Os\t\t\t\tInline some known functions\n"
" -T\t\t\t\tInclude source as comment\n"
" -V\t\t\t\tPrint the compiler version number\n"
" -W\t\t\t\tSuppress warnings\n"
" -d\t\t\t\tDebug mode\n"
" -g\t\t\t\tAdd debug info to object file\n"
" -h\t\t\t\tHelp (this text)\n"
" -j\t\t\t\tDefault characters are signed\n"
" -mm model\t\t\tSet the memory model\n"
" -o name\t\t\tName the output file\n"
" -r\t\t\t\tEnable register variables\n"
" -t sys\t\t\tSet the target system\n"
" -v\t\t\t\tIncrease verbosity\n"
"\n"
"Long options:\n"
" --add-source\t\tInclude source as comment\n"
" --bss-name seg\tSet the name of the BSS segment\n"
" --check-stack\t\tGenerate stack overflow checks\n"
" --code-name seg\tSet the name of the CODE segment\n"
" --codesize x\t\tAccept larger code by factor x\n"
" --cpu type\t\tSet cpu type (6502, 65c02)\n"
" --create-dep\t\tCreate a make dependency file\n"
" --data-name seg\tSet the name of the DATA segment\n"
" --debug\t\tDebug mode\n"
" --debug-info\t\tAdd debug info to object file\n"
" --debug-opt name\tDebug optimization steps\n"
" --disable-opt name\tDisable an optimization step\n"
" --enable-opt name\tEnable an optimization step\n"
" --forget-inc-paths\tForget include search paths\n"
" --help\t\tHelp (this text)\n"
" --include-dir dir\tSet an include directory search path\n"
" --list-opt-steps\tList all optimizer steps and exit\n"
" --local-strings\tEmit string literals immediately\n"
" --memory-model model\tSet the memory model\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"
" --static-locals\tMake local variables static\n"
" --target sys\t\tSet the target system\n"
" --verbose\t\tIncrease verbosity\n"
" --version\t\tPrint the compiler version number\n"
" --writable-strings\tMake string literals writable\n",
" --add-source\t\t\tInclude source as comment\n"
" --bss-name seg\t\tSet the name of the BSS segment\n"
" --check-stack\t\t\tGenerate stack overflow checks\n"
" --code-name seg\t\tSet the name of the CODE segment\n"
" --codesize x\t\t\tAccept larger code by factor x\n"
" --cpu type\t\t\tSet cpu type (6502, 65c02)\n"
" --create-dep name\t\tCreate a make dependency file\n"
" --create-full-dep name\tCreate a full make dependency file\n"
" --data-name seg\t\tSet the name of the DATA segment\n"
" --debug\t\t\tDebug mode\n"
" --debug-info\t\t\tAdd debug info to object file\n"
" --debug-opt name\t\tDebug optimization steps\n"
" --disable-opt name\t\tDisable an optimization step\n"
" --enable-opt name\t\tEnable an optimization step\n"
" --forget-inc-paths\t\tForget include search paths\n"
" --help\t\t\tHelp (this text)\n"
" --include-dir dir\t\tSet an include directory search path\n"
" --list-opt-steps\t\tList all optimizer steps and exit\n"
" --local-strings\t\tEmit string literals immediately\n"
" --memory-model model\t\tSet the memory model\n"
" --register-space b\t\tSet space available for register variables\n"
" --register-vars\t\tEnable register variables\n"
" --rodata-name seg\t\tSet the name of the RODATA segment\n"
" --signed-chars\t\tDefault characters are signed\n"
" --standard std\t\tLanguage standard (c89, c99, cc65)\n"
" --static-locals\t\tMake local variables static\n"
" --target sys\t\t\tSet the target system\n"
" --verbose\t\t\tIncrease verbosity\n"
" --version\t\t\tPrint the compiler version number\n"
" --writable-strings\t\tMake string literals writable\n",
ProgName);
}
@ -242,29 +243,16 @@ static void SetSys (const char* Sys)
static void DoCreateDep (const char* OutputName)
/* Create the dependency file */
static void FileNameOption (const char* Opt, const char* Arg, StrBuf* Name)
/* Handle an option that remembers a file name for later */
{
/* Make the dependency file name from the output file name */
char* DepName = MakeFilename (OutputName, ".u");
/* Open the file */
FILE* F = fopen (DepName, "w");
if (F == 0) {
Fatal ("Cannot open dependency file `%s': %s", DepName, strerror (errno));
/* Cannot have the option twice */
if (SB_NotEmpty (Name)) {
AbEnd ("Cannot use option `%s' twice", Opt);
}
/* Write the dependencies to the file */
WriteDependencies (F, OutputName);
/* Close the file, check for errors */
if (fclose (F) != 0) {
remove (DepName);
Fatal ("Cannot write to dependeny file (disk full?)");
}
/* Free the name */
xfree (DepName);
/* Remember the file name for later */
SB_CopyStr (Name, Arg);
SB_Terminate (Name);
}
@ -325,7 +313,7 @@ static void CheckSegName (const char* Seg)
static void OptAddSource (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
const char* Arg attribute ((unused)))
/* Add source lines as comments in generated assembler file */
{
AddSource = 1;
@ -382,11 +370,19 @@ static void OptCodeSize (const char* Opt, const char* Arg)
static void OptCreateDep (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
static void OptCreateDep (const char* Opt, const char* Arg)
/* Handle the --create-dep option */
{
CreateDep = 1;
FileNameOption (Opt, Arg, &DepName);
}
static void OptCreateFullDep (const char* Opt attribute ((unused)),
const char* Arg)
/* Handle the --create-full-dep option */
{
FileNameOption (Opt, Arg, &FullDepName);
}
@ -750,7 +746,8 @@ int main (int argc, char* argv[])
{ "--code-name", 1, OptCodeName },
{ "--codesize", 1, OptCodeSize },
{ "--cpu", 1, OptCPU },
{ "--create-dep", 0, OptCreateDep },
{ "--create-dep", 1, OptCreateDep },
{ "--create-full-dep", 1, OptCreateFullDep },
{ "--data-name", 1, OptDataName },
{ "--debug", 0, OptDebug },
{ "--debug-info", 0, OptDebugInfo },
@ -868,7 +865,7 @@ int main (int argc, char* argv[])
case 'I':
OptIncludeDir (Arg, GetArg (&I, 2));
break;
break;
case 'O':
IS_Set (&Optimize, 1);
@ -963,11 +960,7 @@ int main (int argc, char* argv[])
CloseOutputFile ();
/* Create dependencies if requested */
if (CreateDep) {
DoCreateDep (OutputFilename);
Print (stdout, 1, "Creating dependeny file\n");
}
CreateDependencies ();
}
/* Return an apropriate exit code */