mirror of
https://github.com/cc65/cc65.git
synced 2024-12-25 02:29:52 +00:00
Added search path relative to running binary on Windows.
In contrast to *IX it doesn't make much sense to add compile time defined search paths to Windows binaries: There's no standard path like /usr/local/bin (and there are no symbolic links to link from there to another location). On the other hand it's (again in contrast to *IX) easy for Windows binaries to determine their own paths. Therefore it's appropriate to make use of that to add run time defined default search paths.
This commit is contained in:
parent
983c6285e1
commit
55667b94fb
@ -87,6 +87,9 @@ void FinishIncludePaths (void)
|
||||
#ifdef CA65_INC
|
||||
AddSearchPath (IncSearchPath, STRINGIZE (CA65_INC));
|
||||
#endif
|
||||
|
||||
/* Add paths relative to the parent directory of the Windows binary. */
|
||||
AddSubSearchPathFromWinBin (IncSearchPath, "asminc");
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,6 +88,9 @@ void FinishIncludePaths (void)
|
||||
#ifdef CC65_INC
|
||||
AddSearchPath (SysIncSearchPath, STRINGIZE (CC65_INC));
|
||||
#endif
|
||||
|
||||
/* Add paths relative to the parent directory of the Windows binary. */
|
||||
AddSubSearchPathFromWinBin (SysIncSearchPath, "include");
|
||||
}
|
||||
|
||||
|
||||
|
@ -157,6 +157,48 @@ void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* Sub
|
||||
|
||||
|
||||
|
||||
void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir)
|
||||
{
|
||||
/* Windows only:
|
||||
* Add a search path from the running binary, adding a subdirectory to
|
||||
* the parent directory of the directory containing the binary.
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
char Dir[_MAX_PATH];
|
||||
char* Ptr;
|
||||
|
||||
if (_get_pgmptr (&Ptr) != 0) {
|
||||
return;
|
||||
}
|
||||
strcpy (Dir, Ptr);
|
||||
|
||||
/* Remove binary name */
|
||||
Ptr = strrchr (Dir, '\\');
|
||||
if (Ptr == 0) {
|
||||
return;
|
||||
}
|
||||
*Ptr = '\0';
|
||||
|
||||
/* Check for 'bin' directory */
|
||||
Ptr = strrchr (Dir, '\\');
|
||||
if (Ptr == 0) {
|
||||
return;
|
||||
}
|
||||
if (strcmp (Ptr++, "\\bin") != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Append SubDir */
|
||||
strcpy (Ptr, SubDir);
|
||||
|
||||
/* Add the search path */
|
||||
AddSearchPath (P, Dir);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int PushSearchPath (SearchPath* P, const char* NewPath)
|
||||
/* Add a new search path to the head of an existing search path list, provided
|
||||
* that it's not already there. If the path is already at the first position,
|
||||
|
@ -79,6 +79,12 @@ void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* Sub
|
||||
* the environment variable value.
|
||||
*/
|
||||
|
||||
void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir);
|
||||
/* Windows only:
|
||||
* Add a search path from the running binary, adding a subdirectory to
|
||||
* the parent directory of the directory containing the binary.
|
||||
*/
|
||||
|
||||
int PushSearchPath (SearchPath* P, const char* NewPath);
|
||||
/* Add a new search path to the head of an existing search path list, provided
|
||||
* that it's not already there. If the path is already at the first position,
|
||||
|
@ -84,7 +84,7 @@ void InitSearchPaths (void)
|
||||
|
||||
/* Add paths relative to a main directory defined in an env. var. */
|
||||
AddSubSearchPathFromEnv (LibDefaultPath, "CC65_HOME", "lib");
|
||||
AddSubSearchPathFromEnv (ObjDefaultPath, "CC65_HOME", "obj");
|
||||
AddSubSearchPathFromEnv (ObjDefaultPath, "CC65_HOME", "lib");
|
||||
AddSubSearchPathFromEnv (CfgDefaultPath, "CC65_HOME", "cfg");
|
||||
|
||||
/* Add some compiled-in search paths if defined at compile time. */
|
||||
@ -97,6 +97,11 @@ void InitSearchPaths (void)
|
||||
#if defined(LD65_CFG)
|
||||
AddSearchPath (CfgDefaultPath, STRINGIZE (LD65_CFG));
|
||||
#endif
|
||||
|
||||
/* Add paths relative to the parent directory of the Windows binary. */
|
||||
AddSubSearchPathFromWinBin (LibDefaultPath, "lib");
|
||||
AddSubSearchPathFromWinBin (ObjDefaultPath, "lib");
|
||||
AddSubSearchPathFromWinBin (CfgDefaultPath, "cfg");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user