Add missing dircategory and direntry to texi file
[tinycc.git] / Makefile
blob3ee162d9b762a25087e0d4d01d3b86418c7e8eaf
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
8 CFLAGS+=-g -Wall
9 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
10 LIBS_P=
12 ifneq ($(GCC_MAJOR),2)
13 CFLAGS+=-fno-strict-aliasing
14 ifneq ($(GCC_MAJOR),3)
15 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
16 endif
17 endif
19 ifeq ($(ARCH),i386)
20 CFLAGS+=-mpreferred-stack-boundary=2
21 ifeq ($(GCC_MAJOR),2)
22 CFLAGS+=-m386 -malign-functions=0
23 else
24 CFLAGS+=-march=i386 -falign-functions=0
25 endif
26 endif
28 ifndef CONFIG_WIN32
29 LIBS=-lm
30 ifndef CONFIG_NOLDL
31 LIBS+=-ldl
32 endif
33 endif
35 ifeq ($(ARCH),i386)
36 NATIVE_DEFINES=-DTCC_TARGET_I386
37 LIBTCC1=libtcc1.a
38 BCHECK_O=bcheck.o
39 ALLOCA_O=alloca86.o alloca86-bt.o
40 else
41 ifeq ($(ARCH),x86-64)
42 NATIVE_DEFINES=-DTCC_TARGET_X86_64
43 NATIVE_DEFINES+=$(if $(wildcard /lib64/ld-linux-x86-64.so.2),-DTCC_TARGET_X86_64_CENTOS)
44 LIBTCC1=libtcc1.a
45 BCHECK_O=
46 ALLOCA_O=alloca86_64.o
47 endif
48 endif
50 ifeq ($(ARCH),arm)
51 NATIVE_DEFINES=-DTCC_TARGET_ARM
52 NATIVE_TARGET=-DWITHOUT_LIBTCC
53 NATIVE_DEFINES+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
54 NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
55 endif
57 ifdef CONFIG_WIN32
58 NATIVE_DEFINES+=-DTCC_TARGET_PE
59 BCHECK_O=
60 endif
62 ifneq ($(wildcard /lib/ld-uClibc.so.0),)
63 NATIVE_DEFINES+=-DTCC_UCLIBC
64 BCHECK_O=
65 endif
67 ifdef CONFIG_USE_LIBGCC
68 LIBTCC1=
69 endif
71 ifeq ($(TOP),.)
73 PROGS=tcc$(EXESUF)
74 I386_CROSS = i386-tcc$(EXESUF)
75 WIN32_CROSS = i386-win32-tcc$(EXESUF)
76 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
77 WINCE_CROSS = arm-win32-tcc$(EXESUF)
78 X64_CROSS = x86_64-tcc$(EXESUF)
79 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
80 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
81 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
82 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
83 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
84 C67_CROSS = c67-tcc$(EXESUF)
86 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
87 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
88 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
89 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
90 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
91 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
92 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
93 ARM_FILES = $(CORE_FILES) arm-gen.c
94 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
96 ifdef CONFIG_WIN32
97 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
98 NATIVE_FILES=$(WIN32_FILES)
99 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
100 else
101 ifeq ($(ARCH),i386)
102 NATIVE_FILES=$(I386_FILES)
103 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
104 else
105 ifeq ($(ARCH),x86-64)
106 NATIVE_FILES=$(X86_64_FILES)
107 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
108 else
109 ifeq ($(ARCH),arm)
110 NATIVE_FILES=$(ARM_FILES)
111 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
112 endif
113 endif
114 endif
115 endif
117 # LIBTCCB decides whether libtcc is installed static or dynamic
118 LIBTCCB=libtcc.a
119 ifdef DISABLE_STATIC
120 CFLAGS+=-fPIC
121 LIBTCCL=-L. -ltcc
122 LIBTCCB=libtcc.so.1.0
123 endif
124 LIBTCCLIBS=$(LIBTCCB)
126 ifdef CONFIG_CROSS
127 PROGS+=$(PROGS_CROSS)
128 # Try to build win32 cross-compiler lib on *nix
129 ifndef CONFIG_WIN32
130 LIBTCCLIBS+=tcc1.def
131 endif
132 endif
134 all: $(PROGS) $(LIBTCC1) $(BCHECK_O) $(LIBTCCLIBS) tcc-doc.html tcc.1 libtcc_test$(EXESUF)
136 # Host Tiny C Compiler
137 tcc$(EXESUF): tcc.o $(LIBTCCB)
138 $(CC) -o $@ $^ $(LIBS) $(LIBTCCL)
140 # Cross Tiny C Compilers
141 %-tcc$(EXESUF):
142 $(CC) -o $@ tcc.c $(DEFINES) $(CFLAGS) $(LIBS)
144 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386
145 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
146 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE
147 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
148 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
149 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
150 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
151 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
152 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
153 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
155 $(I386_CROSS): $(I386_FILES)
156 $(X64_CROSS): $(X86_64_FILES)
157 $(WIN32_CROSS): $(WIN32_FILES)
158 $(WIN64_CROSS): $(WIN64_FILES)
159 $(WINCE_CROSS): $(WINCE_FILES)
160 $(C67_CROSS): $(C67_FILES)
161 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
163 # libtcc generation and test
164 ifdef NOTALLINONE
165 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
166 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
167 $(LIBTCC_OBJ) tcc.o : NATIVE_DEFINES += -DNOTALLINONE
168 else
169 LIBTCC_OBJ = libtcc.o
170 LIBTCC_INC = $(NATIVE_FILES)
171 tcc.o : NATIVE_DEFINES += -DNOTALLINONE
172 endif
174 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
175 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CFLAGS)
177 libtcc.a: $(LIBTCC_OBJ)
178 $(AR) rcs $@ $^
180 libtcc.so.1.0: $(LIBTCC_OBJ)
181 $(CC) -shared -Wl,-soname,$@ -o $@ $^
182 ln -sf libtcc.so.1.0 libtcc.so.1
183 ln -sf libtcc.so.1.0 libtcc.so
185 libtcc_test$(EXESUF): tests/libtcc_test.c $(LIBTCCB)
186 $(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS) $(LIBTCCL)
188 # To build cross-compilers on Linux we must make a fake 32 bit tcc.exe
189 # and use it to build ELF objects into libtcc1.a which is then
190 # renamed to tcc1.def in order to have another target in the Makefile
191 tcc1.def:
192 mv config.mak config.mak.bak
193 mv config.h config.h.bak
194 cp config.h.bak config.h
195 cp config.mak.bak config.mak
196 echo "ARCH=i386" >> config.mak
197 echo "#undef HOST_X86_64" >> config.h
198 echo "#define HOST_I386 1" >> config.h
199 echo "CFLAGS=-O2 -g -pipe -Wall -m32" >> config.mak
200 echo "ARCH=i386" >> config.mak
201 $(MAKE) i386-win32-tcc
202 cp i386-win32-tcc tcc.exe
203 mv libtcc1.a libtcc1.bak
204 $(MAKE) CONFIG_WIN32=1 libtcc1.a
205 mv libtcc1.a lib/tcc1.def
206 mv libtcc1.bak libtcc1.a
207 mv config.mak.bak config.mak
208 mv config.h.bak config.h
210 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
211 ./libtcc_test$(EXESUF) lib_path=.
213 # profiling version
214 tcc_p$(EXESUF): $(NATIVE_FILES)
215 $(CC) -o $@ $< $(NATIVE_DEFINES) $(CFLAGS_P) $(LIBS_P)
217 # windows utilities
218 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
219 $(CC) -o $@ $< $(CFLAGS)
220 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
221 $(CC) -o $@ $< $(CFLAGS)
223 # TinyCC runtime libraries
224 LIBTCC1_OBJS=libtcc1.o $(ALLOCA_O)
225 LIBTCC1_CC=$(CC)
226 VPATH+=lib
228 ifdef CONFIG_WIN32
229 # for windows, we must use TCC because we generate ELF objects
230 LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o
231 LIBTCC1_CC=./tcc.exe -Bwin32 -Iinclude $(NATIVE_DEFINES)
232 VPATH+=win32/lib
233 endif
235 %.o: %.c
236 $(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
237 %.o: %.S
238 $(LIBTCC1_CC) -o $@ -c $<
240 libtcc1.a: $(LIBTCC1_OBJS)
241 $(AR) rcs $@ $^
243 # install
244 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
245 INSTALL=install
247 ifndef CONFIG_WIN32
248 install: $(PROGS) $(LIBTCC1) $(BCHECK_O) $(LIBTCCLIBS) tcc.1 tcc-doc.html
249 mkdir -p "$(bindir)"
250 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
251 mkdir -p "$(mandir)/man1"
252 $(INSTALL) tcc.1 "$(mandir)/man1"
253 mkdir -p "$(tccdir)"
254 mkdir -p "$(tccdir)/include"
255 ifneq ($(LIBTCC1),)
256 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
257 endif
258 ifneq ($(BCHECK_O),)
259 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
260 endif
261 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
262 mkdir -p "$(libdir)"
263 $(INSTALL) -m755 $(LIBTCCB) "$(libdir)"
264 ifdef DISABLE_STATIC
265 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
266 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
267 endif
268 mkdir -p "$(includedir)"
269 $(INSTALL) -m644 libtcc.h "$(includedir)"
270 mkdir -p "$(docdir)"
271 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
272 ifdef CONFIG_CROSS
273 mkdir -p "$(tccdir)/lib"
274 $(INSTALL) -m644 win32/lib/*.def lib/tcc1.def "$(tccdir)/lib"
275 cp -r win32/include/. "$(tccdir)/include"
276 cp -r win32/examples/. "$(tccdir)/examples"
277 endif
279 uninstall:
280 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
281 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
282 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
283 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
284 rm -fv "$(libdir)/$(LIBTCCB)" "$(includedir)/libtcc.h"
285 ifdef DISABLE_STATIC
286 rm -fv "$(libdir)/libtcc.so*"
287 endif
288 ifdef CONFIG_CROSS
289 rm -rf "$(tccdir)/include"
290 rm -rf "$(tccdir)/lib"
291 rm -rf "$(tccdir)/examples"
292 endif
293 else
294 install: $(PROGS) $(LIBTCC1) libtcc.a tcc-doc.html
295 mkdir -p "$(tccdir)"
296 mkdir -p "$(tccdir)/lib"
297 mkdir -p "$(tccdir)/include"
298 mkdir -p "$(tccdir)/examples"
299 mkdir -p "$(tccdir)/doc"
300 mkdir -p "$(tccdir)/libtcc"
301 $(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
302 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
303 cp -r win32/include/. "$(tccdir)/include"
304 cp -r win32/examples/. "$(tccdir)/examples"
305 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
306 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
307 $(INSTALL) -m644 $(LIBTCCB) libtcc.h "$(tccdir)/libtcc"
308 endif
310 # documentation and man page
311 tcc-doc.html: tcc-doc.texi
312 -texi2html -monolithic -number $<
314 tcc.1: tcc-doc.texi
315 -./texi2pod.pl $< tcc.pod
316 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
318 # tar release (use 'make -k tar' on a checkouted tree)
319 TCC-VERSION=tcc-$(shell cat VERSION)
320 tar:
321 rm -rf /tmp/$(TCC-VERSION)
322 cp -r . /tmp/$(TCC-VERSION)
323 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
324 rm -rf /tmp/$(TCC-VERSION)
326 # in tests subdir
327 %est:
328 $(MAKE) -C tests $@
330 clean:
331 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.out *.so* *.exe libtcc_test$(EXESUF) lib/tcc1.def
332 $(MAKE) -C tests $@
334 distclean: clean
335 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.html
337 config.mak:
338 @echo Running configure ...
339 @./configure
341 endif # ifeq ($(TOP),.)