Skip to content

Commit

Permalink
makefile: unify cross with native builds
Browse files Browse the repository at this point in the history
supports building cross compilers on the fly without need
for configure --enable-cross

   $ make cross          # all compilers
   $ make cross-TARGET   # only TARGET-compiler & its libtcc1.a

with TARGET one from
   i386 x86_64 i386-win32 x86_64-win32 arm arm64 arm-wince c67

Type 'make help' for more information
  • Loading branch information
grischka committed Feb 25, 2017
1 parent 669f611 commit bb93064
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 296 deletions.
454 changes: 234 additions & 220 deletions Makefile

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions arm-asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ ST_FUNC void gen_le32(int c);
#else
/*************************************************************/

static void asm_error(void)
{
tcc_error("ARM asm not implemented.");
}

/* XXX: make it faster ? */
ST_FUNC void g(int c)
{
Expand Down Expand Up @@ -49,10 +54,12 @@ ST_FUNC void gen_expr32(ExprValue *pe)

ST_FUNC void asm_opcode(TCCState *s1, int opcode)
{
asm_error();
}

ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier)
{
asm_error();
}

/* generate prolog and epilog code for asm statement */
Expand All @@ -61,21 +68,25 @@ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
uint8_t *clobber_regs,
int out_reg)
{
asm_error();
}

ST_FUNC void asm_compute_constraints(ASMOperand *operands,
int nb_operands, int nb_outputs,
const uint8_t *clobber_regs,
int *pout_reg)
{
asm_error();
}

ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
{
asm_error();
}

ST_FUNC int asm_parse_regvar (int t)
{
asm_error();
return -1;
}

Expand Down
3 changes: 1 addition & 2 deletions examples/ex3.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdlib.h>
#include <stdio.h>
#include <tcclib.h>

int fib(n)
{
Expand Down
105 changes: 50 additions & 55 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,71 @@
TOP = ..
include $(TOP)/Makefile
VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)

ifneq ($(CROSS),yes)
TCC = $(TOP)/tcc$(EXESUF)
OUT = ../libtcc1.a
TCC = $(TOP)/$(X)tcc$(EXESUF)
XCC = $(TCC)
XAR = $(TCC) -ar
XFLAGS-unx = -B$(TOPSRC)
XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include
XFLAGS = $(XFLAGS$(XCFG))
XCFG = $(or $(findstring -win,$T),-unx)

ifeq ($(X),)
BCHECK_O = bcheck.o
else
TCC = $(TOP)/$(TARGET)-tcc$(EXESUF)
OUT = libtcc1-$(TARGET).a
ifeq "$T" "arm"
XCC = $(CC)
XAR = $(AR)
XFLAGS = $(CFLAGS) -fPIC
endif
endif

XCC = $(TCC) -B$(TOPSRC)
XAR = $(TCC) -ar
ifeq ($(TARGETOS),Darwin)
XFLAGS += -D_ANSI_SOURCE
BCHECK_O =
endif

I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O)
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BCHECK_O)
ARM_O = libtcc1.o armeabi.o alloca-arm.o
ARM64_O = lib-arm64.o
WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o

ifeq "$(TARGET)" "i386-win32"
OBJ = $(I386_O) chkstk.o $(WIN_O)
TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
else ifeq "$(TARGET)" "x86_64-win32"
OBJ = $(X86_64_O) chkstk.o $(WIN_O)
TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
else ifeq "$(TARGET)" "arm-wince"
OBJ = $(ARM_O) $(WIN_O)
TGT = -DTCC_TARGET_ARM -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
else ifeq "$(TARGET)" "i386"
OBJ = $(I386_O)
TGT = -DTCC_TARGET_I386
else ifeq "$(TARGET)" "x86_64"
OBJ = $(X86_64_O)
TGT = -DTCC_TARGET_X86_64
else ifeq "$(TARGET)" "arm-eabihf"
OBJ = $(ARM_O)
TGT = -DTCC_TARGET_ARM
ifneq ($(CROSS),yes)
# using gcc, need asm
XCC = $(CC)
XFLAGS = $(CFLAGS) -fPIC
XAR = $(AR)
endif
else ifeq "$(TARGET)" "arm64"
OBJ = $(ARM64_O)
TGT = -DTCC_TARGET_ARM64
else ifneq "$(TARGET)" ""
$(error libtcc1.a not supported on target '$(TARGET)')
endif
OBJ-i386 = $(I386_O)
TGT-i386 = -DTCC_TARGET_I386

ifeq ($(TARGETOS),Darwin)
XFLAGS += -D_ANSI_SOURCE
BCHECK_O =
endif
OBJ-x86_64 = $(X86_64_O)
TGT-x86_64 = -DTCC_TARGET_X86_64

OBJ-arm = $(ARM_O)
TGT-arm = -DTCC_TARGET_ARM

OBJ-arm64 = $(ARM64_O)
TGT-arm64 = -DTCC_TARGET_ARM64

all : $(OUT)
OBJ-i386-win32 = $(I386_O) chkstk.o $(WIN_O)
TGT-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE

$(OUT) : $(patsubst %.o,%-$(TARGET).o,$(OBJ))
OBJ-x86_64-win32 = $(X86_64_O) chkstk.o $(WIN_O)
TGT-x86_64-win32 = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE

