aboutsummaryrefslogtreecommitdiff
path: root/libtcc.c
diff options
context:
space:
mode:
authorAndrei Warkentin <andrey.warkentin@gmail.com>2017-03-28 01:58:42 -0400
committerAndrei Warkentin <awarkentin@awarkentin-mba.local>2017-04-25 13:55:18 +0300
commit91cd148a05e2c492a02eb77b12a2581b87bc9822 (patch)
tree9180f497ced5f98a481def42655f5e12488c2ef4 /libtcc.c
parent0ac29b53dc038408b08e0f8515ae6edabc145f76 (diff)
downloadtinycc-91cd148a05e2c492a02eb77b12a2581b87bc9822.tar.gz
tinycc-91cd148a05e2c492a02eb77b12a2581b87bc9822.tar.bz2
tcc: early OSX native support
- build scripts - working '-run' mode, e.g.: ./tcc -B. -I./include -I. -I.. -D_ANSI_SOURCE -run examples/ex1.c Note: we don't bother parsing Mach-O/Fat images yet. We blindly dlopen the image. Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Diffstat (limited to 'libtcc.c')
-rw-r--r--libtcc.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/libtcc.c b/libtcc.c
index 99bf783..b4b2615 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1081,7 +1081,19 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
break;
#endif
default:
-#ifdef TCC_TARGET_PE
+#if defined(TCC_TARGET_MACHO)
+ if (s1->output_type == TCC_OUTPUT_MEMORY) {
+ ret = 0;
+#ifdef TCC_IS_NATIVE
+ if (NULL == dlopen(filename, RTLD_GLOBAL | RTLD_LAZY)) {
+ ret = -1;
+ }
+#endif /* TCC_TARGET_MACHO */
+ } else {
+ ret = tcc_load_dll(s1, fd, filename,
+ (flags & AFF_REFERENCED_DLL) != 0);
+ }
+#elif defined(TCC_TARGET_PE)
ret = pe_load_file(s1, filename, fd);
#else
/* as GNU ld, consider it is an ld script if not recognized */
@@ -1143,7 +1155,10 @@ ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
/* the library name is the same as the argument of the '-l' option */
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
{
-#ifdef TCC_TARGET_PE
+#if defined(TCC_TARGET_MACHO)
+ const char *libs[] = { "%s/lib%s.dylib", "%s/lib%s.a", NULL };
+ const char **pp = s->static_link ? libs + 1 : libs;
+#elif defined(TCC_TARGET_PE)
const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
const char **pp = s->static_link ? libs + 4 : libs;
#else