tcctools.c: integrate tiny_libmaker/_impdef
[tinycc.git] / lib / Makefile
blob85dc5cf50da76efc0095db3e33f19d3412fdbf7d
2 # Tiny C Compiler Makefile for libtcc1.a
5 TOP = ..
6 include $(TOP)/Makefile
7 VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
9 ifndef TARGET
10 # we're building the native libtcc1.a
11 ifdef CONFIG_WIN32
12 ifeq ($(ARCH),x86-64)
13 TARGET = x86_64-win32
14 else
15 TARGET = i386-win32
16 endif
17 else ifeq ($(ARCH),i386)
18 TARGET = i386
19 else ifeq ($(ARCH),x86-64)
20 TARGET = x86_64
21 else ifeq ($(ARCH),arm)
22 TARGET = arm
23 else ifeq ($(ARCH),arm64)
24 TARGET = arm64
25 endif
26 BCHECK_O = bcheck.o
27 endif
29 DIR = $(TARGET)
31 native : ../libtcc1.a
32 cross : $(DIR)/libtcc1.a
34 native : TCC = $(TOP)/tcc$(EXESUF)
35 cross : TCC = $(TOP)/$(TARGET)-tcc$(EXESUF)
37 XCC = $(TCC) -B$(TOPSRC)
38 XAR = $(TCC) -ar
40 I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O)
41 X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BCHECK_O)
42 ARM_O = libtcc1.o armeabi.o alloca-arm.o
43 ARM64_O = lib-arm64.o
44 WIN32_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
46 ifeq "$(TARGET)" "i386-win32"
47 OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))
48 TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
49 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
50 else ifeq "$(TARGET)" "x86_64-win32"
51 OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O))
52 TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
53 XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
54 else ifeq "$(TARGET)" "i386"
55 OBJ = $(addprefix $(DIR)/,$(I386_O))
56 TGT = -DTCC_TARGET_I386
57 else ifeq "$(TARGET)" "x86_64"
58 OBJ = $(addprefix $(DIR)/,$(X86_64_O))
59 TGT = -DTCC_TARGET_X86_64
60 else ifeq "$(TARGET)" "arm"
61 OBJ = $(addprefix $(DIR)/,$(ARM_O))
62 TGT = -DTCC_TARGET_ARM
63 # using gcc, need asm
64 XCC = $(CC)
65 XFLAGS = $(CFLAGS) -fPIC
66 XAR = $(AR)
67 else ifeq "$(TARGET)" "arm64"
68 OBJ = $(addprefix $(DIR)/,$(ARM64_O))
69 TGT = -DTCC_TARGET_ARM64
70 else
71 $(error libtcc1.a not supported on target '$(TARGET)')
72 endif
74 ifeq ($(TARGETOS),Darwin)
75 XFLAGS += -D_ANSI_SOURCE
76 BCHECK_O =
77 endif
79 $(DIR)/libtcc1.a ../libtcc1.a : $(OBJ)
80 $(XAR) rcs $@ $(OBJ)
81 $(DIR)/%.o : %.c
82 $(XCC) -c $< -o $@ $(TGT) $(XFLAGS)
83 $(DIR)/%.o : %.S
84 $(XCC) -c $< -o $@ $(TGT) $(XFLAGS)
86 $(OBJ) : $(DIR)/exists
88 %/exists :
89 mkdir -p $(DIR)
90 @echo $@ > $@
92 clean :
93 rm -rf i386-win32 x86_64-win32 i386 x86_64 arm arm64