xref: /freebsd-12.1/gnu/lib/libgcc/Makefile (revision 00a91cb7)
1# $FreeBSD$
2
3.include "${.CURDIR}/../../usr.bin/cc/Makefile.tgt"
4
5GCCDIR=	${.CURDIR}/../../../contrib/gcc
6.PATH: ${GCCDIR}/config/${GCC_CPU} ${GCCDIR}
7
8# allow to be overridden for the a.out case
9.if !defined(LIB) || ${LIB} != "gcc_r"
10LIB=	gcc
11.endif
12
13#SHLIB_MAJOR=	1
14
15#
16# XXX This is a hack, but it seems to work.
17# libgcc2.a is meant to be compiled by *this* version of gcc.
18#
19# Normally, this does not make any difference, since we only have gcc, but
20# when bootstrapping from gcc-2.6.3, we have to use the freshly built 2.7.2
21# compiler for some of the libgcc2.c __attribute__ stuff.
22#
23# We now depend on a bootstrap pass (normally in `make world') to build
24# and install the new version of gcc before we get here.  This makes
25# finding the new version (XCC) easy but may break finding the old version
26# (CC).
27#
28XCC=	${CC}
29XCXX=	${CXX}
30
31CFLAGS+=	-fexceptions
32CFLAGS+=	-DIN_GCC -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED \
33		-DFINE_GRAINED_LIBRARIES
34CFLAGS+=	-D_PTHREADS -DGTHREAD_USE_WEAK
35CFLAGS+=	-I${.CURDIR}/../../usr.bin/cc/cc_tools \
36		-I${GCCDIR}/config -I${GCCDIR} -I.
37LDFLAGS=	-nostdlib
38
39OBJS=		# added to below in various ways depending on TARGET_ARCH
40
41#---------------------------------------------------------------------------
42#
43# When upgrading GCC, get the following defintions straight from Makefile.in
44#
45
46# Library members defined in libgcc2.c.
47# Variable length limited to 255 charactes when passed to a shell script.
48LIB2FUNCS_1 = _muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3 _ffsdi2 _clz \
49    _cmpdi2 _ucmpdi2 _floatdidf _floatdisf _fixunsdfsi _fixunssfsi \
50    _fixunsdfdi _fixdfdi _fixunssfdi _fixsfdi _fixxfdi _fixunsxfdi
51
52LIB2FUNCS_2 = _floatdixf _fixunsxfsi _fixtfdi _fixunstfdi _floatditf \
53    _clear_cache _trampoline __main _exit _absvsi2 _absvdi2 _addvsi3 \
54    _addvdi3 _subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors
55
56# Defined in libgcc2.c, included only in the static library.
57LIB2FUNCS_ST = _eprintf _bb __gcc_bcmp
58
59FPBIT_FUNCS = _pack_sf _unpack_sf _addsub_sf _mul_sf _div_sf \
60    _fpcmp_parts_sf _compare_sf _eq_sf _ne_sf _gt_sf _ge_sf \
61    _lt_sf _le_sf _unord_sf _si_to_sf _sf_to_si _negate_sf _make_sf \
62    _sf_to_df _thenan_sf _sf_to_usi _usi_to_sf
63
64DPBIT_FUNCS = _pack_df _unpack_df _addsub_df _mul_df _div_df \
65    _fpcmp_parts_df _compare_df _eq_df _ne_df _gt_df _ge_df \
66    _lt_df _le_df _unord_df _si_to_df _df_to_si _negate_df _make_df \
67    _df_to_sf _thenan_df _df_to_usi _usi_to_df
68
69# These might cause a divide overflow trap and so are compiled with
70# unwinder info.
71LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _udivdi3 _umoddi3 _udiv_w_sdiv _udivmoddi4
72
73MACHMODE_H = machmode.h machmode.def
74
75LIB2ADD = $(LIB2FUNCS_EXTRA)
76LIB2ADD_ST = $(LIB2FUNCS_STATIC_EXTRA)
77
78# Additional sources to handle exceptions; overridden on ia64.
79LIB2ADDEH = unwind-dw2.c unwind-dw2-fde.c unwind-sjlj.c
80
81#-----------------------------------------------------------------------
82#
83#	Platform specific bits.
84#	When upgrading GCC, get the following defintions from config/<cpu>/t-*
85#
86
87.if ${TARGET_ARCH} == "alpha"
88#	from config/alpha/t-alpha
89LIB2FUNCS_EXTRA = qrnnd.asm
90.endif
91
92.if ${TARGET_ARCH} == "arm"
93#	from config/arm/t-strongarm-elf
94LIB1ASMSRC = lib1funcs.asm
95LIB1ASMFUNCS = _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_tls _bb_init_func
96# We want fine grained libraries, so use the new code to build the
97# floating point emulation libraries.
98XXX fix this: NEED_FP_EMULATION set to "yes" with different rules per platform
99.endif
100
101.if ${TARGET_ARCH} == "ia64"
102#	from config/ia64/t-ia64
103LIB1ASMSRC    = lib1funcs.asm
104LIB1ASMFUNCS  = __divtf3 __divdf3 __divsf3 \
105	__divdi3 __moddi3 __udivdi3 __umoddi3 \
106	__divsi3 __modsi3 __udivsi3 __umodsi3 __save_stack_nonlocal \
107	__nonlocal_goto __restore_stack_nonlocal __trampoline
108LIB2ADDEH = unwind-ia64.c unwind-sjlj.c
109.endif
110
111.if ${TARGET_ARCH} == "powerpc"
112#	from config/rs6000/t-ppccomm
113LIB2FUNCS_EXTRA = tramp.asm
114# This one can't end up in shared libgcc
115LIB2FUNCS_STATIC_EXTRA = eabi.asm
116# We want fine grained libraries, so use the new code to build the
117# floating point emulation libraries.
118OBJS+=	dp-bit.o fp-bit.o
119.endif
120
121.if ${TARGET_ARCH} == "sparc64"
122#	from config/sparc/t-elf
123# We want fine grained libraries, so use the new code to build the
124# floating point emulation libraries.
125LIB1ASMSRC = lb1spc.asm
126LIB1ASMFUNCS = _mulsi3 _divsi3 _modsi3
127OBJS+=	dp-bit.o fp-bit.o
128.endif
129
130dp-bit.o: config/fp-bit.c
131	${XCC} -c ${CFLAGS} -o ${.TARGET} ${.ALLSRC:M*fp-bit*}
132
133dp-bit.So: config/fp-bit.c
134	${XCC} ${PICFLAG} -c ${CFLAGS} -o ${.TARGET} ${.ALLSRC:M*fp-bit*}
135
136dp-bit.po: config/fp-bit.c
137	${XCC} -p -c ${CFLAGS} -o ${.TARGET} ${.ALLSRC:M*fp-bit*}
138
139fp-bit.o: config/fp-bit.c
140	${XCC} -DFLOAT=1 -c ${CFLAGS} -o ${.TARGET} ${.ALLSRC:M*fp-bit*}
141
142fp-bit.So: config/fp-bit.c
143	${XCC} ${PICFLAG} -DFLOAT=1 -c ${CFLAGS} -o ${.TARGET} ${.ALLSRC:M*fp-bit*}
144
145fp-bit.po: config/fp-bit.c
146	${XCC} -p -DFLOAT=1 -c ${CFLAGS} -o ${.TARGET} ${.ALLSRC:M*fp-bit*}
147
148#-----------------------------------------------------------------------
149
150# Remove any objects from LIB2FUNCS and LIB2_DIVMOD_FUNCS that are
151# defined as optimized assembly code in LIB1ASMFUNCS.
152.if defined(LIB1ASMFUNCS)
153.for sym in ${LIB1ASMFUNCS}
154LIB2FUNCS_1:=	${LIB2FUNCS_1:S/${sym}//g}
155LIB2FUNCS_2:=	${LIB2FUNCS_2:S/${sym}//g}
156LIB2_DIVMOD_FUNCS:= ${LIB2_DIVMOD_FUNCS:S/${sym}//g}
157.endfor
158.endif
159
160ASM_T=		${LIB1ASMFUNCS:S/$/.o/}
161ASM_P=		${LIB1ASMFUNCS:S/$/.po/}
162ASM_S=		${LIB1ASMFUNCS:S/$/.So/}
163
164SYMS=		${LIB2FUNCS_1}		\
165		${LIB2FUNCS_2}		\
166		${LIB2_DIVMOD_FUNCS}
167.if ${TARGET_ARCH} == "arm" || ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "sparc64"
168SYMS+=		${FPBIT_FUNCS} ${DPBIT_FUNCS}
169.endif
170SYMS_ST=	${LIB2FUNCS_ST}		\
171		${LIB2ADD_ST}
172OBJS+=		${SYMS:S/$/.o/} ${LIB1ASMFUNCS:S/$/.o/}
173OBJS_T=		${SYMS:S/$/.o/}  ${SYMS_ST:S/$/.o/}
174OBJS_P=		${SYMS:S/$/.po/} ${SYMS_ST:S/$/.po/}
175OBJS_S=		${SYMS:S/$/.So/}
176STATICOBJS=	${SYMS_ST:S/$/.o/}
177SRCS=		${LIB2ADD} ${LIB2ADDEH}
178
179COMMONHDRS=	tconfig.h
180SRCS+=		${COMMONHDRS}
181CLEANFILES+=	${COMMONHDRS}
182
183tconfig.h: ${.CURDIR}/../../usr.bin/cc/cc_tools/Makefile
184	${MAKE} -f ${.ALLSRC} MFILE=${.ALLSRC} GCCDIR=${GCCDIR} ${.TARGET}
185
186${OBJS} beforedepend: ${COMMONHDRS}
187
188${OBJS_T}: libgcc2.c
189	${XCC} -c ${CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
190	@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
191	@mv ${.TARGET}.tmp ${.TARGET}
192
193.if !defined(NOPIC)
194${OBJS_S}: libgcc2.c
195	${XCC} -c ${PICFLAG} ${CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
196	@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
197	@mv ${.TARGET}.tmp ${.TARGET}
198.endif
199
200.if !defined(NOPROFILE)
201${OBJS_P}: libgcc2.c
202	${XCC} -c -p ${CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
203	@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
204	@mv ${.TARGET}.tmp ${.TARGET}
205.endif
206
207.if defined(LIB1ASMSRC)
208.for _lib1asmsrc in ${LIB1ASMSRC}
209${ASM_T}: ${_lib1asmsrc}
210	${XCC} -x assembler-with-cpp -c ${CFLAGS} -DL${.PREFIX} \
211	    -o ${.TARGET} ${.ALLSRC:N*.h}
212	@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
213	@mv ${.TARGET}.tmp ${.TARGET}
214
215.if !defined(NOPIC)
216${ASM_S}: ${_lib1asmsrc}
217	${XCC} -x assembler-with-cpp -c ${PICFLAG} ${CFLAGS} -DL${.PREFIX} \
218	    -o ${.TARGET} ${.ALLSRC:N*.h}
219	@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
220	@mv ${.TARGET}.tmp ${.TARGET}
221.endif
222
223.if !defined(NOPROFILE)
224${ASM_P}: ${_lib1asmsrc}
225	${XCC} -x assembler-with-cpp -p -c ${CFLAGS} -DL${.PREFIX} \
226	    -o ${.TARGET} ${.ALLSRC:N*.h}
227	@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
228	@mv ${.TARGET}.tmp ${.TARGET}
229.endif
230.endfor
231.endif
232
233.include <bsd.lib.mk>
234