Makefile revision 215126
1# $FreeBSD: head/gnu/lib/libgcc/Makefile 215126 2010-11-11 15:24:57Z ed $
2
3GCCDIR=	${.CURDIR}/../../../contrib/gcc
4GCCLIB=	${.CURDIR}/../../../contrib/gcclibs
5
6LIB=		gcc
7SHLIB_NAME=	libgcc_s.so.1
8SHLIBDIR?=	/lib
9
10.include <bsd.own.mk>
11#
12# libgcc is linked in last and thus cannot depend on ssp symbols coming
13# from earlier libraries. Disable stack protection for this library.
14#
15MK_SSP=	no
16
17.include "${.CURDIR}/../../usr.bin/cc/Makefile.tgt"
18
19.PATH: ${GCCDIR}/config/${GCC_CPU} ${GCCDIR}/config ${GCCDIR}
20
21CFLAGS+=	-DIN_GCC -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED \
22		-DHAVE_GTHR_DEFAULT \
23		-I${GCCLIB}/include \
24		-I${GCCDIR}/config -I${GCCDIR} -I. \
25		-I${.CURDIR}/../../usr.bin/cc/cc_tools
26
27LDFLAGS+=	-nodefaultlibs
28LDADD+=		-lc
29
30OBJS=		# added to below in various ways depending on TARGET_CPUARCH
31
32#---------------------------------------------------------------------------
33#
34# When upgrading GCC, get the following defintions straight from Makefile.in
35#
36# Library members defined in libgcc2.c.
37LIB2FUNCS= _muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3 \
38	_cmpdi2 _ucmpdi2 _clear_cache \
39	_enable_execute_stack _trampoline __main _absvsi2 _absvdi2 _addvsi3 \
40	_addvdi3 _subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors \
41	_ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 _ctzsi2 _ctzdi2 _popcount_tab \
42	_popcountsi2 _popcountdi2 _paritysi2 _paritydi2 _powisf2 _powidf2 \
43	_powixf2 _powitf2 _mulsc3 _muldc3 _mulxc3 _multc3 _divsc3 _divdc3 \
44	_divxc3 _divtc3
45
46# The floating-point conversion routines that involve a single-word integer.
47.for mode in sf df xf
48LIB2FUNCS+= _fixuns${mode}si
49.endfor
50
51# Likewise double-word routines.
52.for mode in sf df xf tf
53LIB2FUNCS+= _fix${mode}di _fixuns${mode}di
54LIB2FUNCS+= _floatdi${mode} _floatundi${mode}
55.endfor
56
57LIB2ADD = $(LIB2FUNCS_EXTRA)
58LIB2ADD_ST = $(LIB2FUNCS_STATIC_EXTRA)
59
60# Additional sources to handle exceptions; overridden by targets as needed.
61LIB2ADDEH = unwind-dw2.c unwind-dw2-fde-glibc.c unwind-sjlj.c gthr-gnat.c \
62	unwind-c.c
63LIB2ADDEHSTATIC = $(LIB2ADDEH)
64LIB2ADDEHSHARED = $(LIB2ADDEH)
65
66# List of extra C and assembler files to add to static and shared libgcc2.
67# Assembler files should have names ending in `.asm'.
68LIB2FUNCS_EXTRA =
69
70# List of extra C and assembler files to add to static libgcc2.
71# Assembler files should have names ending in `.asm'.
72LIB2FUNCS_STATIC_EXTRA =
73
74# Defined in libgcc2.c, included only in the static library.
75# KAN: Excluded _sf_to_tf and _df_to_tf as TPBIT_FUNCS are not
76# built on any of our platforms.
77LIB2FUNCS_ST = _eprintf __gcc_bcmp
78
79FPBIT_FUNCS = _pack_sf _unpack_sf _addsub_sf _mul_sf _div_sf \
80    _fpcmp_parts_sf _compare_sf _eq_sf _ne_sf _gt_sf _ge_sf \
81    _lt_sf _le_sf _unord_sf _si_to_sf _sf_to_si _negate_sf _make_sf \
82    _sf_to_df _thenan_sf _sf_to_usi _usi_to_sf
83
84DPBIT_FUNCS = _pack_df _unpack_df _addsub_df _mul_df _div_df \
85    _fpcmp_parts_df _compare_df _eq_df _ne_df _gt_df _ge_df \
86    _lt_df _le_df _unord_df _si_to_df _df_to_si _negate_df _make_df \
87    _df_to_sf _thenan_df _df_to_usi _usi_to_df
88
89TPBIT_FUNCS = _pack_tf _unpack_tf _addsub_tf _mul_tf _div_tf \
90    _fpcmp_parts_tf _compare_tf _eq_tf _ne_tf _gt_tf _ge_tf \
91    _lt_tf _le_tf _unord_tf _si_to_tf _tf_to_si _negate_tf _make_tf \
92    _tf_to_df _tf_to_sf _thenan_tf _tf_to_usi _usi_to_tf
93
94# These might cause a divide overflow trap and so are compiled with
95# unwinder info.
96LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _udivdi3 _umoddi3 _udiv_w_sdiv _udivmoddi4
97
98#-----------------------------------------------------------------------
99#
100#	Platform specific bits.
101#	When upgrading GCC, get the following definitions from config/<cpu>/t-*
102#
103.if ${TARGET_CPUARCH} == "arm"
104#	from config/arm/t-strongarm-elf
105CFLAGS+=	-Dinhibit_libc -fno-inline
106LIB1ASMSRC =	lib1funcs.asm
107LIB1ASMFUNCS =  _dvmd_tls _bb_init_func
108LIB2FUNCS_EXTRA = floatunsidf.c floatunsisf.c
109
110# Not now
111#LIB1ASMFUNCS =  _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_tls _bb_init_func
112#LIB1ASMFUNCS+=	_call_via_rX _interwork_call_via_rX \
113#	_lshrdi3 _ashrdi3 _ashldi3 \
114#	_negdf2 _addsubdf3 _muldivdf3 _cmpdf2 _unorddf2 _fixdfsi _fixunsdfsi \
115#	_truncdfsf2 _negsf2 _addsubsf3 _muldivsf3 _cmpsf2 _unordsf2 \
116#	_fixsfsi _fixunssfsi _floatdidf _floatdisf
117.endif
118
119.if ${TARGET_CPUARCH} == "mips"
120LIB2FUNCS_EXTRA = floatunsidf.c floatunsisf.c
121.if defined(TARGET_ABI) && ${TARGET_ABI} != "o32"
122LIB2FUNCS_EXTRA+= floatdidf.c fixunsdfsi.c
123LIB2FUNCS_EXTRA+= floatdisf.c floatundidf.c
124LIB2FUNCS_EXTRA+= fixsfdi.c floatundisf.c
125LIB2FUNCS_EXTRA+= fixdfdi.c fixunssfsi.c
126.endif
127.endif
128
129.if ${TARGET_CPUARCH} == "ia64"
130#	from config/ia64/t-ia64
131LIB1ASMSRC   = lib1funcs.asm
132LIB1ASMFUNCS = __divxf3 __divdf3 __divsf3 \
133	__divdi3 __moddi3 __udivdi3 __umoddi3 \
134	__divsi3 __modsi3 __udivsi3 __umodsi3 __save_stack_nonlocal \
135	__nonlocal_goto __restore_stack_nonlocal __trampoline \
136	_fixtfdi _fixunstfdi _floatditf
137LIB2ADDEH = unwind-ia64.c unwind-sjlj.c unwind-c.c
138.endif
139
140.if ${TARGET_CPUARCH} == "powerpc"
141#	from config/rs6000/t-ppccomm
142LIB2FUNCS_EXTRA = tramp.asm
143LIB2FUNCS_STATIC_EXTRA = eabi.asm
144.endif
145
146.if ${TARGET_CPUARCH} == "powerpc64"
147#	from config/rs6000/t-ppccomm
148LIB2FUNCS_EXTRA = tramp.asm
149.endif
150
151.if ${TARGET_CPUARCH} == "sparc64"
152#	from config/sparc/t-elf
153LIB1ASMSRC =   lb1spc.asm
154LIB1ASMFUNCS = _mulsi3 _divsi3 _modsi3
155.endif
156
157#-----------------------------------------------------------------------
158
159# Remove any objects from LIB2FUNCS and LIB2_DIVMOD_FUNCS that are
160# defined as optimized assembly code in LIB1ASMFUNCS.
161.if defined(LIB1ASMFUNCS)
162.for sym in ${LIB1ASMFUNCS}
163LIB2FUNCS:=	${LIB2FUNCS:S/${sym}//g}
164LIB2_DIVMOD_FUNCS:= ${LIB2_DIVMOD_FUNCS:S/${sym}//g}
165.endfor
166.endif
167
168COMMONHDRS=	tm.h tconfig.h options.h unwind.h gthr-default.h
169
170#-----------------------------------------------------------------------
171#
172# Helpful shortcuts for compiler invocations.
173#
174HIDE =  -fvisibility=hidden -DHIDE_EXPORTS
175CC_T =	${CC} -c ${CFLAGS} ${HIDE} -fPIC
176CC_P =	${CC} -c ${CFLAGS} ${HIDE} -p -fPIC
177CC_S =	${CC} -c ${CFLAGS} ${PICFLAG} -DSHARED
178
179#-----------------------------------------------------------------------
180#
181# Functions from libgcc2.c
182#
183STD_CFLAGS =
184DIV_CFLAGS =	-fexceptions -fnon-call-exceptions
185
186STD_FUNCS =	${LIB2FUNCS}
187DIV_FUNCS =	${LIB2_DIVMOD_FUNCS}
188
189STD_CFILE =	libgcc2.c
190DIV_CFILE =	libgcc2.c
191
192OBJ_GRPS =	STD DIV
193
194#-----------------------------------------------------------------------
195#
196# Floating point emulation functions
197#
198.if ${TARGET_CPUARCH} == "armNOT_YET" || \
199    ${TARGET_CPUARCH} == "powerpc" || ${TARGET_CPUARCH} == "sparc64"
200
201FPBIT_CFLAGS =	-DFINE_GRAINED_LIBRARIES -DFLOAT
202DPBIT_CFLAGS =	-DFINE_GRAINED_LIBRARIES
203
204FPBIT_CFILE =	config/fp-bit.c
205DPBIT_CFILE =	config/fp-bit.c
206
207OBJ_GRPS +=	FPBIT DPBIT
208.endif
209
210#-----------------------------------------------------------------------
211#
212# Generic build rules for object groups defined above
213#
214.for T in ${OBJ_GRPS}
215${T}_OBJS_T =	${${T}_FUNCS:S/$/.o/}
216${T}_OBJS_P =	${${T}_FUNCS:S/$/.po/}
217${T}_OBJS_S =	${${T}_FUNCS:S/$/.So/}
218OBJS +=		${${T}_FUNCS:S/$/.o/}
219
220${${T}_OBJS_T}: ${${T}_CFILE} ${COMMONHDRS}
221	${CC_T} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
222${${T}_OBJS_P}: ${${T}_CFILE} ${COMMONHDRS}
223	${CC_P} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
224${${T}_OBJS_S}: ${${T}_CFILE} ${COMMONHDRS}
225	${CC_S} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
226.endfor
227
228#-----------------------------------------------------------------------
229#
230# Extra objects coming from separate files
231#
232.if !empty(LIB2ADD)
233OBJS  +=	${LIB2ADD:R:S/$/.o/}
234SOBJS +=	${LIB2ADD:R:S/$/.So/}
235POBJS +=	${LIB2ADD:R:S/$/.po/}
236.endif
237
238#-----------------------------------------------------------------------
239#
240# Objects that should be in static library only.
241#
242SYMS_ST =	${LIB2FUNCS_ST}	${LIB2ADD_ST}
243STAT_OBJS_T = 	${SYMS_ST:S/$/.o/}
244STAT_OBJS_P = 	${SYMS_ST:S/$/.po/}
245STATICOBJS  =	${SYMS_ST:S/$/.o/}
246
247${STAT_OBJS_T}:	${STD_CFILE} ${COMMONHDRS}
248	${CC_T} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
249${STAT_OBJS_P}:	${STD_CFILE} ${COMMONHDRS}
250	${CC_P} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
251
252#-----------------------------------------------------------------------
253#
254# Assembler files.
255#
256.if defined(LIB1ASMSRC)
257ASM_T =		${LIB1ASMFUNCS:S/$/.o/}
258ASM_P =		${LIB1ASMFUNCS:S/$/.po/}
259ASM_S =		${LIB1ASMFUNCS:S/$/.So/}
260ASM_V =		${LIB1ASMFUNCS:S/$/.vis/}
261OBJS +=		${LIB1ASMFUNCS:S/$/.o/}
262
263${ASM_T}: ${LIB1ASMSRC} ${.PREFIX}.vis
264	${CC} -x assembler-with-cpp -c ${CFLAGS} -DL${.PREFIX} \
265	    -o ${.TARGET} -include ${.PREFIX}.vis ${.ALLSRC:N*.h:N*.vis}
266${ASM_P}: ${LIB1ASMSRC} ${.PREFIX}.vis
267	${CC} -x assembler-with-cpp -p -c ${CFLAGS} -DL${.PREFIX} \
268	    -o ${.TARGET} -include ${.PREFIX}.vis ${.ALLSRC:N*.h:N*.vis}
269${ASM_S}: ${LIB1ASMSRC}
270	${CC} -x assembler-with-cpp -c ${PICFLAG} ${CFLAGS} -DL${.PREFIX} \
271	    -o ${.TARGET} ${.ALLSRC:N*.h}
272${ASM_V}: ${LIB1ASMSRC}
273	${CC} -x assembler-with-cpp -c ${CFLAGS} -DL${.PREFIX} \
274	    -o ${.PREFIX}.vo ${.ALLSRC:N*.h}
275	( nm -pg ${.PREFIX}.vo | \
276		awk 'NF == 3 && $$2 !~ /^[UN]$$/ { print "\t.hidden ", $$3 }'\
277	) > ${.TARGET}
278
279CLEANFILES += ${ASM_V} ${ASM_V:R:S/$/.vo/}
280.endif
281
282#-----------------------------------------------------------------------
283#
284# Exception handling / unwinding support.
285#
286EH_OBJS_T = ${LIB2ADDEHSTATIC:R:S/$/.o/}
287EH_OBJS_P = ${LIB2ADDEHSTATIC:R:S/$/.po/}
288EH_OBJS_S = ${LIB2ADDEHSHARED:R:S/$/.So/}
289EH_CFLAGS = -fexceptions -D__GLIBC__=3 -DElfW=__ElfN
290SOBJS    += ${EH_OBJS_S}
291
292.for _src in ${LIB2ADDEHSTATIC}
293${_src:R:S/$/.o/}: ${_src} ${COMMONHDRS}
294	${CC_T} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
295${_src:R:S/$/.po/}: ${_src} ${COMMONHDRS}
296	${CC_P} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
297.endfor
298.for _src in ${LIB2ADDEHSHARED}
299${_src:R:S/$/.So/}: ${_src} ${COMMONHDRS}
300	${CC_S} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
301.endfor
302
303
304#-----------------------------------------------------------------------
305#
306# Generated headers
307#
308${COMMONHDRS}: ${.CURDIR}/../../usr.bin/cc/cc_tools/Makefile
309	${MAKE} -f ${.ALLSRC} MFILE=${.ALLSRC} GCCDIR=${GCCDIR} ${.TARGET}
310
311CLEANFILES += ${COMMONHDRS}
312CLEANFILES += cs-*.h option*
313
314#-----------------------------------------------------------------------
315#
316# Build symbol version map
317#
318SHLIB_MKMAP      = ${GCCDIR}/mkmap-symver.awk
319SHLIB_MKMAP_OPTS =
320SHLIB_MAPFILES   = ${GCCDIR}/libgcc-std.ver
321VERSION_MAP      = libgcc.map
322
323libgcc.map: ${SHLIB_MKMAP} ${SHLIB_MAPFILES} ${SOBJS} ${OBJS:R:S/$/.So/}
324	(  nm -pg ${SOBJS};echo %% ; \
325	  cat ${SHLIB_MAPFILES} \
326	    | sed -e '/^[   ]*#/d' \
327	          -e 's/^%\(if\|else\|elif\|endif\|define\)/#\1/' \
328	    | ${CC} ${CFLAGS} -E -xassembler-with-cpp -; \
329	) | awk -f ${SHLIB_MKMAP} ${SHLIB_MKMAP_OPTS} > ${.TARGET}
330
331CLEANFILES +=	libgcc.map
332
333#-----------------------------------------------------------------------
334#
335# Build additional static libgcc_eh[_p].a libraries.
336#
337libgcc_eh.a:	${EH_OBJS_T}
338	@${ECHO} building static gcc_eh library
339	@rm -f ${.TARGET}
340	@${AR} cq ${.TARGET} `lorder ${EH_OBJS_T} | tsort -q`
341	${RANLIB} ${.TARGET}
342
343all:	libgcc_eh.a
344
345.if ${MK_PROFILE} != "no"
346libgcc_eh_p.a:	${EH_OBJS_P}
347	@${ECHO} building profiled gcc_eh library
348	@rm -f ${.TARGET}
349	@${AR} cq ${.TARGET} `lorder ${EH_OBJS_P} | tsort -q`
350	${RANLIB} ${.TARGET}
351all:	libgcc_eh_p.a
352.endif
353
354_libinstall: _lib-eh-install
355
356_lib-eh-install:
357.if ${MK_INSTALLLIB} != "no"
358	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
359		${_INSTALLFLAGS} libgcc_eh.a ${DESTDIR}${LIBDIR}
360.endif
361.if ${MK_PROFILE} != "no"
362	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
363		${_INSTALLFLAGS} libgcc_eh_p.a ${DESTDIR}${LIBDIR}
364.endif
365
366CLEANFILES+=	libgcc_eh.a libgcc_eh_p.a ${EH_OBJS_T} ${EH_OBJS_P}
367
368.include <bsd.lib.mk>
369
370.SUFFIXES: .vis .vo
371