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