History

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.

Andrei Warkentin committed 9 years ago

Commit 91cd1481 parent 0ac29b54 files · +48 −4Browse files

Unified · Split

4 files
  1. Makefile +20 −2
  2. configure +8 −0
  3. lib/Makefile +3 −0
  4. libtcc.c +17 −2
Makefile+20−2
@@ -36,6 +36,21 @@ ifdef CONFIG_WIN32 · 35 unmodified lines
3636 endif
3737 CFGWIN = -win
3838 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
3954 else
4055 LIBS=-lm
4156 ifndef CONFIG_NOLDL
@@ -72,6 +87,7 @@ CONFIG_$(ARCH) = yes · 30 unmodified lines
7287 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
7388 NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
7489 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
90+NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
7591 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
7692 NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
7793 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
@@ -92,11 +108,11 @@ TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info · 14 unmodified lines
92108 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
93109
94110 # 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
96112 # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
97113
98114 # 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
100116
101117 PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
102118 LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a)
@@ -123,6 +139,7 @@ DEF-i386 = -DTCC_TARGET_I386 · 20 unmodified lines
123139 DEF-x86_64 = -DTCC_TARGET_X86_64
124140 DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386
125141 DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64
142+DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64
126143 DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
127144 DEF-arm64 = -DTCC_TARGET_ARM64
128145 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
160177 i386-win32_FILES = $(i386_FILES) tccpe.c
161178 x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
162179 x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
180+x86_64-osx_FILES = $(x86_64_FILES)
163181 arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
164182 arm-wince_FILES = $(arm_FILES) tccpe.c
165183 arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
configure+8−0
@@ -37,6 +37,7 @@ cygwin="no" · 36 unmodified lines
3737 gprof="no"
3838 bigendian="no"
3939 mingw32="no"
40+osx="no"
4041 LIBSUF=".a"
4142 EXESUF=""
4243 DLLSUF=".so"
@@ -52,6 +53,7 @@ cpu= · 9 unmodified lines
5253 # OS specific
5354 targetos=`uname`
5455 case $targetos in
56+ Darwin) osx=yes;;
5557 MINGW*) mingw32=yes;;
5658 MSYS*) mingw32=yes;;
5759 CYGWIN*) mingw32=yes; cygwin=yes; cross_prefix="mingw32-";;
@@ -256,6 +258,9 @@ else · 198 unmodified lines
256258 if test x"$tccdir" = x""; then
257259 tccdir="${libdir}/tcc"
258260 fi
261+ if test "$osx" = "yes" ; then
262+ DLLSUF=".dylib"
263+ fi
259264 fi # mingw32
260265
261266 if test x"$includedir" = x""; then
@@ -486,6 +491,9 @@ fi · 224 unmodified lines
486491 if test "$mingw32" = "yes" ; then
487492 echo "CONFIG_WIN32=yes" >> config.mak
488493 fi
494+if test "$osx" = "yes" ; then
495+ echo "CONFIG_OSX=yes" >> config.mak
496+fi
489497 if test "$bigendian" = "yes" ; then
490498 echo "WORDS_BIGENDIAN=yes" >> config.mak
491499 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
lib/Makefile+3−0
@@ -46,6 +46,9 @@ TGT-i386 = -DTCC_TARGET_I386 · 45 unmodified lines
4646 OBJ-x86_64 = $(X86_64_O)
4747 TGT-x86_64 = -DTCC_TARGET_X86_64
4848
49+OBJ-x86_64-osx = $(X86_64_O)
50+TGT-x86_64-osx = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
51+
4952 OBJ-arm = $(ARM_O)
5053 TGT-arm = -DTCC_TARGET_ARM
5154
libtcc.c+17−2
@@ -1081,7 +1081,19 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 1080 unmodified lines
10811081 break;
10821082 #endif
10831083 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)
10851097 ret = pe_load_file(s1, filename, fd);
10861098 #else
10871099 /* 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
11431155 /* the library name is the same as the argument of the '-l' option */
11441156 LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
11451157 {
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)
11471162 const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
11481163 const char **pp = s->static_link ? libs + 4 : libs;
11491164 #else

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