Unified · Split
| @@ -99,12 +99,50 @@ BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) · 98 unmodified lines | |||
| 99 | /* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */ | 99 | /* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */ |
| 100 | static inline char *config_tccdir_w32(char *path) | 100 | static inline char *config_tccdir_w32(char *path) |
| 101 | { | 101 | { |
| 102 | char temp[1024]; | ||
| 103 | char try[1024]; | ||
| 102 | char *p; | 104 | char *p; |
| 105 | int c; | ||
| 103 | GetModuleFileName(tcc_module, path, MAX_PATH); | 106 | GetModuleFileName(tcc_module, path, MAX_PATH); |
| 104 | p = tcc_basename(normalize_slashes(strlwr(path))); | 107 | p = tcc_basename(normalize_slashes(strlwr(path))); |
| 105 | if (p > path) | 108 | if (p > path) |
| 106 | --p; | 109 | --p; |
| 110 | |||
| 107 | *p = 0; | 111 | *p = 0; |
| 112 | |||
| 113 | /* | ||
| 114 | * See if we are perhaps in a "bin/" subfolder of the | ||
| 115 | * installation path, in which case the real root of | ||
| 116 | * the installation is one level up. We can test this | ||
| 117 | * by looking for the 'include' folder. | ||
| 118 | */ | ||
| 119 | strncpy(temp, path, sizeof(temp)-1); | ||
| 120 | strcat(temp, "/include"); | ||
| 121 | |||
| 122 | if (_access(temp, 0) != 0) { | ||
| 123 | /* No 'include' folder found, so go up one level. */ | ||
| 124 | strncpy(temp, path, sizeof(temp)-1); | ||
| 125 | |||
| 126 | for (c = 0; c < 4; c++) { | ||
| 127 | p = tcc_basename(temp); | ||
| 128 | if (p > temp) { | ||
| 129 | --p; | ||
| 130 | *p = '\0'; | ||
| 131 | } | ||
| 132 | |||
| 133 | strncpy(try, temp, sizeof(try)-1); | ||
| 134 | strcat(try, "/include"); | ||
| 135 | |||
| 136 | if (_access(try, 0) == 0) { | ||
| 137 | if (p != NULL) | ||
| 138 | p = '\0'; | ||
| 139 | path = tcc_malloc(strlen(temp)+1); | ||
| 140 | strcpy(path, temp); | ||
| 141 | break; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 108 | return path; | 146 | return path; |
| 109 | } | 147 | } |
| 110 | #define CONFIG_TCCDIR config_tccdir_w32(alloca(MAX_PATH)) | 148 | #define CONFIG_TCCDIR config_tccdir_w32(alloca(MAX_PATH)) |