forked from Mirrors/tinycc
tccpe: set tcc_lib_path from DLL
parent
1df662c1b0
commit
94ae3984b0
35
libtcc.c
35
libtcc.c
|
@ -509,32 +509,6 @@ char *tcc_fileextension (const char *name)
|
||||||
return e ? e : strchr(b, 0);
|
return e ? e : strchr(b, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
char *normalize_slashes(char *path)
|
|
||||||
{
|
|
||||||
char *p;
|
|
||||||
for (p = path; *p; ++p)
|
|
||||||
if (*p == '\\')
|
|
||||||
*p = '/';
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tcc_set_lib_path_w32(TCCState *s)
|
|
||||||
{
|
|
||||||
/* on win32, we suppose the lib and includes are at the location
|
|
||||||
of 'tcc.exe' */
|
|
||||||
char path[1024], *p;
|
|
||||||
GetModuleFileNameA(NULL, path, sizeof path);
|
|
||||||
p = tcc_basename(normalize_slashes(strlwr(path)));
|
|
||||||
if (p - 5 > path && 0 == strncmp(p - 5, "/bin/", 5))
|
|
||||||
p -= 5;
|
|
||||||
else if (p > path)
|
|
||||||
p--;
|
|
||||||
*p = 0;
|
|
||||||
tcc_set_lib_path(s, path);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void set_pages_executable(void *ptr, unsigned long length)
|
void set_pages_executable(void *ptr, unsigned long length)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -1867,9 +1841,12 @@ TCCState *tcc_new(void)
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
return NULL;
|
||||||
tcc_state = s;
|
tcc_state = s;
|
||||||
|
#ifdef _WIN32
|
||||||
|
tcc_set_lib_path_w32(s);
|
||||||
|
#else
|
||||||
|
tcc_set_lib_path(s, CONFIG_TCCDIR);
|
||||||
|
#endif
|
||||||
s->output_type = TCC_OUTPUT_MEMORY;
|
s->output_type = TCC_OUTPUT_MEMORY;
|
||||||
s->tcc_lib_path = CONFIG_TCCDIR;
|
|
||||||
|
|
||||||
preprocess_new();
|
preprocess_new();
|
||||||
|
|
||||||
/* we add dummy defines for some special macros to speed up tests
|
/* we add dummy defines for some special macros to speed up tests
|
||||||
|
@ -1993,6 +1970,7 @@ void tcc_delete(TCCState *s1)
|
||||||
dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
|
dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
|
||||||
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
|
dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
|
||||||
|
|
||||||
|
tcc_free(s1->tcc_lib_path);
|
||||||
tcc_free(s1);
|
tcc_free(s1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2348,6 +2326,7 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value)
|
||||||
/* set CONFIG_TCCDIR at runtime */
|
/* set CONFIG_TCCDIR at runtime */
|
||||||
void tcc_set_lib_path(TCCState *s, const char *path)
|
void tcc_set_lib_path(TCCState *s, const char *path)
|
||||||
{
|
{
|
||||||
|
tcc_free(s->tcc_lib_path);
|
||||||
s->tcc_lib_path = tcc_strdup(path);
|
s->tcc_lib_path = tcc_strdup(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
tcc.c
4
tcc.c
|
@ -427,9 +427,7 @@ int main(int argc, char **argv)
|
||||||
int64_t start_time = 0;
|
int64_t start_time = 0;
|
||||||
|
|
||||||
s = tcc_new();
|
s = tcc_new();
|
||||||
#ifdef _WIN32
|
|
||||||
tcc_set_lib_path_w32(s);
|
|
||||||
#endif
|
|
||||||
output_type = TCC_OUTPUT_EXE;
|
output_type = TCC_OUTPUT_EXE;
|
||||||
outfile = NULL;
|
outfile = NULL;
|
||||||
multiple_files = 1;
|
multiple_files = 1;
|
||||||
|
|
2
tcc.h
2
tcc.h
|
@ -473,7 +473,7 @@ struct TCCState {
|
||||||
/* compile with built-in memory and bounds checker */
|
/* compile with built-in memory and bounds checker */
|
||||||
int do_bounds_check;
|
int do_bounds_check;
|
||||||
/* give the path of the tcc libraries */
|
/* give the path of the tcc libraries */
|
||||||
const char *tcc_lib_path;
|
char *tcc_lib_path;
|
||||||
|
|
||||||
/* error handling */
|
/* error handling */
|
||||||
void *error_opaque;
|
void *error_opaque;
|
||||||
|
|
2
tccpe.c
2
tccpe.c
|
@ -1511,7 +1511,7 @@ PUB_FN int pe_load_file(struct TCCState *s1, const char *filename, int fd)
|
||||||
else if (pe_load_res(s1, fp) == 0)
|
else if (pe_load_res(s1, fp) == 0)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
else if (read_mem(fp, 0, buf, sizeof buf) && 0 == strncmp(buf, "MZ", 2))
|
else if (read_mem(fp, 0, buf, sizeof buf) && 0 == strncmp(buf, "MZ", 2))
|
||||||
ret = pe_load_dll(s1, filename, fp);
|
ret = pe_load_dll(s1, tcc_basename(filename), fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue