libtcc: new api tcc_set_lib_path

This commit is contained in:
grischka 2009-04-18 13:17:27 +02:00
parent 73ba078d2f
commit d165e87340
4 changed files with 27 additions and 13 deletions

View File

@ -305,7 +305,7 @@ libtcc_test$(EXESUF): libtcc_test.c libtcc.a
$(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS) $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
libtest: libtcc_test libtest: libtcc_test
./libtcc_test ./libtcc_test lib_path=.
# targets for development # targets for development

View File

@ -92,6 +92,9 @@ int tcc_relocate(TCCState *s1, void *ptr);
/* return symbol value or NULL if not found */ /* return symbol value or NULL if not found */
void *tcc_get_symbol(TCCState *s, const char *name); void *tcc_get_symbol(TCCState *s, const char *name);
/* set CONFIG_TCCDIR at runtime */
void tcc_set_lib_path(TCCState *s, const char *path);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -5,6 +5,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "libtcc.h" #include "libtcc.h"
@ -44,10 +45,15 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
/* MUST BE CALLED before any compilation or file loading */ /* if tcclib.h and libtcc1.a are not installed, where can we find them */
if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
tcc_set_lib_path(s, argv[1]+9);
/* MUST BE CALLED before any compilation */
tcc_set_output_type(s, TCC_OUTPUT_MEMORY); tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
tcc_compile_string(s, my_program); if (tcc_compile_string(s, my_program) == -1)
return 1;
/* as a test, we add a symbol that the compiled program can use. /* as a test, we add a symbol that the compiled program can use.
You may also open a dll with tcc_add_dll() and use symbols from that */ You may also open a dll with tcc_add_dll() and use symbols from that */

19
tcc.c
View File

@ -1122,7 +1122,7 @@ char *normalize_slashes(char *path)
return path; return path;
} }
char *w32_tcc_lib_path(void) void tcc_set_lib_path_w32(TCCState *s)
{ {
/* on win32, we suppose the lib and includes are at the location /* on win32, we suppose the lib and includes are at the location
of 'tcc.exe' */ of 'tcc.exe' */
@ -1134,7 +1134,7 @@ char *w32_tcc_lib_path(void)
else if (p > path) else if (p > path)
p--; p--;
*p = 0; *p = 0;
return strdup(path); tcc_set_lib_path(s, path);
} }
#endif #endif
@ -10967,6 +10967,12 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value)
flag_name, value); flag_name, value);
} }
/* set CONFIG_TCCDIR at runtime */
void tcc_set_lib_path(TCCState *s, const char *path)
{
tcc_lib_path = tcc_strdup(path);
}
#if !defined(LIBTCC) #if !defined(LIBTCC)
static int64_t getclock_us(void) static int64_t getclock_us(void)
@ -11217,7 +11223,7 @@ int parse_args(TCCState *s, int argc, char **argv)
break; break;
case TCC_OPTION_B: case TCC_OPTION_B:
/* set tcc utilities path (mainly for tcc development) */ /* set tcc utilities path (mainly for tcc development) */
tcc_lib_path = optarg; tcc_set_lib_path(s, optarg);
break; break;
case TCC_OPTION_l: case TCC_OPTION_l:
dynarray_add((void ***)&files, &nb_files, r); dynarray_add((void ***)&files, &nb_files, r);
@ -11350,11 +11356,10 @@ int main(int argc, char **argv)
char objfilename[1024]; char objfilename[1024];
int64_t start_time = 0; int64_t start_time = 0;
#ifdef _WIN32
tcc_lib_path = w32_tcc_lib_path();
#endif
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;