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
36 endif36 endif
37 CFGWIN = -win37 CFGWIN = -win
38 NATIVE_TARGET = $(ARCH)-$(if $(eq $(ARCH),arm),wince,win32)38 NATIVE_TARGET = $(ARCH)-$(if $(eq $(ARCH),arm),wince,win32)
39else 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
39else54else
40 LIBS=-lm55 LIBS=-lm
41 ifndef CONFIG_NOLDL56 ifndef CONFIG_NOLDL
@@ -72,6 +87,7 @@ CONFIG_$(ARCH) = yes · 30 unmodified lines
72NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I38687NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
73NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_6488NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
74NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE89NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
90NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
75NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC91NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
76NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL92NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
77NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM93NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
@@ -92,11 +108,11 @@ TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info · 14 unmodified lines
92all: $(PROGS) $(TCCLIBS) $(TCCDOCS)108all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
93 109
94# cross compiler targets to build110# cross compiler targets to build
95TCC_X = i386 x86_64 i386-win32 x86_64-win32 arm arm64 arm-wince c67111TCC_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-eabi112# TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
97 113
98# cross libtcc1.a targets to build114# cross libtcc1.a targets to build
99LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 arm arm64 arm-wince115LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
100 116
101PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))117PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
102LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a)118LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a)
@@ -123,6 +139,7 @@ DEF-i386 = -DTCC_TARGET_I386 · 20 unmodified lines
123DEF-x86_64 = -DTCC_TARGET_X86_64139DEF-x86_64 = -DTCC_TARGET_X86_64
124DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386140DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386
125DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64141DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64
142DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64
126DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT143DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
127DEF-arm64 = -DTCC_TARGET_ARM64144DEF-arm64 = -DTCC_TARGET_ARM64
128DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs145DEF-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
160i386-win32_FILES = $(i386_FILES) tccpe.c177i386-win32_FILES = $(i386_FILES) tccpe.c
161x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h178x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
162x86_64-win32_FILES = $(x86_64_FILES) tccpe.c179x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
180x86_64-osx_FILES = $(x86_64_FILES)
163arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c181arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
164arm-wince_FILES = $(arm_FILES) tccpe.c182arm-wince_FILES = $(arm_FILES) tccpe.c
165arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c183arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
configure+8−0
@@ -37,6 +37,7 @@ cygwin="no" · 36 unmodified lines
37gprof="no"37gprof="no"
38bigendian="no"38bigendian="no"
39mingw32="no"39mingw32="no"
40osx="no"
40LIBSUF=".a"41LIBSUF=".a"
41EXESUF=""42EXESUF=""
42DLLSUF=".so"43DLLSUF=".so"
@@ -52,6 +53,7 @@ cpu= · 9 unmodified lines
52# OS specific53# OS specific
53targetos=`uname`54targetos=`uname`
54case $targetos in55case $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""; then258 if test x"$tccdir" = x""; then
257 tccdir="${libdir}/tcc"259 tccdir="${libdir}/tcc"
258 fi260 fi
261 if test "$osx" = "yes" ; then
262 DLLSUF=".dylib"
263 fi
259fi # mingw32264fi # mingw32
260 265
261if test x"$includedir" = x""; then266if test x"$includedir" = x""; then
@@ -486,6 +491,9 @@ fi · 224 unmodified lines
486if test "$mingw32" = "yes" ; then491if test "$mingw32" = "yes" ; then
487 echo "CONFIG_WIN32=yes" >> config.mak492 echo "CONFIG_WIN32=yes" >> config.mak
488fi493fi
494if test "$osx" = "yes" ; then
495 echo "CONFIG_OSX=yes" >> config.mak
496fi
489if test "$bigendian" = "yes" ; then497if test "$bigendian" = "yes" ; then
490 echo "WORDS_BIGENDIAN=yes" >> config.mak498 echo "WORDS_BIGENDIAN=yes" >> config.mak
491 echo "#define WORDS_BIGENDIAN 1" >> $TMPH499 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
lib/Makefile+3−0
@@ -46,6 +46,9 @@ TGT-i386 = -DTCC_TARGET_I386 · 45 unmodified lines
46OBJ-x86_64 = $(X86_64_O)46OBJ-x86_64 = $(X86_64_O)
47TGT-x86_64 = -DTCC_TARGET_X86_6447TGT-x86_64 = -DTCC_TARGET_X86_64
48 48
49OBJ-x86_64-osx = $(X86_64_O)
50TGT-x86_64-osx = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
51
49OBJ-arm = $(ARM_O)52OBJ-arm = $(ARM_O)
50TGT-arm = -DTCC_TARGET_ARM53TGT-arm = -DTCC_TARGET_ARM
51 54
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
1081 break;1081 break;
1082#endif1082#endif
1083 default:1083 default:
1084#ifdef TCC_TARGET_PE1084#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#else1098#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 */
1144LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)1156LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
1145{1157{
1146#ifdef TCC_TARGET_PE1158#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#else1164#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