- 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.
Unified · Split
| @@ -36,6 +36,21 @@ ifdef CONFIG_WIN32 · 35 unmodified lines | ||
| 36 | 36 | endif |
| 37 | 37 | CFGWIN = -win |
| 38 | 38 | NATIVE_TARGET = $(ARCH)-$(if $(eq $(ARCH),arm),wince,win32) |
| 39 | +else ifdef CONFIG_OSX | |
| 40 | + LIBS=-lm | |
| 41 | + ifndef CONFIG_NOLDL | |
| 42 | + LIBS+=-ldl | |
| 43 | + endif | |
| 44 | + # make libtcc as static or dynamic library? | |
| 45 | + ifeq ($(DISABLE_STATIC),yes) | |
| 46 | + LIBTCC=libtcc.dylib | |
| 47 | + ifndef DISABLE_RPATH | |
| 48 | + LINK_LIBTCC += -Wl,-rpath,"$(libdir)" | |
| 49 | + export LD_LIBRARY_PATH := $(CURDIR)/$(TOP) | |
| 50 | + endif | |
| 51 | + endif | |
| 52 | + CFGWIN =-unx | |
| 53 | + NATIVE_TARGET = $(ARCH)-osx | |
| 39 | 54 | else |
| 40 | 55 | LIBS=-lm |
| 41 | 56 | ifndef CONFIG_NOLDL |
| @@ -72,6 +87,7 @@ CONFIG_$(ARCH) = yes · 30 unmodified lines | ||
| 72 | 87 | NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 |
| 73 | 88 | NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64 |
| 74 | 89 | NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE |
| 90 | +NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO | |
| 75 | 91 | NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC |
| 76 | 92 | NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL |
| 77 | 93 | NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM |
| @@ -92,11 +108,11 @@ TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info · 14 unmodified lines | ||
| 92 | 108 | all: $(PROGS) $(TCCLIBS) $(TCCDOCS) |
| 93 | 109 | |
| 94 | 110 | # cross compiler targets to build |
| 95 | −TCC_X = i386 x86_64 i386-win32 x86_64-win32 arm arm64 arm-wince c67 | |
| 111 | +TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67 | |
| 96 | 112 | # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi |
| 97 | 113 | |
| 98 | 114 | # cross libtcc1.a targets to build |
| 99 | −LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 arm arm64 arm-wince | |
| 115 | +LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince | |
| 100 | 116 | |
| 101 | 117 | PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF)) |
| 102 | 118 | LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a) |
| @@ -123,6 +139,7 @@ DEF-i386 = -DTCC_TARGET_I386 · 20 unmodified lines | ||
| 123 | 139 | DEF-x86_64 = -DTCC_TARGET_X86_64 |
| 124 | 140 | DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386 |
| 125 | 141 | DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64 |
| 142 | +DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64 | |
| 126 | 143 | DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT |
| 127 | 144 | DEF-arm64 = -DTCC_TARGET_ARM64 |
| 128 | 145 | DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs |
| @@ -160,6 +177,7 @@ i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok · 31 unmodified lines | ||
| 160 | 177 | i386-win32_FILES = $(i386_FILES) tccpe.c |
| 161 | 178 | x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h |
| 162 | 179 | x86_64-win32_FILES = $(x86_64_FILES) tccpe.c |
| 180 | +x86_64-osx_FILES = $(x86_64_FILES) | |
| 163 | 181 | arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c |
| 164 | 182 | arm-wince_FILES = $(arm_FILES) tccpe.c |
| 165 | 183 | arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c |
| @@ -37,6 +37,7 @@ cygwin="no" · 36 unmodified lines | ||
| 37 | 37 | gprof="no" |
| 38 | 38 | bigendian="no" |
| 39 | 39 | mingw32="no" |
| 40 | +osx="no" | |
| 40 | 41 | LIBSUF=".a" |
| 41 | 42 | EXESUF="" |
| 42 | 43 | DLLSUF=".so" |
| @@ -52,6 +53,7 @@ cpu= · 9 unmodified lines | ||
| 52 | 53 | # OS specific |
| 53 | 54 | targetos=`uname` |
| 54 | 55 | case $targetos in |
| 56 | + Darwin) osx=yes;; | |
| 55 | 57 | MINGW*) mingw32=yes;; |
| 56 | 58 | MSYS*) mingw32=yes;; |
| 57 | 59 | CYGWIN*) mingw32=yes; cygwin=yes; cross_prefix="mingw32-";; |
| @@ -256,6 +258,9 @@ else · 198 unmodified lines | ||
| 256 | 258 | if test x"$tccdir" = x""; then |
| 257 | 259 | tccdir="${libdir}/tcc" |
| 258 | 260 | fi |
| 261 | + if test "$osx" = "yes" ; then | |
| 262 | + DLLSUF=".dylib" | |
| 263 | + fi | |
| 259 | 264 | fi # mingw32 |
| 260 | 265 | |
| 261 | 266 | if test x"$includedir" = x""; then |
| @@ -486,6 +491,9 @@ fi · 224 unmodified lines | ||
| 486 | 491 | if test "$mingw32" = "yes" ; then |
| 487 | 492 | echo "CONFIG_WIN32=yes" >> config.mak |
| 488 | 493 | fi |
| 494 | +if test "$osx" = "yes" ; then | |
| 495 | + echo "CONFIG_OSX=yes" >> config.mak | |
| 496 | +fi | |
| 489 | 497 | if test "$bigendian" = "yes" ; then |
| 490 | 498 | echo "WORDS_BIGENDIAN=yes" >> config.mak |
| 491 | 499 | echo "#define WORDS_BIGENDIAN 1" >> $TMPH |
| @@ -46,6 +46,9 @@ TGT-i386 = -DTCC_TARGET_I386 · 45 unmodified lines | ||
| 46 | 46 | OBJ-x86_64 = $(X86_64_O) |
| 47 | 47 | TGT-x86_64 = -DTCC_TARGET_X86_64 |
| 48 | 48 | |
| 49 | +OBJ-x86_64-osx = $(X86_64_O) | |
| 50 | +TGT-x86_64-osx = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO | |
| 51 | + | |
| 49 | 52 | OBJ-arm = $(ARM_O) |
| 50 | 53 | TGT-arm = -DTCC_TARGET_ARM |
| 51 | 54 | |
| @@ -1081,7 +1081,19 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 1080 unmodified lines | ||
| 1081 | 1081 | break; |
| 1082 | 1082 | #endif |
| 1083 | 1083 | default: |
| 1084 | −#ifdef TCC_TARGET_PE | |
| 1084 | +#if defined(TCC_TARGET_MACHO) | |
| 1085 | + if (s1->output_type == TCC_OUTPUT_MEMORY) { | |
| 1086 | + ret = 0; | |
| 1087 | +#ifdef TCC_IS_NATIVE | |
| 1088 | + if (NULL == dlopen(filename, RTLD_GLOBAL | RTLD_LAZY)) { | |
| 1089 | + ret = -1; | |
| 1090 | + } | |
| 1091 | +#endif /* TCC_TARGET_MACHO */ | |
| 1092 | + } else { | |
| 1093 | + ret = tcc_load_dll(s1, fd, filename, | |
| 1094 | + (flags & AFF_REFERENCED_DLL) != 0); | |
| 1095 | + } | |
| 1096 | +#elif defined(TCC_TARGET_PE) | |
| 1085 | 1097 | ret = pe_load_file(s1, filename, fd); |
| 1086 | 1098 | #else |
| 1087 | 1099 | /* 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) · 55 unmodified lines | ||
| 1143 | 1155 | /* the library name is the same as the argument of the '-l' option */ |
| 1144 | 1156 | LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) |
| 1145 | 1157 | { |
| 1146 | −#ifdef TCC_TARGET_PE | |
| 1158 | +#if defined(TCC_TARGET_MACHO) | |
| 1159 | + const char *libs[] = { "%s/lib%s.dylib", "%s/lib%s.a", NULL }; | |
| 1160 | + const char **pp = s->static_link ? libs + 1 : libs; | |
| 1161 | +#elif defined(TCC_TARGET_PE) | |
| 1147 | 1162 | const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL }; |
| 1148 | 1163 | const char **pp = s->static_link ? libs + 4 : libs; |
| 1149 | 1164 | #else |