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