- 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 | endif | 36 | endif |
| 37 | CFGWIN = -win | 37 | CFGWIN = -win |
| 38 | NATIVE_TARGET = $(ARCH)-$(if $(eq $(ARCH),arm),wince,win32) | 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 | else | 54 | else |
| 40 | LIBS=-lm | 55 | LIBS=-lm |
| 41 | ifndef CONFIG_NOLDL | 56 | ifndef CONFIG_NOLDL |
| @@ -72,6 +87,7 @@ CONFIG_$(ARCH) = yes · 30 unmodified lines | |||
| 72 | NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 | 87 | NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 |
| 73 | NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64 | 88 | NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64 |
| 74 | NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE | 89 | NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE |
| 90 | NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO | ||
| 75 | NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC | 91 | NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC |
| 76 | NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL | 92 | NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL |
| 77 | NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM | 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 | all: $(PROGS) $(TCCLIBS) $(TCCDOCS) | 108 | all: $(PROGS) $(TCCLIBS) $(TCCDOCS) |
| 93 | 109 | ||
| 94 | # cross compiler targets to build | 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 | # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi | 112 | # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi |
| 97 | 113 | ||
| 98 | # cross libtcc1.a targets to build | 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 | PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF)) | 117 | PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF)) |
| 102 | LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a) | 118 | LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a) |
| @@ -123,6 +139,7 @@ DEF-i386 = -DTCC_TARGET_I386 · 20 unmodified lines | |||
| 123 | DEF-x86_64 = -DTCC_TARGET_X86_64 | 139 | DEF-x86_64 = -DTCC_TARGET_X86_64 |
| 124 | DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386 | 140 | DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386 |
| 125 | DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64 | 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 | DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT | 143 | DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT |
| 127 | DEF-arm64 = -DTCC_TARGET_ARM64 | 144 | DEF-arm64 = -DTCC_TARGET_ARM64 |
| 128 | DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs | 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 | i386-win32_FILES = $(i386_FILES) tccpe.c | 177 | i386-win32_FILES = $(i386_FILES) tccpe.c |
| 161 | x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h | 178 | x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h |
| 162 | x86_64-win32_FILES = $(x86_64_FILES) tccpe.c | 179 | x86_64-win32_FILES = $(x86_64_FILES) tccpe.c |
| 180 | x86_64-osx_FILES = $(x86_64_FILES) | ||
| 163 | arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c | 181 | arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c |
| 164 | arm-wince_FILES = $(arm_FILES) tccpe.c | 182 | arm-wince_FILES = $(arm_FILES) tccpe.c |
| 165 | arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c | 183 | arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c |
| @@ -37,6 +37,7 @@ cygwin="no" · 36 unmodified lines | |||
| 37 | gprof="no" | 37 | gprof="no" |
| 38 | bigendian="no" | 38 | bigendian="no" |
| 39 | mingw32="no" | 39 | mingw32="no" |
| 40 | osx="no" | ||
| 40 | LIBSUF=".a" | 41 | LIBSUF=".a" |
| 41 | EXESUF="" | 42 | EXESUF="" |
| 42 | DLLSUF=".so" | 43 | DLLSUF=".so" |
| @@ -52,6 +53,7 @@ cpu= · 9 unmodified lines | |||
| 52 | # OS specific | 53 | # OS specific |
| 53 | targetos=`uname` | 54 | targetos=`uname` |
| 54 | case $targetos in | 55 | case $targetos in |
| 56 | Darwin) osx=yes;; | ||
| 55 | MINGW*) mingw32=yes;; | 57 | MINGW*) mingw32=yes;; |
| 56 | MSYS*) mingw32=yes;; | 58 | MSYS*) mingw32=yes;; |
| 57 | CYGWIN*) mingw32=yes; cygwin=yes; cross_prefix="mingw32-";; | 59 | CYGWIN*) mingw32=yes; cygwin=yes; cross_prefix="mingw32-";; |
| @@ -256,6 +258,9 @@ else · 198 unmodified lines | |||
| 256 | if test x"$tccdir" = x""; then | 258 | if test x"$tccdir" = x""; then |
| 257 | tccdir="${libdir}/tcc" | 259 | tccdir="${libdir}/tcc" |
| 258 | fi | 260 | fi |
| 261 | if test "$osx" = "yes" ; then | ||
| 262 | DLLSUF=".dylib" | ||
| 263 | fi | ||
| 259 | fi # mingw32 | 264 | fi # mingw32 |
| 260 | 265 | ||
| 261 | if test x"$includedir" = x""; then | 266 | if test x"$includedir" = x""; then |
| @@ -486,6 +491,9 @@ fi · 224 unmodified lines | |||
| 486 | if test "$mingw32" = "yes" ; then | 491 | if test "$mingw32" = "yes" ; then |
| 487 | echo "CONFIG_WIN32=yes" >> config.mak | 492 | echo "CONFIG_WIN32=yes" >> config.mak |
| 488 | fi | 493 | fi |
| 494 | if test "$osx" = "yes" ; then | ||
| 495 | echo "CONFIG_OSX=yes" >> config.mak | ||
| 496 | fi | ||
| 489 | if test "$bigendian" = "yes" ; then | 497 | if test "$bigendian" = "yes" ; then |
| 490 | echo "WORDS_BIGENDIAN=yes" >> config.mak | 498 | echo "WORDS_BIGENDIAN=yes" >> config.mak |
| 491 | echo "#define WORDS_BIGENDIAN 1" >> $TMPH | 499 | echo "#define WORDS_BIGENDIAN 1" >> $TMPH |
| @@ -46,6 +46,9 @@ TGT-i386 = -DTCC_TARGET_I386 · 45 unmodified lines | |||
| 46 | OBJ-x86_64 = $(X86_64_O) | 46 | OBJ-x86_64 = $(X86_64_O) |
| 47 | TGT-x86_64 = -DTCC_TARGET_X86_64 | 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 | OBJ-arm = $(ARM_O) | 52 | OBJ-arm = $(ARM_O) |
| 50 | TGT-arm = -DTCC_TARGET_ARM | 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 | break; | 1081 | break; |
| 1082 | #endif | 1082 | #endif |
| 1083 | default: | 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 | ret = pe_load_file(s1, filename, fd); | 1097 | ret = pe_load_file(s1, filename, fd); |
| 1086 | #else | 1098 | #else |
| 1087 | /* as GNU ld, consider it is an ld script if not recognized */ | 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 | /* the library name is the same as the argument of the '-l' option */ | 1155 | /* the library name is the same as the argument of the '-l' option */ |
| 1144 | LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) | 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 | const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL }; | 1162 | const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL }; |
| 1148 | const char **pp = s->static_link ? libs + 4 : libs; | 1163 | const char **pp = s->static_link ? libs + 4 : libs; |
| 1149 | #else | 1164 | #else |