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