xref: /openbsd/gnu/usr.bin/cc/libgcc/Makefile (revision 264ca280)
1# $FreeBSD: src/gnu/lib/libgcc/Makefile,v 1.58.8.1 2009/04/15 03:14:26 kensmith Exp $
2# $OpenBSD: Makefile,v 1.27 2015/12/18 16:44:03 visa Exp $
3
4.include <bsd.own.mk>
5
6GCCLIB= ${.CURDIR}/../../../gcc
7GCCDIR= ${GCCLIB}/gcc
8
9.include "../Makefile.tgt"
10
11.if defined(CROSSDIR)
12LD=${CROSSDIR}/usr/${GCC_TARGET}/bin/ld
13RANLIB=${CROSSDIR}/usr/${GCC_TARGET}/bin/ranlib
14.endif
15
16.if defined(CROSS_TARGET)
17#Building cc for target, CC should already be the cross compiler
18.elif ${.OBJDIR} != ${.CURDIR}
19CC=${.OBJDIR}/../cc/cc -B ${.OBJDIR}/../cc1
20.else
21CC=${.CURDIR}/../cc/cc -B ${.CURDIR}/../cc1
22.endif
23
24.include "${.CURDIR}/../Makefile.ver"
25
26LIB=		gcc
27LIBDIR=		/usr/lib/gcc-lib/${GCC_TARGET}/${BASEVER}
28
29NOPROFILE=	Yes
30NOPIC=		Yes
31
32.include "${.CURDIR}/../Makefile.tgt"
33
34.PATH: ${GCCDIR}/config/${GCC_CPU} ${GCCDIR}/config ${GCCDIR}
35
36CFLAGS+=	-DIN_GCC -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED \
37		-DHAVE_GTHR_DEFAULT \
38		-I${GCCLIB}/include \
39		-I${GCCDIR}/config -I${GCCDIR} -I. \
40		-I${.CURDIR}/../cc_tools \
41		-fno-stack-protector
42
43LDFLAGS+=	-nodefaultlibs
44LDADD+=		-lc
45
46OBJS=		# added to below in various ways depending on TARGET_ARCH
47
48#---------------------------------------------------------------------------
49#
50# When upgrading GCC, get the following defintions straight from Makefile.in
51#
52# Library members defined in libgcc2.c.
53LIB2FUNCS= _muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3 \
54	_cmpdi2 _ucmpdi2 _clear_cache \
55	_enable_execute_stack _trampoline __main _absvsi2 _absvdi2 _addvsi3 \
56	_addvdi3 _subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors \
57	_ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 _ctzsi2 _ctzdi2 _popcount_tab \
58	_popcountsi2 _popcountdi2 _paritysi2 _paritydi2 _powisf2 _powidf2 \
59	_powixf2 _powitf2 _mulsc3 _muldc3 _mulxc3 _multc3 _divsc3 _divdc3 \
60	_divxc3 _divtc3
61
62# The floating-point conversion routines that involve a single-word integer.
63.for mode in sf df xf
64SWFLOATFUNCS+= _fixuns${mode}si
65.endfor
66
67# Likewise double-word routines.
68.for mode in sf df xf tf
69DWFLOATFUNCS+= _fix${mode}di _fixuns${mode}di
70DWFLOATFUNCS+= _floatdi${mode} _floatundi${mode}
71.endfor
72
73LIB2ADD = $(LIB2FUNCS_EXTRA)
74LIB2ADD_ST = $(LIB2FUNCS_STATIC_EXTRA)
75
76# Additional sources to handle exceptions; overridden by targets as needed.
77LIB2ADDEH = unwind-dw2.c unwind-sjlj.c gthr-gnat.c \
78	unwind-c.c unwind-dw2-fde-openbsd.c
79LIB2ADDEHSTATIC = $(LIB2ADDEH)
80LIB2ADDEHSHARED = $(LIB2ADDEH)
81
82# List of extra C and assembler files to add to static and shared libgcc2.
83# Assembler files should have names ending in `.asm'.
84LIB2FUNCS_EXTRA =
85
86# List of extra C and assembler files to add to static libgcc2.
87# Assembler files should have names ending in `.asm'.
88LIB2FUNCS_STATIC_EXTRA =
89
90# Defined in libgcc2.c, included only in the static library.
91LIB2FUNCS_ST = _eprintf __gcc_bcmp
92
93FPBIT_FUNCS = _pack_sf _unpack_sf _addsub_sf _mul_sf _div_sf \
94    _fpcmp_parts_sf _compare_sf _eq_sf _ne_sf _gt_sf _ge_sf \
95    _lt_sf _le_sf _unord_sf _si_to_sf _sf_to_si _negate_sf _make_sf \
96    _sf_to_df _sf_to_tf _thenan_sf _sf_to_usi _usi_to_sf _sf_to_tf
97
98DPBIT_FUNCS = _pack_df _unpack_df _addsub_df _mul_df _div_df \
99    _fpcmp_parts_df _compare_df _eq_df _ne_df _gt_df _ge_df \
100    _lt_df _le_df _unord_df _si_to_df _df_to_si _negate_df _make_df \
101    _df_to_sf _df_to_tf _thenan_df _df_to_usi _usi_to_df
102
103TPBIT_FUNCS = _pack_tf _unpack_tf _addsub_tf _mul_tf _div_tf \
104    _fpcmp_parts_tf _compare_tf _eq_tf _ne_tf _gt_tf _ge_tf \
105    _lt_tf _le_tf _unord_tf _si_to_tf _tf_to_si _negate_tf _make_tf \
106    _tf_to_df _tf_to_sf _thenan_tf _tf_to_usi _usi_to_tf
107
108# These might cause a divide overflow trap and so are compiled with
109# unwinder info.
110LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _udivdi3 _umoddi3 _udiv_w_sdiv _udivmoddi4
111
112#-----------------------------------------------------------------------
113#
114#	Platform specific bits.
115#	When upgrading GCC, get the following definitions from config/<cpu>/t-*
116#
117.if ${TARGET_ARCH} == "alpha"
118CFLAGS+=	-mieee
119LIB2FUNCS_EXTRA = qrnnd.asm
120.endif
121
122.if ${TARGET_ARCH} == "arm"
123#	from config/arm/t-strongarm-elf
124CFLAGS+=	-Dinhibit_libc -fno-inline
125LIB1ASMSRC =	lib1funcs.asm
126LIB1ASMFUNCS =  _dvmd_tls _bb_init_func
127LIB2FUNCS_EXTRA = floatunsidf.c floatunsisf.c
128
129# Not now
130#LIB1ASMFUNCS =  _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_tls _bb_init_func
131#LIB1ASMFUNCS+=	_call_via_rX _interwork_call_via_rX \
132#	_lshrdi3 _ashrdi3 _ashldi3 \
133#	_negdf2 _addsubdf3 _muldivdf3 _cmpdf2 _unorddf2 _fixdfsi _fixunsdfsi \
134#	_truncdfsf2 _negsf2 _addsubsf3 _muldivsf3 _cmpsf2 _unordsf2 \
135#	_fixsfsi _fixunssfsi _floatdidf _floatdisf
136.endif
137
138.if ${TARGET_ARCH} == "hppa"
139CFLAGS+=	-fPIC -DELF=1 -DLINUX=1
140LIB1ASMFUNCS =	_divI _divU _remI _remU _div_const _mulI _dyncall
141LIB1ASMSRC =	pa/milli64.S
142LIB2FUNCS_EXTRA = fptr.c
143.endif
144
145.if ${TARGET_ARCH} == "hppa64"
146CFLAGS+=	-fPIC -Dpa64=1 -DELF=1
147LIB1ASMFUNCS =	_divI _divU _remI _remU _div_const _mulI
148LIB1ASMSRC =	pa/milli64.S
149LIB2FUNCS_EXTRA = fptr.c
150.endif
151
152.if ${TARGET_ARCH} == "ia64"
153LIB1ASMSRC =	ia64/lib1funcs.asm
154LIB1ASMFUNCS =	__divxf3 __divdf3 __divsf3 \
155	__divdi3 __moddi3 __udivdi3 __umoddi3 \
156	__divsi3 __modsi3 __udivsi3 __umodsi3 __save_stack_nonlocal \
157	__nonlocal_goto __restore_stack_nonlocal __trampoline \
158	_fixtfdi _fixunstfdi _floatditf
159LIB2ADDEH = unwind-ia64.c unwind-sjlj.c unwind-c.c
160.endif
161
162.if ${TARGET_ARCH} == "mips64" || ${TARGET_ARCH} == "mips64el"
163LIB2FUNCS_EXTRA = sync.S
164.endif
165
166.if ${TARGET_ARCH} == "sh"
167CFLAGS+=	-fpic -DNO_FPSCR_VALUES
168LIB1ASMSRC = sh/lib1funcs.asm
169LIB1ASMFUNCS = _ashiftrt _ashiftrt_n _ashiftlt _lshiftrt _movmem \
170  _movmem_i4 _mulsi3 _sdivsi3 _sdivsi3_i4 _udivsi3 _udivsi3_i4 _set_fpscr \
171  _udiv_qrnnd_16 _ic_invalidate _ic_invalidate_array
172.endif
173
174.if ${TARGET_ARCH} == "powerpc"
175#	from config/rs6000/t-ppccomm
176LIB2FUNCS_EXTRA = tramp.asm darwin-ldouble.c
177LIB2FUNCS_STATIC_EXTRA = eabi.asm
178.endif
179
180#-----------------------------------------------------------------------
181
182# Remove any objects from LIB2FUNCS and LIB2_DIVMOD_FUNCS that are
183# defined as optimized assembly code in LIB1ASMFUNCS.
184.if defined(LIB1ASMFUNCS)
185.for sym in ${LIB1ASMFUNCS}
186LIB2FUNCS:=	${LIB2FUNCS:S/${sym}//g}
187LIB2_DIVMOD_FUNCS:= ${LIB2_DIVMOD_FUNCS:S/${sym}//g}
188.endfor
189.endif
190
191COMMONHDRS=	tm.h tconfig.h options.h unwind.h gthr-default.h
192
193#-----------------------------------------------------------------------
194#
195# Helpful shortcuts for compiler invocations.
196#
197#HIDE =  -fvisibility=hidden -DHIDE_EXPORTS
198CC_T =	${CC} -c ${CFLAGS} ${HIDE} -fPIC
199CC_P =	${CC} -c ${CFLAGS} ${HIDE} -p -fPIC
200CC_S =	${CC} -c ${CFLAGS} ${PICFLAG} -DSHARED
201
202#-----------------------------------------------------------------------
203#
204# Functions from libgcc2.c
205#
206STD_CFLAGS =
207DIV_CFLAGS =	-fexceptions -fnon-call-exceptions
208SW_CFLAGS =
209DW_CFLAGS =
210
211STD_FUNCS =	${LIB2FUNCS}
212DIV_FUNCS =	${LIB2_DIVMOD_FUNCS}
213SI_FUNCS =	${SWFLOATFUNCS}
214DI_FUNCS =	${DWFLOATFUNCS}
215
216STD_CFILE =	libgcc2.c
217DIV_CFILE =	libgcc2.c
218SI_CFILE =	libgcc2.c
219DI_CFILE =	libgcc2.c
220
221OBJ_GRPS =	STD DIV SI DI
222
223#-----------------------------------------------------------------------
224#
225# Floating point emulation functions
226#
227.if ${TARGET_ARCH} == "armNOT_YET" || ${TARGET_ARCH} == "m88k" || \
228    ${TARGET_ARCH} == "mips64" || ${TARGET_ARCH} == "mips64el" || \
229    ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "sparc" || \
230    ${TARGET_ARCH} == "sparc64"
231
232FPBIT_CFLAGS =	-DFINE_GRAINED_LIBRARIES -DFLOAT
233DPBIT_CFLAGS =	-DFINE_GRAINED_LIBRARIES
234
235.if ${TARGET_ARCH} == "mips64" || ${TARGET_ARCH} == "mips64el"
236SI_CFLAGS +=	-DLIBGCC2_UNITS_PER_WORD=4
237DI_CFLAGS +=	-DLIBGCC2_UNITS_PER_WORD=4
238
239TI_FUNCS =	${DWFLOATFUNCS:S/di/ti/}
240TI_CFILE =	libgcc2.c
241
242FPBIT_CFLAGS +=	-DTMODES
243DPBIT_CFLAGS +=	-DTMODES
244.endif
245
246.if ${TARGET_ARCH} == "mips64el"
247FPBIT_CFLAGS +=	-DFLOAT_BIT_ORDER_MISMATCH
248DPBIT_CFLAGS +=	-DFLOAT_BIT_ORDER_MISMATCH
249.endif
250
251FPBIT_CFILE =	config/fp-bit.c
252DPBIT_CFILE =	config/fp-bit.c
253
254OBJ_GRPS +=	FPBIT DPBIT
255.endif
256
257.if ${TARGET_ARCH} == "mips64" || ${TARGET_ARCH} == "mips64el"
258
259TPBIT_CFLAGS =	-DFINE_GRAINED_LIBRARIES -DTFLOAT
260
261.if ${TARGET_ARCH} == "mips64el"
262TPBIT_CFLAGS +=	-DFLOAT_BIT_ORDER_MISMATCH
263.endif
264
265TPBIT_CFILE =	config/fp-bit.c
266
267OBJ_GRPS +=	TPBIT
268.endif
269
270#-----------------------------------------------------------------------
271#
272# Generic build rules for object groups defined above
273#
274.for T in ${OBJ_GRPS}
275${T}_OBJS_T =	${${T}_FUNCS:S/$/.o/}
276${T}_OBJS_P =	${${T}_FUNCS:S/$/.po/}
277${T}_OBJS_S =	${${T}_FUNCS:S/$/.So/}
278OBJS +=		${${T}_FUNCS:S/$/.o/}
279
280${${T}_OBJS_T}: ${${T}_CFILE} ${COMMONHDRS}
281	${CC_T} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
282${${T}_OBJS_P}: ${${T}_CFILE} ${COMMONHDRS}
283	${CC_P} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
284${${T}_OBJS_S}: ${${T}_CFILE} ${COMMONHDRS}
285	${CC_S} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
286.endfor
287
288#-----------------------------------------------------------------------
289#
290# Special versions of the floating-point conversion routines.
291#
292.if !empty{TI_FUNCS}
293TI_OBJS_T =	${TI_FUNCS:S/$/.o/}
294OBJS +=		${TI_FUNCS:S/$/.o/}
295
296${TI_OBJS_T}: ${TI_CFILE} ${COMMONHDRS}
297	${CC_T} ${TI_CFLAGS} -DL${.PREFIX:S/ti/di/} -o ${.TARGET} ${.ALLSRC:M*.c}
298${TI_OBJS_P}: ${TI_CFILE} ${COMMONHDRS}
299	${CC_P} ${TI_CFLAGS} -DL${.PREFIX:S/ti/di/} -o ${.TARGET} ${.ALLSRC:M*.c}
300${TI_OBJS_T}: ${TI_CFILE} ${COMMONHDRS}
301	${CC_S} ${TI_CFLAGS} -DL${.PREFIX:S/ti/di/} -o ${.TARGET} ${.ALLSRC:M*.c}
302.endif
303
304#-----------------------------------------------------------------------
305#
306# Extra objects coming from separate files
307#
308.if !empty(LIB2ADD)
309OBJS  +=	${LIB2ADD:R:S/$/.o/}
310SOBJS +=	${LIB2ADD:R:S/$/.So/}
311POBJS +=	${LIB2ADD:R:S/$/.po/}
312.endif
313
314#-----------------------------------------------------------------------
315#
316# Objects that should be in static library only.
317#
318SYMS_ST =	${LIB2FUNCS_ST}	${LIB2ADD_ST}
319STAT_OBJS_T = 	${SYMS_ST:S/$/.o/}
320STAT_OBJS_P = 	${SYMS_ST:S/$/.po/}
321STATICOBJS  =	${SYMS_ST:S/$/.o/}
322
323${STAT_OBJS_T}:	${STD_CFILE} ${COMMONHDRS}
324	${CC_T} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
325${STAT_OBJS_P}:	${STD_CFILE} ${COMMONHDRS}
326	${CC_P} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
327
328#-----------------------------------------------------------------------
329#
330# Assembler files.
331#
332.if defined(LIB1ASMSRC)
333ASM_T =		${LIB1ASMFUNCS:S/$/.o/}
334ASM_P =		${LIB1ASMFUNCS:S/$/.po/}
335ASM_S =		${LIB1ASMFUNCS:S/$/.So/}
336ASM_V =		${LIB1ASMFUNCS:S/$/.vis/}
337OBJS +=		${LIB1ASMFUNCS:S/$/.o/}
338
339${ASM_T}: ${LIB1ASMSRC} ${.PREFIX}.vis
340	${CC} -x assembler-with-cpp -c ${CFLAGS} -DL${.PREFIX} \
341	    -o ${.TARGET} -include ${.PREFIX}.vis ${.ALLSRC:N*.h:N*.vis}
342${ASM_P}: ${LIB1ASMSRC} ${.PREFIX}.vis
343	${CC} -x assembler-with-cpp -p -c ${CFLAGS} -DL${.PREFIX} \
344	    -o ${.TARGET} -include ${.PREFIX}.vis ${.ALLSRC:N*.h:N*.vis}
345${ASM_S}: ${LIB1ASMSRC}
346	${CC} -x assembler-with-cpp -c ${PICFLAG} ${CFLAGS} -DL${.PREFIX} \
347	    -o ${.TARGET} ${.ALLSRC:N*.h}
348${ASM_V}: ${LIB1ASMSRC}
349	${CC} -x assembler-with-cpp -c ${CFLAGS} -DL${.PREFIX} \
350	    -o ${.PREFIX}.vo ${.ALLSRC:N*.h}
351	( nm -pg ${.PREFIX}.vo | \
352		awk 'NF == 3 && $$2 !~ /^[FUN]$$/ { print "\t.hidden ", $$3 }'\
353	) > ${.TARGET}
354
355CLEANFILES += ${ASM_V} ${ASM_V:R:S/$/.vo/}
356.endif
357
358#-----------------------------------------------------------------------
359#
360# Exception handling / unwinding support.
361#
362EH_OBJS_T = ${LIB2ADDEHSTATIC:R:S/$/.o/}
363EH_OBJS_P = ${LIB2ADDEHSTATIC:R:S/$/.po/}
364EH_OBJS_S = ${LIB2ADDEHSHARED:R:S/$/.So/}
365EH_CFLAGS = -fexceptions
366.if ${TARGET_ARCH} == "sh"
367EH_CFLAGS+= -fno-stack-protector	# necessary for unwind-dw2.c
368.endif
369SOBJS   += ${EH_OBJS_S}
370OBJS    += ${EH_OBJS_T}
371
372.for _src in ${LIB2ADDEHSTATIC}
373${_src:R:S/$/.o/}: ${_src} ${COMMONHDRS}
374	${CC_T} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
375${_src:R:S/$/.po/}: ${_src} ${COMMONHDRS}
376	${CC_P} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
377.endfor
378
379#-----------------------------------------------------------------------
380#
381# Generated headers
382#
383${COMMONHDRS}: ${.CURDIR}/../cc_tools/Makefile
384	${MAKE} -f ${.ALLSRC} MFILE=${.ALLSRC} GCCDIR=${GCCDIR} ${.TARGET}
385
386CLEANFILES += ${COMMONHDRS}
387CLEANFILES += cs-*.h option*
388
389beforeinstall:
390	${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m ${DIRMODE} \
391		${DESTDIR}${LIBDIR}
392
393.include <bsd.lib.mk>
394
395
396.SUFFIXES: .vis .vo .asm
397
398.if ${TARGET_ARCH} == "alpha" || ${TARGET_ARCH} == "powerpc"
399.asm.o:
400	${CC_T} ${CFLAGS} -xassembler-with-cpp -o ${.TARGET} ${.IMPSRC}
401.endif
402