OBJ-arm-wince = $(ARM_O) $(WIN_O)
TGT-arm-wince = -DTCC_TARGET_ARM -DTCC_TARGET_PE

all : $(BIN)

$(BIN) : $(patsubst %.o,$(X)%.o,$(OBJ-$T))
$(XAR) rcs $@ $^
%-$(TARGET).o : %.c
$(XCC) -c $< -o $@ $(TGT) $(XFLAGS)
%-$(TARGET).o : %.S
$(XCC) -c $< -o $@ $(TGT) $(XFLAGS)

crt1w-$(TARGET).o : crt1.c
wincrt1w-$(TARGET).o : wincrt1.c
bcheck-$(TARGET).o : XFLAGS += -w
$(X)%.o : %.c
$(XCC) -c $< -o $@ $(TGT-$T) $(XFLAGS)

$(X)%.o : %.S
$(XCC) -c $< -o $@ $(TGT-$T) $(XFLAGS)

$(X)crt1w.o : crt1.c
$(X)wincrt1w.o : wincrt1.c

clean :
rm -f *.a *.o $(OUT)
rm -f *.a *.o $(BIN)
2 changes: 1 addition & 1 deletion lib/bcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
|| defined(__DragonFly__) || defined(__dietlibc__) \
|| defined(__UCLIBC__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(_WIN32) || defined(TCC_UCLIBC)
#warning Bound checking does not support malloc (etc.) in this environment.
//#warning Bound checking does not support malloc (etc.) in this environment.
#undef CONFIG_TCC_MALLOC_HOOKS
#undef HAVE_MEMALIGN
#endif
Expand Down
2 changes: 1 addition & 1 deletion tcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ ST_FUNC void gen_opl(int op);
/* ------------ arm-gen.c ------------ */
#ifdef TCC_TARGET_ARM
#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
ST_FUNC char *default_elfinterp(struct TCCState *s);
PUB_FUNC char *default_elfinterp(struct TCCState *s);
#endif
ST_FUNC void arm_init(struct TCCState *s);
ST_FUNC void gen_cvt_itof1(int t);
Expand Down
24 changes: 17 additions & 7 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TESTS = \
dlltest \
abitest \
vla_test-run \
cross-test \
tests2-dir \
pp-dir

Expand Down Expand Up @@ -45,23 +46,22 @@ endif
ifeq (,$(filter i386 x86_64,$(ARCH)))
TESTS := $(filter-out dlltest,$(TESTS))
endif
ifndef CONFIG_CROSS
TESTS := $(filter-out cross-%,$(TESTS))
endif

# run local version of tcc with local libraries and includes
TCCFLAGS = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
ifdef CONFIG_WIN32
TCCFLAGS = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
PATH := $(CURDIR)/$(TOP):$(PATH) # for libtcc_test to find libtcc.dll
PATH := $(CURDIR)/$(TOP);$(PATH) # for libtcc_test to find libtcc.dll
endif

TCC = $(TOP)/tcc $(TCCFLAGS)
RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS)

ifeq ($(TARGETOS),Darwin)
CFLAGS += -Wl,-flat_namespace,-undefined,warning
TCCFLAGS += -D_ANSI_SOURCE
export MACOSX_DEPLOYMENT_TARGET:=10.2
endif

RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOPSRC)/tcc.c $(TCCFLAGS)

DISAS = objdump -d

all test : clean-s $(TESTS)
Expand Down Expand Up @@ -236,6 +236,16 @@ vla_test-run: vla_test$(EXESUF)
@echo ------------ $@ ------------
./vla_test$(EXESUF)

cross-test :
@echo ------------ $@ ------------
$(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
$(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
$(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
$(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"

# targets for development
%.bin: %.c tcc
$(TCC) -g -o $@ $<
Expand Down
3 changes: 1 addition & 2 deletions tests/pp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#

TOP = ../..
include $(TOP)/config.mak
include $(TOP)/Makefile
SRC = $(TOPSRC)/tests/pp
VPATH = $(SRC)

TCC = ../../tcc
files = $(patsubst %.$1,%.test,$(notdir $(wildcard $(SRC)/*.$1)))
TESTS = $(call files,c) $(call files,S)

Expand Down
9 changes: 1 addition & 8 deletions tests/tests2/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
TOP = ../..
include $(TOP)/config.mak
include $(TOP)/Makefile
SRC = $(TOPSRC)/tests/tests2
VPATH = $(SRC)

# run local version of tcc with local libraries and includes
TCCFLAGS = -B$(TOP) -I$(TOPSRC)/include
ifdef CONFIG_WIN32
TCCFLAGS = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -L$(TOP)
endif
TCC = $(TOP)/tcc $(TCCFLAGS)

TESTS = $(patsubst %.c,%.test,$(sort $(notdir $(wildcard $(SRC)/*.c))))

# 34_array_assignment.test -- array assignment is not in C standard
Expand Down
4 changes: 4 additions & 0 deletions win32/include/_mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@
#define _M_IX86 300 /* Visual Studio */
#define WIN32 1
#define _USE_32BIT_TIME_T
#ifdef __arm__
#define __TRY__
#else
#define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec);
#endif
#endif

/* in stddef.h */
#define _SIZE_T_DEFINED
Expand Down

0 comments on commit bb93064

Please sign in to comment.