From: Oliver Schmidt
Date: Fri, 3 Jun 2016 09:08:53 +0000 (+0200)
Subject: Added --print-target-path option.
X-Git-Tag: V2.16~118
X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8dd003d2b3e462ca982016d64d17a01dddc8a771;p=cc65
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.
---
diff --git a/doc/cl65.sgml b/doc/cl65.sgml
index 6e044b8d5..6f29fa29d 100644
--- a/doc/cl65.sgml
+++ b/doc/cl65.sgml
@@ -103,6 +103,7 @@ Long options:
--o65-model model Override the o65 model
--obj file Link this object file
--obj-path path Specify an object file search path
+ --print-target-path Print the target file path
--register-space b Set space available for register variables
--register-vars Enable register variables
--rodata-name seg Set the name of the RODATA segment
@@ -154,6 +155,14 @@ There are a few remaining options that control the behaviour of cl65:
shouldn't use -o when more than one output file is created.
+ --print-target-path
+
+ This option prints the absolute path of the target file directory and exits
+ then. It is supposed to be used with shell backquotes or the GNU make shell
+ function This way you can write build scripts or Makefiles accessing target
+ files without any assumption about the cc65 installation path.
+
+
-t sys, --target sys
The default for this option is different from the compiler and linker in the
@@ -162,6 +171,7 @@ There are a few remaining options that control the behaviour of cl65:
the C64 as a target system by default. This was chosen since most people
seem to use cc65 to develop for the C64.
+
-Wa options, --asm-args options
Pass options directly to the assembler. This may be used to pass options
@@ -172,6 +182,7 @@ There are a few remaining options that control the behaviour of cl65:
if cl65 supports an option by itself, do not pass this option to the
assembler by means of the -Wc options, --cc-args options
Pass options directly to the compiler. This may be used to pass options
@@ -182,6 +193,7 @@ There are a few remaining options that control the behaviour of cl65:
if cl65 supports an option by itself, do not pass this option to the
compiler by means of the -Wl options, --ld-args options
Pass options directly to the linker. This may be used to pass options that
@@ -192,7 +204,7 @@ There are a few remaining options that control the behaviour of cl65:
supports an option by itself, do not pass this option to the linker by means
of the
+
@@ -304,4 +316,3 @@ freely, subject to the following restrictions:
-
diff --git a/src/Makefile b/src/Makefile
index f10c189b3..edb6f5aa8 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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
diff --git a/src/cl65/main.c b/src/cl65/main.c
index 4268a569b..654bd97b2 100644
--- a/src/cl65/main.c
+++ b/src/cl65/main.c
@@ -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;
diff --git a/src/common/searchpath.c b/src/common/searchpath.c
index 78443f34c..ca7017e6f 100644
--- a/src/common/searchpath.c
+++ b/src/common/searchpath.c
@@ -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.
diff --git a/src/common/searchpath.h b/src/common/searchpath.h
index 6f5bafa7a..974886a67 100644
--- a/src/common/searchpath.h
+++ b/src/common/searchpath.h
@@ -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.