Skip to content

Commit

Permalink
Small patch to allow for the TCC.EXE (and TCCLIB.DLL) to reside in a …
Browse files Browse the repository at this point in the history
…(directory under) a "bin/" directory at the same level where the "include/" and "lib/" directories are. This allows one to set the PATH to the (proper) binaries directory and TCC will then "find" itself there. Tested under Windows 7, Windows 8.1 (ARM) and Windows 10+11, but should also be workable for Linux and macOS.
  • Loading branch information
waltje committed May 27, 2023
1 parent a46372e commit da3a763
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions libtcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,50 @@ BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved)
/* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */
static inline char *config_tccdir_w32(char *path)
{
char temp[1024];
char try[1024];
char *p;
int c;
GetModuleFileName(tcc_module, path, MAX_PATH);
p = tcc_basename(normalize_slashes(strlwr(path)));
if (p > path)
--p;

*p = 0;

/*
* See if we are perhaps in a "bin/" subfolder of the
* installation path, in which case the real root of
* the installation is one level up. We can test this
* by looking for the 'include' folder.
*/
strncpy(temp, path, sizeof(temp)-1);
strcat(temp, "/include");

if (_access(temp, 0) != 0) {
/* No 'include' folder found, so go up one level. */
strncpy(temp, path, sizeof(temp)-1);

for (c = 0; c < 4; c++) {
p = tcc_basename(temp);
if (p > temp) {
--p;
*p = '\0';
}

strncpy(try, temp, sizeof(try)-1);
strcat(try, "/include");

if (_access(try, 0) == 0) {
if (p != NULL)
p = '\0';
path = tcc_malloc(strlen(temp)+1);
strcpy(path, temp);
break;
}
}
}

return path;
}
#define CONFIG_TCCDIR config_tccdir_w32(alloca(MAX_PATH))
Expand Down

0 comments on commit da3a763

Please sign in to comment.