History

libtcc: new api tcc_set_lib_path

grischka committed 17 years ago

Commit d165e871 parent 73ba0784 files · +26 −12Browse files

Unified · Split

4 files
  1. Makefile +1 −1
  2. libtcc.h +3 −0
  3. libtcc_test.c +11 −5
  4. tcc.c +11 −6
Makefile+1−1
@@ -305,7 +305,7 @@ libtcc_test$(EXESUF): libtcc_test.c libtcc.a · 304 unmodified lines
305305 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
306306
307307 libtest: libtcc_test
308− ./libtcc_test
308+ ./libtcc_test lib_path=.
309309
310310 # targets for development
311311
libtcc.h+3−0
@@ -92,6 +92,9 @@ int tcc_relocate(TCCState *s1, void *ptr); · 91 unmodified lines
9292 /* return symbol value or NULL if not found */
9393 void *tcc_get_symbol(TCCState *s, const char *name);
9494
95+/* set CONFIG_TCCDIR at runtime */
96+void tcc_set_lib_path(TCCState *s, const char *path);
97+
9598 #ifdef __cplusplus
9699 }
97100 #endif
libtcc_test.c+11−5
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 */
66 #include <stdlib.h>
77 #include <stdio.h>
8+#include <string.h>
89
910 #include "libtcc.h"
1011
@@ -14,7 +15,7 @@ int add(int a, int b) · 3 unmodified lines
1415 return a + b;
1516 }
1617
17−char my_program[] =
18+char my_program[] =
1819 "int fib(int n)\n"
1920 "{\n"
2021 " if (n <= 2)\n"
@@ -37,22 +38,27 @@ int main(int argc, char **argv) · 16 unmodified lines
3738 int (*func)(int);
3839 void *mem;
3940 int size;
40−
41+
4142 s = tcc_new();
4243 if (!s) {
4344 fprintf(stderr, "Could not create tcc state\n");
4445 exit(1);
4546 }
4647
47− /* MUST BE CALLED before any compilation or file loading */
48+ /* if tcclib.h and libtcc1.a are not installed, where can we find them */
49+ if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
50+ tcc_set_lib_path(s, argv[1]+9);
51+
52+ /* MUST BE CALLED before any compilation */
4853 tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
4954
50− tcc_compile_string(s, my_program);
55+ if (tcc_compile_string(s, my_program) == -1)
56+ return 1;
5157
5258 /* as a test, we add a symbol that the compiled program can use.
5359 You may also open a dll with tcc_add_dll() and use symbols from that */
5460 tcc_add_symbol(s, "add", add);
55−
61+
5662 /* get needed size of the code */
5763 size = tcc_relocate(s, NULL);
5864 if (size == -1)
tcc.c+11−6
@@ -1122,7 +1122,7 @@ char *normalize_slashes(char *path) · 1121 unmodified lines
11221122 return path;
11231123 }
11241124
1125−char *w32_tcc_lib_path(void)
1125+void tcc_set_lib_path_w32(TCCState *s)
11261126 {
11271127 /* on win32, we suppose the lib and includes are at the location
11281128 of 'tcc.exe' */
@@ -1134,7 +1134,7 @@ char *w32_tcc_lib_path(void) · 5 unmodified lines
11341134 else if (p > path)
11351135 p--;
11361136 *p = 0;
1137− return strdup(path);
1137+ tcc_set_lib_path(s, path);
11381138 }
11391139 #endif
11401140
@@ -10967,6 +10967,12 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value) · 9826 unmodified lines
1096710967 flag_name, value);
1096810968 }
1096910969
10970+/* set CONFIG_TCCDIR at runtime */
10971+void tcc_set_lib_path(TCCState *s, const char *path)
10972+{
10973+ tcc_lib_path = tcc_strdup(path);
10974+}
10975+
1097010976 #if !defined(LIBTCC)
1097110977
1097210978 static int64_t getclock_us(void)
@@ -11217,7 +11223,7 @@ int parse_args(TCCState *s, int argc, char **argv) · 244 unmodified lines
1121711223 break;
1121811224 case TCC_OPTION_B:
1121911225 /* set tcc utilities path (mainly for tcc development) */
11220− tcc_lib_path = optarg;
11226+ tcc_set_lib_path(s, optarg);
1122111227 break;
1122211228 case TCC_OPTION_l:
1122311229 dynarray_add((void ***)&files, &nb_files, r);
@@ -11350,11 +11356,10 @@ int main(int argc, char **argv) · 126 unmodified lines
1135011356 char objfilename[1024];
1135111357 int64_t start_time = 0;
1135211358
11359+ s = tcc_new();
1135311360 #ifdef _WIN32
11354− tcc_lib_path = w32_tcc_lib_path();
11361+ tcc_set_lib_path_w32(s);
1135511362 #endif
11356−
11357− s = tcc_new();
1135811363 output_type = TCC_OUTPUT_EXE;
1135911364 outfile = NULL;
1136011365 multiple_files = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t