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