Added --print-target-path option.

If cc65 is installed and used as designed there's no need whatsoever for CC65_HOME (both on *IX and Windows) from the perspective of the cc65 binaries. If the user however has to access files from the 'target' directory thenhe ends up with some assumption on the cc65 installation path nevertheless :-(

In order to avoid this I added the --print-target-path option. It "exports" the logic used by the cc65 binaries to locate their files to the user thus allowing him to leverage the same logic to locate the target files in his build scripts / Makefiles.
This commit is contained in:
Oliver Schmidt
2016-06-03 11:08:53 +02:00
parent 9f01392922
commit 8dd003d2b3
5 changed files with 103 additions and 53 deletions

View File

@@ -24,6 +24,7 @@ datadir := $(if $(prefix),$(prefix)/share/cc65,$(abspath ..))
CA65_INC = $(datadir)/asminc
CC65_INC = $(datadir)/include
CL65_TGT = $(datadir)/target
LD65_LIB = $(datadir)/lib
LD65_OBJ = $(datadir)/lib
LD65_CFG = $(datadir)/cfg
@@ -63,8 +64,9 @@ endif
CFLAGS += -MMD -MP -O -I common \
-Wall -Wextra -Wno-char-subscripts $(USER_CFLAGS) \
-DGIT_SHA=$(GIT_SHA) -DCA65_INC=$(CA65_INC) -DCC65_INC=$(CC65_INC) \
-DCA65_INC=$(CA65_INC) -DCC65_INC=$(CC65_INC) -DCL65_TGT=$(CL65_TGT) \
-DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG)
-DGIT_SHA=$(GIT_SHA)
LDLIBS += -lm

View File

@@ -73,6 +73,7 @@
#include "filetype.h"
#include "fname.h"
#include "mmodel.h"
#include "searchpath.h"
#include "strbuf.h"
#include "target.h"
#include "version.h"
@@ -759,6 +760,7 @@ static void Usage (void)
" --o65-model model\t\tOverride the o65 model\n"
" --obj file\t\t\tLink this object file\n"
" --obj-path path\t\tSpecify an object file search path\n"
" --print-target-path\t\tPrint the target file path\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"
@@ -1126,6 +1128,23 @@ static void OptObjPath (const char* Opt attribute ((unused)), const char* Arg)
static void OptPrintTargetPath (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Print the target file path */
{
SearchPaths* TargetPath = NewSearchPath ();
AddSubSearchPathFromEnv (TargetPath, "CC65_HOME", "target");
#if defined(CL65_TGT) && !defined(_WIN32)
AddSearchPath (TargetPath, STRINGIZE (CL65_TGT));
#endif
AddSubSearchPathFromWinBin (TargetPath, "target");
printf ("%s\n", GetSearchPath (TargetPath, 0));
exit (EXIT_SUCCESS);
}
static void OptRegisterSpace (const char* Opt attribute ((unused)), const char* Arg)
/* Handle the --register-space option */
{
@@ -1240,56 +1259,57 @@ int main (int argc, char* argv [])
{
/* Program long options */
static const LongOpt OptTab[] = {
{ "--add-source", 0, OptAddSource },
{ "--asm-args", 1, OptAsmArgs },
{ "--asm-define", 1, OptAsmDefine },
{ "--asm-include-dir", 1, OptAsmIncludeDir },
{ "--bin-include-dir", 1, OptBinIncludeDir },
{ "--bss-label", 1, OptBssLabel },
{ "--bss-name", 1, OptBssName },
{ "--cc-args", 1, OptCCArgs },
{ "--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", 1, OptCreateDep },
{ "--create-full-dep", 1, OptCreateFullDep },
{ "--data-label", 1, OptDataLabel },
{ "--data-name", 1, OptDataName },
{ "--debug", 0, OptDebug },
{ "--debug-info", 0, OptDebugInfo },
{ "--feature", 1, OptFeature },
{ "--force-import", 1, OptForceImport },
{ "--help", 0, OptHelp },
{ "--include-dir", 1, OptIncludeDir },
{ "--ld-args", 1, OptLdArgs },
{ "--lib", 1, OptLib },
{ "--lib-path", 1, OptLibPath },
{ "--list-targets", 0, OptListTargets },
{ "--listing", 1, OptListing },
{ "--list-bytes", 1, OptListBytes },
{ "--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 },
{ "--signed-chars", 0, OptSignedChars },
{ "--standard", 1, OptStandard },
{ "--start-addr", 1, OptStartAddr },
{ "--static-locals", 0, OptStaticLocals },
{ "--target", 1, OptTarget },
{ "--verbose", 0, OptVerbose },
{ "--version", 0, OptVersion },
{ "--zeropage-label", 1, OptZeropageLabel },
{ "--zeropage-name", 1, OptZeropageName },
{ "--add-source", 0, OptAddSource },
{ "--asm-args", 1, OptAsmArgs },
{ "--asm-define", 1, OptAsmDefine },
{ "--asm-include-dir", 1, OptAsmIncludeDir },
{ "--bin-include-dir", 1, OptBinIncludeDir },
{ "--bss-label", 1, OptBssLabel },
{ "--bss-name", 1, OptBssName },
{ "--cc-args", 1, OptCCArgs },
{ "--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", 1, OptCreateDep },
{ "--create-full-dep", 1, OptCreateFullDep },
{ "--data-label", 1, OptDataLabel },
{ "--data-name", 1, OptDataName },
{ "--debug", 0, OptDebug },
{ "--debug-info", 0, OptDebugInfo },
{ "--feature", 1, OptFeature },
{ "--force-import", 1, OptForceImport },
{ "--help", 0, OptHelp },
{ "--include-dir", 1, OptIncludeDir },
{ "--ld-args", 1, OptLdArgs },
{ "--lib", 1, OptLib },
{ "--lib-path", 1, OptLibPath },
{ "--list-targets", 0, OptListTargets },
{ "--listing", 1, OptListing },
{ "--list-bytes", 1, OptListBytes },
{ "--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 },
{ "--print-target-path", 0, OptPrintTargetPath},
{ "--register-space", 1, OptRegisterSpace },
{ "--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 },
{ "--verbose", 0, OptVerbose },
{ "--version", 0, OptVersion },
{ "--zeropage-label", 1, OptZeropageLabel },
{ "--zeropage-name", 1, OptZeropageName },
};
char* CmdPath;

View File

@@ -238,6 +238,18 @@ void PopSearchPath (SearchPaths* P)
char* GetSearchPath (SearchPaths* P, unsigned Index)
/* Return the search path at the given index, if the index is valid, return an
** empty string otherwise.
*/
{
if (Index < CollCount (P))
return CollAtUnchecked (P, Index);
return "";
}
char* SearchFile (const SearchPaths* P, const char* File)
/* Search for a file in a list of directories. Return a pointer to a malloced
** area that contains the complete path, if found, return 0 otherwise.

View File

@@ -94,6 +94,11 @@ int PushSearchPath (SearchPaths* P, const char* NewPath);
void PopSearchPath (SearchPaths* P);
/* Remove a search path from the head of an existing search path list */
char* GetSearchPath (SearchPaths* P, unsigned Index);
/* Return the search path at the given index, if the index is valid, return an
** empty string otherwise.
*/
char* SearchFile (const SearchPaths* P, const char* File);
/* Search for a file in a list of directories. Return a pointer to a malloced
** area that contains the complete path, if found, return 0 otherwise.