tinycc/Makefile

342 lines
9.4 KiB
Makefile
Raw Normal View History

2001-11-11 21:01:29 +03:00
#
# Tiny C Compiler Makefile
#
2009-04-18 16:31:35 +04:00
TOP ?= .
include $(TOP)/config.mak
2001-10-28 02:48:39 +03:00
2005-09-03 22:34:22 +04:00
CFLAGS+=-g -Wall
2001-12-18 00:57:01 +03:00
CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
LIBS_P=
ifneq ($(GCC_MAJOR),2)
CFLAGS+=-fno-strict-aliasing
2009-07-19 00:06:54 +04:00
ifneq ($(GCC_MAJOR),3)
CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
endif
endif
ifeq ($(ARCH),i386)
2003-04-13 23:48:19 +04:00
CFLAGS+=-mpreferred-stack-boundary=2
ifeq ($(GCC_MAJOR),2)
CFLAGS+=-m386 -malign-functions=0
else
CFLAGS+=-march=i386 -falign-functions=0
2003-04-13 23:48:19 +04:00
endif
endif
2009-04-19 23:24:32 +04:00
ifndef CONFIG_WIN32
LIBS=-lm
ifndef CONFIG_NOLDL
LIBS+=-ldl
endif
endif
ifeq ($(ARCH),i386)
2009-12-20 22:34:35 +03:00
NATIVE_DEFINES=-DTCC_TARGET_I386
2009-04-19 23:24:32 +04:00
LIBTCC1=libtcc1.a
BCHECK_O=bcheck.o
2009-07-19 00:06:54 +04:00
ALLOCA_O=alloca86.o alloca86-bt.o
2009-04-19 23:24:32 +04:00
else
ifeq ($(ARCH),x86-64)
2009-12-20 22:34:35 +03:00
NATIVE_DEFINES=-DTCC_TARGET_X86_64
NATIVE_DEFINES+=$(if $(wildcard /lib64/ld-linux-x86-64.so.2),-DTCC_TARGET_X86_64_CENTOS)
2009-04-19 23:24:32 +04:00
LIBTCC1=libtcc1.a
2009-07-19 00:06:54 +04:00
BCHECK_O=
ALLOCA_O=alloca86_64.o
2009-04-19 23:24:32 +04:00
endif
endif
2009-07-19 00:06:54 +04:00
ifeq ($(ARCH),arm)
2009-12-20 22:34:35 +03:00
NATIVE_DEFINES=-DTCC_TARGET_ARM
NATIVE_TARGET=-DWITHOUT_LIBTCC
2009-12-20 22:34:35 +03:00
NATIVE_DEFINES+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
2009-04-19 23:24:32 +04:00
endif
2009-07-19 00:06:54 +04:00
ifdef CONFIG_WIN32
2009-12-20 22:34:35 +03:00
NATIVE_DEFINES+=-DTCC_TARGET_PE
2009-07-19 00:06:54 +04:00
BCHECK_O=
2009-04-19 23:24:32 +04:00
endif
ifneq ($(wildcard /lib/ld-uClibc.so.0),)
2009-12-20 22:34:35 +03:00
NATIVE_DEFINES+=-DTCC_UCLIBC
BCHECK_O=
endif
2009-04-19 23:24:32 +04:00
ifdef CONFIG_USE_LIBGCC
LIBTCC1=
endif
2009-04-18 16:31:35 +04:00
ifeq ($(TOP),.)
PROGS=tcc$(EXESUF)
2009-04-18 16:31:35 +04:00
I386_CROSS = i386-tcc$(EXESUF)
WIN32_CROSS = i386-win32-tcc$(EXESUF)
2009-07-19 00:05:40 +04:00
WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
2009-08-27 12:25:28 +04:00
WINCE_CROSS = arm-win32-tcc$(EXESUF)
2009-04-18 16:31:35 +04:00
X64_CROSS = x86_64-tcc$(EXESUF)
2009-12-20 22:34:35 +03:00
ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
2009-04-19 23:24:32 +04:00
C67_CROSS = c67-tcc$(EXESUF)
2009-12-20 22:34:35 +03:00
CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
CORE_FILES += tcc.h config.h libtcc.h tcctok.h
2009-08-27 11:53:50 +04:00
I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
2009-08-27 12:25:28 +04:00
WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
2009-04-19 23:24:32 +04:00
ARM_FILES = $(CORE_FILES) arm-gen.c
C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
2009-04-18 16:31:35 +04:00
ifdef CONFIG_WIN32
PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
2009-04-19 23:24:32 +04:00
NATIVE_FILES=$(WIN32_FILES)
2009-07-19 00:05:40 +04:00
PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
2009-04-19 23:24:32 +04:00
else
ifeq ($(ARCH),i386)
NATIVE_FILES=$(I386_FILES)
PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
2009-04-19 23:24:32 +04:00
else
ifeq ($(ARCH),x86-64)
NATIVE_FILES=$(X86_64_FILES)
PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
2009-04-19 23:24:32 +04:00
else
ifeq ($(ARCH),arm)
NATIVE_FILES=$(ARM_FILES)
2009-07-19 00:05:40 +04:00
PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
2009-04-19 23:24:32 +04:00
endif
endif
endif
endif
2009-04-18 16:31:35 +04:00
# LIBTCCB decides whether libtcc is installed static or dynamic
LIBTCCB=libtcc.a
ifdef DISABLE_STATIC
CFLAGS+=-fPIC
LIBTCCL=-L. -ltcc
LIBTCCB=libtcc.so.1.0
endif
LIBTCCLIBS=$(LIBTCCB)
ifdef CONFIG_CROSS
2009-04-18 16:31:35 +04:00
PROGS+=$(PROGS_CROSS)
# Try to build win32 cross-compiler lib on *nix
ifndef CONFIG_WIN32
LIBTCCLIBS+=tcc1.def
endif
endif
all: $(PROGS) $(LIBTCC1) $(BCHECK_O) $(LIBTCCLIBS) tcc-doc.html tcc.1 libtcc_test$(EXESUF)
2009-04-18 16:31:35 +04:00
# Host Tiny C Compiler
tcc$(EXESUF): tcc.o $(LIBTCCB)
$(CC) -o $@ $^ $(LIBS) $(LIBTCCL)
2001-11-11 21:01:29 +03:00
# Cross Tiny C Compilers
2009-12-20 22:34:35 +03:00
%-tcc$(EXESUF):
$(CC) -o $@ tcc.c $(DEFINES) $(CFLAGS) $(LIBS)
$(I386_CROSS): DEFINES = -DTCC_TARGET_I386
$(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
$(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE
2009-12-20 22:34:35 +03:00
$(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
$(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
$(C67_CROSS): DEFINES = -DTCC_TARGET_C67
$(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
$(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
$(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
$(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
$(I386_CROSS): $(I386_FILES)
$(X64_CROSS): $(X86_64_FILES)
$(WIN32_CROSS): $(WIN32_FILES)
$(WIN64_CROSS): $(WIN64_FILES)
$(WINCE_CROSS): $(WINCE_FILES)
$(C67_CROSS): $(C67_FILES)
$(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
2009-04-18 16:31:35 +04:00
# libtcc generation and test
ifdef NOTALLINONE
LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
2009-12-20 22:34:35 +03:00
$(LIBTCC_OBJ) tcc.o : NATIVE_DEFINES += -DNOTALLINONE
else
LIBTCC_OBJ = libtcc.o
LIBTCC_INC = $(NATIVE_FILES)
2009-12-20 22:34:35 +03:00
tcc.o : NATIVE_DEFINES += -DNOTALLINONE
endif
$(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
2009-12-20 22:34:35 +03:00
$(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CFLAGS)
libtcc.a: $(LIBTCC_OBJ)
2009-04-18 16:31:35 +04:00
$(AR) rcs $@ $^
libtcc.so.1.0: $(LIBTCC_OBJ)
$(CC) -shared -Wl,-soname,$@ -o $@ $^
ln -sf libtcc.so.1.0 libtcc.so.1
ln -sf libtcc.so.1.0 libtcc.so
libtcc_test$(EXESUF): tests/libtcc_test.c $(LIBTCCB)
$(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS) $(LIBTCCL)
# To build cross-compilers on Linux we must make a fake 32 bit tcc.exe
# and use it to build ELF objects into libtcc1.a which is then
# renamed to tcc1.def in order to have another target in the Makefile
tcc1.def:
mv config.mak config.mak.bak
mv config.h config.h.bak
cp config.h.bak config.h
cp config.mak.bak config.mak
echo "ARCH=i386" >> config.mak
echo "#undef HOST_X86_64" >> config.h
echo "#define HOST_I386 1" >> config.h
echo "CFLAGS=-O2 -g -pipe -Wall -m32" >> config.mak
echo "ARCH=i386" >> config.mak
$(MAKE) i386-win32-tcc
cp i386-win32-tcc tcc.exe
mv libtcc1.a libtcc1.bak
$(MAKE) CONFIG_WIN32=1 libtcc1.a
mv libtcc1.a lib/tcc1.def
mv libtcc1.bak libtcc1.a
mv config.mak.bak config.mak
mv config.h.bak config.h
2009-04-18 16:31:35 +04:00
libtest: libtcc_test$(EXESUF) $(LIBTCC1)
./libtcc_test$(EXESUF) lib_path=.
2004-10-05 02:19:21 +04:00
2009-04-18 16:31:35 +04:00
# profiling version
2009-04-19 23:24:32 +04:00
tcc_p$(EXESUF): $(NATIVE_FILES)
2009-12-20 22:34:35 +03:00
$(CC) -o $@ $< $(NATIVE_DEFINES) $(CFLAGS_P) $(LIBS_P)
2005-04-11 01:46:58 +04:00
# windows utilities
tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
2009-04-18 16:31:35 +04:00
$(CC) -o $@ $< $(CFLAGS)
tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
2009-04-18 16:31:35 +04:00
$(CC) -o $@ $< $(CFLAGS)
2002-07-25 02:13:02 +04:00
# TinyCC runtime libraries
2009-07-19 00:06:54 +04:00
LIBTCC1_OBJS=libtcc1.o $(ALLOCA_O)
2009-04-18 16:31:35 +04:00
LIBTCC1_CC=$(CC)
VPATH+=lib
2009-07-19 00:06:54 +04:00
ifdef CONFIG_WIN32
2005-06-18 02:03:50 +04:00
# for windows, we must use TCC because we generate ELF objects
LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o
2009-12-20 22:34:35 +03:00
LIBTCC1_CC=./tcc.exe -Bwin32 -Iinclude $(NATIVE_DEFINES)
2009-04-18 16:31:35 +04:00
VPATH+=win32/lib
endif
%.o: %.c
2009-04-19 23:24:32 +04:00
$(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
%.o: %.S
2009-04-18 16:31:35 +04:00
$(LIBTCC1_CC) -o $@ -c $<
2005-06-18 02:03:50 +04:00
libtcc1.a: $(LIBTCC1_OBJS)
$(AR) rcs $@ $^
2009-04-18 16:31:35 +04:00
# install
TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
INSTALL=install
2003-04-13 23:48:19 +04:00
2004-10-08 01:11:43 +04:00
ifndef CONFIG_WIN32
install: $(PROGS) $(LIBTCC1) $(BCHECK_O) $(LIBTCCLIBS) tcc.1 tcc-doc.html
2009-04-18 16:31:35 +04:00
mkdir -p "$(bindir)"
$(INSTALL) -s -m755 $(PROGS) "$(bindir)"
mkdir -p "$(mandir)/man1"
$(INSTALL) tcc.1 "$(mandir)/man1"
mkdir -p "$(tccdir)"
mkdir -p "$(tccdir)/include"
ifneq ($(LIBTCC1),)
$(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
2004-10-08 01:11:43 +04:00
endif
2009-04-18 16:31:35 +04:00
ifneq ($(BCHECK_O),)
$(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
endif
2009-04-18 16:31:35 +04:00
$(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
mkdir -p "$(libdir)"
$(INSTALL) -m755 $(LIBTCCB) "$(libdir)"
ifdef DISABLE_STATIC
ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
endif
2009-04-18 16:31:35 +04:00
mkdir -p "$(includedir)"
$(INSTALL) -m644 libtcc.h "$(includedir)"
mkdir -p "$(docdir)"
$(INSTALL) -m644 tcc-doc.html "$(docdir)"
ifdef CONFIG_CROSS
mkdir -p "$(tccdir)/lib"
$(INSTALL) -m644 win32/lib/*.def lib/tcc1.def "$(tccdir)/lib"
cp -r win32/include/. "$(tccdir)/include"
cp -r win32/examples/. "$(tccdir)/examples"
endif
2009-04-18 16:31:35 +04:00
uninstall:
rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
rm -fv "$(libdir)/$(LIBTCCB)" "$(includedir)/libtcc.h"
ifdef DISABLE_STATIC
rm -fv "$(libdir)/libtcc.so*"
endif
ifdef CONFIG_CROSS
rm -rf "$(tccdir)/include"
rm -rf "$(tccdir)/lib"
rm -rf "$(tccdir)/examples"
endif
else
2009-04-18 16:31:35 +04:00
install: $(PROGS) $(LIBTCC1) libtcc.a tcc-doc.html
mkdir -p "$(tccdir)"
mkdir -p "$(tccdir)/lib"
mkdir -p "$(tccdir)/include"
mkdir -p "$(tccdir)/examples"
mkdir -p "$(tccdir)/doc"
mkdir -p "$(tccdir)/libtcc"
$(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
$(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
cp -r win32/include/. "$(tccdir)/include"
cp -r win32/examples/. "$(tccdir)/examples"
2009-07-19 00:06:37 +04:00
$(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
2009-04-19 23:24:32 +04:00
$(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
$(INSTALL) -m644 $(LIBTCCB) libtcc.h "$(tccdir)/libtcc"
endif
2002-05-14 02:58:22 +04:00
# documentation and man page
2002-07-25 02:13:02 +04:00
tcc-doc.html: tcc-doc.texi
-texi2html -monolithic -number $<
2002-07-25 02:13:02 +04:00
tcc.1: tcc-doc.texi
-./texi2pod.pl $< tcc.pod
-pod2man --section=1 --center=" " --release=" " tcc.pod > $@
2005-04-15 04:11:02 +04:00
# tar release (use 'make -k tar' on a checkouted tree)
2009-04-18 16:31:35 +04:00
TCC-VERSION=tcc-$(shell cat VERSION)
2001-11-11 21:01:29 +03:00
tar:
2009-04-18 16:31:35 +04:00
rm -rf /tmp/$(TCC-VERSION)
cp -r . /tmp/$(TCC-VERSION)
( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
rm -rf /tmp/$(TCC-VERSION)
# in tests subdir
%est:
2009-04-18 16:31:35 +04:00
$(MAKE) -C tests $@
clean:
rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.out *.so* *.exe libtcc_test$(EXESUF) lib/tcc1.def
$(MAKE) -C tests $@
2009-04-18 16:31:35 +04:00
distclean: clean
rm -vf config.h config.mak config.texi tcc.1 tcc-doc.html
2009-04-18 16:31:35 +04:00
config.mak:
@echo Running configure ...
@./configure
2009-04-19 23:24:32 +04:00
endif # ifeq ($(TOP),.)