final adjustments for release

- configure/Makefiles: minor adjustments

- build-tcc.bat: add -static to gcc options
  (avoids libgcc_s*.dll dependency with some mingw versions)

- tccpe.c/tcctools.c: eliminate MAX_PATH
  (not available for cross compilers)

- tccasm.c: use uint64_t/strtoull in unary()
  (unsigned long sometimes is only uint32_t, as always on windows)

- tccgen.c: Revert (f077d16c) "tccgen: gen_cast: cast FLOAT to DOUBLE"
  Was a rather experimental, tentative commit, not really necessary
  and somewhat ugly too.

- cleanup recent osx support:
  - Makefile/libtcc.c: cleanup copy&paste code
  - tccpp.c: restore deleted function
This commit is contained in:
grischka 2017-04-25 21:01:54 +02:00
parent fb4f57666c
commit 7acf9aa862
13 changed files with 158 additions and 159 deletions

114
Makefile
View File

@ -4,8 +4,8 @@
# #
ifndef TOP ifndef TOP
TOP = . TOP = .
INCLUDED = no INCLUDED = no
endif endif
include $(TOP)/config.mak include $(TOP)/config.mak
@ -31,26 +31,11 @@ VPATH = $(TOPSRC)
ifdef CONFIG_WIN32 ifdef CONFIG_WIN32
ifneq ($(DISABLE_STATIC),no) ifneq ($(DISABLE_STATIC),no)
LIBTCC = libtcc.dll LIBTCC = libtcc$(DLLSUF)
LIBTCCDEF = libtcc.def LIBTCCDEF = libtcc.def
endif endif
CFGWIN = -win CFGWIN = -win
NATIVE_TARGET = $(ARCH)-$(if $(eq $(ARCH),arm),wince,win32) NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32)
else ifdef CONFIG_OSX
LIBS=-lm
ifndef CONFIG_NOLDL
LIBS+=-ldl
endif
# make libtcc as static or dynamic library?
ifeq ($(DISABLE_STATIC),yes)
LIBTCC=libtcc.dylib
ifndef DISABLE_RPATH
LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
endif
endif
CFGWIN =-unx
NATIVE_TARGET = $(ARCH)-osx
else else
LIBS=-lm LIBS=-lm
ifndef CONFIG_NOLDL ifndef CONFIG_NOLDL
@ -58,19 +43,19 @@ else
endif endif
# make libtcc as static or dynamic library? # make libtcc as static or dynamic library?
ifeq ($(DISABLE_STATIC),yes) ifeq ($(DISABLE_STATIC),yes)
LIBTCC=libtcc.so LIBTCC=libtcc$(DLLSUF)
export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
ifndef DISABLE_RPATH ifndef DISABLE_RPATH
LINK_LIBTCC += -Wl,-rpath,"$(libdir)" LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
endif endif
endif endif
CFGWIN =-unx CFGWIN =-unx
NATIVE_TARGET = $(ARCH) NATIVE_TARGET = $(ARCH)
endif ifdef CONFIG_OSX
NATIVE_TARGET = $(ARCH)-osx
ifeq ($(TARGETOS),Darwin) LDFLAGS += -flat_namespace -undefined warning
LDFLAGS += -flat_namespace -undefined warning export MACOSX_DEPLOYMENT_TARGET := 10.2
export MACOSX_DEPLOYMENT_TARGET:=10.2 endif
endif endif
# run local version of tcc with local libraries and includes # run local version of tcc with local libraries and includes
@ -78,16 +63,19 @@ TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP) TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
TCCFLAGS = $(TCCFLAGS$(CFGWIN)) TCCFLAGS = $(TCCFLAGS$(CFGWIN))
TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS) TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
ifdef CONFIG_OSX
TCCFLAGS += -D_ANSI_SOURCE
endif
CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
LIBS_P= $(LIBS) LIBS_P = $(LIBS)
LDFLAGS_P = $(LDFLAGS) LDFLAGS_P = $(LDFLAGS)
CONFIG_$(ARCH) = yes CONFIG_$(ARCH) = yes
NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64 NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO
NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
@ -117,12 +105,8 @@ LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF)) PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a) LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a)
ifdef CONFIG_CROSS
all : $(LIBTCC1_CROSS) $(PROGS_CROSS)
endif
# build cross compilers & libs # build cross compilers & libs
cross: all $(LIBTCC1_CROSS) $(PROGS_CROSS) cross: $(LIBTCC1_CROSS) $(PROGS_CROSS)
# build specific cross compiler & lib # build specific cross compiler & lib
cross-%: %-tcc$(EXESUF) libtcc1-%.a ; cross-%: %-tcc$(EXESUF) libtcc1-%.a ;
@ -130,6 +114,10 @@ cross-%: %-tcc$(EXESUF) libtcc1-%.a ;
install: install$(CFGWIN) install: install$(CFGWIN)
uninstall: uninstall$(CFGWIN) uninstall: uninstall$(CFGWIN)
ifdef CONFIG_CROSS
all : cross
endif
# -------------------------------------------- # --------------------------------------------
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
@ -206,7 +194,7 @@ $(X)tcc.o : tcctools.c
$(X)arm-gen.o : arm-asm.c $(X)arm-gen.o : arm-asm.c
# Host Tiny C Compiler # Host Tiny C Compiler
tcc$(EXESUF): $(X)tcc.o $(LIBTCC) tcc$(EXESUF): tcc.o $(LIBTCC)
$(CC) -o $@ $^ $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS) $(LINK_LIBTCC) $(CC) -o $@ $^ $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
# Cross Tiny C Compilers # Cross Tiny C Compilers
@ -218,7 +206,7 @@ $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
# profiling version # profiling version
tcc_p$(EXESUF): $($T_FILES) tcc_p$(EXESUF): $($T_FILES)
$(CC) -o $@ $< -$(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P) $(CC) -o $@ $< $(DEFINES) -DONE_SOURCE $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
# static libtcc library # static libtcc library
libtcc.a: $(LIBTCC_OBJ) libtcc.a: $(LIBTCC_OBJ)
@ -226,13 +214,13 @@ libtcc.a: $(LIBTCC_OBJ)
# dynamic libtcc library # dynamic libtcc library
libtcc.so: $(LIBTCC_OBJ) libtcc.so: $(LIBTCC_OBJ)
$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS) $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(CFLAGS) $(LDFLAGS)
libtcc.so: CFLAGS+=-fPIC libtcc.so: CFLAGS+=-fPIC
# windows dynamic libtcc library # windows dynamic libtcc library
libtcc.dll : $(LIBTCC_OBJ) libtcc.dll : $(LIBTCC_OBJ)
$(CC) -shared $(LIBTCC_OBJ) -o $@ $(LDFLAGS) $(CC) -shared -o $@ $^ $(CFLAGS) $(LDFLAGS)
libtcc.def : libtcc.dll tcc$(EXESUF) libtcc.def : libtcc.dll tcc$(EXESUF)
./tcc$(EXESUF) -impdef $< -o $@ ./tcc$(EXESUF) -impdef $< -o $@
@ -241,11 +229,11 @@ libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
# TinyCC runtime libraries # TinyCC runtime libraries
libtcc1.a : tcc$(EXESUF) FORCE libtcc1.a : tcc$(EXESUF) FORCE
@$(MAKE) -f lib/Makefile BIN=$@ $@ TOP=. --no-print-directory @$(MAKE) -C lib
# Cross libtcc1.a # Cross libtcc1.a
libtcc1-%.a : %-tcc$(EXESUF) FORCE libtcc1-%.a : %-tcc$(EXESUF) FORCE
@$(MAKE) -f lib/Makefile BIN=$@ $@ CROSS_TARGET=$* TOP=. --no-print-directory @$(MAKE) -C lib CROSS_TARGET=$*
FORCE: FORCE:
@ -290,19 +278,21 @@ install-unx:
$(call TRY-INSTALL,tcc.1,"$(mandir)/man1") $(call TRY-INSTALL,tcc.1,"$(mandir)/man1")
$(call TRY-INSTALL,tcc-doc.info,"$(infodir)") $(call TRY-INSTALL,tcc-doc.info,"$(infodir)")
$(call TRY-INSTALL,tcc-doc.html,"$(docdir)") $(call TRY-INSTALL,tcc-doc.html,"$(docdir)")
mkdir -p "$(tccdir)/win32/include" ifneq "$(LIBTCC1_W)" ""
cp -r $(TOPSRC)/include/. "$(tccdir)/win32/include"
cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
mkdir -p "$(tccdir)/win32/lib" mkdir -p "$(tccdir)/win32/lib"
$(INSTALL) $(TOPSRC)/win32/lib/*.def $(LIBTCC1_W) "$(tccdir)/win32/lib" $(INSTALL) $(TOPSRC)/win32/lib/*.def $(LIBTCC1_W) "$(tccdir)/win32/lib"
mkdir -p "$(tccdir)/win32/include"
cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
$(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/win32/include"
endif
# uninstall # uninstall
uninstall-unx: uninstall-unx:
rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P") @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P")
rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h" @rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info" @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
rm -fv "$(docdir)/tcc-doc.html" @rm -fv "$(docdir)/tcc-doc.html"
rm -rv "$(tccdir)" rm -r "$(tccdir)"
# install progs & libs on windows # install progs & libs on windows
install-win: install-win:
@ -310,12 +300,10 @@ install-win:
$(INSTALL) $(PROGS) $(subst libtcc.a,,$(LIBTCC)) $(PROGS_X) "$(tccdir)" $(INSTALL) $(PROGS) $(subst libtcc.a,,$(LIBTCC)) $(PROGS_X) "$(tccdir)"
mkdir -p "$(tccdir)/lib" mkdir -p "$(tccdir)/lib"
$(INSTALL) $(TOPSRC)/win32/lib/*.def "$(tccdir)/lib" $(INSTALL) $(TOPSRC)/win32/lib/*.def "$(tccdir)/lib"
$(INSTALL) libtcc1.a $(LIBTCC1_W) $(LIBTCC1_U) "$(tccdir)/lib" $(INSTALL) libtcc1.a $(LIBTCC1_W) "$(tccdir)/lib"
mkdir -p "$(tccdir)/include" mkdir -p "$(tccdir)/include"
cp -r $(TOPSRC)/win32/include/. "$(tccdir)/include" cp -r $(TOPSRC)/win32/include/. "$(tccdir)/include"
$(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include" $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
mkdir -p "$(tccdir)/lib/include";
$(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
mkdir -p "$(tccdir)/examples" mkdir -p "$(tccdir)/examples"
cp -r $(TOPSRC)/win32/examples/. "$(tccdir)/examples" cp -r $(TOPSRC)/win32/examples/. "$(tccdir)/examples"
$(INSTALL) $(TOPSRC)/tests/libtcc_test.c "$(tccdir)/examples" $(INSTALL) $(TOPSRC)/tests/libtcc_test.c "$(tccdir)/examples"
@ -323,13 +311,18 @@ install-win:
$(INSTALL) $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc" $(INSTALL) $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc"
mkdir -p "$(tccdir)/doc" mkdir -p "$(tccdir)/doc"
$(INSTALL) $(TOPSRC)/win32/tcc-win32.txt $(wildcard tcc-doc.html) "$(tccdir)/doc" $(INSTALL) $(TOPSRC)/win32/tcc-win32.txt $(wildcard tcc-doc.html) "$(tccdir)/doc"
ifneq "$(LIBTCC1_U)" ""
$(INSTALL) $(LIBTCC1_U) "$(tccdir)/lib"
mkdir -p "$(tccdir)/lib/include";
$(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
endif
# the msys-git shell works to configure && make except it does not have install # the msys-git shell works to configure && make except it does not have install
install-win : INSTALL = cp install-win : INSTALL = cp
# uninstall on windows # uninstall on windows
uninstall-win: uninstall-win:
rm -rfv "$(tccdir)/"* rm -r "$(tccdir)/"*
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# other stuff # other stuff
@ -341,7 +334,7 @@ ETAGS : ; etags $(TAGFILES)
# create release tarball from *current* git branch (including tcc-doc.html # create release tarball from *current* git branch (including tcc-doc.html
# and converting two files to CRLF) # and converting two files to CRLF)
TCC-VERSION = $(VERSION) TCC-VERSION = tcc-$(VERSION)
tar: tcc-doc.html tar: tcc-doc.html
mkdir $(TCC-VERSION) mkdir $(TCC-VERSION)
( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f ) ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
@ -361,11 +354,10 @@ test:
$(MAKE) -C tests $(MAKE) -C tests
clean: clean:
rm -f $(PROGS) $(PROGS_CROSS) tcc_p$(EXESUF) tcc.pod \ rm -f $(PROGS) $(PROGS_CROSS) tcc_p$(EXESUF) tcc.pod
*~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out \ rm -f *~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out tags TAGS
tags TAGS libtcc_test$(EXESUF) @$(MAKE) -C tests $@
$(MAKE) -C tests $@ @$(MAKE) -C lib $@
$(MAKE) -C lib $@
distclean: clean distclean: clean
rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
@ -389,12 +381,12 @@ help:
@echo "Cross compiler configuration:" @echo "Cross compiler configuration:"
@echo " make will read custom configuration for cross compilers from a file" @echo " make will read custom configuration for cross compilers from a file"
@echo " 'config-cross.mak' if present. For example for a windows->i386-linux" @echo " 'config-cross.mak' if present. For example for a windows->i386-linux"
@echo " cross-compiler that expects the linux files in <prefix>/i386-linux:" @echo " cross-compiler that expects the linux files in <tccdir>/i386-linux:"
@echo "" @echo ""
@echo " ROOT-i386 = {B}/i386-linux" @echo " ROOT-i386 = {B}/i386-linux"
@echo " CRT-i386 = $(ROOT-i386)/usr/lib" @echo " CRT-i386 = {B}/i386-linux/usr/lib"
@echo " LIB-i386 = $(ROOT-i386)/lib:$(ROOT-i386)/usr/lib" @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
@echo " INC-i386 = {B}/lib/include:$(ROOT-i386)/usr/include" @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
@echo " DEF-i386 += -D__linux__" @echo " DEF-i386 += -D__linux__"
@echo "" @echo ""
@echo "Other supported make targets:" @echo "Other supported make targets:"

34
configure vendored Executable file → Normal file
View File

@ -33,7 +33,7 @@ cross_prefix=""
cc="gcc" cc="gcc"
ar="ar" ar="ar"
strip="strip" strip="strip"
cygwin="no" noldl="no"
gprof="no" gprof="no"
bigendian="no" bigendian="no"
mingw32="no" mingw32="no"
@ -53,28 +53,26 @@ cpu=
# OS specific # OS specific
targetos=`uname` targetos=`uname`
case $targetos in case $targetos in
Darwin) osx=yes;; Darwin)
MINGW*) mingw32=yes;; osx=yes
MSYS*) mingw32=yes;; ;;
CYGWIN*) mingw32=yes; cygwin=yes; cross_prefix="mingw32-";; MINGW*|MSYS*|CYGWIN*)
DragonFly) noldl=yes;; mingw32=yes
OpenBSD) noldl=yes;; ;;
FreeBSD) noldl=yes;; DragonFly|OpenBSD|FreeBSD|NetBSD)
NetBSD) noldl=yes;; noldl=yes
*) ;; ;;
*)
;;
esac esac
# find source path # find source path
# XXX: we assume an absolute path is given when launching configure,
# except in './configure' case.
source_path=${0%configure} source_path=${0%configure}
source_path=${source_path%/} source_path=${source_path%/}
source_path_used="yes" source_path_used="yes"
if test -z "$source_path" -o "$source_path" = "." ; then if test -z "$source_path" -o "$source_path" = "." ; then
source_path=`pwd` source_path=`pwd`
source_path_used="no" source_path_used="no"
# mingw compilers might not understand cygwin paths
if test $cygwin = "yes"; then source_path="."; fi
fi fi
for opt do for opt do
@ -130,7 +128,7 @@ for opt do
;; ;;
--enable-gprof) gprof="yes" --enable-gprof) gprof="yes"
;; ;;
--enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86 --enable-mingw32) mingw32="yes"
;; ;;
--enable-cross) build_cross="yes" --enable-cross) build_cross="yes"
;; ;;
@ -211,6 +209,12 @@ if test -z "$CFLAGS"; then
fi fi
if test "$mingw32" = "yes" ; then if test "$mingw32" = "yes" ; then
if test "$source_path_used" = "no"; then
source_path="."
fi
if test "$cc" = gcc; then
test -z "$LDFLAGS" && LDFLAGS="-static"
fi
if test x"$tccdir" = x""; then if test x"$tccdir" = x""; then
tccdir="tcc" tccdir="tcc"
fi fi

View File

@ -7,6 +7,7 @@ include $(TOP)/Makefile
VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
BIN = $(TOP)/libtcc1$(if $(CROSS_TARGET),-$(CROSS_TARGET)).a
TCC = $(TOP)/$(X)tcc$(EXESUF) TCC = $(TOP)/$(X)tcc$(EXESUF)
XCC = $(TCC) XCC = $(TCC)
@ -25,25 +26,24 @@ ifeq ($(X),)
endif endif
endif endif
ifeq ($(TARGETOS),Darwin) ifdef CONFIG_OSX
XFLAGS += -D_ANSI_SOURCE XFLAGS += -D_ANSI_SOURCE
BCHECK_O =
endif endif
ifeq ($(CONFIG_musl),yes) ifeq ($(CONFIG_musl),yes)
BCHECK_O = BCHECK_O =
endif endif
I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O) I386_O = libtcc1.o alloca86.o alloca86-bt.o
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BCHECK_O) X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o
ARM_O = libtcc1.o armeabi.o alloca-arm.o ARM_O = libtcc1.o armeabi.o alloca-arm.o
ARM64_O = lib-arm64.o ARM64_O = lib-arm64.o
WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o
OBJ-i386 = $(I386_O) OBJ-i386 = $(I386_O) $(BCHECK_O)
TGT-i386 = -DTCC_TARGET_I386 TGT-i386 = -DTCC_TARGET_I386
OBJ-x86_64 = $(X86_64_O) OBJ-x86_64 = $(X86_64_O) $(BCHECK_O)
TGT-x86_64 = -DTCC_TARGET_X86_64 TGT-x86_64 = -DTCC_TARGET_X86_64
OBJ-x86_64-osx = $(X86_64_O) OBJ-x86_64-osx = $(X86_64_O)
@ -55,17 +55,15 @@ TGT-arm = -DTCC_TARGET_ARM
OBJ-arm64 = $(ARM64_O) OBJ-arm64 = $(ARM64_O)
TGT-arm64 = -DTCC_TARGET_ARM64 TGT-arm64 = -DTCC_TARGET_ARM64
OBJ-i386-win32 = $(I386_O) chkstk.o $(WIN_O) OBJ-i386-win32 = $(I386_O) chkstk.o bcheck.o $(WIN_O)
TGT-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE TGT-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE
OBJ-x86_64-win32 = $(X86_64_O) chkstk.o $(WIN_O) OBJ-x86_64-win32 = $(X86_64_O) chkstk.o bcheck.o $(WIN_O)
TGT-x86_64-win32 = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE TGT-x86_64-win32 = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
OBJ-arm-wince = $(ARM_O) $(WIN_O) OBJ-arm-wince = $(ARM_O) $(WIN_O)
TGT-arm-wince = -DTCC_TARGET_ARM -DTCC_TARGET_PE TGT-arm-wince = -DTCC_TARGET_ARM -DTCC_TARGET_PE
all : $(BIN)
$(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T)) $(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T))
$(XAR) rcs $@ $^ $(XAR) rcs $@ $^

View File

@ -1054,6 +1054,11 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
/* do not display line number if error */ /* do not display line number if error */
file->line_num = 0; file->line_num = 0;
#ifdef TCC_TARGET_MACHO
if (0 == obj_type && 0 == strcmp(tcc_fileextension(filename), "dylib"))
obj_type = AFF_BINTYPE_DYN;
#endif
switch (obj_type) { switch (obj_type) {
case AFF_BINTYPE_REL: case AFF_BINTYPE_REL:
ret = tcc_load_object_file(s1, fd, 0); ret = tcc_load_object_file(s1, fd, 0);
@ -1081,19 +1086,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
break; break;
#endif #endif
default: default:
#if defined(TCC_TARGET_MACHO) #ifdef TCC_TARGET_PE
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); ret = pe_load_file(s1, filename, fd);
#else #else
/* as GNU ld, consider it is an ld script if not recognized */ /* as GNU ld, consider it is an ld script if not recognized */
@ -1155,12 +1148,12 @@ ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
/* the library name is the same as the argument of the '-l' option */ /* the library name is the same as the argument of the '-l' option */
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
{ {
#if defined(TCC_TARGET_MACHO) #if defined TCC_TARGET_PE
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 *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; const char **pp = s->static_link ? libs + 4 : libs;
#elif 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;
#else #else
const char *libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL }; const char *libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
const char **pp = s->static_link ? libs + 1 : libs; const char **pp = s->static_link ? libs + 1 : libs;

View File

@ -87,13 +87,13 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe)
{ {
Sym *sym; Sym *sym;
int op, label; int op, label;
unsigned long n; uint64_t n;
const char *p; const char *p;
switch(tok) { switch(tok) {
case TOK_PPNUM: case TOK_PPNUM:
p = tokc.str.data; p = tokc.str.data;
n = strtoul(p, (char **)&p, 0); n = strtoull(p, (char **)&p, 0);
if (*p == 'b' || *p == 'f') { if (*p == 'b' || *p == 'f') {
/* backward or forward label */ /* backward or forward label */
label = asm_get_local_label_name(s1, n); label = asm_get_local_label_name(s1, n);

View File

@ -906,10 +906,6 @@ ST_FUNC void save_reg_upstack(int r, int n)
#else #else
type = &int_type; type = &int_type;
#endif #endif
if ((type->t & VT_BTYPE) == VT_FLOAT) {
/* cast to DOUBLE to avoid precision loss */
type->t = (type->t & ~VT_BTYPE) | VT_DOUBLE;
}
size = type_size(type, &align); size = type_size(type, &align);
loc = (loc - size) & -align; loc = (loc - size) & -align;
sv.type.t = type->t; sv.type.t = type->t;
@ -2383,11 +2379,6 @@ static void gen_cast(CType *type)
vpushi(0); vpushi(0);
gen_op(TOK_NE); gen_op(TOK_NE);
} else { } else {
if (sbt == VT_FLOAT) {
/* cast to DOUBLE to avoid precision loss */
gen_cvt_ftof(VT_DOUBLE);
vtop->type.t = (vtop->type.t & ~VT_BTYPE) | VT_DOUBLE;
}
/* we handle char/short/etc... with generic code */ /* we handle char/short/etc... with generic code */
if (dbt != (VT_INT | VT_UNSIGNED) && if (dbt != (VT_INT | VT_UNSIGNED) &&
dbt != (VT_LLONG | VT_UNSIGNED) && dbt != (VT_LLONG | VT_UNSIGNED) &&

View File

@ -28,10 +28,6 @@
#define strnicmp strncasecmp #define strnicmp strncasecmp
#endif #endif
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
#ifdef TCC_TARGET_X86_64 #ifdef TCC_TARGET_X86_64
# define ADDR3264 ULONGLONG # define ADDR3264 ULONGLONG
# define REL_TYPE_DIRECT R_X86_64_64 # define REL_TYPE_DIRECT R_X86_64_64
@ -907,7 +903,7 @@ static void pe_build_exports(struct pe_info *pe)
struct pe_sort_sym **sorted, *p; struct pe_sort_sym **sorted, *p;
FILE *op; FILE *op;
char buf[MAX_PATH]; char buf[260];
const char *dllname; const char *dllname;
const char *name; const char *name;

32
tccpp.c
View File

@ -1021,8 +1021,38 @@ ST_FUNC void restore_parse_state(ParseState *s)
tokc = s->tokc; tokc = s->tokc;
} }
/* token string handling */ #if 0
/* return the number of additional 'ints' necessary to store the
token */
static inline int tok_size(const int *p)
{
switch(*p) {
/* 4 bytes */
case TOK_CINT:
case TOK_CUINT:
case TOK_CCHAR:
case TOK_LCHAR:
case TOK_CFLOAT:
case TOK_LINENUM:
return 1 + 1;
case TOK_STR:
case TOK_LSTR:
case TOK_PPNUM:
case TOK_PPSTR:
return 1 + ((sizeof(CString) + ((CString *)(p+1))->size + 3) >> 2);
case TOK_CDOUBLE:
case TOK_CLLONG:
case TOK_CULLONG:
return 1 + 2;
case TOK_CLDOUBLE:
return 1 + LDOUBLE_SIZE / 4;
default:
return 1 + 0;
}
}
#endif
/* token string handling */
ST_INLN void tok_str_new(TokenString *s) ST_INLN void tok_str_new(TokenString *s)
{ {
s->str = NULL; s->str = NULL;

View File

@ -304,15 +304,15 @@ the_end:
ST_FUNC int tcc_tool_impdef(TCCState *s1, int argc, char **argv) ST_FUNC int tcc_tool_impdef(TCCState *s1, int argc, char **argv)
{ {
int ret, v, i; int ret, v, i;
char infile[MAX_PATH]; char infile[260];
char outfile[MAX_PATH]; char outfile[260];
const char *file; const char *file;
char *p, *q; char *p, *q;
FILE *fp, *op; FILE *fp, *op;
#ifdef _WIN32 #ifdef _WIN32
char path[MAX_PATH]; char path[260];
#endif #endif
infile[0] = outfile[0] = 0; infile[0] = outfile[0] = 0;

View File

@ -5,7 +5,7 @@
TOP = .. TOP = ..
include $(TOP)/Makefile include $(TOP)/Makefile
VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP) VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
# what tests to run # what tests to run
TESTS = \ TESTS = \
@ -34,8 +34,8 @@ endif
ifdef CONFIG_WIN32 ifdef CONFIG_WIN32
TESTS := $(filter-out $(BTESTS),$(TESTS)) TESTS := $(filter-out $(BTESTS),$(TESTS))
endif endif
ifeq ($(TARGETOS),Darwin) ifdef CONFIG_OSX # -run only
TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS)) TESTS := hello-run libtest tests2-dir pp-dir
endif endif
ifeq (,$(filter arm64 i386 x86_64,$(ARCH))) ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
TESTS := $(filter-out vla_test-run,$(TESTS)) TESTS := $(filter-out vla_test-run,$(TESTS))
@ -51,28 +51,23 @@ ifndef CONFIG_CROSS
endif endif
ifdef CONFIG_WIN32 ifdef CONFIG_WIN32
PATH := $(CURDIR)/$(TOP):$(PATH) # for libtcc_test to find libtcc.dll SEP = $(if $(findstring :\,$(PATH)),;,:)
endif PATH := $(CURDIR)/$(TOP)$(SEP)$(PATH) # for libtcc_test to find libtcc.dll
ifeq ($(TARGETOS),Darwin)
CFLAGS += -Wl,-flat_namespace,-undefined,warning
TCCFLAGS += -D_ANSI_SOURCE
export MACOSX_DEPLOYMENT_TARGET:=10.2
endif endif
RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS) RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS)
DISAS = objdump -d DISAS = objdump -d
DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
all test : clean-s $(TESTS) all test : clean-s $(TESTS)
hello-exe: ../examples/ex1.c hello-exe: ../examples/ex1.c
@echo ------------ $@ ------------ @echo ------------ $@ ------------
$(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF) $(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
hello-run: ../examples/ex1.c hello-run: ../examples/ex1.c
@echo ------------ $@ ------------ @echo ------------ $@ ------------
$(TCC) -run $< $(TCC) -run $< || $(DUMPTCC)
libtest: libtcc_test$(EXESUF) libtest: libtcc_test$(EXESUF)
@echo ------------ $@ ------------ @echo ------------ $@ ------------
@ -263,11 +258,11 @@ cache: tcc_g
# clean # clean
clean: clean:
rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc \ rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
*-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] \ rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
ex? tcc_g *.def weaktest.*.txt rm -f ex? tcc_g weaktest.*.txt *.def
$(MAKE) -C tests2 $@ @$(MAKE) -C tests2 $@
$(MAKE) -C pp $@ @$(MAKE) -C pp $@
# silent clean, used before running tests # silent clean, used before running tests
clean-s: clean-s:

View File

@ -5,23 +5,6 @@ VPATH = $(SRC)
TESTS = $(patsubst %.c,%.test,$(sort $(notdir $(wildcard $(SRC)/*.c)))) TESTS = $(patsubst %.c,%.test,$(sort $(notdir $(wildcard $(SRC)/*.c))))
# 34_array_assignment.test -- array assignment is not in C standard
SKIP = 34_array_assignment.test
# some tests do not pass on all platforms, remove them for now
ifeq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
SKIP += 22_floating_point.test
endif
ifeq ($(TARGETOS),Darwin)
SKIP += 40_stdio.test
endif
ifeq ($(ARCH),x86_64)
SKIP += 73_arm64.test
endif
ifeq (,$(filter i386 x86_64,$(ARCH)))
SKIP += 85_asm-outside-function.test
endif
# Some tests might need arguments # Some tests might need arguments
ARGS = ARGS =
31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5
@ -42,6 +25,22 @@ ifeq (-$(findstring arm,$(ARCH))-,-arm-)
FILTER += 2>&1 | grep -v 'warning: soft float ABI currently not supported' FILTER += 2>&1 | grep -v 'warning: soft float ABI currently not supported'
endif endif
# some tests do not pass on all platforms, remove them for now
SKIP = 34_array_assignment.test # array assignment is not in C standard
ifeq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
SKIP += 22_floating_point.test
endif
ifdef CONFIG_OSX
SKIP += 40_stdio.test 42_function_pointer.test
FLAGS += -w
endif
ifeq ($(ARCH),x86_64)
SKIP += 73_arm64.test
endif
ifeq (,$(filter i386 x86_64,$(ARCH)))
SKIP += 85_asm-outside-function.test
endif
all test: $(filter-out $(SKIP),$(TESTS)) all test: $(filter-out $(SKIP),$(TESTS))
%.test: %.c %.expect %.test: %.c %.expect

View File

@ -5,7 +5,7 @@
@echo off @echo off
setlocal setlocal
set CC=gcc -Os -s set CC=gcc -Os -s -static
set /p VERSION= < ..\VERSION set /p VERSION= < ..\VERSION
set INST= set INST=
set DOC=no set DOC=no

View File

@ -165,5 +165,6 @@ typedef struct localeinfo_struct _locale_tstruct,*_locale_t;
#define __C89_NAMELESS #define __C89_NAMELESS
#define __MINGW_EXTENSION #define __MINGW_EXTENSION
#define WINAPI_FAMILY_PARTITION(X) 1 #define WINAPI_FAMILY_PARTITION(X) 1
#define MINGW_HAS_SECURE_API
#endif /* __MINGW_H */ #endif /* __MINGW_H */